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);
}
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);
}
}
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();
}
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);
}
}
Aggregations