-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskFormScreen.java
More file actions
160 lines (129 loc) · 6.08 KB
/
TaskFormScreen.java
File metadata and controls
160 lines (129 loc) · 6.08 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
package com.example.hellofx;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.function.Consumer;
public class TaskFormScreen extends VBox {
private final TextField title = new TextField();
private final CheckBox fullDay = new CheckBox("Full Day");
private final TextField startTime = new TextField();
private final TextField endTime = new TextField();
private final ComboBox<String> month = new ComboBox<>();
private final ComboBox<String> day = new ComboBox<>();
private final ComboBox<String> year = new ComboBox<>();
private final TextField location = new TextField();
private final TextField details = new TextField();
private final ColorPicker importanceColor = new ColorPicker(Color.RED);
public TaskFormScreen(Stage stage, AppState state, Consumer<LocalDate> onSaveCallback) {
this(stage, state, null, onSaveCallback);
}
public TaskFormScreen(Stage stage, AppState state, Task taskToEdit, Consumer<LocalDate> onSaveCallback) {
setPadding(new Insets(20));
setSpacing(10);
setStyle("-fx-background-color: linear-gradient(to bottom, #1e0036, #2a0070);");
HBox topBar = new HBox();
Button back = new Button("←");
Button save = new Button("✔");
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
topBar.getChildren().addAll(back, spacer, save);
back.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
save.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
title.setPromptText("Task Title");
fullDay.setTextFill(Color.WHITE);
startTime.setPromptText("Start Time");
endTime.setPromptText("End Time");
for (int i = 1; i <= 12; i++) month.getItems().add(String.format("%02d", i));
month.setPromptText("Month");
int currentYear = java.time.Year.now().getValue();
for (int y = currentYear; y >= 1980; y--) year.getItems().add(String.valueOf(y));
year.setPromptText("Year");
month.setOnAction(e -> updateDayList());
year.setOnAction(e -> updateDayList());
HBox dateBox = new HBox(10, month, day, year);
dateBox.setAlignment(Pos.CENTER_LEFT);
ComboBox<String> repeat = new ComboBox<>();
repeat.getItems().addAll("None", "Daily", "Weekly");
repeat.setPromptText("Repeat");
ComboBox<String> reminder = new ComboBox<>();
reminder.getItems().addAll("Before 30 minutes", "Before 1 hour");
reminder.setPromptText("Reminder");
location.setPromptText("Location");
details.setPromptText("Details");
getChildren().addAll(
topBar, title, fullDay, startTime, endTime,
dateBox, repeat, reminder, importanceColor,
location, details
);
// Pre-fill if editing
if (taskToEdit != null) {
title.setText(taskToEdit.title);
fullDay.setSelected("All Day".equals(taskToEdit.time));
if (!fullDay.isSelected() && taskToEdit.time.contains(" - ")) {
String[] parts = taskToEdit.time.split(" - ");
startTime.setText(parts[0]);
endTime.setText(parts[1]);
}
month.setValue(String.format("%02d", taskToEdit.date.getMonthValue()));
year.setValue(String.valueOf(taskToEdit.date.getYear()));
updateDayList();
day.setValue(String.format("%02d", taskToEdit.date.getDayOfMonth()));
location.setText(taskToEdit.location);
details.setText(taskToEdit.notes);
importanceColor.setValue(taskToEdit.color);
} else {
LocalDate date = state.selectedDate;
month.setValue(String.format("%02d", date.getMonthValue()));
year.setValue(String.valueOf(date.getYear()));
updateDayList();
day.setValue(String.format("%02d", date.getDayOfMonth()));
}
back.setOnAction(e -> stage.setScene(new Scene(new CalendarScreen(stage, state), 375, 812)));
save.setOnAction(e -> {
LocalDate selectedDate = LocalDate.of(
Integer.parseInt(year.getValue()),
Integer.parseInt(month.getValue()),
Integer.parseInt(day.getValue())
);
String time = fullDay.isSelected() ? "All Day" : startTime.getText() + " - " + endTime.getText();
if (taskToEdit != null) {
taskToEdit.title = title.getText();
taskToEdit.time = time;
taskToEdit.location = location.getText();
taskToEdit.notes = details.getText();
taskToEdit.color = importanceColor.getValue();
taskToEdit.date = selectedDate;
} else {
Task newTask = new Task(title.getText(), time, location.getText(), details.getText(), importanceColor.getValue(), selectedDate);
state.taskMap.computeIfAbsent(selectedDate, d -> new java.util.ArrayList<>()).add(newTask);
}
onSaveCallback.accept(selectedDate);
stage.setScene(new Scene(new CalendarScreen(stage, state), 375, 812));
});
}
private void updateDayList() {
day.getItems().clear();
int maxDays = 31;
String mVal = month.getValue();
String yVal = year.getValue();
if (mVal == null) return;
if (mVal.equals("02")) {
if (yVal != null) {
int y = Integer.parseInt(yVal);
maxDays = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0) ? 29 : 28;
} else maxDays = 28;
} else if (Arrays.asList("04", "06", "09", "11").contains(mVal)) {
maxDays = 30;
}
for (int i = 1; i <= maxDays; i++) {
day.getItems().add(String.format("%02d", i));
}
day.setPromptText("Day");
}
}