-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
363 lines (281 loc) · 9.61 KB
/
Controller.java
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* Jennifer Minnich
** Program 4: Using JavaFx to create GUI
** Controller.java
*/
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.FileChooser;
import java.io.File;
public class Controller {
@FXML
private TextArea taSummary;
@FXML
private ComboBox<String> comboBoxMain;
@FXML
private TextField tfPersonalizeLeft;
@FXML
private TextField tfPersonalizeRight;
@FXML
private Slider sliderMain;
@FXML
private RadioButton rBtnOneGroupTwo;
@FXML
private ToggleGroup rBtnGroupTwo;
@FXML
private RadioButton rBtnTwoGroupTwo;
@FXML
private RadioButton rBtnThreeGroupTwo;
@FXML
private RadioButton rBtnOneGroupOne;
@FXML
private ToggleGroup rBtnGroupOne;
@FXML
private RadioButton rBtnTwoGroupOne;
@FXML
private RadioButton rBtnThreeGroupOne;
@FXML
private CheckBox chkBoxOne;
@FXML
private CheckBox chkBoxTwo;
@FXML
private CheckBox chkBoxThree;
@FXML
private Button btnMake;
@FXML
private Button btnSave;
@FXML
private Label lblPrice;
@FXML
private ObservableList<String> dropDown;
@FXML
private TextField tfName;
@FXML
private TextField tfEmail;
private P4Data data;
private Font oldFont;
private int price = 0;
private Double priceHigh = 175.00;
private Double priceLow = 95.00;
//private Double priceFinal = 0.0;
@FXML
private void initialize() {
//new Data instance
data = new P4Data();
//button groups
this.rBtnOneGroupOne.setSelected(true);
price += priceLow;
this.rBtnOneGroupTwo.setSelected(true);
price += priceLow;
//comboBox
this.dropDown = FXCollections.observableArrayList(new String[]{"Beats Theme", "Air Pod Theme", "Sound Sport Theme", "Noise Cancelling Theme"});
this.comboBoxMain.setItems(this.dropDown);
this.comboBoxMain.setValue("Beats Theme");
price += priceHigh;
//slider
this.sliderMain.setValue(50);
price += priceLow;
// price label
String priceString = Integer.toString(price);
this.lblPrice.setText("Base model preselected.\nPrice: $" + priceString
+ "\nClick features to see individual pricing.");
}
@FXML
void sliderAction(MouseEvent event) {
if (sliderMain.getValue() == 50) {
this.lblPrice.setText("$95");
//priceFinal += priceLow;
} else if (sliderMain.getValue() == 100) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
} else {
this.lblPrice.setText("");
}
data.setVolume((int) sliderMain.getValue());
}
@FXML
void btnSaveAction(ActionEvent event) throws Exception {
data.setName(tfName.getText());
data.setEmail(tfEmail.getText());
String theme = comboBoxMain.getValue();
data.setTheme(theme);
String left = tfPersonalizeLeft.getText();
data.setLeft(left);
String right = tfPersonalizeRight.getText();
data.setRight(right);
String addOn1 = chkBoxOne.getText();
data.setAddOn1(addOn1);
String addOn2 = chkBoxTwo.getText();
data.setAddOn2(addOn2);
String addOn3 = chkBoxThree.getText();
data.setAddOn3(addOn3);
RadioButton selectedRadioButton = (RadioButton) this.rBtnGroupOne.getSelectedToggle();
RadioButton selectedRadioButton2 = (RadioButton) this.rBtnGroupTwo.getSelectedToggle();
String toggleColor = selectedRadioButton.getText();
data.setToggleColor(toggleColor);
String toggleFinish = selectedRadioButton2.getText();
data.setToggleFinish(toggleFinish);
int volume = (int) sliderMain.getValue();
data.setVolume(volume);
FileChooser chooser = new FileChooser();
File file = chooser.showSaveDialog(null);
if (file != null) {
data.writeFile(file);
}
}
@FXML
void chkBoxOneAction(ActionEvent event) {
if (chkBoxOne.isSelected() && chkBoxTwo.isSelected()) {
this.lblPrice.setText("$350");
//priceFinal += priceHigh * 2;
} else if (chkBoxOne.isSelected()) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
} else {
this.lblPrice.setText("");
}
if (chkBoxThree.isSelected() && chkBoxOne.isSelected()) {
this.lblPrice.setText("$350");
//priceFinal += priceHigh * 2;
}
if (chkBoxThree.isSelected() && chkBoxTwo.isSelected() && chkBoxOne.isSelected()) {
this.lblPrice.setText("$525");
//priceFinal += priceHigh * 3;
}
}
@FXML
void chkBoxThreeAction(ActionEvent event) {
if (chkBoxThree.isSelected()) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
} else {
this.lblPrice.setText("");
}
if (chkBoxThree.isSelected() && chkBoxTwo.isSelected()) {
this.lblPrice.setText("$350");
//priceFinal += priceHigh * 2;
}
if (chkBoxThree.isSelected() && chkBoxOne.isSelected()) {
this.lblPrice.setText("$350");
}
if (chkBoxThree.isSelected() && chkBoxTwo.isSelected() && chkBoxOne.isSelected()) {
this.lblPrice.setText("$525");
}
}
@FXML
void chkBoxTwoAction(ActionEvent event) {
if (chkBoxTwo.isSelected()) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
} else {
this.lblPrice.setText("");
}
if (chkBoxOne.isSelected() && chkBoxTwo.isSelected()) {
this.lblPrice.setText("$350");
}
if (chkBoxThree.isSelected() && chkBoxTwo.isSelected()) {
this.lblPrice.setText("$350");
}
}
@FXML
void comboBoxMainAction(ActionEvent event) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
}
@FXML
void rBtnGroupOneAction(ActionEvent event) {
RadioButton selectedRadioButton = (RadioButton) this.rBtnGroupOne.getSelectedToggle();
if (selectedRadioButton == this.rBtnOneGroupOne) {
this.lblPrice.setText("$95");
//priceFinal += priceLow;
} else if (selectedRadioButton == this.rBtnTwoGroupOne) {
this.lblPrice.setText("$95");
//priceFinal += priceLow;
} else if (selectedRadioButton == this.rBtnThreeGroupOne) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
}
}
@FXML
void rBtnGroupTwoAction(ActionEvent event) {
RadioButton selectedRadioButton = (RadioButton) this.rBtnGroupTwo.getSelectedToggle();
if (selectedRadioButton == this.rBtnOneGroupTwo) {
this.lblPrice.setText("95");
//priceFinal += priceLow;
} else if (selectedRadioButton == this.rBtnTwoGroupTwo) {
this.lblPrice.setText("$95");
//priceFinal += priceLow;
} else if (selectedRadioButton == this.rBtnThreeGroupTwo) {
this.lblPrice.setText("$175");
//priceFinal += priceHigh;
}
}
@FXML
void onActionMouseEntered() {
oldFont = btnSave.getFont();
Font font = Font.font("Times New Roman", FontWeight.BOLD, 14);
btnSave.setFont(font);
}
@FXML
void onActionMouseEntered2() {
oldFont = btnSave.getFont();
Font font = Font.font("Times New Roman", FontWeight.BOLD, 14);
btnMake.setFont(font);
}
@FXML
void onActionMouseExited() {
btnSave.setFont(oldFont);
}
@FXML
void onActionMouseExited2() {
btnMake.setFont(oldFont);
}
@FXML
void btnMakeAction(ActionEvent event) {
String theme = comboBoxMain.getValue();
int volume = (int) sliderMain.getValue();
RadioButton selectedRadioButton = (RadioButton) this.rBtnGroupOne.getSelectedToggle();
RadioButton selectedRadioButton2 = (RadioButton) this.rBtnGroupTwo.getSelectedToggle();
String toggleColor = selectedRadioButton.getText();
String toggleFinish = selectedRadioButton2.getText();
String left = tfPersonalizeLeft.getText();
String right = tfPersonalizeRight.getText();
String addOn1= "";
String addOn2= "";
String addOn3= "";
String quote = "\"";
if (chkBoxOne.isSelected()) {
addOn1 = chkBoxOne.getText();
}
if (chkBoxTwo.isSelected()) {
addOn2 = chkBoxTwo.getText();
}
if (chkBoxThree.isSelected()) {
addOn3 = chkBoxThree.getText();
}
this.taSummary.setText("Theme: " + theme + "\n"
+ "Volume Boost: " + volume + "\n"
+ "Color: " + toggleColor + "\n"
+ "Finish: " + toggleFinish + "\n"
+ "Personalized left ear: " + quote + left + quote + "\n"
+ "Personalized right ear: " + quote + right + quote + "\n"
+ "Add Ons: " + addOn1 + ", " + addOn2 + ", " + addOn3 + "\n");
}
@FXML
void tfPersonalizeRightAction(ActionEvent event) {
}
@FXML
void tfPersonalizeLeftAction(ActionEvent actionEvent) {
}
@FXML
void onActionMouseClicked(MouseEvent mouseEvent) {
lblPrice.setText("$95");
}
}