Search in sources :

Example 6 with MenuBuilder

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

the class AddOnDetailsPanel method formatMenuLocation.

private String formatMenuLocation(ScriptAddOnProperties.Script script) {
    final String location = script.menuLocation == null ? "main_menu_scripting" : script.menuLocation;
    MenuBuilder menuBuilder = Controller.getCurrentModeController().getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    // "/menu_bar/edit/menu_extensions" -> [Node Extensions, Edit]
    final List<String> pathElements = getMenuPathElements(menuBuilder, location);
    Collections.reverse(pathElements);
    pathElements.add(TextUtils.getText(script.menuTitleKey));
    // TODO - impl. ribbons contribution
    return StringUtils.join(pathElements.iterator(), "->");
}
Also used : MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 7 with MenuBuilder

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

the class FilterController method setFilterConditions.

void setFilterConditions(final DefaultComboBoxModel newConditionModel) {
    filterConditions.removeListDataListener(filterChangeListener);
    filterConditions.removeAllElements();
    for (int i = 0; i < newConditionModel.getSize(); i++) {
        filterConditions.addElement(newConditionModel.getElementAt(i));
    }
    filterConditions.setSelectedItem(newConditionModel.getSelectedItem());
    addStandardConditions();
    filterConditions.addListDataListener(filterChangeListener);
    applyFilter(false);
    Controller controller = Controller.getCurrentController();
    final ModeController modeController = controller.getModeController();
    final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    filterMenuBuilder.updateMenus(modeController, menuBuilder);
// TODO RIBBONS: apply to ribbons as well, if necessary
}
Also used : ModeController(org.freeplane.features.mode.ModeController) Controller(org.freeplane.features.mode.Controller) ResourceController(org.freeplane.core.resources.ResourceController) FrameController(org.freeplane.features.ui.FrameController) ModeController(org.freeplane.features.mode.ModeController) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 8 with MenuBuilder

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

the class MLogicalStyleController method initM.

