diff --git a/src/main/java/com/github/creme332/controller/CanvasController.java b/src/main/java/com/github/creme332/controller/CanvasController.java index d495a2a6..01058562 100644 --- a/src/main/java/com/github/creme332/controller/CanvasController.java +++ b/src/main/java/com/github/creme332/controller/CanvasController.java @@ -176,8 +176,7 @@ private void resetCanvasView() { model.setXZero(canvas.getWidth() / 2); model.setYZero(canvas.getHeight() / 2); - // reset zoom level - model.setCellSize(CanvasModel.DEFAULT_CELL_SIZE); + model.resetZoom(); canvas.repaint(); } @@ -195,7 +194,8 @@ public void propertyChange(PropertyChangeEvent e) { } // if guidelines were toggled or zoom was changed or axes were toggled - if ("enableGuidelines".equals(propertyName) || "zoomChange".equals(propertyName) || "axesVisible".equals(propertyName)) { + if ("enableGuidelines".equals(propertyName) || "cellSize".equals(propertyName) + || "axesVisible".equals(propertyName)) { canvas.repaint(); return; } diff --git a/src/main/java/com/github/creme332/model/CanvasModel.java b/src/main/java/com/github/creme332/model/CanvasModel.java index bf1fb85c..32be11fd 100644 --- a/src/main/java/com/github/creme332/model/CanvasModel.java +++ b/src/main/java/com/github/creme332/model/CanvasModel.java @@ -145,17 +145,25 @@ public Point2D toPolySpace(Point2D point) { * @param zoomIn Zoom in if true, zoom out otherwise */ public void updateCanvasZoom(boolean zoomIn) { - support.firePropertyChange("guidelines", null, zoomIn); + int newCellSize; if (zoomIn) { - setCellSize(Math.min(CanvasModel.MAX_CELL_SIZE, getCellSize() + CanvasModel.ZOOM_INCREMENT)); + newCellSize = (Math.min(CanvasModel.MAX_CELL_SIZE, getCellSize() + CanvasModel.ZOOM_INCREMENT)); } else { - setCellSize(Math.max(CanvasModel.MIN_CELL_SIZE, getCellSize() - CanvasModel.ZOOM_INCREMENT)); + newCellSize = (Math.max(CanvasModel.MIN_CELL_SIZE, getCellSize() - CanvasModel.ZOOM_INCREMENT)); } + support.firePropertyChange("cellSize", cellSize, newCellSize); + cellSize = newCellSize; + } + + public void resetZoom() { + support.firePropertyChange("cellSize", cellSize, DEFAULT_CELL_SIZE); + cellSize = DEFAULT_CELL_SIZE; } public void addPropertyChangeListener(PropertyChangeListener listener) { support.addPropertyChangeListener("enableGuidelines", listener); support.addPropertyChangeListener("axesVisible", listener); + support.addPropertyChangeListener("cellSize", listener); } public List getShapes() { @@ -174,10 +182,6 @@ public float getLabelFontSizeSF() { return labelFontSizeScaleFactor; } - public void setCellSize(int newCellSize) { - cellSize = newCellSize; - } - public int getXZero() { return xZero; }