diff --git a/src/org/jetuml/gui/EditorFrame.java b/src/org/jetuml/gui/EditorFrame.java index e42fe494..718ec0fb 100644 --- a/src/org/jetuml/gui/EditorFrame.java +++ b/src/org/jetuml/gui/EditorFrame.java @@ -103,7 +103,6 @@ public EditorFrame(Stage pMainStage) { aMainStage = pMainStage; aDialogStage = new DialogStage(aMainStage); - RenderingUtils aRenderingUtility = new RenderingUtils(); // Acts as an observer for dark mode aRecentFiles.deserialize(Preferences.userNodeForPackage(JetUML.class).get("recent", "").trim()); MenuBar menuBar = new MenuBar(); @@ -129,6 +128,9 @@ public EditorFrame(Stage pMainStage) { getStylesheets().add(aDarkModeURL); aDialogStage.getScene().getStylesheets().add(aDarkModeURL); + RenderingUtils.setFill(RenderingUtils.DARK_MODE_FILL_COLOR); + RenderingUtils.setStroke(RenderingUtils.WHITE); + RenderingUtils.setDropShadow(RenderingUtils.DARK_MODE_DROPSHADOW); } setOnKeyPressed(e -> @@ -758,11 +760,18 @@ public void booleanPreferenceChanged(BooleanPreference pPreference) { getStylesheets().add(aDarkModeURL); aDialogStage.getScene().getStylesheets().add(aDarkModeURL); + RenderingUtils.setFill(RenderingUtils.DARK_MODE_FILL_COLOR); + RenderingUtils.setStroke(RenderingUtils.WHITE); + RenderingUtils.setDropShadow(RenderingUtils.DARK_MODE_DROPSHADOW); + } else { getStylesheets().remove(aDarkModeURL); aDialogStage.getScene().getStylesheets().remove(aDarkModeURL); + RenderingUtils.setFill(RenderingUtils.WHITE); + RenderingUtils.setStroke(RenderingUtils.BLACK); + RenderingUtils.setDropShadow(RenderingUtils.LIGHT_MODE_DROPSHADOW); } } } diff --git a/src/org/jetuml/rendering/RenderingUtils.java b/src/org/jetuml/rendering/RenderingUtils.java index dde6dced..e4d8e422 100644 --- a/src/org/jetuml/rendering/RenderingUtils.java +++ b/src/org/jetuml/rendering/RenderingUtils.java @@ -20,9 +20,6 @@ *******************************************************************************/ package org.jetuml.rendering; -import org.jetuml.application.UserPreferences; -import org.jetuml.application.UserPreferences.BooleanPreference; -import org.jetuml.application.UserPreferences.BooleanPreferenceChangeHandler; import org.jetuml.geom.Rectangle; import javafx.scene.canvas.GraphicsContext; @@ -40,36 +37,20 @@ * * In the method names, "draw" refers to stroke and fill. */ -public final class RenderingUtils implements BooleanPreferenceChangeHandler +public final class RenderingUtils { - private static Color aFill; - private static Color aStroke; - private static DropShadow aShadow; - private static final Color DARK_MODE_FILL_COLOR = Color.web("#1C1C1F"); - private static final DropShadow DARK_MODE_DROPSHADOW = new DropShadow(3, 3, 3, Color.web("#2f2f34")); - private static final DropShadow LIGHT_MODE_DROPSHADOW = new DropShadow(3, 3, 3, Color.LIGHTGRAY); + public static final Color WHITE = Color.WHITE; + public static final Color BLACK = Color.BLACK; + public static final Color DARK_MODE_FILL_COLOR = Color.web("#1C1C1F"); + public static final DropShadow LIGHT_MODE_DROPSHADOW = new DropShadow(3, 3, 3, Color.LIGHTGRAY); + public static final DropShadow DARK_MODE_DROPSHADOW = new DropShadow(3, 3, 3, Color.web("#2f2f34")); + private static Color aFill = WHITE; + private static Color aStroke = BLACK; + private static DropShadow aShadow = LIGHT_MODE_DROPSHADOW; private static final int ARC_SIZE = 20; - /** - * RenderingUtils should be a unique object which manages the - * color scheme of diagram elements depending on whether dark mode is on or off. - */ - public RenderingUtils() - { - if( UserPreferences.instance().getBoolean(BooleanPreference.darkMode) ) - { - aFill = DARK_MODE_FILL_COLOR; - aStroke = Color.WHITE; - aShadow = DARK_MODE_DROPSHADOW; - } - else - { - aFill = Color.WHITE; - aStroke = DARK_MODE_FILL_COLOR; - aShadow = LIGHT_MODE_DROPSHADOW; - } - UserPreferences.instance().addBooleanPreferenceChangeHandler(this); - } + private RenderingUtils() + {} /** * Getter for fill color. @@ -101,6 +82,36 @@ public static DropShadow getDropShadow() return aShadow; } + /** + * Getter for fill color. + * + * @return The fill color. + */ + public static void setFill(Color pColor) + { + aFill = pColor; + } + + /** + * Getter for stroke color. + * + * @return The stroke color. + */ + public static void setStroke(Color pColor) + { + aStroke = pColor; + } + + /** + * Getter for DropShadow. + * + * @return The DropShadow. + */ + public static void setDropShadow(DropShadow pShadow) + { + aShadow = pShadow; + } + /** * Draws a circle with default attributes, without a drop shadow. * @@ -242,24 +253,4 @@ public static void drawText(GraphicsContext pGraphics, int pX, int pY, String pT pGraphics.setFont(font); pGraphics.setFill(Color.WHITE); } - - @Override - public void booleanPreferenceChanged(BooleanPreference pPreference) - { - if( pPreference == BooleanPreference.darkMode ) - { - if( UserPreferences.instance().getBoolean(pPreference) ) - { - aFill = DARK_MODE_FILL_COLOR; - aStroke = Color.WHITE; - aShadow = DARK_MODE_DROPSHADOW; - } - else - { - aFill = Color.WHITE; - aStroke = DARK_MODE_FILL_COLOR; - aShadow = LIGHT_MODE_DROPSHADOW; - } - } - } } diff --git a/src/org/jetuml/rendering/ToolGraphics.java b/src/org/jetuml/rendering/ToolGraphics.java index 8e205621..31c0fcea 100644 --- a/src/org/jetuml/rendering/ToolGraphics.java +++ b/src/org/jetuml/rendering/ToolGraphics.java @@ -25,7 +25,6 @@ import org.jetuml.geom.Rectangle; import javafx.scene.canvas.GraphicsContext; -import javafx.scene.effect.DropShadow; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.shape.LineTo; @@ -151,7 +150,6 @@ public static void strokeSharpLine(GraphicsContext pGraphics, int pX1, int pY1, */ public static void strokeSharpPath(GraphicsContext pGraphics, Path pPath, LineStyle pStyle) { - //Paint oldStroke = pGraphics.getStroke(); pGraphics.setStroke(RenderingUtils.getStroke()); double[] oldDash = pGraphics.getLineDashes(); pGraphics.setLineDashes(pStyle.getLineDashes()); @@ -161,7 +159,6 @@ public static void strokeSharpPath(GraphicsContext pGraphics, Path pPath, LineSt pGraphics.stroke(); pGraphics.setLineDashes(oldDash); pGraphics.setLineWidth(width); - //pGraphics.setStroke(oldStroke); } private static void applyPath(GraphicsContext pGraphics, Path pPath)