public void initM() {
    final ModeController modeController = Controller.getCurrentModeController();
    modeController.getMapController().addNodeChangeListener(new StyleRemover());
    modeController.registerExtensionCopier(new ExtensionCopier());
    modeController.addAction(new RedefineStyleAction());
    modeController.addAction(new NewUserStyleAction());
    modeController.addAction(new ManageMapConditionalStylesAction());
    modeController.addAction(new ManageNodeConditionalStylesAction());
    modeController.addAction(new CopyStyleExtensionsAction());
    if (modeController.getModeName().equals("MindMap")) {
        modeController.addAction(new MapBackgroundColorAction());
        modeController.addAction(new MapBackgroundImageAction());
        modeController.addAction(new MapBackgroundClearAction());
        modeController.addAction(new SetBooleanMapPropertyAction(MapStyle.FIT_TO_VIEWPORT));
        modeController.addAction(new CopyMapStylesAction());
    }
    if (!modeController.getController().getViewController().isHeadless()) {
        final IUserInputListenerFactory userInputListenerFactory = modeController.getUserInputListenerFactory();
        final MenuBuilder menuBuilder = userInputListenerFactory.getMenuBuilder(MenuBuilder.class);
        // TODO RIBBONS - apply to ribbons as well
        Controller.getCurrentController().getMapViewManager().addMapSelectionListener(new IMapSelectionListener() {

            public void beforeMapChange(final MapModel oldMap, final MapModel newMap) {
                removeStyleMenu(menuBuilder, "main_menu_styles");
                removeStyleMenu(menuBuilder, "node_popup_styles");
            }

            public void afterMapChange(final MapModel oldMap, final MapModel newMap) {
                addStyleMenu(menuBuilder, "main_menu_styles", newMap);
                addStyleMenu(menuBuilder, "node_popup_styles", newMap);
            }
        });
        final MapController mapController = modeController.getMapController();
        mapController.addMapChangeListener(new IMapChangeListener() {

            public void onPreNodeMoved(final NodeModel oldParent, final int oldIndex, final NodeModel newParent, final NodeModel child, final int newIndex) {
            }

            public void onPreNodeDelete(final NodeModel oldParent, final NodeModel selectedNode, final int index) {
            }

            public void onNodeMoved(final NodeModel oldParent, final int oldIndex, final NodeModel newParent, final NodeModel child, final int newIndex) {
            }

            public void onNodeInserted(final NodeModel parent, final NodeModel child, final int newIndex) {
            }

            public void onNodeDeleted(final NodeModel parent, final NodeModel child, final int index) {
            }

            public void mapChanged(final MapChangeEvent event) {
                if (event.getProperty().equals(MapStyle.MAP_STYLES)) {
                    removeStyleMenu(menuBuilder, "main_menu_styles");
                    addStyleMenu(menuBuilder, "main_menu_styles", event.getMap());
                    removeStyleMenu(menuBuilder, "node_popup_styles");
                    addStyleMenu(menuBuilder, "node_popup_styles", event.getMap());
                }
            }
        });
        mapController.addNodeSelectionListener(new INodeSelectionListener() {

            public void onSelect(final NodeModel node) {
                selectActions();
            }

            public void onDeselect(final NodeModel node) {
            }
        });
    }
}
Also used : IMapSelectionListener(org.freeplane.features.map.IMapSelectionListener) IMapChangeListener(org.freeplane.features.map.IMapChangeListener) IUserInputListenerFactory(org.freeplane.core.ui.IUserInputListenerFactory) MapBackgroundImageAction(org.freeplane.view.swing.features.filepreview.MapBackgroundImageAction) IExtensionCopier(org.freeplane.features.map.IExtensionCopier) ModeController(org.freeplane.features.mode.ModeController) MapModel(org.freeplane.features.map.MapModel) MenuBuilder(org.freeplane.core.ui.MenuBuilder) MapController(org.freeplane.features.map.MapController) INodeSelectionListener(org.freeplane.features.map.INodeSelectionListener) NodeModel(org.freeplane.features.map.NodeModel) MapBackgroundClearAction(org.freeplane.view.swing.features.filepreview.MapBackgroundClearAction) MapChangeEvent(org.freeplane.features.map.MapChangeEvent)

Example 9 with MenuBuilder

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

the class ModeController method updateMenus.

public void updateMenus(String menuStructure, final Set<String> plugins) {
    final IUserInputListenerFactory userInputListenerFactory = getUserInputListenerFactory();
    userInputListenerFactory.getAcceleratorManager().loadDefaultAcceleratorPresets();
    userInputListenerFactory.updateMenus(menuStructure, plugins);
    final MenuBuilder menuBuilder = userInputListenerFactory.getMenuBuilder(MenuBuilder.class);
    final Iterator<IMenuContributor> iterator = menuContributors.iterator();
    while (iterator.hasNext()) {
        iterator.next().updateMenus(this, menuBuilder);
    }
}
Also used : IMenuContributor(org.freeplane.core.ui.IMenuContributor) IUserInputListenerFactory(org.freeplane.core.ui.IUserInputListenerFactory) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 10 with MenuBuilder

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

the class MModeWorkspaceController method setupController.

