Esempio n. 1
0
 private void updateMenus() {
   Controller controller = Controller.getCurrentController();
   final ModeController modeController = controller.getModeController();
   final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder();
   menuBuilder.removeChildElements(MENU_CATEGORY);
   int i = 0;
   int maxEntries = getMaxMenuEntries();
   for (final String key : lastOpenedList) {
     if (i == 0
         && (!modeController.getModeName().equals(MModeController.MODENAME)
             || controller.getMap() == null
             || controller.getMap().getURL() == null)) {
       i++;
       maxEntries++;
     }
     if (i == maxEntries) {
       break;
     }
     final AFreeplaneAction lastOpenedActionListener = new OpenLastOpenedAction(i++, this);
     final IFreeplaneAction decoratedAction = menuBuilder.decorateAction(lastOpenedActionListener);
     final JMenuItem item = new JFreeplaneMenuItem(decoratedAction);
     item.setActionCommand(key);
     String text = createOpenMapItemName(key);
     item.setText(text);
     item.setMnemonic(0);
     menuBuilder.addMenuItem(
         MENU_CATEGORY,
         item,
         MENU_CATEGORY + '/' + lastOpenedActionListener.getKey(),
         UIBuilder.AS_CHILD);
   }
 }
Esempio n. 2
0
 /**
  * returns a tree of all <code>JMenuItem</code> nodes the menu contains (omitting Strings and
  * Separators). The tree is build from <code>DefaultMutableTreeNode</code> nodes having <code>
  * MenuEntry</code> objects as their userObjects.
  *
  * <p>Note that the root node may have null as userObject if the menu item at <code>menuRootKey
  * </code> doesn't contain a <code>JMenuItem</code>!
  *
  * @param menuRootKey the key of the node that should form the root of the output.
  * @param menuBuilder access point for the menu(s).
  */
 public static DefaultMutableTreeNode createMenuEntryTree(
     final String menuRootKey, final MenuBuilder menuBuilder) {
   final HashMap<String, KeyStroke> menuKeyToKeyStrokeMap =
       MenuUtils.invertAcceleratorMap(menuBuilder.getAcceleratorMap());
   final DefaultMutableTreeNode menuRoot = menuBuilder.get(menuRootKey);
   final DefaultMutableTreeNode treeRoot =
       new DefaultMutableTreeNode(
           MenuUtils.menuNode2menuEntryNode(menuRoot, menuKeyToKeyStrokeMap));
   MenuUtils.addChildrenRecursively(treeRoot, menuRoot.children(), menuKeyToKeyStrokeMap);
   return treeRoot;
 }
 private void addSubMenu(
     final MenuBuilder menuBuilder,
     final String parentLocation,
     final String location,
     String menuTitle) {
   if (menuBuilder.get(location) == null) {
     final JMenu menuItem = new JMenu();
     MenuBuilder.setLabelAndMnemonic(menuItem, menuTitle);
     menuBuilder.addMenuItem(parentLocation, menuItem, location, MenuBuilder.AS_CHILD);
   }
 }
Esempio n. 4
0
 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);
   }
 }
 private void registerScripts(
     final MenuBuilder menuBuilder, ScriptingConfiguration configuration) {
   final HashSet<String> registeredLocations = new HashSet<String>();
   for (final String scriptsParentLocation : ScriptingConfiguration.getScriptsParentLocations()) {
     final String scriptsLocation =
         ScriptingConfiguration.getScriptsLocation(scriptsParentLocation);
     addSubMenu(
         menuBuilder,
         scriptsParentLocation,
         scriptsLocation,
         TextUtils.getText("ExecuteScripts.text"));
     registeredLocations.add(scriptsLocation);
     if (configuration.getNameScriptMap().isEmpty()) {
       final String message =
           "<html><body><em>"
               + TextUtils.getText("ExecuteScripts.noScriptsAvailable")
               + "</em></body></html>";
       menuBuilder.addElement(scriptsLocation, new JMenuItem(message), 0);
     }
     for (final Entry<String, String> entry : configuration.getNameScriptMap().entrySet()) {
       final String scriptName = entry.getKey();
       final ScriptMetaData metaData = configuration.getNameScriptMetaDataMap().get(scriptName);
       // in the worst case three actions will cache a script - should not matter that much since
       // it's unlikely
       // that one script is used in multiple modes by the same user
       for (final ExecutionMode executionMode : metaData.getExecutionModes()) {
         final String titleKey;
         final String scriptLocation;
         String location = metaData.getMenuLocation(executionMode);
         // FIXME: reduce code duplication (VB)
         if (location == null) {
           location = scriptsLocation + "/" + scriptName;
           if (!registeredLocations.contains(location)) {
             final String parentMenuTitle = pimpMenuTitle(metaData.getScriptName());
             addSubMenu(menuBuilder, parentLocation(location), location, parentMenuTitle);
             registeredLocations.add(location);
           }
           titleKey = metaData.getTitleKey(executionMode);
           scriptLocation = location + "/" + titleKey;
         } else {
           if (!registeredLocations.contains(location)) {
             addSubMenu(menuBuilder, parentLocation(location), location, getMenuTitle(location));
             registeredLocations.add(location);
           }
           titleKey = metaData.getTitleKey(executionMode);
           scriptLocation = location + "/" + titleKey;
         }
         if (!registeredLocations.contains(scriptLocation)) {
           addMenuItem(menuBuilder, location, entry, executionMode, titleKey, metaData);
           registeredLocations.add(scriptLocation);
         }
       }
     }
   }
 }
