Esempio n. 1
0
  /** Creates a new view. */
  public NetView() {
    initComponents();

    scrollPane.setLayout(new PlacardScrollPaneLayout());
    scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));

    setEditor(new DefaultDrawingEditor());
    undo = new UndoRedoManager();
    view.setDrawing(createDrawing());
    view.getDrawing().addUndoableEditListener(undo);
    initActions();
    undo.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            setHasUnsavedChanges(undo.hasSignificantEdits());
          }
        });

    ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");

    JPanel placardPanel = new JPanel(new BorderLayout());
    javax.swing.AbstractButton pButton;
    pButton = ButtonFactory.createZoomButton(view);
    pButton.putClientProperty("Quaqua.Button.style", "placard");
    pButton.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
    pButton.setFont(UIManager.getFont("SmallSystemFont"));
    placardPanel.add(pButton, BorderLayout.WEST);
    toggleGridButton = pButton = ButtonFactory.createToggleGridButton(view);
    pButton.putClientProperty("Quaqua.Button.style", "placard");
    pButton.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
    pButton.setFont(UIManager.getFont("SmallSystemFont"));
    labels.configureToolBarButton(pButton, "view.toggleGrid.placard");
    placardPanel.add(pButton, BorderLayout.EAST);
    scrollPane.add(placardPanel, JScrollPane.LOWER_LEFT_CORNER);

    toggleGridButton.setSelected(preferences.getBoolean("view.gridVisible", false));
    view.setScaleFactor(preferences.getDouble("view.scaleFactor", 1d));

    view.addPropertyChangeListener(
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if ("scaleFactor".equals(name)) {
              preferences.putDouble("view.scaleFactor", (Double) evt.getNewValue());
              firePropertyChange("scaleFactor", evt.getOldValue(), evt.getNewValue());
            }
          }
        });
  }
Esempio n. 2
0
  /** Creates new instance. */
  public ODGDrawingPanel() {
    ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
    initComponents();
    undoManager = new UndoRedoManager();
    editor = new DefaultDrawingEditor();
    editor.add(view);

    addCreationButtonsTo(creationToolbar, editor);
    ButtonFactory.addAttributesButtonsTo(attributesToolbar, editor);

    JPopupButton pb = new JPopupButton();
    pb.setItemFont(UIManager.getFont("MenuItem.font"));
    labels.configureToolBarButton(pb, "actions");
    pb.add(new DuplicateAction());
    pb.addSeparator();
    pb.add(new GroupAction(editor));
    pb.add(new UngroupAction(editor));
    pb.addSeparator();
    pb.add(new BringToFrontAction(editor));
    pb.add(new SendToBackAction(editor));
    pb.addSeparator();
    pb.add(new CutAction());
    pb.add(new CopyAction());
    pb.add(new PasteAction());
    pb.add(new SelectAllAction());
    pb.add(new SelectSameAction(editor));
    pb.addSeparator();
    pb.add(undoManager.getUndoAction());
    pb.add(undoManager.getRedoAction());
    // FIXME - We need a toggle grid action
    // pb.addSeparator();
    // pb.add(new ToggleGridAction(editor));

    JMenu m = new JMenu(labels.getString("view.zoomFactor.text"));
    JRadioButtonMenuItem rbmi;
    ButtonGroup group = new ButtonGroup();
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.1, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.25, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.5, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.75, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.0, null)));
    rbmi.setSelected(true);
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.25, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.5, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 2, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 3, null)));
    group.add(rbmi);
    m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 4, null)));
    group.add(rbmi);
    pb.add(m);
    pb.setFocusable(false);
    creationToolbar.addSeparator();
    creationToolbar.add(pb);

    DefaultDrawing drawing = new DefaultDrawing();
    view.setDrawing(drawing);
    drawing.addUndoableEditListener(undoManager);
  }
Esempio n. 3
0
 public void setDrawing(Drawing d) {
   undoManager.discardAllEdits();
   view.getDrawing().removeUndoableEditListener(undoManager);
   view.setDrawing(d);
   d.addUndoableEditListener(undoManager);
 }
Esempio n. 4
0
 @Override
 protected void setHasUnsavedChanges(boolean newValue) {
   super.setHasUnsavedChanges(newValue);
   undo.setHasSignificantEdits(newValue);
 }
Esempio n. 5
0
 /** Initializes view specific actions. */
 private void initActions() {
   getActionMap().put(UndoAction.ID, undo.getUndoAction());
   getActionMap().put(RedoAction.ID, undo.getRedoAction());
 }