private void setupController(ModeController modeController) {
    modeController.removeExtension(UrlManager.class);
    UrlManager.install(new MModeWorkspaceUrlManager());
    modeController.removeExtension(LinkController.class);
    LinkController.install(MModeWorkspaceLinkController.getController());
    // add link type entry to the chooser
    MModeWorkspaceLinkController.getController().prepareOptionPanelBuilder(((MModeController) modeController).getOptionPanelBuilder());
    modeController.addINodeViewLifeCycleListener(new INodeViewLifeCycleListener() {

        public void onViewCreated(Container nodeView) {
            NodeView node = (NodeView) nodeView;
            final DropTarget dropTarget = new DropTarget(node.getMainView(), new MNodeDropListener() {

                public void drop(final DropTargetDropEvent dtde) {
                    DropTargetDropEvent evt = dtde;
                    if (dtde.getTransferable().isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR)) {
                        evt = new DropTargetDropEvent(dtde.getDropTargetContext(), dtde.getLocation(), dtde.getDropAction(), dtde.getSourceActions(), false);
                    }
                    super.drop(evt);
                }
            });
            dropTarget.setActive(true);
        }

        public void onViewRemoved(Container nodeView) {
        }
    });
    modeController.addMenuContributor(new IMenuContributor() {

        public void updateMenus(ModeController modeController, MenuBuilder builder) {
            final String MENU_PROJECT_KEY = "/menu_bar/project";
            // insert project menu into main menu
            JMenu projectMenu = new JMenu(TextUtils.getText("menu.project.entry.label"));
            projectMenu.setMnemonic('o');
            builder.addMenuItem("/menu_bar/format", projectMenu, MENU_PROJECT_KEY, MenuBuilder.AFTER);
            builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceNewProjectAction.KEY), MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceImportProjectAction.KEY), MenuBuilder.AS_CHILD);
            builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
            final String MENU_PROJECT_ADD_KEY = builder.getMenuKey(MENU_PROJECT_KEY, "new");
            final JMenu addMenu = new JMenu(TextUtils.getText("workspace.action.new.label"));
            builder.addMenuItem(MENU_PROJECT_KEY, addMenu, MENU_PROJECT_ADD_KEY, MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewFolderAction(), MenuBuilder.AS_CHILD);
            builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewLinkAction(), MenuBuilder.AS_CHILD);
            final WorkspaceRemoveProjectAction rmProjectAction = new WorkspaceRemoveProjectAction();
            builder.addAction(MENU_PROJECT_KEY, rmProjectAction, MenuBuilder.AS_CHILD);
            builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
            setDefaultAccelerator(builder.getShortcutKey(builder.getMenuKey(MENU_PROJECT_KEY, WorkspaceProjectOpenLocationAction.KEY)), "control alt L");
            final WorkspaceProjectOpenLocationAction openLocAction = new WorkspaceProjectOpenLocationAction();
            builder.addAction(MENU_PROJECT_KEY, openLocAction, MenuBuilder.AS_CHILD);
            projectMenu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    rmProjectAction.setEnabled();
                    openLocAction.setEnabled();
                    if (WorkspaceController.getCurrentProject() == null) {
                        addMenu.setEnabled(false);
                    } else {
                        addMenu.setEnabled(true);
                    }
                }

                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                }

                public void popupMenuCanceled(PopupMenuEvent e) {
                }
            });
        }

        private void setDefaultAccelerator(final String shortcutKey, String accelerator) {
            if (accelerator != null) {
                if (null == ResourceController.getResourceController().getProperty(shortcutKey, null)) {
                    if (Compat.isMacOsX()) {
                        accelerator = accelerator.replaceFirst("CONTROL", "META").replaceFirst("control", "meta");
                    }
                    ResourceController.getResourceController().setDefaultProperty(shortcutKey, accelerator);
                }
            }
        }
    });
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) NodeView(org.freeplane.view.swing.map.NodeView) MenuBuilder(org.freeplane.core.ui.MenuBuilder) PopupMenuEvent(javax.swing.event.PopupMenuEvent) INodeViewLifeCycleListener(org.freeplane.features.ui.INodeViewLifeCycleListener) Container(java.awt.Container) IMenuContributor(org.freeplane.core.ui.IMenuContributor) NodeNewFolderAction(org.freeplane.plugin.workspace.actions.NodeNewFolderAction) NodeNewLinkAction(org.freeplane.plugin.workspace.actions.NodeNewLinkAction) MNodeDropListener(org.freeplane.view.swing.ui.mindmapmode.MNodeDropListener) WorkspaceRemoveProjectAction(org.freeplane.plugin.workspace.actions.WorkspaceRemoveProjectAction) DropTarget(java.awt.dnd.DropTarget) WorkspaceProjectOpenLocationAction(org.freeplane.plugin.workspace.actions.WorkspaceProjectOpenLocationAction) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) JMenu(javax.swing.JMenu)

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