/** Refresh system menu */
  public void updateSystemMenu() {
    if ((systemMenuBar != null) && (systemMenuBar.getMenuCount() > 0)) {
      final JMenu menu;

      if (systemMenuCallback != null) menu = systemMenuCallback.getMenu();
      else menu = getDefaultSystemMenu();

      // ensure compatibility with heavyweight component
      menu.getPopupMenu().setLightWeightPopupEnabled(false);

      // rebuild menu
      systemMenuBar.removeAll();
      systemMenuBar.add(menu);
      systemMenuBar.validate();
    }
  }
예제 #2
0
 public boolean isValid(final KeyStroke keystroke, final Character keyChar) {
   if (keystroke == null) {
     return true;
   }
   final Node menuBarNode = menuBuilder.getMenuBar(menuBuilder.get(key));
   if (menuBarNode == null) {
     return true;
   }
   if (keyChar != KeyEvent.CHAR_UNDEFINED
       && (keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK))
           == 0) {
     final String keyTypeActionString =
         ResourceController.getResourceController()
             .getProperty("key_type_action", FirstAction.EDIT_CURRENT.toString());
     FirstAction keyTypeAction = FirstAction.valueOf(keyTypeActionString);
     return FirstAction.IGNORE.equals(keyTypeAction);
   }
   if ((keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK))
       == Event.ALT_MASK) {
     final JMenuBar menuBar = (JMenuBar) menuBarNode.getUserObject();
     final int menuCount = menuBar.getMenuCount();
     for (int i = 0; i < menuCount; i++) {
       final JMenu menu = menuBar.getMenu(i);
       final char c = (char) menu.getMnemonic();
       if (Character.toLowerCase(keystroke.getKeyCode()) == Character.toLowerCase(c)) {
         JOptionPane.showMessageDialog(
             parentComponent,
             menu.getText(),
             TextUtils.getText("used_in_menu"),
             JOptionPane.WARNING_MESSAGE);
         return false;
       }
     }
   }
   if (!checkForOverwriteShortcut(menuBarNode, keystroke)) {
     return false;
   }
   final KeyStroke derivedKS = FreeplaneMenuBar.derive(keystroke, keyChar);
   if (derivedKS == keystroke) {
     return true;
   }
   return checkForOverwriteShortcut(menuBarNode, derivedKS);
 }
예제 #3
0
  private void hookMenu(View view, ExtensionHook hook) {

    if (view == null) {
      return;
    }

    if (hook.getHookMenu() == null) {
      return;
    }

    ExtensionHookMenu hookMenu = hook.getHookMenu();

    // init menus
    List<JMenuItem> list = null;
    JMenuItem item = null;
    JMenu menu = null;
    JMenu menuFile = view.getMainFrame().getMainMenuBar().getMenuFile();
    JMenu menuEdit = view.getMainFrame().getMainMenuBar().getMenuEdit();
    JMenu menuView = view.getMainFrame().getMainMenuBar().getMenuView();
    JMenu menuAnalyse = view.getMainFrame().getMainMenuBar().getMenuAnalyse();
    JMenu menuTools = view.getMainFrame().getMainMenuBar().getMenuTools();
    JMenu menuHelp = view.getMainFrame().getMainMenuBar().getMenuHelp();
    JMenu menuReport = view.getMainFrame().getMainMenuBar().getMenuReport();

    // process new menus

    JMenuBar bar = view.getMainFrame().getMainMenuBar();
    list = hookMenu.getNewMenus();
    for (int i = 0; i < list.size(); i++) {
      menu = (JMenu) list.get(i);
      bar.add(menu, bar.getMenuCount() - 2); // 2 menus at the back (Tools/Help)
    }

    // process menu - File
    list = hookMenu.getFile();
    int existingCount = 2;

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuFile.addSeparator();
        continue;
      }

      menuFile.add(item, menuFile.getItemCount() - existingCount);
    }

    // process menu - Tools
    list = hookMenu.getTools();
    existingCount = 2;

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuTools.addSeparator();
        continue;
      }

      menuTools.add(item, menuTools.getItemCount() - existingCount);
    }

    // process Edit menu
    list = hookMenu.getEdit();

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuEdit.addSeparator();
        continue;
      }
      menuEdit.add(item, menuEdit.getItemCount());
    }

    // process View menu
    list = hookMenu.getView();

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuView.addSeparator();
        continue;
      }

      menuView.add(item, menuView.getItemCount());
    }

    // process Analyse menu
    list = hookMenu.getAnalyse();

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuAnalyse.addSeparator();
        continue;
      }

      menuAnalyse.add(item, menuAnalyse.getItemCount());
    }

    // process popup menus

    list = hookMenu.getPopupMenus();

    for (int i = 0; i < list.size(); i++) {
      item = (ExtensionPopupMenu) list.get(i);
      if (item == null) continue;

      view.getPopupList().add(item);
    }

    // ZAP: process Help menu
    list = hookMenu.getHelpMenus();

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuHelp.addSeparator();
        continue;
      }

      menuHelp.add(item, menuHelp.getItemCount());
    }
    // ZAP: process Report menu
    list = hookMenu.getReportMenus();

    for (int i = 0; i < list.size(); i++) {
      item = (JMenuItem) list.get(i);
      if (item == null) continue;
      if (item == ExtensionHookMenu.MENU_SEPARATOR) {
        menuReport.addSeparator();
        continue;
      }

      menuReport.add(item, menuReport.getItemCount());
    }
  }