Task 2.3 Step 3: Add color-coding by day to Course Schedule View

This commit is contained in:
Omnicscient
2025-12-16 22:13:31 +03:00
parent e9f4d2a45a
commit 9e082c6cac

View File

@@ -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<CourseScheduleEntry>() {
// 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();