Skip to content

Commit

Permalink
Added dark mode (#231)
Browse files Browse the repository at this point in the history
* Added dark mode

Co-Authored-By: tomerisraeli <tomer.israeli19@gmail.com>

* Fix style

* Fix style

Co-authored-by: Noam Zaks <noamzaks@outlook.com>
Co-authored-by: tomerisraeli <tomer.israeli19@gmail.com>
  • Loading branch information
3 people committed Apr 4, 2021
1 parent 5e8ea0c commit 1de5666
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 18 deletions.
10 changes: 10 additions & 0 deletions src/main/java/edu/wpi/first/pathweaver/FxUtils.java
Expand Up @@ -13,6 +13,7 @@
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.MenuItem;
Expand Down Expand Up @@ -157,6 +158,7 @@ private static TextFormatter<Object> textRestriction(String regex) {
*/
public static boolean promptDelete(String value) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
applyDarkMode(alert);
alert.setTitle("Delete " + value + "?");
alert.setHeaderText("Delete " + value + "?");
alert.setContentText("Are you sure you want to delete: " + value + "?");
Expand All @@ -166,4 +168,12 @@ public static boolean promptDelete(String value) {
}
return false;
}

public static void applyDarkMode(Alert alert){
final boolean darkIsOn = PathWeaver.mainScene.getStylesheets().contains(FxUtils.class.getResource("dark.css").toExternalForm());
if(darkIsOn) {
DialogPane dp = alert.getDialogPane();
dp.getStylesheets().add(FxUtils.class.getResource("dark.css").toExternalForm());
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/edu/wpi/first/pathweaver/MainController.java
Expand Up @@ -346,11 +346,13 @@ private void buildPaths() {

if(!path.getSpline().writeToFile(pathNameFile)) {
Alert alert = new Alert(Alert.AlertType.WARNING);
FxUtils.applyDarkMode(alert);
alert.setTitle("Path export failure!");
alert.setContentText("Could not export to: " + output.toAbsolutePath());
}
}
Alert alert = new Alert(Alert.AlertType.INFORMATION);
FxUtils.applyDarkMode(alert);
alert.setTitle("Paths exported!");
alert.setContentText("Paths exported to: " + output.toAbsolutePath());

Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/wpi/first/pathweaver/PathCell.java
Expand Up @@ -106,6 +106,7 @@ public void commitEdit(String newValue) {
} else {
editing = false;
Alert a = new Alert(Alert.AlertType.INFORMATION);
FxUtils.applyDarkMode(a);
a.setTitle("");
a.setHeaderText("The item could not be renamed.");
String content = String.format("The name \"%s\" is already used in this location. \n"
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/edu/wpi/first/pathweaver/PathWeaver.java
Expand Up @@ -2,11 +2,9 @@

import edu.wpi.first.math.WPIMathJNI;
import edu.wpi.first.pathweaver.extensions.ExtensionManager;

import edu.wpi.first.wpiutil.CombinedRuntimeLoader;
import edu.wpi.first.wpiutil.WPIUtilJNI;
import java.io.IOException;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
Expand All @@ -15,21 +13,26 @@
import javafx.stage.Stage;

public class PathWeaver extends Application {
public static Scene mainScene;

@Override
public void start(Stage primaryStage) throws IOException {
WPIUtilJNI.Helper.setExtractOnStaticLoad(false);
WPIMathJNI.Helper.setExtractOnStaticLoad(false);
CombinedRuntimeLoader.loadLibraries(PathWeaver.class, "wpiutiljni", "wpimathjni");
CombinedRuntimeLoader.loadLibraries(PathWeaver.class, "wpiutiljni",
"wpimathjni");

ExtensionManager.getInstance().refresh();
Pane root = FXMLLoader.load(getClass().getResource("welcomeScreen.fxml"));
Scene scene = new Scene(root);
this.mainScene = new Scene(root);
primaryStage.setTitle("PathWeaver - " + getVersion());
// Work around dialog bug
// See https://stackoverflow.com/questions/55190380/javafx-creates-alert-dialog-which-is-too-small
// See
// https://stackoverflow.com/questions/55190380/javafx-creates-alert-dialog-which-is-too-small
primaryStage.setResizable(true);
primaryStage.onShownProperty().addListener(e -> Platform.runLater(() -> primaryStage.setResizable(false)));
primaryStage.setScene(scene);
primaryStage.onShownProperty().addListener(
e -> Platform.runLater(() -> primaryStage.setResizable(false)));
primaryStage.setScene(this.mainScene);
primaryStage.show();
Loggers.setupLoggers();
}
Expand Down
Expand Up @@ -33,6 +33,7 @@ private ProgramPreferences() {
updatePrefs();
} catch (JsonParseException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
FxUtils.applyDarkMode(alert);
alert.setTitle("Preferences import error");
alert.setContentText(
"Preferences have been reset due to file corruption. You may reimport your projects with the 'Import Project' button");
Expand Down
Expand Up @@ -73,6 +73,7 @@ private ProjectPreferences(String directory) {
values.exportUnit = "Same as Project";

Alert alert = new Alert(Alert.AlertType.WARNING);
FxUtils.applyDarkMode(alert);
alert.setTitle("Export Units Warning");
alert.setContentText(
"Your project was imported from an older version of PathWeaver, where the exported units were always in the specified units. " +
Expand All @@ -84,6 +85,7 @@ private ProjectPreferences(String directory) {
}
} catch (JsonParseException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
FxUtils.applyDarkMode(alert);
alert.setTitle("Preferences import error");
alert.setContentText(
"Preferences have been reset due to file corruption. You may have to reconfigure your project.");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/wpi/first/pathweaver/SaveManager.java
Expand Up @@ -52,6 +52,7 @@ public boolean promptSaveAll() {
public boolean promptSaveAll(boolean allowCancel) {
for (Path path : paths) {
Alert alert = new Alert(Alert.AlertType.NONE);
FxUtils.applyDarkMode(alert);
alert.setTitle(path.getPathName() + " has been modified");
alert.setContentText("Save " + path.getPathName() + "?");
alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
Expand Down
37 changes: 26 additions & 11 deletions src/main/java/edu/wpi/first/pathweaver/WelcomeController.java
Expand Up @@ -8,7 +8,6 @@
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
Expand All @@ -22,19 +21,18 @@

@SuppressWarnings("PMD.UnusedPrivateMethod")
public class WelcomeController {
public static boolean dark;

@FXML
private BorderPane borderPane;
@FXML
private ListView<String> projects;
@FXML
private Label version;
@FXML private BorderPane borderPane;
@FXML private ListView<String> projects;
@FXML private Label version;

@FXML
private void initialize() {
version.setText(PathWeaver.getVersion());

projects.getItems().setAll(ProgramPreferences.getInstance().getRecentProjects());
projects.getItems().setAll(
ProgramPreferences.getInstance().getRecentProjects());

projects.setOnMouseClicked(event -> {
String folder = projects.getSelectionModel().getSelectedItem();
Expand All @@ -54,7 +52,6 @@ private void createProject() {
Logger log = Logger.getLogger(getClass().getName());
log.log(Level.WARNING, "Couldn't load create project screen", e);
}

}

private void loadProject(String folder) {
Expand All @@ -69,6 +66,7 @@ private void loadProject(String folder) {

private void invalidProject(String folder) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
FxUtils.applyDarkMode(alert);
alert.setTitle("Project Does Not Exist!");
alert.setHeaderText("The project does not exist.");
alert.setContentText("What do you want to do?");
Expand All @@ -89,7 +87,8 @@ private void invalidProject(String folder) {
@FXML
private void importProject() {
DirectoryChooser chooser = new DirectoryChooser();
File selectedDirectory = chooser.showDialog(borderPane.getScene().getWindow());
File selectedDirectory =
chooser.showDialog(borderPane.getScene().getWindow());
if (selectedDirectory != null) {
ProgramPreferences.getInstance().addProject(selectedDirectory.getPath());
loadProject(selectedDirectory.getPath());
Expand All @@ -98,6 +97,22 @@ private void importProject() {

@FXML
private void help() throws URISyntaxException, IOException {
Desktop.getDesktop().browse(new URI("https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/pathweaver/index.html"));
Desktop.getDesktop().browse(new URI(
"https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/pathweaver/index.html"));
}

@FXML
private void darkToggle() {
final String darkModeFile = "dark.css";
final boolean darkIsOn = PathWeaver.mainScene.getStylesheets().contains(
getClass().getResource(darkModeFile).toExternalForm());
if (darkIsOn) {
PathWeaver.mainScene.getStylesheets().removeAll(
getClass().getResource(darkModeFile).toExternalForm());
} else {
PathWeaver.mainScene.getStylesheets().add(
getClass().getResource(darkModeFile).toExternalForm());
}
dark = !darkIsOn;
}
}
2 changes: 2 additions & 0 deletions src/main/java/edu/wpi/first/pathweaver/path/Path.java
Expand Up @@ -2,6 +2,7 @@

import com.sun.javafx.collections.ObservableListWrapper;
import edu.wpi.first.pathweaver.Field;
import edu.wpi.first.pathweaver.FxUtils;
import edu.wpi.first.pathweaver.ProjectPreferences;
import edu.wpi.first.pathweaver.Waypoint;
import edu.wpi.first.pathweaver.global.CurrentSelections;
Expand Down Expand Up @@ -250,6 +251,7 @@ public void flip(boolean horizontal, Pane drawPane) {
for (Waypoint wp : waypoints) {
if (!drawPane.contains(reflectPoint(getStart(), wp, horizontal, false))) {
Alert a = new Alert(Alert.AlertType.INFORMATION);
FxUtils.applyDarkMode(a);
a.setTitle("");
a.setHeaderText("The path could not be flipped.");
a.setContentText("Flipping this path would cause it to go out of bounds");
Expand Down
107 changes: 107 additions & 0 deletions src/main/resources/edu/wpi/first/pathweaver/dark.css
@@ -0,0 +1,107 @@
.root {
-fx-background: #2e3032;
-fx-base: #252628;
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}

.table-view {
-fx-background-color: #202020;
}

.titled-pane > .title {
-fx-background-color: #212323;
-fx-border-color: black;
-fx-border-width: 1px 1px 0px 1px;
}

.menu-bar{
-fx-background-color: #1c1e20;
-fx-border-color: black;
-fx-border-width: 0px 0px 1px 0px;
}

.menu:hover , .menu:focused, .menu:pressed, .menu:showing{
-fx-background-color: #434547;
}

.menu-item{
-fx-background-color: #202020;
-fx-border-width: 0;
}

.menu-item:hover {
-fx-background-color: #303030;
}

.menu-item:disabled {
-fx-background-color: #3b3b3b;
}

.separator{
-fx-color: #303030;
}

.context-menu {
-fx-background-color: #202020;
}

.tab-header-area , .tab-header-background{
-fx-background-color: rgba(0,0,0,0);
-fx-border-width: 0 0 1 0;
-fx-border-color: black;
}

.tab-pane:focused > .tab-header-area > .headers-region > .tab:selected .focus-indicator {
-fx-border-color: black;
}

.tab:hover{
-fx-border-width: 1;
-fx-background-color: #404040;
}

.tab:selected{
-fx-background-color: #565a5c;
}

.choice-box{
-fx-background-color: #938f8e;
}

.column-resize-line{
-fx-background-color: #938f8e;
}

.table-view{
-fx-selection-bar: rgb(126,12,46);
-fx-selection-bar-non-focused: #252628;
}

.text-field{
-fx-highlight-fill: rgb(126,12,46);
}

.dialog-pane .button{
-fx-background-color: #525358;
-fx-text-fill: white;
}

.dialog-pane .button:hover{
-fx-background-color: #5e5f64;
}

.header-panel {
-fx-background-color: #252525;
-fx-border-width: 0 0 1 0;
-fx-border-color: black;
}

.list-view{
-fx-background-color: #484848;
}

.tree-cell:selected, .list-cell:selected {
-fx-background-color: rgb(126,12,46);
-fx-text-fill: white;
}
Expand Up @@ -40,6 +40,7 @@
</children>
</HBox>
<Button fx:id="help" mnemonicParsing="false" onAction="#help" text="Help" />
<Button fx:id="darkToggle" mnemonicParsing="false" onAction="#darkToggle" text="Toggle Dark Mode" />
</children>
<BorderPane.margin>
<Insets bottom="20.0" left="10.0" right="10.0" top="10.0" />
Expand Down

0 comments on commit 1de5666

Please sign in to comment.