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