Search in sources :

Example 1 with Node

use of org.freeplane.core.ui.IndexedTree.Node in project freeplane by freeplane.

the class MenuUtils method menuNode2menuEntryNode.

// in: node for JMenu, out: node for MenuEntry
private static DefaultMutableTreeNode menuNode2menuEntryNode(final DefaultMutableTreeNode menuNode, final HashMap<String, KeyStroke> menuKeyToKeyStrokeMap) {
    final IndexedTree.Node node = (Node) menuNode;
    final Object userObject = menuNode.getUserObject();
    if (userObject instanceof JMenuItem) {
        final JMenuItem jMenuItem = (JMenuItem) userObject;
        final IFreeplaneAction action = (IFreeplaneAction) jMenuItem.getAction();
        final String key = String.valueOf(node.getKey());
        final String iconKey = action == null ? null : action.getIconKey();
        return new DefaultMutableTreeNode(new MenuEntry(key, jMenuItem.getText(), iconKey, menuKeyToKeyStrokeMap.get(key), jMenuItem.getToolTipText()));
    }
    // - just omit them
    return null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Node(org.freeplane.core.ui.IndexedTree.Node) IFreeplaneAction(org.freeplane.core.ui.IFreeplaneAction) Node(org.freeplane.core.ui.IndexedTree.Node) IndexedTree(org.freeplane.core.ui.IndexedTree) JMenuItem(javax.swing.JMenuItem)

Example 2 with Node

use of org.freeplane.core.ui.IndexedTree.Node in project freeplane by freeplane.

the class MenuUtils method findAssignedMenuItemNodeRecursively.

/**
 * there are little reasons to use this in scripts.
 */
public static Node findAssignedMenuItemNodeRecursively(final DefaultMutableTreeNode menubarNode, final KeyStroke keystroke) {
    final Enumeration<?> children = menubarNode.children();
    while (children.hasMoreElements()) {
        final Node child = (Node) children.nextElement();
        final Object childUserObject = child.getUserObject();
        if (childUserObject instanceof JMenuItem) {
            final JMenuItem childMenuItem = (JMenuItem) childUserObject;
            if (keystroke.equals(childMenuItem.getAccelerator())) {
                return child;
            }
        }
        // recurse
        final Node assignedMenuItemNode = findAssignedMenuItemNodeRecursively(child, keystroke);
        if (assignedMenuItemNode != null)
            return assignedMenuItemNode;
    }
    return null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Node(org.freeplane.core.ui.IndexedTree.Node) JMenuItem(javax.swing.JMenuItem)

Aggregations

JMenuItem (javax.swing.JMenuItem)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Node (org.freeplane.core.ui.IndexedTree.Node)2 IFreeplaneAction (org.freeplane.core.ui.IFreeplaneAction)1 IndexedTree (org.freeplane.core.ui.IndexedTree)1