Search in sources :

Example 1 with MenuEntry

use of org.freeplane.core.util.MenuUtils.MenuEntry in project freeplane by freeplane.

the class HotKeyInfoAction method appendChildrenAsHtml.

@SuppressWarnings("unchecked")
private void appendChildrenAsHtml(final StringBuilder builder, final Enumeration<DefaultMutableTreeNode> children, final String title, final int level) {
    final ArrayList<MenuEntry> menuEntries = new ArrayList<MenuEntry>();
    final ArrayList<DefaultMutableTreeNode> submenus = new ArrayList<DefaultMutableTreeNode>();
    // sort and divide
    while (children.hasMoreElements()) {
        final DefaultMutableTreeNode node = children.nextElement();
        if (node.isLeaf()) {
            menuEntries.add((MenuEntry) node.getUserObject());
        } else {
            submenus.add(node);
        }
    }
    // actions
    if (!menuEntries.isEmpty()) {
        builder.append("<table cellspacing=\"0\" cellpadding=\"0\">");
        for (final MenuEntry entry : menuEntries) {
            final String keystroke = // 
            entry.getKeyStroke() == null ? // 
            "" : MenuUtils.formatKeyStroke(entry.getKeyStroke());
            builder.append(el("tr", el("td", entry.getLabel() + "&#xa0;") + el("td", keystroke) + el("td", entry.getToolTipText())));
        }
        builder.append("</table>");
    }
    // submenus
    for (final DefaultMutableTreeNode node : submenus) {
        final String subtitle = (level > 2 ? title + "&#8594;" : "") + String.valueOf(node.getUserObject());
        appendAsHtml(builder, node.children(), subtitle, level + 1);
    }
}
Also used : MenuEntry(org.freeplane.core.util.MenuUtils.MenuEntry) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList)

Example 2 with MenuEntry

use of org.freeplane.core.util.MenuUtils.MenuEntry in project freeplane by freeplane.

the class HotKeyInfoAction method appendChildrenAsHtml.

@SuppressWarnings("unchecked")
private void appendChildrenAsHtml(final StringBuilder builder, final Enumeration<TreeNode> children, final String title, final int level) {
    final ArrayList<MenuEntry> menuEntries = new ArrayList<MenuEntry>();
    final ArrayList<DefaultMutableTreeNode> submenus = new ArrayList<DefaultMutableTreeNode>();
    // sort and divide
    while (children.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
        if (node.isLeaf()) {
            menuEntries.add((MenuEntry) node.getUserObject());
        } else {
            submenus.add(node);
        }
    }
    // actions
    if (!menuEntries.isEmpty()) {
        builder.append("<table cellspacing=\"0\" cellpadding=\"0\">");
        for (final MenuEntry entry : menuEntries) {
            final String keystroke = // 
            entry.getKeyStroke() == null ? // 
            "" : MenuUtils.formatKeyStroke(entry.getKeyStroke());
            builder.append(el("tr", el("td", entry.getLabel() + "&#xa0;") + el("td", keystroke) + el("td", entry.getToolTipText())));
        }
        builder.append("</table>");
    }
    // submenus
    for (final DefaultMutableTreeNode node : submenus) {
        final String subtitle = (level > 2 ? title + "&#8594;" : "") + String.valueOf(node.getUserObject());
        appendAsHtml(builder, node.children(), subtitle, level + 1);
    }
}
Also used : MenuEntry(org.freeplane.core.util.MenuUtils.MenuEntry) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList)

Example 3 with MenuEntry

use of org.freeplane.core.util.MenuUtils.MenuEntry in project freeplane by freeplane.

the class SelectMenuItemDialog method createTree.

private JTree createTree() {
    final MModeController modeController = (MModeController) Controller.getCurrentModeController();
    final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    final DefaultMutableTreeNode treeRoot = MenuUtils.createMenuEntryTree(SELECTION_ROOT_KEY, menuBuilder);
    if (treeRoot.getUserObject() == null)
        treeRoot.setUserObject(new MenuEntry(null, TextUtils.getText("select_menu_item_root_node")));
    JTree jTree = new JTree(treeRoot);
    jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    // replace the standard icons
    jTree.setCellRenderer(new MenuIconRenderer());
    jTree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(final TreeSelectionEvent e) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            btnOK.setEnabled(node != null && node.isLeaf());
        }
    });
    jTree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                if (btnOK.isEnabled())
                    btnOK.doClick();
            }
        }
    });
    return jTree;
}
Also used : JTree(javax.swing.JTree) MenuEntry(org.freeplane.core.util.MenuUtils.MenuEntry) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) MenuBuilder(org.freeplane.core.ui.MenuBuilder) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 4 with MenuEntry

use of org.freeplane.core.util.MenuUtils.MenuEntry in project freeplane by freeplane.

the class AddMenuItemLinkAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final NodeModel selectedNode = Controller.getCurrentModeController().getMapController().getSelectedNode();
    final SelectMenuItemDialog dialog = new SelectMenuItemDialog(selectedNode);
    final MenuEntry menuItem = dialog.getMenuItem();
    if (menuItem != null) {
        ((MLinkController) LinkController.getController()).setLink(selectedNode, LinkController.createMenuItemLink(menuItem.getKey()), LinkController.LINK_ABSOLUTE);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MenuEntry(org.freeplane.core.util.MenuUtils.MenuEntry)

Aggregations

MenuEntry (org.freeplane.core.util.MenuUtils.MenuEntry)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 ArrayList (java.util.ArrayList)2 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 JTree (javax.swing.JTree)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 MenuBuilder (org.freeplane.core.ui.MenuBuilder)1 NodeModel (org.freeplane.features.map.NodeModel)1 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)1