Search in sources :

Example 1 with FreeplaneResourceAccessor

use of org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor in project freeplane by freeplane.

the class MenuUtils method getMenuItemIcon.

/**
 * returns the icon for a menuItemKey or null if it has none.
 */
public static Icon getMenuItemIcon(String menuItemKey) {
    Entry menuItem = genericMenuStructure().findEntry(menuItemKey);
    if (menuItem == null)
        return null;
    final EntryAccessor entryAccessor = new EntryAccessor(new FreeplaneResourceAccessor());
    final AFreeplaneAction action = entryAccessor.getAction(menuItem);
    return (Icon) action.getValue(Action.SMALL_ICON);
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) Icon(javax.swing.Icon) MindIcon(org.freeplane.features.icon.MindIcon)

Example 2 with FreeplaneResourceAccessor

use of org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor in project freeplane by freeplane.

the class UserInputListenerFactory method updateMenus.

public void updateMenus(String menuStructureResource, Set<String> plugins) {
    mapsPopupMenu = new JPopupMenu();
    mapsPopupMenu.setName(TextUtils.getText("mindmaps"));
    final URL genericStructure = ResourceController.getResourceController().getResource(menuStructureResource);
    try {
        final FreeplaneResourceAccessor resourceAccessor = new FreeplaneResourceAccessor();
        final EntriesForAction entries = new EntriesForAction();
        final ActionAcceleratorManager acceleratorManager = ResourceController.getResourceController().getAcceleratorManager();
        final BuildProcessFactory buildProcessFactory = new MenuBuildProcessFactory(this, modeController, resourceAccessor, acceleratorManager, entries, buildPhaseListeners);
        final PhaseProcessor buildProcessor = buildProcessFactory.getBuildProcessor();
        subtreeBuilder = buildProcessFactory.getChildProcessor();
        acceleratorManager.addAcceleratorChangeListener(modeController, new MenuAcceleratorChangeListener(entries));
        for (final Phase phase : Phase.values()) for (java.util.Map.Entry<String, BuilderDestroyerPair> entry : customBuilders.get(phase.ordinal()).entrySet()) buildProcessor.phase(phase).addBuilderPair(entry.getKey(), entry.getValue());
        final InputStream resource = genericStructure.openStream();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(resource));
        genericMenuStructure = XmlEntryStructureBuilder.buildMenuStructure(reader);
        filterPlugins(genericMenuStructure, plugins);
        buildProcessor.build(genericMenuStructure);
        if (Boolean.getBoolean("org.freeplane.outputUnusedActions"))
            outputUnusedActions();
    } catch (Exception e) {
        final boolean isUserDefined = isUserDefined(genericStructure);
        if (isUserDefined) {
            LogUtils.warn(e);
            String myMessage = TextUtils.format("menu_error", genericStructure.getPath(), e.getMessage());
            UITools.backOtherWindows();
            JOptionPane.showMessageDialog(UITools.getMenuComponent(), myMessage, "Freeplane", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
        }
        throw new RuntimeException("Error in menu resource " + menuStructureResource, e);
    }
}
Also used : Phase(org.freeplane.core.ui.menubuilders.generic.PhaseProcessor.Phase) InputStreamReader(java.io.InputStreamReader) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) InputStream(java.io.InputStream) JPopupMenu(javax.swing.JPopupMenu) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) BuildProcessFactory(org.freeplane.core.ui.menubuilders.generic.BuildProcessFactory) MenuBuildProcessFactory(org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory) MenuBuildProcessFactory(org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) PhaseProcessor(org.freeplane.core.ui.menubuilders.generic.PhaseProcessor) ActionAcceleratorManager(org.freeplane.core.ui.ActionAcceleratorManager) BufferedReader(java.io.BufferedReader) MenuAcceleratorChangeListener(org.freeplane.core.ui.menubuilders.menu.MenuAcceleratorChangeListener)

Example 3 with FreeplaneResourceAccessor

use of org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor in project freeplane by freeplane.

the class AddOnDetailsPanel method formatMenuLocation.

private String formatMenuLocation(ScriptAddOnProperties.Script script) {
    final MModeController modeController = (MModeController) Controller.getCurrentModeController();
    Entry top = modeController.getUserInputListenerFactory().getGenericMenuStructure();
    final String canonicalPath = entryNavigator.replaceAliases(script.menuLocation);
    final String[] pathElements = canonicalPath.split("/");
    Entry entry = top;
    final ListIterator<String> pathIterator = Arrays.asList(pathElements).listIterator();
    while (pathIterator.hasNext()) {
        String name = pathIterator.next();
        if (!name.isEmpty()) {
            final Entry child = entry.getChild(name);
            if (child == null) {
                pathIterator.previous();
                break;
            }
            entry = child;
        }
    }
    if (entry == null)
        return script.menuLocation;
    final FreeplaneResourceAccessor resourceAccessor = new FreeplaneResourceAccessor();
    final EntryAccessor entryAccessor = new EntryAccessor(resourceAccessor);
    final String entryLocationDescription = entryAccessor.getLocationDescription(entry);
    if (!pathIterator.hasNext())
        return entryLocationDescription;
    StringBuilder menuLocationDescription = new StringBuilder(entryLocationDescription);
    while (pathIterator.hasNext()) {
        menuLocationDescription.append(EntryAccessor.MENU_ELEMENT_SEPARATOR);
        menuLocationDescription.append(ScriptingMenuUtils.scriptNameToMenuItemTitle(pathIterator.next()));
    }
    return menuLocationDescription.toString();
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 4 with FreeplaneResourceAccessor

use of org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor 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 Entry genericMenuStructure = genericMenuStructure();
    final EntryAccessor entryAccessor = new EntryAccessor(new FreeplaneResourceAccessor());
    for (String menuItemKey : menuItemKeys) {
        Entry menuItem = genericMenuStructure.findEntry(menuItemKey);
        final AFreeplaneAction action = menuItem != null ? entryAccessor.getAction(menuItem) : null;
        if (action == null) {
            UITools.errorMessage(TextUtils.format("MenuUtils.invalid_menuitem", menuItemKey));
            return;
        }
        LogUtils.info("executing " + ActionUtils.getActionTitle(action) + "(" + menuItemKey + ")");
        ActionEvent e = new ActionEvent(menuItem, 0, null);
        action.actionPerformed(e);
    }
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) ActionEvent(java.awt.event.ActionEvent) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Aggregations

FreeplaneResourceAccessor (org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor)4 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)4 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)3 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)2 ActionEvent (java.awt.event.ActionEvent)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Icon (javax.swing.Icon)1 JPopupMenu (javax.swing.JPopupMenu)1 ActionAcceleratorManager (org.freeplane.core.ui.ActionAcceleratorManager)1 EntriesForAction (org.freeplane.core.ui.menubuilders.action.EntriesForAction)1 BuildProcessFactory (org.freeplane.core.ui.menubuilders.generic.BuildProcessFactory)1 PhaseProcessor (org.freeplane.core.ui.menubuilders.generic.PhaseProcessor)1 Phase (org.freeplane.core.ui.menubuilders.generic.PhaseProcessor.Phase)1 MenuAcceleratorChangeListener (org.freeplane.core.ui.menubuilders.menu.MenuAcceleratorChangeListener)1 MenuBuildProcessFactory (org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory)1 MindIcon (org.freeplane.features.icon.MindIcon)1