-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarScreen.java
More file actions
196 lines (160 loc) · 7.24 KB
/
CalendarScreen.java
File metadata and controls
196 lines (160 loc) · 7.24 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
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.scene.shape.Rectangle;
import javafx.stage.Stage;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
public class CalendarScreen extends VBox {
private final AppState state;
private final Stage stage;
private final Map<LocalDate, Button> dateButtonMap = new HashMap<>();
private final VBox scheduleList = new VBox(10);
private final Label calendarTitle = new Label();
private final GridPane calendarGrid = new GridPane();
private YearMonth currentYearMonth;
public CalendarScreen(Stage stage, AppState state) {
this.stage = stage;
this.state = state;
this.currentYearMonth = YearMonth.of(state.selectedDate.getYear(), state.selectedDate.getMonth());
setPadding(new Insets(20));
setSpacing(20);
setStyle("-fx-background-color: linear-gradient(to bottom, #1e0036, #2a0070);");
HBox header = new HBox();
Label logo = new Label("Doit");
logo.setStyle("-fx-font-size: 24px; -fx-text-fill: white;");
Region spacer = new Region();
Button bellIcon = new Button("🔔");
Button menuIcon = new Button("⋮");
bellIcon.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
menuIcon.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
HBox.setHgrow(spacer, Priority.ALWAYS);
header.getChildren().addAll(logo, spacer, bellIcon, menuIcon);
HBox nav = new HBox(10);
Button prevMonth = new Button("←");
Button nextMonth = new Button("→");
prevMonth.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
nextMonth.setStyle("-fx-background-color: transparent; -fx-text-fill: white;");
calendarTitle.setStyle("-fx-font-size: 18px; -fx-text-fill: white;");
Region navSpacer = new Region();
HBox.setHgrow(navSpacer, Priority.ALWAYS);
nav.getChildren().addAll(prevMonth, navSpacer, calendarTitle, nextMonth);
nav.setAlignment(Pos.CENTER_LEFT);
prevMonth.setOnAction(e -> {
currentYearMonth = currentYearMonth.minusMonths(1);
updateCalendarGrid();
});
nextMonth.setOnAction(e -> {
currentYearMonth = currentYearMonth.plusMonths(1);
updateCalendarGrid();
});
Button scheduleButton = new Button("Add Task");
scheduleButton.setStyle("-fx-background-color: #6f00ff; -fx-text-fill: white;");
scheduleButton.setOnAction(e -> {
TaskFormScreen form = new TaskFormScreen(stage, state, updatedDate -> {
state.selectedDate = updatedDate;
currentYearMonth = YearMonth.of(updatedDate.getYear(), updatedDate.getMonth());
updateCalendarGrid();
});
stage.setScene(new Scene(form, 375, 812));
});
calendarGrid.setHgap(5);
calendarGrid.setVgap(5);
calendarGrid.setAlignment(Pos.CENTER);
scheduleList.setPadding(new Insets(10));
updateCalendarGrid();
getChildren().addAll(header, nav, scheduleButton, calendarGrid, scheduleList);
}
private void updateCalendarGrid() {
calendarGrid.getChildren().clear();
dateButtonMap.clear();
scheduleList.getChildren().clear();
int year = currentYearMonth.getYear();
int month = currentYearMonth.getMonthValue();
calendarTitle.setText(currentYearMonth.getMonth() + " " + year);
YearMonth yearMonth = YearMonth.of(year, month);
int daysInMonth = yearMonth.lengthOfMonth();
LocalDate today = LocalDate.now();
for (int day = 1; day <= daysInMonth; day++) {
int col = (day - 1) % 7;
int row = (day - 1) / 7;
LocalDate thisDate = LocalDate.of(year, month, day);
Button dayBtn = new Button(String.valueOf(day));
dayBtn.setPrefSize(35, 35);
dayBtn.setStyle("-fx-background-color: #4e1a95; -fx-text-fill: white;");
if (thisDate.equals(today)) {
dayBtn.setStyle("-fx-background-color: #6f00ff; -fx-text-fill: white; -fx-font-weight: bold;");
}
dayBtn.setOnAction(e -> {
state.selectedDate = thisDate;
highlightSelectedDate();
refreshScheduleList();
});
calendarGrid.add(dayBtn, col, row);
dateButtonMap.put(thisDate, dayBtn);
}
if (!dateButtonMap.containsKey(state.selectedDate)) {
state.selectedDate = LocalDate.of(year, month, 1);
}
highlightSelectedDate();
refreshScheduleList();
}
private void highlightSelectedDate() {
for (Map.Entry<LocalDate, Button> entry : dateButtonMap.entrySet()) {
Button btn = entry.getValue();
LocalDate date = entry.getKey();
if (date.equals(state.selectedDate)) {
btn.setStyle("-fx-background-color: #00ffcc; -fx-text-fill: black; -fx-effect: dropshadow(gaussian, white, 10, 0, 0, 0);");
} else if (date.equals(LocalDate.now())) {
btn.setStyle("-fx-background-color: #6f00ff; -fx-text-fill: white; -fx-font-weight: bold;");
} else {
btn.setStyle("-fx-background-color: #4e1a95; -fx-text-fill: white;");
}
}
}
public void refreshScheduleList() {
scheduleList.getChildren().clear();
Label dateLabel = new Label("Tasks for " + state.selectedDate.toString());
dateLabel.setTextFill(Color.WHITE);
dateLabel.setStyle("-fx-font-size: 16px;");
scheduleList.getChildren().add(dateLabel);
List<Task> tasks = state.taskMap.getOrDefault(state.selectedDate, new ArrayList<>());
if (tasks.isEmpty()) {
Label none = new Label("No tasks scheduled.");
none.setTextFill(Color.WHITE);
scheduleList.getChildren().add(none);
} else {
for (Task t : tasks) {
scheduleList.getChildren().add(createTaskCard(t));
}
}
}
private HBox createTaskCard(Task task) {
VBox info = new VBox(
new Label(task.title),
new Label("Time: " + task.time),
new Label("Place: " + task.location),
new Label("Notes: " + task.notes)
);
info.setStyle("-fx-background-color: rgba(255,255,255,0.1); -fx-padding: 10; -fx-border-radius: 10;");
info.setPrefWidth(280);
info.setSpacing(5);
info.getChildren().forEach(node -> ((Label) node).setTextFill(Color.WHITE));
Rectangle colorTag = new Rectangle(10, 10, task.color);
HBox taskCard = new HBox(info, colorTag);
// ✅ Click to open edit form
taskCard.setOnMouseClicked(e -> {
TaskFormScreen editForm = new TaskFormScreen(stage, state, task, updatedDate -> {
state.selectedDate = updatedDate;
updateCalendarGrid();
});
stage.setScene(new Scene(editForm, 375, 812));
});
return taskCard;
}
}