public void actionPerformed(final ActionEvent e) {
    final ModeController modeController = Controller.getCurrentModeController();
    final Controller controller = modeController.getController();
    final NodeModel selected = controller.getSelection().getSelected();
    if (selected.depth() < 2) {
      UITools.errorMessage(TextUtils.getText("can_not_delete_style_group"));
      return;
    }
    final MapModel map = selected.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final NodeModel styleNodeGroup = styleModel.getStyleNodeGroup(selected);
    if (!((StyleNamedObject) styleNodeGroup.getUserObject())
        .getObject()
        .equals("styles.user-defined")) {
      UITools.errorMessage(TextUtils.getText("can_not_delete_predefined_style"));
      return;
    }
    final MMapController mapController = (MMapController) modeController.getMapController();
    mapController.deleteNode(selected);
    final IActor actor =
        new IActor() {
          public void undo() {
            styleModel.addStyleNode(selected);
          }

          public String getDescription() {
            return "DeleteStyle";
          }

          public void act() {
            styleModel.removeStyleNode(selected);
          }
        };
    Controller.getCurrentModeController().execute(actor, map);
  }
예제 #2
0
 private String createOpenMapItemName(final String restorable) {
   final int separatorIndex = restorable.indexOf(':');
   if (separatorIndex == -1) return restorable;
   String key = restorable.substring(0, separatorIndex);
   String fileName = restorable.substring(separatorIndex);
   if (fileName.startsWith("::"))
     return TextUtils.getText("open_as" + key, key) + " " + fileName.substring(2);
   else return TextUtils.getText("open_as" + key, key) + " " + fileName.substring(1);
 }
예제 #3
0
 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);
         }
       }
     }
   }
 }
예제 #4
0
 private void addAutomaticLayout(final DefaultFormBuilder rightBuilder) {
   {
     if (mAutomaticLayoutComboBox == null) {
       NamedObject[] automaticLayoutTypes = NamedObject.fromEnum(AutomaticLayout.class);
       mAutomaticLayoutComboBox = new JComboBox(automaticLayoutTypes);
       DefaultComboBoxModel automaticLayoutComboBoxModel =
           (DefaultComboBoxModel) mAutomaticLayoutComboBox.getModel();
       automaticLayoutComboBoxModel.addElement(AUTOMATIC_LAYOUT_DISABLED);
       automaticLayoutComboBoxModel.setSelectedItem(AUTOMATIC_LAYOUT_DISABLED);
       mAutomaticLayoutComboBox.addActionListener(
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               if (internalChange) return;
               final ModeController modeController = Controller.getCurrentModeController();
               AutomaticLayoutController al =
                   modeController.getExtension(AutomaticLayoutController.class);
               NamedObject selectedItem = (NamedObject) mAutomaticLayoutComboBox.getSelectedItem();
               al.undoableDeactivateHook(Controller.getCurrentController().getMap().getRootNode());
               if (!selectedItem.equals(AUTOMATIC_LAYOUT_DISABLED)) {
                 al.undoableActivateHook(
                     Controller.getCurrentController().getMap().getRootNode(),
                     (AutomaticLayout) selectedItem.getObject());
               }
             }
           });
     }
     final String label = TextUtils.getText("AutomaticLayoutAction.text");
     rightBuilder.append(new JLabel(label), 5);
     rightBuilder.append(mAutomaticLayoutComboBox);
     rightBuilder.nextLine();
   }
   {
     if (mAutomaticEdgeColorCheckBox == null) {
       mAutomaticEdgeColorCheckBox = new JCheckBox();
       mAutomaticEdgeColorCheckBox.addActionListener(
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               final ModeController modeController = Controller.getCurrentModeController();
               AutomaticEdgeColorHook al =
                   (AutomaticEdgeColorHook)
                       modeController.getExtension(AutomaticEdgeColorHook.class);
               al.undoableToggleHook(Controller.getCurrentController().getMap().getRootNode());
             }
           });
     }
     final String label = TextUtils.getText("AutomaticEdgeColorHookAction.text");
     rightBuilder.append(new JLabel(label), 5);
     rightBuilder.append(mAutomaticEdgeColorCheckBox);
     rightBuilder.nextLine();
   }
 }
