示例#1
0
 private void loadAction(DefaultMutableTreeNode node, MenuElement menu) {
   Object userObject = null;
   MenuElement menuElement = menu;
   if (menu.getSubElements().length > 0 && menu.getSubElements()[0] instanceof JPopupMenu) {
     menuElement = menu.getSubElements()[0];
   }
   for (MenuElement item : menuElement.getSubElements()) {
     if (item instanceof JMenuItem) {
       JMenuItem menuItem = ((JMenuItem) item);
       if (menuItem.getAction() != null) {
         Action action = menuItem.getAction();
         userObject = action;
         Object tb = action.getValue("toolbar");
         if (tb == null) {
           System.out.println(tr("Toolbar action without name: {0}", action.getClass().getName()));
           continue;
         } else if (!(tb instanceof String)) {
           if (!(tb instanceof Boolean) || (Boolean) tb) {
             System.out.println(tr("Strange toolbar value: {0}", action.getClass().getName()));
           }
           continue;
         } else {
           String toolbar = (String) tb;
           Action r = actions.get(toolbar);
           if (r != null && r != action && !toolbar.startsWith("imagery_")) {
             System.out.println(
                 tr(
                     "Toolbar action {0} overwritten: {1} gets {2}",
                     toolbar, r.getClass().getName(), action.getClass().getName()));
           }
           actions.put(toolbar, action);
         }
       } else {
         userObject = menuItem.getText();
       }
     }
     DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObject);
     node.add(newNode);
     loadAction(newNode, item);
   }
 }