Esempio n. 1
0
  public SchemaEditorToolBar(final BasicGraphEditor editor, int orientation) {
    super(orientation);
    setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3), getBorder()));
    setFloatable(false);

    add(
        editor.bind(
            "New", new EditorActions.NewAction(), "/com/gkd/jgraphx_example/images/new.gif"));
    add(
        editor.bind(
            "Open", new EditorActions.OpenAction(), "/com/gkd/jgraphx_example/images/open.gif"));
    add(
        editor.bind(
            "Save",
            new EditorActions.SaveAction(false),
            "/com/gkd/jgraphx_example/images/save.gif"));

    addSeparator();

    add(
        editor.bind(
            "Print", new EditorActions.PrintAction(), "/com/gkd/jgraphx_example/images/print.gif"));

    addSeparator();

    add(
        editor.bind(
            "Cut", TransferHandler.getCutAction(), "/com/gkd/jgraphx_example/images/cut.gif"));
    add(
        editor.bind(
            "Copy", TransferHandler.getCopyAction(), "/com/gkd/jgraphx_example/images/copy.gif"));
    add(
        editor.bind(
            "Paste",
            TransferHandler.getPasteAction(),
            "/com/gkd/jgraphx_example/images/paste.gif"));

    addSeparator();

    add(
        editor.bind(
            "Delete",
            mxGraphActions.getDeleteAction(),
            "/com/gkd/jgraphx_example/images/delete.gif"));

    addSeparator();

    add(
        editor.bind(
            "Undo",
            new EditorActions.HistoryAction(true),
            "/com/gkd/jgraphx_example/images/undo.gif"));
    add(
        editor.bind(
            "Redo",
            new EditorActions.HistoryAction(false),
            "/com/gkd/jgraphx_example/images/redo.gif"));

    addSeparator();

    final mxGraphView view = editor.getGraphComponent().getGraph().getView();
    final JComboBox zoomCombo =
        new JComboBox(
            new Object[] {
              "400%",
              "200%",
              "150%",
              "100%",
              "75%",
              "50%",
              mxResources.get("page"),
              mxResources.get("width"),
              mxResources.get("actualSize")
            });
    zoomCombo.setEditable(true);
    zoomCombo.setMinimumSize(new Dimension(75, 0));
    zoomCombo.setPreferredSize(new Dimension(75, 0));
    zoomCombo.setMaximumSize(new Dimension(75, 100));
    zoomCombo.setMaximumRowCount(9);
    add(zoomCombo);

    // Sets the zoom in the zoom combo the current value
    mxIEventListener scaleTracker =
        new mxIEventListener() {
          /** */
          public void invoke(Object sender, mxEventObject evt) {
            ignoreZoomChange = true;

            try {
              zoomCombo.setSelectedItem((int) Math.round(100 * view.getScale()) + "%");
            } finally {
              ignoreZoomChange = false;
            }
          }
        };

    // Installs the scale tracker to update the value in the combo box
    // if the zoom is changed from outside the combo box
    view.getGraph().getView().addListener(mxEvent.SCALE, scaleTracker);
    view.getGraph().getView().addListener(mxEvent.SCALE_AND_TRANSLATE, scaleTracker);

    // Invokes once to sync with the actual zoom value
    scaleTracker.invoke(null, null);

    zoomCombo.addActionListener(
        new ActionListener() {
          /** */
          public void actionPerformed(ActionEvent e) {
            mxGraphComponent graphComponent = editor.getGraphComponent();

            // Zoomcombo is changed when the scale is changed in the diagram
            // but the change is ignored here
            if (!ignoreZoomChange) {
              String zoom = zoomCombo.getSelectedItem().toString();

              if (zoom.equals(mxResources.get("page"))) {
                graphComponent.setPageVisible(true);
                graphComponent.setZoomPolicy(mxGraphComponent.ZOOM_POLICY_PAGE);
              } else if (zoom.equals(mxResources.get("width"))) {
                graphComponent.setPageVisible(true);
                graphComponent.setZoomPolicy(mxGraphComponent.ZOOM_POLICY_WIDTH);
              } else if (zoom.equals(mxResources.get("actualSize"))) {
                graphComponent.zoomActual();
              } else {
                try {
                  zoom = zoom.replace("%", "");
                  double scale = Math.min(16, Math.max(0.01, Double.parseDouble(zoom) / 100));
                  graphComponent.zoomTo(scale, graphComponent.isCenterZoom());
                } catch (Exception ex) {
                  JOptionPane.showMessageDialog(editor, ex.getMessage());
                }
              }
            }
          }
        });
  }
Esempio n. 2
0
  /** To support drag-drop of strings, and cut-copy-paste actions in the code window text editor. */
  protected void setShortcutKeystrokes() {
    final int SHORTCUT_KEY_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    InputMap imap = textarea.getInputMap();
    imap.put(
        KeyStroke.getKeyStroke('X', SHORTCUT_KEY_MASK),
        TransferHandler.getCutAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('C', SHORTCUT_KEY_MASK),
        TransferHandler.getCopyAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('V', SHORTCUT_KEY_MASK),
        TransferHandler.getPasteAction().getValue(Action.NAME));
    imap.put(KeyStroke.getKeyStroke('A', SHORTCUT_KEY_MASK), "selectAll");
    imap.put(KeyStroke.getKeyStroke('/', SHORTCUT_KEY_MASK), "commentUncomment");
    imap.put(KeyStroke.getKeyStroke(']', SHORTCUT_KEY_MASK), "increaseIndent");
    imap.put(KeyStroke.getKeyStroke('[', SHORTCUT_KEY_MASK), "decreaseIndent");

    ActionMap amap = textarea.getActionMap();
    amap.put(
        TransferHandler.getCutAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> cut "+e.getSource());
            ((JEditTextArea) e.getSource()).cut();
          }
        });
    amap.put(
        TransferHandler.getCopyAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> copy "+e.getSource());
            ((JEditTextArea) e.getSource()).copy();
          }
        });
    amap.put(
        TransferHandler.getPasteAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> paste "+e.getSource());
            ((JEditTextArea) e.getSource()).paste();
          }
        });
    amap.put(
        "selectAll",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> select all "+e.getSource());
            ((JEditTextArea) e.getSource()).selectAll();
          }
        });
    amap.put(
        "commentUncomment",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> comment
            // uncomment"+e.getSource());
            handleCommentUncomment();
          }
        });
    amap.put(
        "increaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> increaseIndent"+e.getSource());
            handleIndentOutdent(true);
          }
        });
    amap.put(
        "decreaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> decreaseIndent"+e.getSource());
            handleIndentOutdent(false);
          }
        });
  }