public static DefaultMutableTreeNode createAcceleratebleMenuEntryTree( final String menuRootKey, final MenuBuilder menuBuilder) { final DefaultMutableTreeNode menuEntryTreeNode = MenuUtils.createMenuEntryTree(menuRootKey, menuBuilder); final DefaultMutableTreeNode result = new DefaultMutableTreeNode(menuEntryTreeNode.getUserObject()); MenuUtils.addAcceleratableChildrenRecursively(result, menuEntryTreeNode.children()); return result; }
@SuppressWarnings("rawtypes") public static void insertAsNodeModelRecursively( final NodeModel nodeModel, final Enumeration children, final MapController mapController) { while (children.hasMoreElements()) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); final NodeModel newNodeModel = MenuUtils.insertAsNodeModel(nodeModel, child, mapController); if (!child.isLeaf()) { MenuUtils.insertAsNodeModelRecursively(newNodeModel, child.children(), mapController); } } }
/** * 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; }
@SuppressWarnings("rawtypes") private static void addChildrenRecursively( final DefaultMutableTreeNode treeNode, final Enumeration menuChildren, final HashMap<String, KeyStroke> menuKeyToKeyStrokeMap) { while (menuChildren.hasMoreElements()) { final DefaultMutableTreeNode childMenu = (DefaultMutableTreeNode) menuChildren.nextElement(); final DefaultMutableTreeNode treeChild = MenuUtils.menuNode2menuEntryNode(childMenu, menuKeyToKeyStrokeMap); if (treeChild != null) { treeNode.add(treeChild); MenuUtils.addChildrenRecursively(treeChild, childMenu.children(), menuKeyToKeyStrokeMap); } else { MenuUtils.addChildrenRecursively(treeNode, childMenu.children(), menuKeyToKeyStrokeMap); } } }
private boolean checkForOverwriteShortcut( final DefaultMutableTreeNode menubarNode, final KeyStroke keystroke) { final Node priorAssigned = MenuUtils.findAssignedMenuItemNodeRecursively(menubarNode, keystroke); if (priorAssigned == null || editedItem.equals(priorAssigned.getUserObject())) { return true; } return replaceOrCancel(priorAssigned, ((JMenuItem) priorAssigned.getUserObject()).getText()); }
private String formatShortcut(final Script script) { final String menuItemKey = ExecuteScriptAction.makeMenuItemKey(script.menuTitleKey, script.executionMode); final String shortcutKey = MenuUtils.makeAcceleratorKey(menuItemKey); final String oldShortcut = ResourceController.getResourceController().getProperty(shortcutKey); final KeyStroke keyStroke = UITools.getKeyStroke(oldShortcut != null ? oldShortcut : script.keyboardShortcut); return UITools.keyStrokeToString(keyStroke); }
private static NodeModel insertAsNodeModel( final NodeModel nodeModel, final DefaultMutableTreeNode treeNode, final MapController mapController) { final MenuEntry menuEntry = (MenuEntry) treeNode.getUserObject(); final String text = menuEntry.getKeyStroke() == null ? menuEntry.getLabel() : menuEntry.getLabel() + ": " + MenuUtils.formatKeyStroke(menuEntry.getKeyStroke()); final NodeModel newNodeModel = mapController.newNode(text, nodeModel.getMap()); if (!treeNode.isLeaf()) { newNodeModel.setFolded(true); } if (menuEntry.getIconKey() != null) { final MindIcon mindIcon = menuEntry.createMindIcon(); if (mindIcon != null) newNodeModel.addIcon(mindIcon); } nodeModel.insert(newNodeModel); return newNodeModel; }
// filters out non-acceleratable menu entries @SuppressWarnings("rawtypes") private static void addAcceleratableChildrenRecursively( final DefaultMutableTreeNode target, final Enumeration sourceChildren) { while (sourceChildren.hasMoreElements()) { final DefaultMutableTreeNode sourceChild = (DefaultMutableTreeNode) sourceChildren.nextElement(); final MenuEntry menuEntry = (MenuEntry) sourceChild.getUserObject(); if (sourceChild.isLeaf()) { if (menuEntry.getKeyStroke() != null) { target.add(new DefaultMutableTreeNode(menuEntry)); } } else { final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(menuEntry); target.add(newNode); MenuUtils.addAcceleratableChildrenRecursively(newNode, sourceChild.children()); if (newNode.isLeaf()) { target.remove(newNode); } } } }