Skip to content

Commit

Permalink
[prmr#538] Add dark mode for Properties and Alert dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoding7 committed Jun 5, 2024
1 parent 2f6b689 commit 3f6ffb3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/org/jetuml/gui/DiagramCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void editSelected()
Optional<DiagramElement> edited = getLastSelected();
if( edited.isPresent() )
{
PropertyEditorDialog dialog = new PropertyEditorDialog((Stage)getScene().getWindow(),
PropertyEditorDialog dialog = new PropertyEditorDialog( ((EditorFrame) getScene().getRoot()).getDialogStage(),
edited.get(), ()-> paintPanel());

CompoundOperation operation = dialog.show();
Expand Down
1 change: 1 addition & 0 deletions src/org/jetuml/gui/DiagramTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
* A tab holding a single diagram.
Expand Down
12 changes: 8 additions & 4 deletions src/org/jetuml/gui/DialogStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@

/**
* A Stage that is to be shared by different dialogs.
* Different dialogs sharing a common stage simplifies
* applying the dark mode theme to the dialogs.
* Different dialogs sharing a common stage simplifies applying
* the dark mode theme to the dialogs. There is only one DialogStage
* in the program's life cycle.
*/
public class DialogStage extends Stage
{
/**
* Creates the stage for different dialogs.
* Dialogs that use this stage should not change the scene - doing
* so will stop applying the dark theme to dialogs. Instead,
* dialogs can customize the UI by reassigning the root of the scene.
*
* @param pOwner The main JetUML stage.
*/
public DialogStage(Stage pOwner)
{
Scene dialogScene = new Scene(new GridPane());
setScene(dialogScene);
// The root is defined only for compilation.
setScene(new Scene(new GridPane()));
setResizable(false);
initModality(Modality.WINDOW_MODAL);
initOwner(pOwner);
Expand Down
25 changes: 24 additions & 1 deletion src/org/jetuml/gui/EditorFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ private void open(File pFile)
{
Alert alert = new DeserializationErrorAlert(exception);
alert.initOwner(aMainStage);
applyDarkTheme(alert);
alert.showAndWait();
}
}
Expand Down Expand Up @@ -441,6 +442,7 @@ private void close()
alert.initOwner(aMainStage);
alert.setTitle(RESOURCES.getString("dialog.close.title"));
alert.setHeaderText(RESOURCES.getString("dialog.close.title"));
applyDarkTheme(alert);
alert.showAndWait();

if(alert.getResult() == ButtonType.YES)
Expand Down Expand Up @@ -469,6 +471,7 @@ public void close(DiagramTab pDiagramTab)
alert.initOwner(aMainStage);
alert.setTitle(RESOURCES.getString("dialog.close.title"));
alert.setHeaderText(RESOURCES.getString("dialog.close.title"));
applyDarkTheme(alert);
alert.showAndWait();

if(alert.getResult() == ButtonType.YES)
Expand Down Expand Up @@ -507,6 +510,7 @@ private void save()
{
Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
alert.initOwner(aMainStage);
applyDarkTheme(alert);
alert.showAndWait();
}
}
Expand Down Expand Up @@ -552,6 +556,7 @@ private void saveAs()
{
Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
alert.initOwner(aMainStage);
applyDarkTheme(alert);
alert.showAndWait();
}
}
Expand Down Expand Up @@ -623,6 +628,7 @@ else if("bmp".equals(format)) // to correct the BufferedImage type
{
Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
alert.initOwner(aMainStage);
applyDarkTheme(alert);
alert.showAndWait();
}
}
Expand Down Expand Up @@ -684,6 +690,7 @@ public void exit()
alert.initOwner(aMainStage);
alert.setTitle(RESOURCES.getString("dialog.exit.title"));
alert.setHeaderText(RESOURCES.getString("dialog.exit.title"));
applyDarkTheme(alert);
alert.showAndWait();

if(alert.getResult() == ButtonType.YES)
Expand All @@ -699,6 +706,16 @@ public void exit()
}
}

/**
* Getter for the dialog stage.
*
* @return The dialog stage.
*/
public Stage getDialogStage()
{
return aDialogStage;
}

private List<Tab> tabs()
{
return ((TabPane) getCenter()).getTabs();
Expand Down Expand Up @@ -749,7 +766,13 @@ private void removeGraphFrameFromTabbedPane(DiagramTab pTab)
showWelcomeTabIfNecessary();
}


private void applyDarkTheme(Alert pAlert)
{
if( UserPreferences.instance().getBoolean(BooleanPreference.darkMode) )
{
pAlert.getDialogPane().getStylesheets().add(aDarkModeURL);
}
}

@Override
public void booleanPreferenceChanged(BooleanPreference pPreference)
Expand Down
21 changes: 10 additions & 11 deletions src/org/jetuml/gui/PropertyEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;

Expand All @@ -48,34 +49,32 @@ public class PropertyEditorDialog
{
private static final int LAYOUT_PADDING = 20;

private final Stage aStage = new Stage();
private final Stage aStage;
private final DiagramElement aElement;

/**
* Creates a new dialog.
*
* @param pOwner The stage that owns this stage.
* @param pDialogStage The stage that owns this stage.
* @param pElement The element to edit with this dialog.
* @param pPropertyChangeListener A callback to run whenever a property changes.
*/
public PropertyEditorDialog( Stage pOwner, DiagramElement pElement,
public PropertyEditorDialog( Stage pDialogStage, DiagramElement pElement,
PropertySheet.PropertyChangeListener pPropertyChangeListener )
{
aStage = pDialogStage;
aElement = pElement;
prepareStage(pOwner);
aStage.setScene(createScene(pPropertyChangeListener));
prepareStage();
aStage.getScene().setRoot(createRoot(pPropertyChangeListener));
}

private void prepareStage(Stage pOwner)
private void prepareStage()
{
aStage.setResizable(false);
aStage.initModality(Modality.APPLICATION_MODAL);
aStage.initOwner(pOwner);
aStage.setTitle(RESOURCES.getString("dialog.properties"));
aStage.getIcons().add(new Image(RESOURCES.getString("application.icon")));
}

private Scene createScene(PropertySheet.PropertyChangeListener pPropertyChangeListener)
private Pane createRoot(PropertySheet.PropertyChangeListener pPropertyChangeListener)
{
PropertySheet sheet = new PropertySheet(aElement, pPropertyChangeListener);

Expand All @@ -92,7 +91,7 @@ private Scene createScene(PropertySheet.PropertyChangeListener pPropertyChangeLi
layout.setCenter(sheet);
layout.setBottom(button);

return new Scene(layout);
return layout;
}

private PropertySheet getPropertySheet()
Expand Down
2 changes: 1 addition & 1 deletion src/org/jetuml/gui/tips/TipDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static HBox createEmptyTipMenu()
{
HBox tipMenu = new HBox();
tipMenu.setPadding(new Insets(PADDING));
tipMenu.setStyle("-fx-background-color: gainsboro;");
tipMenu.setStyle("-fx-background-color: slategrey;");

BorderStroke bs = new BorderStroke(Color.DARKGRAY, BorderStrokeStyle.SOLID,
CornerRadii.EMPTY, BorderWidths.DEFAULT);
Expand Down

0 comments on commit 3f6ffb3

Please sign in to comment.