Skip to content

Commit

Permalink
[prmr#538] Move observer in RenderingUtils to EditorFrame.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoding7 committed May 27, 2024
1 parent 85c869a commit df6d5bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
11 changes: 10 additions & 1 deletion src/org/jetuml/gui/EditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 ->
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
91 changes: 41 additions & 50 deletions src/org/jetuml/rendering/RenderingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
}
}
3 changes: 0 additions & 3 deletions src/org/jetuml/rendering/ToolGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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)
Expand Down

0 comments on commit df6d5bc

Please sign in to comment.