Search in sources :

Example 11 with MenuBuilder

use of org.freeplane.core.ui.MenuBuilder in project freeplane by freeplane.

the class MenuUtils method executeMenuItems.

/**
 * to be used from scripts to execute menu items.
 * Find out the menuItemKey of a menu item with the devtools add-on. It contains a tool for that.
 */
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);
    }
}
Also used : IFreeplaneAction(org.freeplane.core.ui.IFreeplaneAction) Action(javax.swing.Action) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 12 with MenuBuilder

use of org.freeplane.core.ui.MenuBuilder in project freeplane by freeplane.

the class MenuUtils method getMenuBuilder.

private static MenuBuilder getMenuBuilder() {
    final ModeController modeController = Controller.getCurrentModeController();
    final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    return menuBuilder;
}
Also used : ModeController(org.freeplane.features.mode.ModeController) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 13 with MenuBuilder

use of org.freeplane.core.ui.MenuBuilder in project freeplane by freeplane.

the class Compat method macMenuChanges.

public static void macMenuChanges() {
    if (!Compat.isMacOsX()) {
        return;
    }
    final Controller controller = Controller.getCurrentController();
    final Set<String> modes = controller.getModes();
    for (final String mode : modes) {
        final MenuBuilder builder = controller.getModeController(mode).getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
        final String[] keys = { "MB_ToggleMenubarAction", "MP_ToggleMenubarAction", "MB_QuitAction", "MB_PropertyAction", "MB_AboutAction" };
        for (final String key : keys) {
            if (builder.contains(key)) {
                builder.removeElement(key);
            }
        }
    }
}
Also used : Controller(org.freeplane.features.mode.Controller) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 14 with MenuBuilder

use of org.freeplane.core.ui.MenuBuilder 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 15 with MenuBuilder

use of org.freeplane.core.ui.MenuBuilder in project freeplane by freeplane.

the class LinkController method loadURL.

public void loadURL(final NodeModel selectedNode, final ActionEvent e, final URI link) {
    if (link != null) {
        onDeselect(selectedNode);
        ModeController modeController = Controller.getCurrentModeController();
        if (LinkController.isMenuItemLink(link)) {
            if (e == null) {
                throw new IllegalArgumentException("ActionEvent is needed for menu item links");
            }
            final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
            final DefaultMutableTreeNode treeNode = menuBuilder.get(LinkController.parseMenuItemLink(link));
            if (treeNode == null || !treeNode.isLeaf() || !(treeNode.getUserObject() instanceof JMenuItem)) {
                LogUtils.warn("node " + link + " should have been an executable action");
                return;
            }
            final JMenuItem menuItem = (JMenuItem) treeNode.getUserObject();
            final Action action = menuItem.getAction();
            if (action != null) {
                action.actionPerformed(e);
            } else {
                LogUtils.warn("Trying to call a menu hyperlink action that doesn't exist.");
            }
        } else {
            loadURI(link);
        }
        onSelect(modeController.getController().getSelection().getSelected());
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ModeController(org.freeplane.features.mode.ModeController) JMenuItem(javax.swing.JMenuItem) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Aggregations

MenuBuilder (org.freeplane.core.ui.MenuBuilder)15 ModeController (org.freeplane.features.mode.ModeController)10 Controller (org.freeplane.features.mode.Controller)5 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 ResourceController (org.freeplane.core.resources.ResourceController)4 JMenuItem (javax.swing.JMenuItem)3 IMenuContributor (org.freeplane.core.ui.IMenuContributor)3 Action (javax.swing.Action)2 IFreeplaneAction (org.freeplane.core.ui.IFreeplaneAction)2 IUserInputListenerFactory (org.freeplane.core.ui.IUserInputListenerFactory)2 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 DropTarget (java.awt.dnd.DropTarget)1 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 IOException (java.io.IOException)1