Search in sources :

Example 1 with MenuBuilder

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

the class HotKeyInfoAction method actionPerformed.

@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
    // use the MModeController for the mindmap mode menu if possible - the browse menu doesn't have much entries!
    final ModeController modeController = ResourceController.getResourceController().isApplet() ? Controller.getCurrentModeController() : MModeController.getMModeController();
    final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    // TODO - find a similar way to outline the hotkeys for the ribbons
    final DefaultMutableTreeNode menuEntryTree = MenuUtils.createAcceleratebleMenuEntryTree(FreeplaneMenuBar.MENU_BAR_PREFIX, menuBuilder);
    final String title = TextUtils.getText("hot_keys_table");
    final String html = formatAsHtml(menuEntryTree.children());
    JEditorPane refPane = new JEditorPane("text/html", html);
    refPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, false);
    refPane.setCaretPosition(0);
    refPane.setEditable(false);
    final Dimension preferredSize = refPane.getPreferredSize();
    JScrollPane scrollPane = new JScrollPane(refPane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(preferredSize.width, 600));
    JOptionPane.showMessageDialog((Component) e.getSource(), scrollPane, title, JOptionPane.INFORMATION_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JEditorPane(javax.swing.JEditorPane) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) Dimension(java.awt.Dimension) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 2 with MenuBuilder

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

the class LoadAcceleratorPresetsAction method install.

public static final void install() {
    final File[] dirs = { LoadAcceleratorPresetsAction.getAcceleratorsUserDirectory(), LoadAcceleratorPresetsAction.getAcceleratorsSysDirectory() };
    final Controller controller = Controller.getCurrentController();
    ModeController modecontroller = controller.getModeController(MModeController.MODENAME);
    final MenuBuilder menuBuilder = modecontroller.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
    // TODO RIBBONS: impl. eventually
    for (final File dir : dirs) {
        final File[] fileList = dir.listFiles();
        if (fileList == null) {
            continue;
        }
        for (final File prop : fileList) {
            final String fileName = prop.getName();
            if (prop.isDirectory()) {
                continue;
            }
            if (!fileName.endsWith(".properties")) {
                continue;
            }
            try {
                final int propNameLength = fileName.lastIndexOf('.');
                final String propName = fileName.substring(0, propNameLength);
                final String key = "LoadAcceleratorPresetsAction." + propName;
                if (controller.getAction(key) == null) {
                    final String title = TextUtils.getText(key + ".text", propName);
                    final LoadAcceleratorPresetsAction loadAcceleratorPresetsAction = new LoadAcceleratorPresetsAction(prop.toURL(), key, title);
                    controller.addAction(loadAcceleratorPresetsAction);
                    menuBuilder.addAction("main_menu_new_load_accelerator_presets", key, loadAcceleratorPresetsAction, MenuBuilder.AS_CHILD);
                }
            } catch (final Exception e) {
                UITools.errorMessage(TextUtils.format("accelerators_loading_error", prop.getPath()));
            }
        }
    }
}
Also used : ModeController(org.freeplane.features.mode.ModeController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File) MenuBuilder(org.freeplane.core.ui.MenuBuilder) IOException(java.io.IOException)

Example 3 with MenuBuilder

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

the class LastOpenedList method updateMenus.

private void updateMenus() {
    Controller controller = Controller.getCurrentController();
    final ModeController modeController = controller.getModeController();
    if (!modeController.getUserInputListenerFactory().useRibbonMenu()) {
        final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
        menuBuilder.removeChildElements(MENU_CATEGORY);
        List<AFreeplaneAction> openMapActions = createOpenLastMapActionList();
        for (AFreeplaneAction openMapAction : openMapActions) {
            final IFreeplaneAction acceleratableAction = menuBuilder.acceleratableAction(openMapAction);
            final JMenuItem item = new JFreeplaneMenuItem(acceleratableAction);
            item.setMnemonic(0);
            menuBuilder.addMenuItem(MENU_CATEGORY, item, MENU_CATEGORY + '/' + openMapAction.getKey(), UIBuilder.AS_CHILD);
        }
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) IFreeplaneAction(org.freeplane.core.ui.IFreeplaneAction) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) JMenuItem(javax.swing.JMenuItem) MenuBuilder(org.freeplane.core.ui.MenuBuilder) JFreeplaneMenuItem(org.freeplane.core.ui.components.JFreeplaneMenuItem)

Example 4 with MenuBuilder

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

the class Activator method start.

/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
@Override
public void start(final BundleContext context) throws Exception {
    final Hashtable<String, String[]> props = new Hashtable<String, String[]>();
    props.put("mode", new String[] { MModeController.MODENAME /*TODO: other modes too?*/
    });
    context.registerService(IModeControllerExtensionProvider.class.getName(), new IModeControllerExtensionProvider() {

        @Override
        public void installExtension(ModeController modeController) {
            final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
            final $$$$Action action = new $$$$Action();
            modeController.addAction(action);
            modeController.addMenuContributor(new IMenuContributor() {

                @Override
                public void updateMenus(ModeController modeController, MenuBuilder builder) {
                    menuBuilder.addAction("/menu_bar/file", action, MenuBuilder.AS_CHILD);
                }
            });
        }
    }, props);
}
Also used : IMenuContributor(org.freeplane.core.ui.IMenuContributor) Hashtable(java.util.Hashtable) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ModeController(org.freeplane.features.mode.ModeController) IModeControllerExtensionProvider(org.freeplane.main.osgi.IModeControllerExtensionProvider) MenuBuilder(org.freeplane.core.ui.MenuBuilder)

Example 5 with MenuBuilder

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

the class UpdateCheckAction method addUpdateButton.

private void addUpdateButton(final FreeplaneVersion lastVersion) {
    Controller controller = Controller.getCurrentController();
    final Set<String> modes = controller.getModes();
    for (final String mode : modes) {
        ModeController modeController = controller.getModeController(mode);
        if (!modeController.getUserInputListenerFactory().useRibbonMenu()) {
            final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
            if (lastVersion == null || lastVersion.compareTo(FreeplaneVersion.getVersion()) <= 0) {
                ResourceController.getResourceController().setProperty(LAST_UPDATE_VERSION, "");
                if (menuBuilder.get(UPDATE_BUTTON_PATH) != null) {
                    menuBuilder.removeElement(UPDATE_BUTTON_PATH);
                }
                continue;
            }
            ResourceController.getResourceController().setProperty(LAST_UPDATE_VERSION, lastVersion.toString());
            final String updateAvailable = TextUtils.format("new_version_available", lastVersion.toString());
            controller.getViewController().out(updateAvailable);
            putValue(SHORT_DESCRIPTION, updateAvailable);
            putValue(LONG_DESCRIPTION, updateAvailable);
            if (menuBuilder.get(UPDATE_BUTTON_PATH) == null) {
                menuBuilder.addAction(UPDATE_BUTTON_LOCATION, UPDATE_BUTTON_PATH, UpdateCheckAction.this, MenuBuilder.AS_CHILD);
            }
        }
    }
}
Also used : ModeController(org.freeplane.features.mode.ModeController) AddOnsController(org.freeplane.main.addons.AddOnsController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) 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