Skip to content

Commit

Permalink
Merge pull request #198 from triya12/main
Browse files Browse the repository at this point in the history
persist canvas settings across sessions
  • Loading branch information
creme332 authored Aug 7, 2024
2 parents 8521e4f + fdf312c commit 5cde41c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/com/github/creme332/model/CanvasModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.beans.PropertyChangeSupport;
import java.awt.Color;
import java.awt.Dimension;
import java.util.prefs.Preferences;

public class CanvasModel {
private Dimension canvasDimension;
Expand Down Expand Up @@ -85,14 +86,24 @@ public class CanvasModel {
/**
* Mouse position of user on canvas in polyspace coordinates.
*/
Point2D userMousePosition;
private Point2D userMousePosition;

ShapeManager shapeManager = new ShapeManager();
private ShapeManager shapeManager = new ShapeManager();

/**
* Index of shape on which user clicked when in Mode.MOVE_CANVAS.
*/
int selectedShapeIndex = -1;
private int selectedShapeIndex = -1;

private Preferences canvasPreferences;

public CanvasModel() {
canvasPreferences = Preferences.userNodeForPackage(CanvasModel.class);

this.labelFontSize = canvasPreferences.getInt("labelFontSize", DEFAULT_LABEL_FONT_SIZE);
this.axesVisible = canvasPreferences.getBoolean("axesVisible", true);
this.enableGuidelines = canvasPreferences.getBoolean("enableGuidelines", true);
}

public ShapeManager getShapeManager() {
return shapeManager;
Expand Down Expand Up @@ -276,6 +287,7 @@ public void setLabelFontSize(int newFontSize) {
final int oldFontSize = labelFontSize;
labelFontSize = newFontSize;
support.firePropertyChange("labelFontSize", oldFontSize, newFontSize);
canvasPreferences.putInt("labelFontSize", newFontSize);
}

public int getLabelFontSize() {
Expand Down Expand Up @@ -306,6 +318,7 @@ public void setGuidelinesEnabled(boolean enableGuidelines) {
final boolean oldValue = this.enableGuidelines;
this.enableGuidelines = enableGuidelines;
support.firePropertyChange("enableGuidelines", oldValue, enableGuidelines);
canvasPreferences.putBoolean("enableGuidelines", enableGuidelines);
}

public LineType getLineType() {
Expand Down Expand Up @@ -340,5 +353,6 @@ public void setAxesVisible(boolean axesVisible) {
final boolean oldValue = this.axesVisible;
this.axesVisible = axesVisible;
support.firePropertyChange("axesVisible", oldValue, axesVisible);
canvasPreferences.putBoolean("axesVisible", axesVisible);
}
}

0 comments on commit 5cde41c

Please sign in to comment.