예제 #5
0
 /**
  * Creates all controls and adds them to the frame.
  *
  * @param modeController
  */
 private void init() {
   if (mControls != null) return;
   final String form = "right:max(20dlu;p), 2dlu, p, 1dlu,right:max(20dlu;p), 4dlu, 80dlu, 7dlu";
   final FormLayout rightLayout = new FormLayout(form, "");
   final DefaultFormBuilder rightBuilder = new DefaultFormBuilder(rightLayout);
   rightBuilder.setBorder(Borders.DLU2_BORDER);
   rightBuilder.appendSeparator(TextUtils.getText("OptionPanel.separator.NodeStyle"));
   if (addStyleBox) {
     addAutomaticLayout(rightBuilder);
     addStyleBox(rightBuilder);
   }
   mNodeStyleButton =
       addStyleButton(
           rightBuilder,
           "actual_node_styles",
           modeController.getAction(ManageNodeConditionalStylesAction.NAME));
   if (addStyleBox) {
     mMapStyleButton =
         addStyleButton(
             rightBuilder,
             "actual_map_styles",
             modeController.getAction(ManageMapConditionalStylesAction.NAME));
   }
   mControls = getControls();
   for (final IPropertyControl control : mControls) {
     control.layout(rightBuilder);
   }
   add(rightBuilder.getPanel(), BorderLayout.CENTER);
   addListeners();
   setFont(this, 10);
 }
예제 #6
0
 protected void editScript(boolean selectAll) {
   JEditorPane textEditor = new JEditorPane();
   textEditor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
   final JRestrictedSizeScrollPane scrollPane = new JRestrictedSizeScrollPane(textEditor);
   scrollPane.setMinimumSize(minimumSize);
   textEditor.setContentType("text/groovy");
   textEditor.setText(script);
   if (selectAll) {
     textEditor.selectAll();
   }
   String title = TextUtils.getText("plugins/ScriptEditor/window.title");
   final JOptionPane optionPane =
       new JOptionPane(scrollPane, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog = optionPane.createDialog(showEditorBtn, title);
   dialog.setResizable(true);
   if (bounds != null) dialog.setBounds(bounds);
   dialog.setVisible(true);
   bounds = dialog.getBounds();
   final Integer result = ((Integer) optionPane.getValue());
   if (result == null || result != JOptionPane.OK_OPTION) return;
   script = textEditor.getText();
   setButtonText();
   final ActionEvent actionEvent = new ActionEvent(this, 0, null);
   for (final ActionListener l : actionListeners) {
     l.actionPerformed(actionEvent);
   }
 }
예제 #7
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;
 }
예제 #8
0
 private void addStyleBox(final DefaultFormBuilder rightBuilder) {
   mStyleBox = uiFactory.createStyleBox();
   mSetStyle = new BooleanProperty(StyleEditorPanel.SET_RESOURCE);
   final StyleChangeListener listener = new StyleChangeListener();
   mSetStyle.addPropertyChangeListener(listener);
   mSetStyle.layout(rightBuilder);
   rightBuilder.append(new JLabel(TextUtils.getText("style")));
   rightBuilder.append(mStyleBox);
   rightBuilder.nextLine();
 }
예제 #9
0
 public static String createDescription(
     final String attribute,
     final String simpleCondition,
     final String value,
     final boolean matchCase,
     final boolean matchApproximately) {
   final String description =
       attribute
           + " "
           + simpleCondition
           + (value != null ? " \"" + value + "\"" : "")
           + (matchCase && value != null
               ? ", " + TextUtils.getText(ConditionFactory.FILTER_MATCH_CASE)
               : "")
           + (matchApproximately && value != null
               ? ", " + TextUtils.getText(ConditionFactory.FILTER_MATCH_APPROX)
               : "");
   return description;
 }
예제 #10
0
 private String formatMenuLocation(ScriptAddOnProperties.Script script) {
   final String location =
       script.menuLocation == null ? "main_menu_scripting" : script.menuLocation;
   MenuBuilder menuBuilder =
       Controller.getCurrentModeController().getUserInputListenerFactory().getMenuBuilder();
   // "/menu_bar/edit/menu_extensions" -> [Node Extensions, Edit]
   final List<String> pathElements = getMenuPathElements(menuBuilder, location);
   Collections.reverse(pathElements);
   pathElements.add(TextUtils.getText(script.menuTitleKey));
   return StringUtils.join(pathElements.iterator(), "->");
 }
