-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
executable file
·211 lines (194 loc) · 5.66 KB
/
Main.java
File metadata and controls
executable file
·211 lines (194 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* Main.java created by wenxiyang on MacBook Pro in a2
*
* Author: Wenxi Yang(wyang235@wisc.edu)
* Date: 4/21/2020
*
* Course: CS400
* Semester: Spring 2020
* Lecture: 001
*
* IDE: Eclipse IDE for Java Developers
* Version: 2019-12 (4.14.0)
* Build id: 20191212-1212
*
* Device: Wenxi's MacBook Pro
* OS: MacOS Mojave
* Version: 10.14.4
* OS Build: 18E226
*
* List Collaboratons:
*
* Other Credits:
*
* Known bugs:
*/
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.RadialGradient;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
/**
* The Class Main.
*/
public class Main extends Application {
/** The milk data. */
public static MilkData milkData = new MilkData();
/**
* Start the program.
*
* @param primaryStage the primary stage
*/
@Override
public void start(Stage primaryStage) {
try {
EventLog.getInstance().log("Start Milk Manager.");
primaryStage.setTitle("Milk Manager");
BorderPane root = createMainPane(primaryStage);
Scene scene = new Scene(root, 840, 600);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This method is called when the application should stop, and provides a
* convenient place to prepare for application exit and destroy resources.
*
* @throws java.lang.Exception if something goes wrong
*/
public void stop() throws Exception {
EventLog.getInstance().log("Exit Milk Manager.");
EventLog.getInstance().close();
}
/**
* Creates the main pane.
*
* @return the border pane
* @throws FileNotFoundException when the file is not found
*/
private BorderPane createMainPane(Stage primaryStage) throws FileNotFoundException {
BorderPane root = new BorderPane();
root.setPadding(new Insets(20, 20, 20, 20));
FileInputStream input = new FileInputStream("cow1.png");
Image imageL = new Image(input);
ImageView ingvL = new ImageView(imageL);
Text tt = new Text("Milk Manager");
tt.setFont(Font.font("Kalam", FontWeight.BOLD, FontPosture.REGULAR, 70));
tt.setFill(RadialGradient.valueOf("center 100px 100px, radius 200px, red 0%, #00b3ff 100%, black 30%"));
HBox topPane = new HBox(ingvL, tt);
HBox.setHgrow(tt, Priority.ALWAYS);
HBox.setHgrow(ingvL, Priority.NEVER);
topPane.setSpacing(80);
topPane.setMaxHeight(180);
topPane.setPrefHeight(180);
root.setTop(topPane);
Button bt_dataManager = new Button("Data Manager");
bt_dataManager.setId("blue_button");
bt_dataManager.setPrefWidth(200);
Insets insets = new Insets(15);
bt_dataManager.setOnAction(new EventHandler<ActionEvent>() {
/**
* Handle actions.
*
* @param event the event
*/
@Override
public void handle(ActionEvent event) {
Pane centerPane = DataManagerPane.getDataManagerPane(milkData);
root.setCenter(centerPane);
BorderPane.setMargin(centerPane, insets);
}
});
Button bt_userFun = new Button("User Functions");
bt_userFun.setPrefWidth(200);
bt_userFun.setId("blue_button");
bt_userFun.setOnAction(new EventHandler<ActionEvent>() {
/**
* Handle actions.
*
* @param event the event
*/
@Override
public void handle(ActionEvent event) {
Pane centerPane = UserFunctionPane.getUserFunctionPane(primaryStage, milkData);
root.setCenter(centerPane);
BorderPane.setMargin(centerPane, insets);
}
});
Button bt_desc = new Button("Description");
bt_desc.setPrefWidth(200);
bt_desc.setId("blue_button");
bt_desc.setOnAction(new EventHandler<ActionEvent>() {
/**
* Handle actions.
*
* @param event the event
*/
@Override
public void handle(ActionEvent event) {
TextArea text = null;
try {
text = readTxt("Description.txt");
} catch (IOException e) {
e.printStackTrace();
}
root.setCenter(text);
BorderPane.setMargin(text, insets);
}
});
VBox leftPane = new VBox(bt_dataManager, bt_userFun, bt_desc);
leftPane.setMaxWidth(200);
leftPane.setPrefWidth(200);
leftPane.setSpacing(20);
root.setLeft(leftPane);
BorderPane.setMargin(topPane, insets);
BorderPane.setMargin(leftPane, insets);
return root;
}
/**
* Read text.
*
* @param filename the filename
* @return the text area
* @throws IOException Signals that an I/O exception has occurred.
*/
private TextArea readTxt(String filename) throws IOException {
FileReader reader = new FileReader(filename);
char[] chars = new char[1024];
reader.read(chars);
String text = new String(chars);
TextArea textArea = new TextArea(text);
textArea.setWrapText(true);
return textArea;
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
launch(args);
}
}