-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefineTimeslotController.java
More file actions
140 lines (122 loc) · 4.43 KB
/
DefineTimeslotController.java
File metadata and controls
140 lines (122 loc) · 4.43 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
package s25.cs151.application.controller;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import java.io.IOException;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Modality;
import s25.cs151.application.model.DataManager;
import s25.cs151.application.model.Timeslot;
public class DefineTimeslotController {
@FXML
private ComboBox<String> startHourCombo;
@FXML
private ComboBox<String> startMinuteCombo;
@FXML
private ComboBox<String> startAmPmCombo;
@FXML
private ComboBox<String> endHourCombo;
@FXML
private ComboBox<String> endMinuteCombo;
@FXML
private ComboBox<String> endAmPmCombo;
@FXML
private Button saveButton;
@FXML
private Button cancelButton;
@FXML
private void initialize() {
// Initialize hours (1-12)
for (int i = 1; i <= 12; i++) {
String hour = String.format("%d", i);
startHourCombo.getItems().add(hour);
endHourCombo.getItems().add(hour);
}
// Initialize minutes (00-55, increment by 5)
for (int i = 0; i < 60; i += 5) {
String minute = String.format("%02d", i);
startMinuteCombo.getItems().add(minute);
endMinuteCombo.getItems().add(minute);
}
// Initialize AM/PM
startAmPmCombo.getItems().addAll("AM", "PM");
endAmPmCombo.getItems().addAll("AM", "PM");
}
@FXML
private void onSave() {
// Validate inputs
if (startHourCombo.getValue() == null || startMinuteCombo.getValue() == null ||
startAmPmCombo.getValue() == null || endHourCombo.getValue() == null ||
endMinuteCombo.getValue() == null || endAmPmCombo.getValue() == null) {
showAlert("Please fill in all time fields");
return;
}
// Create and save new timeslot
Timeslot timeslot = new Timeslot(
startHourCombo.getValue(),
startMinuteCombo.getValue(),
startAmPmCombo.getValue(),
endHourCombo.getValue(),
endMinuteCombo.getValue(),
endAmPmCombo.getValue()
);
DataManager.saveTimeslot(timeslot);
showAlert("Timeslot saved successfully!");
Stage stage = (Stage) saveButton.getScene().getWindow();
stage.close();
}
@FXML
private void onCancel() {
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
}
@FXML
private void onViewTimeslots() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/s25/cs151/application/view/view-timeslots.fxml"));
Parent root = loader.load();
Stage viewStage = new Stage();
viewStage.initModality(Modality.APPLICATION_MODAL);
viewStage.setTitle("View Timeslots");
viewStage.setScene(new Scene(root, 400, 300));
viewStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void onClear() {
Alert confirmAlert = new Alert(Alert.AlertType.CONFIRMATION);
confirmAlert.setTitle("Clear All Timeslots");
confirmAlert.setHeaderText("Are you sure?");
confirmAlert.setContentText("This will permanently delete all saved timeslots.");
confirmAlert.showAndWait().ifPresent(response -> {
if (response == ButtonType.OK) {
// Clear the data
DataManager.clearAllTimeslots();
// Show success message
Alert successAlert = new Alert(Alert.AlertType.INFORMATION);
successAlert.setTitle("Success");
successAlert.setHeaderText(null);
successAlert.setContentText("All timeslots have been cleared.");
successAlert.show();
// Refresh the view if needed
refreshTimeslotList();
}
});
}
private void refreshTimeslotList() {
// Add code to refresh your timeslot display if needed
}
private void showAlert(String message) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information");
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}