-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskController.java
More file actions
151 lines (140 loc) · 3.86 KB
/
TaskController.java
File metadata and controls
151 lines (140 loc) · 3.86 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
package cs3500.pa05.controller;
import cs3500.pa05.model.DayType;
import cs3500.pa05.model.Task;
import java.util.ArrayList;
import java.util.List;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
/**
* Represents a controller for the window that creates a new task.
*/
public class TaskController implements ControllerInterface {
private Task task;
@FXML
private TextField nameField;
@FXML
private TextField descripField;
@FXML
private ComboBox<DayType> dayField;
@FXML
private Button save;
private List<Task> taskList;
private Dialog<String> warning;
private WeekController weekController;
private Stage stage;
private Scene weekScene;
@FXML
private HBox taskQueue;
/**
* Instantiates a TaskController by creating new buttons and text fields.
*
* @param w the scene to generate
* @param s the stage to render the scene on
* @param c the current week controller
*/
public TaskController(Scene w, Stage s, WeekController c) {
this.nameField = new TextField();
this.descripField = new TextField();
this.dayField = new ComboBox<DayType>();
this.save = new Button("Save");
this.taskList = new ArrayList<>();
this.warning = new Dialog<>();
this.weekController = c;
this.stage = s;
this.weekScene = w;
this.taskQueue = new HBox();
}
/**
* Sets up warning dialog to display incorrect user input.
*/
private void setWarning() {
ButtonType ok = new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE);
warning.setTitle("Warning");
warning.getDialogPane().getButtonTypes().add(ok);
}
/**
* Displays a warning popup with given message.
*
* @param message the warning to give to the user
*/
private void displayWarning(String message) {
warning.setContentText(message);
}
/**
* Sets this task to the current user input.
*/
private boolean setTask() {
String name = nameField.getText();
String description = descripField.getText();
DayType day = dayField.getValue();
// handles cases of incorrect user input
if (name.isEmpty()) {
displayWarning("Name cannot be empty");
warning.showAndWait();
return false;
} else {
// creates a new task when the input is valid
Task newTask = new Task(name, description, day, false);
this.task = newTask;
return true;
}
}
/**
* Gets the current new task.
*
* @return the current task
*/
public Task getTask() {
return this.task;
}
/**
* Sets the given task as complete.
*
* @param task the task to set complete
*/
private void setComplete(Task task) {
for (Task t : taskList) {
if (t.equals(task)) {
t.setIsComplete(true);
}
}
}
/**
* Sets choices for day combo box.
*/
private void addDayChoices() {
dayField.getItems().add(DayType.MONDAY);
dayField.getItems().add(DayType.TUESDAY);
dayField.getItems().add(DayType.WEDNESDAY);
dayField.getItems().add(DayType.THURSDAY);
dayField.getItems().add(DayType.FRIDAY);
dayField.getItems().add(DayType.SATURDAY);
dayField.getItems().add(DayType.SUNDAY);
}
/**
* Runs the controller.
*/
@Override
public void run() {
addDayChoices();
setWarning();
save.setOnAction(e -> closeScene());
}
/**
* Closes new task scene based on set task.
*/
private void closeScene() {
if (setTask()) {
weekController.saveNewTask();
stage.setScene(weekScene);
}
}
}