Esempio n. 6
0
 public static List<String> getMenuPathElements(MenuBuilder menuBuilder, final String location) {
   final ArrayList<String> pathElements = new ArrayList<String>();
   final DefaultMutableTreeNode node = menuBuilder.get(location);
   if (node != null) {
     pathElements.addAll(getMenuPathElements(node));
   } else {
     int index = location.lastIndexOf('/');
     if (index != -1) {
       final String lastKey = location.substring(index + 1);
       pathElements.add(
           TextUtils.getText(lastKey, TextUtils.getText("addons." + lastKey, lastKey)));
       // recurse
       if (index > 1)
         pathElements.addAll(getMenuPathElements(menuBuilder, location.substring(0, index)));
     }
   }
   return pathElements;
 }
 private void addMenuItem(
     final MenuBuilder menuBuilder,
     final String location,
     final Entry<String, String> entry,
     final ExecutionMode executionMode,
     final String titleKey,
     ScriptMetaData metaData) {
   final String scriptName = entry.getKey();
   final String translation = TextUtils.getText(titleKey, titleKey.replace('_', ' '));
   final String menuName =
       translation.contains("{0}")
           ? MessageFormat.format(translation, pimpMenuTitle(scriptName))
           : translation;
   menuBuilder.addAction(
       location,
       new ExecuteScriptAction(
           scriptName,
           menuName,
           entry.getValue(),
           executionMode,
           metaData.cacheContent(),
           metaData.getPermissions()),
       MenuBuilder.AS_CHILD);
 }
Esempio n. 8
0
 public void buildPanel(final DefaultMutableTreeNode controlsTree) {
   final FormLayout leftLayout = new FormLayout("max(80dlu;p):grow", "");
   final DefaultFormBuilder leftBuilder = new DefaultFormBuilder(leftLayout);
   final CardLayout cardLayout = new VariableSizeCardLayout();
   final JPanel rightStack = new JPanel(cardLayout);
   FormLayout rightLayout = null;
   DefaultFormBuilder rightBuilder = null;
   String lastTabName = null;
   initControls(controlsTree);
   final Iterator<IPropertyControl> iterator = controls.iterator();
   // MaG:
   Controller.getCurrentController()
       .getOptionPanelController()
       .setCurrentPropertyControls(controls);
   while (iterator.hasNext()) {
     final IPropertyControl control = iterator.next();
     if (control instanceof TabProperty) {
       final TabProperty newTab = (TabProperty) control;
       if (rightBuilder != null) {
         rightStack.add(rightBuilder.getPanel(), lastTabName);
       }
       rightLayout = new FormLayout(newTab.getDescription(), "");
       rightBuilder = new DefaultFormBuilder(rightLayout);
       rightBuilder.setDefaultDialogBorder();
       lastTabName = newTab.getLabel();
       final JButton tabButton = new JButton(TextUtils.getOptionalText(lastTabName));
       final ChangeTabAction changeTabAction =
           new ChangeTabAction(cardLayout, rightStack, lastTabName);
       tabButton.addActionListener(changeTabAction);
       registerTabButton(tabButton, lastTabName, changeTabAction);
       leftBuilder.append(tabButton);
     } else {
       control.layout(rightBuilder);
     }
   }
   rightStack.add(rightBuilder.getPanel(), lastTabName);
   if (selectedPanel != null && tabActionMap.containsKey(selectedPanel)) {
     (tabActionMap.get(selectedPanel)).actionPerformed(null);
   }
   final JScrollPane rightComponent = new JScrollPane(rightStack);
   UITools.setScrollbarIncrement(rightComponent);
   final JSplitPane centralPanel =
       new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftBuilder.getPanel(), rightComponent);
   topDialog.getContentPane().add(centralPanel, BorderLayout.CENTER);
   final JButton cancelButton = new JButton();
   MenuBuilder.setLabelAndMnemonic(cancelButton, TextUtils.getRawText("cancel"));
   cancelButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(final ActionEvent arg0) {
           closeWindow();
         }
       });
   final JButton okButton = new JButton();
   MenuBuilder.setLabelAndMnemonic(okButton, TextUtils.getRawText("ok"));
   okButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(final ActionEvent arg0) {
           if (validate()) {
             closeWindow();
             feedback.writeProperties(getOptionProperties());
           }
         }
       });
   topDialog.getRootPane().setDefaultButton(okButton);
   topDialog
       .getContentPane()
       .add(ButtonBarFactory.buildOKCancelBar(cancelButton, okButton), BorderLayout.SOUTH);
 }