Esempio n. 1
0
 static JComponent createMenuComponent(JComponent menu, ActionMap actionMap, List actions) {
   MenuAdapter menuAdapter = new MenuAdapter(menu);
   for (Object menuElement : actions) {
     if (MenuFactory.SEPARATOR.equals(menuElement)) {
       menuAdapter.addSeparator();
     } else if (menuElement instanceof Object[]) {
       Object[] items = (Object[]) menuElement;
       if (items.length > 1) {
         JMenu subMenu = new JMenu(items[0].toString());
         List<Object> keys = Arrays.asList(items).subList(1, items.length);
         createMenuComponent(subMenu, actionMap, keys);
         if (subMenu.getMenuComponents().length > 0) {
           menuAdapter.addSubMenu(subMenu);
         }
       }
     } else if (menuElement instanceof List) {
       List items = (List) menuElement;
       if (items.size() > 1) {
         JMenu subMenu = new JMenu(items.get(0).toString());
         List<List> keys = Arrays.asList(items).subList(1, items.size());
         createMenuComponent(subMenu, actionMap, keys);
         if (subMenu.getMenuComponents().length > 0) {
           menuAdapter.addSubMenu(subMenu);
         }
       }
     } else {
       Action action = actionMap.get(menuElement);
       if (action != null) {
         menuAdapter.add(action);
       }
     }
   }
   return trim(menuAdapter);
 }
Esempio n. 2
0
 public static void addFastKeys(JMenuBar menuBar) {
   for (Component menuComponent : menuBar.getComponents()) { // iterate over menus
     JMenu menu = (JMenu) menuComponent;
     menu.setMnemonic(menu.getText().charAt(menu.getText().indexOf('&') + 1));
     menu.setText(menu.getText().replace("&", ""));
     for (Component menuItemComponent : menu.getMenuComponents())
       if (menuItemComponent instanceof JMenuItem) { // skip separators
         JMenuItem menuItem = (JMenuItem) menuItemComponent;
         menuItem.setMnemonic(menuItem.getText().charAt(menuItem.getText().indexOf('&') + 1));
         menuItem.setText(menuItem.getText().replace("&", ""));
       }
     /*
     for (int count = 0; count < menu.getMenuComponentCount(); count++) {  //iterate over menu items
        Component menuItemComponent = menu.getMenuComponent(count);
        if (menuItemComponent instanceof JMenuItem) {   //skip separators
           JMenuItem menuItem = (JMenuItem)menuItemComponent;
           menuItem.setMnemonic(menuItem.getText().charAt(
                 menuItem.getText().indexOf('&') + 1));
           menuItem.setText(menuItem.getText().replace("&", ""));
           }
        }
     */
   }
 }