/** 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()); } } }); }
@Override protected void setHasUnsavedChanges(boolean newValue) { super.setHasUnsavedChanges(newValue); undo.setHasSignificantEdits(newValue); }
/** Initializes view specific actions. */ private void initActions() { getActionMap().put(UndoAction.ID, undo.getUndoAction()); getActionMap().put(RedoAction.ID, undo.getRedoAction()); }