예제 #11
0
 public void newAccelerator(final JMenuItem editedItem, final KeyStroke newAccelerator) {
   final Object key = menuBuilder.getKeyByUserObject(editedItem);
   final String shortcutKey = menuBuilder.getShortcutKey(key.toString());
   final String oldShortcut = ResourceController.getResourceController().getProperty(shortcutKey);
   if (newAccelerator == null
       || !new KeystrokeValidator(editedItem, key, editedItem)
           .isValid(newAccelerator, newAccelerator.getKeyChar())) {
     final GrabKeyDialog grabKeyDialog = new GrabKeyDialog(oldShortcut);
     final IKeystrokeValidator validator = new KeystrokeValidator(grabKeyDialog, key, editedItem);
     grabKeyDialog.setValidator(validator);
     grabKeyDialog.setVisible(true);
     if (grabKeyDialog.isOK()) {
       final String shortcut = grabKeyDialog.getShortcut();
       final KeyStroke accelerator = UITools.getKeyStroke(shortcut);
       menuBuilder.setAccelerator((Node) menuBuilder.get(key), accelerator);
       ResourceController.getResourceController().setProperty(shortcutKey, shortcut);
       LogUtils.info(
           "created shortcut '"
               + shortcut
               + "' for menuitem '"
               + key
               + "', shortcutKey '"
               + shortcutKey
               + "' ("
               + editedItem.getText()
               + ")");
     }
   } else {
     if (oldShortcut != null) {
       final int replace =
           JOptionPane.showConfirmDialog(
               editedItem,
               oldShortcut,
               TextUtils.getText("remove_shortcut_question"),
               JOptionPane.YES_NO_OPTION);
       if (replace != JOptionPane.YES_OPTION) {
         return;
       }
     }
     menuBuilder.setAccelerator((Node) menuBuilder.get(key), newAccelerator);
     ResourceController.getResourceController().setProperty(shortcutKey, toString(newAccelerator));
     LogUtils.info(
         "created shortcut '"
             + toString(newAccelerator)
             + "' for menuitem '"
             + key
             + "', shortcutKey '"
             + shortcutKey
             + "' ("
             + editedItem.getText()
             + ")");
   }
 }
예제 #12
0
 protected void setButtonText() {
   final String text =
       script.substring(0, Math.min(40, script.length())).trim().replaceAll("\\s+", " ");
   if (!text.equals("")) {
     showEditorBtn.setToolTipText(HtmlUtils.plainToHTML(script));
     showEditorBtn.setText(text);
   } else {
     final String title = TextUtils.getText("EditScript");
     showEditorBtn.setToolTipText(null);
     showEditorBtn.setText(title);
   }
 }
예제 #13
0
 static void setNewAcceleratorOnNextClick(KeyStroke accelerator) {
   if (AccelerateableAction.isNewAcceleratorOnNextClickEnabled()) {
     return;
   }
   acceleratorForNextClickedAction = accelerator;
   String title = TextUtils.getText("SetAccelerator.dialogTitle");
   String text = TextUtils.getText(SET_ACCELERATOR_ON_NEXT_CLICK_ACTION);
   if (accelerator != null)
     text =
         TextUtils.format("SetAccelerator.keystrokeDetected", toString(accelerator)) + "\n" + text;
   final Frame frame = Controller.getCurrentController().getViewController().getFrame();
   setAcceleratorOnNextClickActionDialog = UITools.createCancelDialog(frame, title, text);
   getAcceleratorOnNextClickActionDialog()
       .addComponentListener(
           new ComponentAdapter() {
             @Override
             public void componentHidden(final ComponentEvent e) {
               setAcceleratorOnNextClickActionDialog = null;
               acceleratorForNextClickedAction = null;
             }
           });
   getAcceleratorOnNextClickActionDialog().setVisible(true);
 }
예제 #14
0
  private JButton addStyleButton(
      DefaultFormBuilder rightBuilder, String label, AFreeplaneAction action) {
    final JButton button =
        new JButton() {
          private static final long serialVersionUID = 1L;

          {
            setUI(BasicButtonUI.createUI(this));
          }
        };
    button.addActionListener(action);
    button.setHorizontalAlignment(SwingConstants.LEFT);
    final String labelText = TextUtils.getText(label);
    UITools.addTitledBorder(button, labelText, 10);
    rightBuilder.append(button, rightBuilder.getColumnCount());
    rightBuilder.nextLine();
    return button;
  }
