Exemplo n.º 1
0
 private void addSubMenu(
     final MenuBuilder menuBuilder,
     final String parentLocation,
     final String location,
     String menuTitle) {
   if (menuBuilder.get(location) == null) {
     final JMenu menuItem = new JMenu();
     MenuBuilder.setLabelAndMnemonic(menuItem, menuTitle);
     menuBuilder.addMenuItem(parentLocation, menuItem, location, MenuBuilder.AS_CHILD);
   }
 }
Exemplo n.º 2
0
 /**
  * returns a tree of all <code>JMenuItem</code> nodes the menu contains (omitting Strings and
  * Separators). The tree is build from <code>DefaultMutableTreeNode</code> nodes having <code>
  * MenuEntry</code> objects as their userObjects.
  *
  * <p>Note that the root node may have null as userObject if the menu item at <code>menuRootKey
  * </code> doesn't contain a <code>JMenuItem</code>!
  *
  * @param menuRootKey the key of the node that should form the root of the output.
  * @param menuBuilder access point for the menu(s).
  */
 public static DefaultMutableTreeNode createMenuEntryTree(
     final String menuRootKey, final MenuBuilder menuBuilder) {
   final HashMap<String, KeyStroke> menuKeyToKeyStrokeMap =
       MenuUtils.invertAcceleratorMap(menuBuilder.getAcceleratorMap());
   final DefaultMutableTreeNode menuRoot = menuBuilder.get(menuRootKey);
   final DefaultMutableTreeNode treeRoot =
       new DefaultMutableTreeNode(
           MenuUtils.menuNode2menuEntryNode(menuRoot, menuKeyToKeyStrokeMap));
   MenuUtils.addChildrenRecursively(treeRoot, menuRoot.children(), menuKeyToKeyStrokeMap);
   return treeRoot;
 }
Exemplo n.º 3
0
 public static void executeMenuItems(final List<String> menuItemKeys) {
   LogUtils.info("menu items to execute: " + menuItemKeys);
   final MenuBuilder menuBuilder = getMenuBuilder();
   for (String menuItemKey : menuItemKeys) {
     final DefaultMutableTreeNode treeNode = menuBuilder.get(menuItemKey);
     if (treeNode == null
         || !treeNode.isLeaf()
         || !(treeNode.getUserObject() instanceof JMenuItem)) {
       UITools.errorMessage(TextUtils.format("MenuUtils.invalid_menuitem", menuItemKey));
       return;
     }
     final JMenuItem menuItem = (JMenuItem) treeNode.getUserObject();
     final Action action = menuItem.getAction();
     LogUtils.info("executing " + menuItem.getText() + "(" + menuItemKey + ")");
     ActionEvent e = new ActionEvent(menuItem, 0, null);
     action.actionPerformed(e);
   }
 }
Exemplo n.º 4
0
 public static List<String> getMenuPathElements(MenuBuilder menuBuilder, final String location) {
   final ArrayList<String> pathElements = new ArrayList<String>();
   final DefaultMutableTreeNode node = menuBuilder.get(location);
   if (node != null) {
     pathElements.addAll(getMenuPathElements(node));
   } else {
     int index = location.lastIndexOf('/');
     if (index != -1) {
       final String lastKey = location.substring(index + 1);
       pathElements.add(
           TextUtils.getText(lastKey, TextUtils.getText("addons." + lastKey, lastKey)));
       // recurse
       if (index > 1)
         pathElements.addAll(getMenuPathElements(menuBuilder, location.substring(0, index)));
     }
   }
   return pathElements;
 }