8
8
import javafx .scene .control .Alert ;
9
9
import javafx .scene .control .Button ;
10
10
import javafx .scene .control .ButtonType ;
11
+ import javafx .scene .control .DialogPane ;
11
12
import javafx .scene .layout .AnchorPane ;
12
13
import javafx .stage .Modality ;
13
14
import javafx .stage .Stage ;
14
15
import javafx .stage .WindowEvent ;
16
+ import programminglife .gui .Alerts ;
15
17
import programminglife .gui .controller .GuiController ;
16
18
import programminglife .parser .Cache ;
17
- import programminglife .utility .Alerts ;
18
19
import programminglife .utility .Console ;
19
20
20
21
import java .io .File ;
28
29
public final class ProgrammingLife extends Application {
29
30
30
31
private static Stage primaryStage ;
32
+ private static boolean showCSS = false ;
33
+ private static AnchorPane root ;
31
34
32
35
/**
33
36
* Main method for the application.
37
+ *
34
38
* @param args argument
35
39
*/
36
40
public static void main (String [] args ) {
@@ -40,7 +44,8 @@ public static void main(String[] args) {
40
44
@ Override
41
45
public void start (Stage stage ) throws IOException {
42
46
FXMLLoader loader = new FXMLLoader (getClass ().getResource ("/Basic_Gui.fxml" ));
43
- AnchorPane root = loader .load ();
47
+ root = loader .load ();
48
+ root .getStylesheets ().add ("/LightTheme.css" );
44
49
primaryStage = stage ;
45
50
primaryStage .setTitle ("Programming Life" );
46
51
primaryStage .setScene (new Scene (root ));
@@ -49,8 +54,8 @@ public void start(Stage stage) throws IOException {
49
54
close .setOnAction (event -> primaryStage .fireEvent (
50
55
new WindowEvent (primaryStage , WindowEvent .WINDOW_CLOSE_REQUEST ))
51
56
);
52
- primaryStage .setMinWidth (600 );
53
- primaryStage .setMinHeight (400 );
57
+ primaryStage .setMinWidth (1280 );
58
+ primaryStage .setMinHeight (720 );
54
59
primaryStage .sizeToScene ();
55
60
primaryStage .show ();
56
61
primaryStage .setMaximized (true );
@@ -65,6 +70,7 @@ public void start(Stage stage) throws IOException {
65
70
66
71
/**
67
72
* Process command line arguments.
73
+ *
68
74
* @param guiCtrl the {@link GuiController}, needed for opening files
69
75
* @throws IOException if a specified file cannot be opened
70
76
*/
@@ -85,8 +91,14 @@ private void arguments(GuiController guiCtrl) throws IOException {
85
91
* The event handler for when the application is closed.
86
92
* It will give show a confirmation box if the user wants to exit the application.
87
93
*/
88
- private EventHandler <WindowEvent > confirmCloseEventHandler = event -> {
94
+ private final EventHandler <WindowEvent > confirmCloseEventHandler = event -> {
89
95
Alert closeConfirmation = new Alert (Alert .AlertType .CONFIRMATION , "Do you really want to exit?" );
96
+ DialogPane pane = closeConfirmation .getDialogPane ();
97
+ if (ProgrammingLife .getShowCSS ()) {
98
+ pane .getStylesheets ().add ("/Alerts.css" );
99
+ } else {
100
+ pane .getStylesheets ().removeAll ();
101
+ }
90
102
Button exitButton = (Button ) closeConfirmation .getDialogPane ().lookupButton (ButtonType .OK );
91
103
exitButton .setText ("Exit" );
92
104
closeConfirmation .setHeaderText ("Confirm Exit" );
@@ -104,11 +116,30 @@ private void arguments(GuiController guiCtrl) throws IOException {
104
116
});
105
117
};
106
118
119
+ /**
120
+ * Toggles which styleSheets is used for the program.
121
+ */
122
+ public static void toggleCSS () {
123
+ showCSS = !showCSS ;
124
+ if (showCSS ) {
125
+ root .getStylesheets ().remove ("/LightTheme.css" );
126
+ root .getStylesheets ().add ("/DarkTheme.css" );
127
+ } else {
128
+ root .getStylesheets ().remove ("/DarkTheme.css" );
129
+ root .getStylesheets ().add ("/LightTheme.css" );
130
+ }
131
+ }
132
+
107
133
/**
108
134
* Returns the Stage if called upon.
135
+ *
109
136
* @return stage
110
137
*/
111
138
public static Stage getStage () {
112
139
return primaryStage ;
113
140
}
141
+
142
+ public static boolean getShowCSS () {
143
+ return showCSS ;
144
+ }
114
145
}
0 commit comments