// Adds a new keybinding equal to the character provided and the default super key (ctrl/cmd)
 private static void bind(int Character) {
   frame
       .getRootPane()
       .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
       .put(
           KeyStroke.getKeyStroke(Character, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
           "console");
 }
示例#2
0
 static synchronized void loadLibrary() {
   if (loaded) return;
   loaded = true;
   Toolkit.getDefaultToolkit();
   /*
    * Note that the jawt library is loaded explicitly
    * because it cannot be found by the library loader.
    * All exceptions are caught because the library may
    * have been loaded already.
    */
   try {
     System.loadLibrary("jawt");
   } catch (Throwable e) {
   }
   Library.loadLibrary("swt-awt");
 }
  public void start() {
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              public void eventDispatched(AWTEvent e) {
                System.out.println(e.toString());
              }
            },
            FocusEvent.FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_EVENT_MASK);

    frame = new Frame("Frame");
    frame.setName("Frame-owner");
    frame.setBounds(100, 0, 100, 100);
    dialog = new Dialog(frame, "Dialog");
    dialog.setName("Dialog-owner");
    dialog.setBounds(100, 0, 100, 100);

    window1 = new Window(frame);
    window1.setName("1st child");
    window1.setBounds(100, 300, 100, 100);
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(frame, window1);
    test2(frame, window1, window2);
    test3(frame, window1, window2);

    window1 = new Window(dialog);
    window1.setBounds(100, 300, 100, 100);
    window1.setName("1st child");
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(dialog, window1);
    test2(dialog, window1, window2);
    test3(dialog, window1, window2);

    System.out.println("Test passed.");
  }
示例#4
0
  private void dumpFlavorsOld(Transferable t) {
    DataFlavor[] dfa = t.getTransferDataFlavors();

    if (dfa != null) {
      if (dfa.length == 0) {
        JConfig.log().logVerboseDebug("Trying a second attack...");
        try {
          Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
          Transferable t2 = sysClip.getContents(null);
          StringBuffer stBuff;

          stBuff = getTransferData(t2);
          JConfig.log().logVerboseDebug("Check out: " + stBuff);
        } catch (Exception e) {
          JConfig.log().handleException("Caught: " + e, e);
        }
        JConfig.log().logVerboseDebug("Done trying a second attack...");
      }
    }
    dumpDataFlavors(dfa);
  }
示例#5
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);
 }
示例#6
0
  private Icon getStockIcon(SynthContext context, String key, int type) {
    TextDirection direction = TextDirection.LTR;

    if (context != null) {
      ComponentOrientation co = context.getComponent().getComponentOrientation();

      if (co != null && !co.isLeftToRight()) {
        direction = TextDirection.RTL;
      }
    }

    // First try loading a theme-specific icon using the native
    // GTK libraries (native GTK handles the resizing for us).
    Icon icon = getStyleSpecificIcon(key, direction, type);
    if (icon != null) {
      return icon;
    }

    // In a failure case where native GTK (unexpectedly) returns a
    // null icon, we can try loading a default icon as a fallback.
    String propName =
        ICON_PROPERTY_PREFIX
            + key
            + '.'
            + type
            + '.'
            + (direction == TextDirection.RTL ? "rtl" : "ltr");
    Image img = (Image) Toolkit.getDefaultToolkit().getDesktopProperty(propName);
    if (img != null) {
      return new ImageIcon(img);
    }

    // In an extreme failure situation, just return null (callers are
    // already prepared to handle a null icon, so the worst that can
    // happen is that an icon won't be included in the button/dialog).
    return null;
  }
示例#7
0
 private Icon getStyleSpecificIcon(String key, TextDirection direction, int type) {
   UNIXToolkit tk = (UNIXToolkit) Toolkit.getDefaultToolkit();
   Image img = tk.getStockIcon(widgetType, key, type, direction.ordinal(), null);
   return (img != null) ? new ImageIcon(img) : null;
 }
示例#8
0
 void deinstallModalityListener() {
   ((SunToolkit) Toolkit.getDefaultToolkit()).removeModalityListener(this);
 }
示例#9
0
 void installModalityListener() {
   ((SunToolkit) Toolkit.getDefaultToolkit()).addModalityListener(this);
 }
示例#10
0
  public void drop(DropTargetDropEvent dtde) {
    Transferable t = dtde.getTransferable();
    StringBuffer dropData = null;
    DataFlavor dtf;

    JConfig.log().logVerboseDebug("Dropping!");

    if (t.getTransferDataFlavors().length == 0) {
      Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t2 = sysClip.getContents(null);
      DataFlavor[] dfa2;
      int j;

      JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard.");
      dfa2 = null;

      if (t2 != null) {
        JConfig.log().logVerboseDebug("t2 is not null: " + t2);
        dfa2 = t2.getTransferDataFlavors();
        JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!");
      } else {
        JConfig.log().logVerboseDebug("t2 is null!");
      }

      if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) {
        if (dfa2 != null) {
          if (dfa2.length == 0) {
            JConfig.log().logVerboseDebug("Length is still zero!");
          }
          for (j = 0; j < dfa2.length; j++) {
            JConfig.log()
                .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName());
            JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType());
          }
        } else {
          JConfig.log().logVerboseDebug("Flavahs supported: none!\n");
        }
      }
    }

    if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
      dumpFlavorsOld(t);

    dtf = testAllFlavors(t);
    if (dtf != null) {
      JConfig.log().logVerboseDebug("Accepting!");
      acceptDrop(dtde);

      dropData = getTransferData(t);
      dtde.dropComplete(true);
      dtde.getDropTargetContext().dropComplete(true);
      if (dropData != null) {
        if (handler != null) {
          handler.receiveDropString(dropData);
        }
      }
    } else {
      JConfig.log().logVerboseDebug("Rejecting!");
      dtde.rejectDrop();
      handler.receiveDropString(dropData);
    }
  }
 public static void setClipboardText(String text) {
   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null);
 }
示例#12
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;
  }