From 9e082c6cacda64d1de003cae67136577f180d0b7 Mon Sep 17 00:00:00 2001 From: Omnicscient <115184891+Omnicscient@users.noreply.github.com> Date: Tue, 16 Dec 2025 22:13:31 +0300 Subject: [PATCH] Task 2.3 Step 3: Add color-coding by day to Course Schedule View --- .../controller/ScheduleCourseController.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/example/se302/controller/ScheduleCourseController.java b/src/main/java/org/example/se302/controller/ScheduleCourseController.java index d3f6316..bae7a9a 100644 --- a/src/main/java/org/example/se302/controller/ScheduleCourseController.java +++ b/src/main/java/org/example/se302/controller/ScheduleCourseController.java @@ -6,6 +6,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.TableColumn; +import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import org.example.se302.model.Course; import org.example.se302.model.ExamAssignment; @@ -17,6 +18,9 @@ import java.time.format.DateTimeFormatter; import java.util.Comparator; import java.util.Map; +// Color palette for days (pastel colors for readability) +// Day 0 = Light Blue, Day 1 = Light Green, Day 2 = Light Yellow, etc. + /** * Controller for the Course Schedule view. * Displays courses with their exam date, time, and assigned classroom. @@ -83,6 +87,35 @@ public class ScheduleCourseController { } }); + // Color-code rows by day + courseScheduleTable.setRowFactory(tv -> new TableRow() { + // Pastel color palette for different days + private final String[] dayColors = { + "#E3F2FD", // Day 0 - Light Blue + "#E8F5E9", // Day 1 - Light Green + "#FFF8E1", // Day 2 - Light Yellow + "#FCE4EC", // Day 3 - Light Pink + "#F3E5F5", // Day 4 - Light Purple + "#E0F7FA", // Day 5 - Light Cyan + "#FBE9E7" // Day 6 - Light Orange + }; + + @Override + protected void updateItem(CourseScheduleEntry item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setStyle(""); + } else if (item.getDayIndex() == Integer.MAX_VALUE) { + // Not scheduled - gray background + setStyle("-fx-background-color: #F5F5F5;"); + } else { + // Color by day (cycle through palette) + int colorIndex = item.getDayIndex() % dayColors.length; + setStyle("-fx-background-color: " + dayColors[colorIndex] + ";"); + } + } + }); + // Load data loadScheduleData();