Example #1
0
 /** Flip the state of tooltips to that described by the global isToolTipTextShown. */
 public static void handleToolTipShownStateChange() {
   ToolTipManager.sharedInstance().setEnabled(SettingsHandler.isToolTipTextShown());
 }
Example #2
0
  /**
   * Create a new menu item with all the contaminant expectations fulfilled.
   *
   * @param label String what to display?
   * @param listener ActionListener what to do as code, <code>null</code> for none
   * @param command String menu command, <code>null</code> for none
   * @param mnemonic char menu shortcut key, <code>0</code> for none
   * @param accelerator String keyboard shortcut key, <code>0</code> for none
   * @param description String tooltip
   * @param iconName String icon name
   * @param enable boolean item enabled?
   * @return JMenuItem the new menu item
   */
  public static JMenuItem createMenuItem(
      final String label,
      final ActionListener listener,
      final String command,
      final char mnemonic,
      final String accelerator,
      final String description,
      final String iconName,
      final boolean enable) {
    final JMenuItem item = new JMenuItem(label);

    if (listener != null) {
      item.addActionListener(listener);
    }

    if (command != null) {
      item.setActionCommand(command);
    }

    if (mnemonic != '\0') {
      item.setMnemonic(mnemonic);
    }

    if (accelerator != null) {
      // accelerator has three possible forms:
      // 1) shortcut +
      // 2) shortcut-alt +
      // 3) F1
      // (error checking is for the weak!)
      int iShortCut = Event.CTRL_MASK;
      StringTokenizer aTok = new StringTokenizer(accelerator);

      // get the first argument
      String aString = aTok.nextToken();

      if (aString.equalsIgnoreCase("shortcut")) {
        iShortCut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
      } else if (aString.equalsIgnoreCase("alt")) {
        if (System.getProperty("mrj.version") != null) {
          iShortCut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | Event.ALT_MASK;
        } else {
          iShortCut = Event.ALT_MASK;
        }
      } else if (aString.equalsIgnoreCase("shift-shortcut")) {
        iShortCut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | Event.SHIFT_MASK;
      }

      if (aTok.hasMoreTokens()) {
        // get the second argument
        aString = aTok.nextToken();
      }

      KeyStroke aKey = KeyStroke.getKeyStroke(aString);

      if (aKey != null) {
        int iKeyCode = aKey.getKeyCode();
        item.setAccelerator(KeyStroke.getKeyStroke(iKeyCode, iShortCut));
      }
    }

    if (SettingsHandler.isToolTipTextShown()) {
      setDescription(item, description);
    }

    IconUtilitities.maybeSetIcon(item, iconName);
    item.setEnabled(enable);

    return item;
  }