예제 #15
0
 public boolean isValid(final KeyStroke keystroke, final Character keyChar) {
   if (keystroke == null) {
     return true;
   }
   final Node menuBarNode = menuBuilder.getMenuBar(menuBuilder.get(key));
   if (menuBarNode == null) {
     return true;
   }
   if (keyChar != KeyEvent.CHAR_UNDEFINED
       && (keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK))
           == 0) {
     final String keyTypeActionString =
         ResourceController.getResourceController()
             .getProperty("key_type_action", FirstAction.EDIT_CURRENT.toString());
     FirstAction keyTypeAction = FirstAction.valueOf(keyTypeActionString);
     return FirstAction.IGNORE.equals(keyTypeAction);
   }
   if ((keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK))
       == Event.ALT_MASK) {
     final JMenuBar menuBar = (JMenuBar) menuBarNode.getUserObject();
     final int menuCount = menuBar.getMenuCount();
     for (int i = 0; i < menuCount; i++) {
       final JMenu menu = menuBar.getMenu(i);
       final char c = (char) menu.getMnemonic();
       if (Character.toLowerCase(keystroke.getKeyCode()) == Character.toLowerCase(c)) {
         JOptionPane.showMessageDialog(
             parentComponent,
             menu.getText(),
             TextUtils.getText("used_in_menu"),
             JOptionPane.WARNING_MESSAGE);
         return false;
       }
     }
   }
   if (!checkForOverwriteShortcut(menuBarNode, keystroke)) {
     return false;
   }
   final KeyStroke derivedKS = FreeplaneMenuBar.derive(keystroke, keyChar);
   if (derivedKS == keystroke) {
     return true;
   }
   return checkForOverwriteShortcut(menuBarNode, derivedKS);
 }
 public void actionPerformed(ActionEvent e) {
   PopupFactory popupFactory = PopupFactory.getSharedInstance();
   JToolTip tip = new JToolTip();
   tip.setTipText(TextUtils.getText("docear.monitoring.reload.name"));
   final Point locationOnScreen = comp.getLocationOnScreen();
   final int height = comp.getHeight();
   Rectangle sBounds = comp.getGraphicsConfiguration().getBounds();
   final int minX = sBounds.x;
   final int maxX = sBounds.x + sBounds.width;
   final int minY = sBounds.y;
   final int maxY = sBounds.y + sBounds.height;
   int x = locationOnScreen.x;
   int y = locationOnScreen.y + height;
   final Dimension tipSize = tip.getPreferredSize();
   final int tipWidth = tipSize.width;
   if (x + tipWidth > maxX) {
     x = maxX - tipWidth;
   }
   if (x < minX) {
     x = minX;
   }
   final int tipHeight = tipSize.height;
   if (y + tipHeight > maxY) {
     if (locationOnScreen.y - tipHeight > minY) {
       y = locationOnScreen.y - tipHeight;
     } else {
       y = maxY - tipHeight;
     }
   }
   if (y < minY) {
     y = minY;
   }
   final Popup tipPopup = popupFactory.getPopup(comp, tip, x, y);
   tipPopup.show();
   showTimer.removeActionListener(this);
   hideTimer.addActionListener(new HideToolTipAction(tipPopup, tip, comp));
   hideTimer.start();
 }
예제 #17
0
 private JComponent createDetails(final AddOnProperties addOn) {
   final StringBuilder text = new StringBuilder(1024);
   text.append("<html><body>");
   text.append(toHtml(addOn.getDescription()));
   text.append("<p>");
   if (addOn instanceof ScriptAddOnProperties) {
     List<Script> scripts = ((ScriptAddOnProperties) addOn).getScripts();
     if (!scripts.isEmpty()) {
       text.append("<table border='1'>");
       text.append(
           row(
               "th",
               getText("header.function"),
               getText("header.menu"),
               getText("header.shortcut")));
       for (ScriptAddOnProperties.Script script : scripts) {
         text.append(
             row(
                 "td",
                 bold(TextUtils.getText(script.menuTitleKey)),
                 formatMenuLocation(script),
                 formatShortcut(script)));
       }
       text.append("</table>");
     }
   }
   if (warning != null) {
     text.append("<p><p>");
     text.append(warning.replaceAll("</?(html|body)>", ""));
   }
   text.append("</body></html>");
   final JLabel label = new JLabel(text.toString());
   final ImageIcon icon =
       IconNotFound.createIconOrReturnNull(addOn.getName() + "-screenshot-1.png");
   if (icon != null) label.setIcon(icon);
   return label;
 }
예제 #18
0
 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);
 }
예제 #19
0
 private final void doUpdateLinks() {
   MindmapUpdateController mindmapUpdateController = new MindmapUpdateController();
   mindmapUpdateController.addMindmapUpdater(
       new MindmapLinkTypeUpdater(TextUtils.getText("updating_link_types")));
   mindmapUpdateController.updateRegisteredMindmapsInWorkspace(true);
 }
예제 #20
0
 private String formatErrors(String key, ArrayList<String> errors) {
   // TextUtils.format() xml escapes the format arguments - we don't want that
   final MessageFormat formatter = new MessageFormat(TextUtils.getText(key));
   return formatter.format(new Object[] {StringUtils.join(errors.iterator(), "<br>")});
 }
예제 #21
0
 // location might be something like /menu_bar/edit/editGoodies
 private String getMenuTitle(final String location) {
   int index = location.lastIndexOf('/');
   final String lastKey = location.substring(index + 1);
   return TextUtils.getText(lastKey, TextUtils.getText("addons." + lastKey, lastKey));
 }
예제 #22
0
 /** menuTitle may either be a scriptName or a translation key. */
 private String pimpMenuTitle(final String menuTitle) {
   final String translation = TextUtils.getText(menuTitle, null);
   // convert CamelCase to Camel Case
   return translation != null ? translation : menuTitle.replaceAll("([a-z])([A-Z])", "$1 $2");
 }