Ejemplo n.º 1
0
 public static void openFrame(Object frame) {
   boolean packFrame = false;
   if (packFrame) {
     ((JFrame) frame).pack();
   } else {
     ((JFrame) frame).validate();
   }
   // Center the window
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension frameSize = ((JFrame) frame).getSize();
   if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
   if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
   ((JFrame) frame)
       .setLocation(
           (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
   ((JFrame) frame).setVisible(true);
 }
Ejemplo n.º 2
0
  public static Image getImage(JopSession session, String image) {
    String fullName;
    if (session.getRoot() instanceof JopApplet) {
      String name;
      try {
        URL current = ((JApplet) session.getRoot()).getCodeBase();
        String current_str = current.toString();
        int idx1 = current_str.lastIndexOf('/');
        int idx2 = current_str.lastIndexOf(':');
        int idx = idx1;
        if (idx2 > idx) idx = idx2;
        String path = current_str.substring(0, idx + 1);
        String url_str;

        //        String url_str = new String( path + name);
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("jar:" + path + "pwr_" + name + ".jar!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("jar:" + path + "pwrp_" + systemName + "_web.jar!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
      return null;
    } else {
      // Add default directory /pwrp/img
      System.out.println("Image: " + image);

      //      int idx = image.lastIndexOf('/');
      //      if ( idx == -1)
      //  fullName = new String("/pwrp/img/" + image);
      // else
      fullName = new String(image);
      //      return Toolkit.getDefaultToolkit().getImage( fullName);

      try {
        String name;
        String url_str;
        int idx;
        String path = new String("file://");
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("$pwr_lib/pwr_" + name + ".jar");
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("$pwrp_lib/pwrp_" + systemName + ".jar");
          System.out.println("java: " + url_str);
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
    }
    return null;
  }