Skip to content

Commit

Permalink
Added dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole committed Jul 22, 2021
1 parent bbc27bb commit 0a3ad9a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/main/java/com/BlendGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@

public class BlendGUI extends Application {

Logger log = Logger.getLogger(BlendGUI.class.getSimpleName());
String currentTheme = "LIGHT";

Logger log = Logger.getLogger(BlendGUI.class.getSimpleName());
String defaultFont = "Arial";

protected static String currentNick;
Expand Down Expand Up @@ -147,9 +148,7 @@ public void start(Stage stage) throws Exception {
Menu menuFile = new Menu("File");

MenuItem saveItem = new MenuItem("Save");
saveItem.setOnAction( e -> {
trySave(stage, codeFields);
});
saveItem.setOnAction( e -> trySave(stage, codeFields));

MenuItem loadItem = new MenuItem("Load");
loadItem.setOnAction( e -> {
Expand All @@ -166,7 +165,7 @@ public void start(Stage stage) throws Exception {


// Menu - Edit
Menu menuEdit = new Menu("Tools");
Menu menuTools = new Menu("Tools");

MenuItem copyItem = new MenuItem("Copy To Clipboard");
copyItem.setOnAction( e -> {
Expand All @@ -177,9 +176,11 @@ public void start(Stage stage) throws Exception {
}
});

menuEdit.getItems().add(copyItem);
MenuItem programTheme = new MenuItem("Dark Mode");

menuBar.getMenus().addAll(menuFile, menuEdit);
menuTools.getItems().addAll(copyItem, programTheme);

menuBar.getMenus().addAll(menuFile, menuTools);

VBox mainBox = new VBox();

Expand Down Expand Up @@ -296,12 +297,13 @@ public void start(Stage stage) throws Exception {

mainBox.getChildren().addAll(codesAndPicker, nickInput, previewCopyPane);

VBox emptyBox = new VBox();
emptyBox.setMaxSize(0, 0);

Scene mainScene = new Scene(mainBox);
((VBox)mainScene.getRoot()).getChildren().addAll(menuBar);

programTheme.setOnAction(e -> {
changeTheme(programTheme, mainScene);
});

menuBar.toBack();
mainBox.toFront();

Expand Down Expand Up @@ -480,6 +482,29 @@ public String generateRandomHex(){
return rndHex;
}

public void changeTheme(MenuItem programTheme, Scene mainScene){

if(currentTheme.equals("LIGHT")){
goDark(mainScene, programTheme);
currentTheme = "DARK";
}
else{
goLight(mainScene, programTheme);
currentTheme = "LIGHT";
}

}

public void goDark(Scene mainScene, MenuItem programTheme){
mainScene.getStylesheets().add(getClass().getResource("dark.css").toString());
programTheme.setText("Light Mode");
}

public void goLight(Scene mainScene, MenuItem programTheme){
mainScene.getStylesheets().remove(getClass().getResource("dark.css").toString());
programTheme.setText("Dark Mode");
}

public static void main(String[] args) {
launch();
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.root {
-fx-base: #3f474f;
-fx-accent: #e7eff7 ;
-fx-default-button: #7f878f ;
-fx-focus-color: #efefef;
-fx-faint-focus-color: #efefef22;
-fx-focused-text-base-color : ladder(
-fx-selection-bar,
-fx-light-text-color 45%,
-fx-dark-text-color 46%,
-fx-dark-text-color 59%,
-fx-mid-text-color 60%
);
-fx-focused-mark-color : -fx-focused-text-base-color ;

}

.text-input:focused {
-fx-highlight-text-fill: ladder(
-fx-highlight-fill,
-fx-light-text-color 45%,
-fx-dark-text-color 46%,
-fx-dark-text-color 59%,
-fx-mid-text-color 60%
);
}

0 comments on commit 0a3ad9a

Please sign in to comment.