diff --git a/src/main/java/com/github/creme332/controller/console/SideMenuController.java b/src/main/java/com/github/creme332/controller/console/SideMenuController.java index 7ac3de30..5bfd5b53 100644 --- a/src/main/java/com/github/creme332/controller/console/SideMenuController.java +++ b/src/main/java/com/github/creme332/controller/console/SideMenuController.java @@ -28,14 +28,13 @@ public class SideMenuController { """; private SideMenuPanel sidebar; + private AppState app; public SideMenuController(AppState app, SideMenuPanel sidebar) { + this.app = app; this.sidebar = sidebar; - // set default values in canvas settings - sidebar.getGridLinesCheckBox().setSelected(app.getCanvasModel().isGuidelinesEnabled()); - sidebar.getAxesCheckBox().setSelected(app.getCanvasModel().isAxesVisible()); - sidebar.getFontSizeSelector().setSelectedItem(String.format("%d", app.getCanvasModel().getLabelFontSize())); + refreshCanvasSettingsUI(); // Initialize button listeners initializeButtonListeners(app); @@ -55,6 +54,16 @@ public void mouseMoved(MouseEvent e) { }); } + /** + * Updates default values in canvas settings to match values from canvas model + */ + public void refreshCanvasSettingsUI() { + // set default values in canvas settings + sidebar.getGridLinesCheckBox().setSelected(app.getCanvasModel().isGuidelinesEnabled()); + sidebar.getAxesCheckBox().setSelected(app.getCanvasModel().isAxesVisible()); + sidebar.getFontSizeSelector().setSelectedItem(String.format("%d", app.getCanvasModel().getLabelFontSize())); + } + private void initializeButtonListeners(AppState app) { CanvasModel canvasModel = app.getCanvasModel(); @@ -123,17 +132,27 @@ public void mousePressed(MouseEvent e) { JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (confirmation == JOptionPane.YES_OPTION) { + boolean settingsChanged = false; // Reset guidelines checkbox and model - if (sidebar.getGridLinesCheckBox().isSelected()) { - sidebar.getGridLinesCheckBox().setSelected(false); + if (!canvasModel.isGuidelinesEnabled()) { + settingsChanged = true; canvasModel.setGuidelinesEnabled(true); } // Reset axes checkbox and model - if (sidebar.getAxesCheckBox().isSelected()) { - sidebar.getAxesCheckBox().setSelected(false); + if (!canvasModel.isAxesVisible()) { + settingsChanged = true; canvasModel.setAxesVisible(true); } + + // Reset font size + if (canvasModel.getLabelFontSize() != CanvasModel.DEFAULT_LABEL_FONT_SIZE) { + settingsChanged = true; + canvasModel.setLabelFontSize(CanvasModel.DEFAULT_LABEL_FONT_SIZE); + } + + if (settingsChanged) + refreshCanvasSettingsUI(); } }); } diff --git a/src/main/java/com/github/creme332/model/CanvasModel.java b/src/main/java/com/github/creme332/model/CanvasModel.java index 217d7379..dfa8ae5b 100644 --- a/src/main/java/com/github/creme332/model/CanvasModel.java +++ b/src/main/java/com/github/creme332/model/CanvasModel.java @@ -47,10 +47,12 @@ public class CanvasModel { */ int cellSize = Math.max(MIN_CELL_SIZE, Math.min(DEFAULT_CELL_SIZE, MAX_CELL_SIZE)); + public static final int DEFAULT_LABEL_FONT_SIZE = 20; + /** * Font size of labels on canvas in pixels. */ - private int labelFontSize = 20; + private int labelFontSize = DEFAULT_LABEL_FONT_SIZE; public static final Color labelForegroundColor = new Color(82, 82, 82);