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);
  }
 private String formatShortcut(final Script script) {
   final String menuItemKey =
       ExecuteScriptAction.makeMenuItemKey(script.menuTitleKey, script.executionMode);
   final String shortcutKey = MenuUtils.makeAcceleratorKey(menuItemKey);
   final String oldShortcut = ResourceController.getResourceController().getProperty(shortcutKey);
   final KeyStroke keyStroke =
       UITools.getKeyStroke(oldShortcut != null ? oldShortcut : script.keyboardShortcut);
   return UITools.keyStrokeToString(keyStroke);
 }
Beispiel #3
0
 public void safeOpen(final String restoreable) {
   try {
     open(restoreable);
   } catch (final Exception ex) {
     LogUtils.warn(ex);
     final String message = TextUtils.format("remove_file_from_list_on_error", restoreable);
     UITools.showFrame();
     final Frame frame = UITools.getFrame();
     final int remove =
         JOptionPane.showConfirmDialog(frame, message, "Freeplane", JOptionPane.YES_NO_OPTION);
     if (remove == JOptionPane.YES_OPTION) {
       remove(restoreable);
     }
   }
 }
Beispiel #4
0
 private boolean validate() {
   final Properties properties = getOptionProperties();
   final ValidationResult result = new ValidationResult();
   for (IValidator validator : Controller.getCurrentController().getOptionValidators()) {
     result.add(validator.validate(properties));
   }
   if (!result.isValid()) {
     UITools.errorMessage(formatErrors("OptionPanel.validation_error", result.getErrors()));
     LogUtils.severe(result.toString());
   } else if (result.hasWarnings()) {
     UITools.informationMessage(
         formatErrors("OptionPanel.validation_warning", result.getWarnings()));
     LogUtils.warn(result.toString());
   }
   return result.isValid();
 }
 private JComponent createAddOnHomepageButton(final AddOnProperties addOn) {
   // parse the URI on creation of the dialog to test the URI syntax early
   try {
     return UITools.createHtmlLinkStyleButton(
         addOn.getHomepage().toURI(), addOn.getHomepage().toString());
   } catch (Exception e) {
     LogUtils.warn("add-on " + addOn + " has no valid homepage: " + e);
     return new JLabel("-");
   }
 }
 public PreviewDialog(
     final PrintController printController, final String title, final Component c) {
   super(JOptionPane.getFrameForComponent(c), title, true);
   view = (Printable) c;
   final Rectangle desktopBounds = UITools.getDesktopBounds(c);
   Dimension previewSize =
       new Dimension(desktopBounds.width * 3 / 4, desktopBounds.height * 3 / 4);
   final Preview preview = new Preview(printController, view, previewSize);
   final JScrollPane scrollPane =
       new JScrollPane(
           preview,
           JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
           JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
   UITools.setScrollbarIncrement(scrollPane);
   getContentPane().add(scrollPane, "Center");
   final JToolBar toolbar = new FreeplaneToolBar("preview_toolbar", SwingConstants.HORIZONTAL);
   getContentPane().add(toolbar, "North");
   pageNumber = new JLabel("- 9999 -");
   final JButton button = getButton("Back24.gif", new BrowseAction(preview, pageNumber, -1));
   toolbar.add(button);
   pageNumber.setPreferredSize(
       new Dimension(pageNumber.getPreferredSize().width, button.getPreferredSize().height));
   pageNumber.setText("- 1 -");
   pageNumber.setHorizontalAlignment(SwingConstants.CENTER);
   toolbar.add(pageNumber);
   toolbar.add(getButton("Forward24.gif", new BrowseAction(preview, pageNumber, 1)));
   toolbar.add(new JToolBar.Separator());
   toolbar.add(
       getButton("ZoomIn24.png", new ZoomAction(preview, PreviewDialog.DEFAULT_ZOOM_FACTOR_STEP)));
   toolbar.add(
       getButton(
           "ZoomOut24.png",
           new ZoomAction(preview, 1.0 / PreviewDialog.DEFAULT_ZOOM_FACTOR_STEP)));
   toolbar.add(new JToolBar.Separator());
   final JPanel buttons = new JPanel();
   buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
   final JButton ok = new JButton("OK");
   ok.addActionListener(this);
   buttons.add(ok);
   getContentPane().add(buttons, "South");
   UITools.addEscapeActionToDialog(this);
 }
 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()
             + ")");
   }
 }
 /**
  * Creates a reader that pipes the input file through a XSLT-Script that updates the version to
  * the current.
  *
  * @throws IOException
  */
 public Reader getUpdateReader(final File file, final String xsltScript)
     throws FileNotFoundException, IOException {
   try {
     String updatedXml = transform(file, xsltScript);
     return new StringReader(updatedXml);
   } catch (final Exception ex) {
     final String message = ex.getMessage();
     UITools.errorMessage(TextUtils.format("update_failed", String.valueOf(message)));
     LogUtils.warn(ex);
     final InputStream input = new BufferedInputStream(new FileInputStream(file));
     return getActualReader(input);
   }
 }
Beispiel #9
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);
   }
 }
Beispiel #10
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;
  }
 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);
 }
Beispiel #12
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);
 }