mirror of
https://github.com/sabazadam/Se302.git
synced 2025-12-31 12:21:22 +00:00
Task 2.4 Step 3: Show time slots with sorting and color coding
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
|
import javafx.scene.control.TableRow;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import org.example.se302.model.Classroom;
|
import org.example.se302.model.Classroom;
|
||||||
import org.example.se302.model.ExamAssignment;
|
import org.example.se302.model.ExamAssignment;
|
||||||
@@ -16,6 +17,7 @@ import org.example.se302.service.DataManager;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +66,52 @@ public class ScheduleClassroomController {
|
|||||||
cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
|
cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
|
||||||
utilizationColumn.setCellValueFactory(
|
utilizationColumn.setCellValueFactory(
|
||||||
cellData -> new SimpleStringProperty(cellData.getValue().getUtilization()));
|
cellData -> new SimpleStringProperty(cellData.getValue().getUtilization()));
|
||||||
|
|
||||||
|
// Custom comparators for proper sorting
|
||||||
|
dateColumn.setComparator((d1, d2) -> {
|
||||||
|
if (d1.startsWith("Day") && d2.startsWith("Day")) {
|
||||||
|
try {
|
||||||
|
int day1 = Integer.parseInt(d1.replace("Day ", ""));
|
||||||
|
int day2 = Integer.parseInt(d2.replace("Day ", ""));
|
||||||
|
return Integer.compare(day1, day2);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return d1.compareTo(d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d1.compareTo(d2);
|
||||||
|
});
|
||||||
|
|
||||||
|
timeColumn.setComparator((t1, t2) -> {
|
||||||
|
try {
|
||||||
|
int slot1 = Integer.parseInt(t1.replace("Slot ", ""));
|
||||||
|
int slot2 = Integer.parseInt(t2.replace("Slot ", ""));
|
||||||
|
return Integer.compare(slot1, slot2);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return t1.compareTo(t2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Color-code rows by utilization percentage
|
||||||
|
scheduleTable.setRowFactory(tv -> new TableRow<ClassroomSlotEntry>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(ClassroomSlotEntry item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
if (empty || item == null) {
|
||||||
|
setStyle("");
|
||||||
|
} else {
|
||||||
|
int utilPercent = item.getUtilizationPercent();
|
||||||
|
if (utilPercent >= 90) {
|
||||||
|
setStyle("-fx-background-color: #FFCDD2;"); // Red - high
|
||||||
|
} else if (utilPercent >= 70) {
|
||||||
|
setStyle("-fx-background-color: #FFF9C4;"); // Yellow - medium
|
||||||
|
} else if (utilPercent > 0) {
|
||||||
|
setStyle("-fx-background-color: #C8E6C9;"); // Green - low
|
||||||
|
} else {
|
||||||
|
setStyle("-fx-background-color: #F5F5F5;"); // Gray - empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +164,8 @@ public class ScheduleClassroomController {
|
|||||||
|
|
||||||
entries.add(new ClassroomSlotEntry(
|
entries.add(new ClassroomSlotEntry(
|
||||||
dateStr, timeStr, assignment.getCourseCode(),
|
dateStr, timeStr, assignment.getCourseCode(),
|
||||||
studentCount, utilizationStr));
|
studentCount, utilizationStr, utilizationPercent,
|
||||||
|
assignment.getDay(), assignment.getTimeSlotIndex()));
|
||||||
|
|
||||||
usedSlots++;
|
usedSlots++;
|
||||||
totalStudents += studentCount;
|
totalStudents += studentCount;
|
||||||
@@ -129,6 +178,10 @@ public class ScheduleClassroomController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort by day then slot
|
||||||
|
entries.sort(Comparator.comparingInt(ClassroomSlotEntry::getDayIndex)
|
||||||
|
.thenComparingInt(ClassroomSlotEntry::getSlotIndex));
|
||||||
|
|
||||||
scheduleTable.setItems(entries);
|
scheduleTable.setItems(entries);
|
||||||
|
|
||||||
// Update overall utilization label
|
// Update overall utilization label
|
||||||
@@ -149,14 +202,20 @@ public class ScheduleClassroomController {
|
|||||||
private final String course;
|
private final String course;
|
||||||
private final int studentCount;
|
private final int studentCount;
|
||||||
private final String utilization;
|
private final String utilization;
|
||||||
|
private final int utilizationPercent;
|
||||||
|
private final int dayIndex;
|
||||||
|
private final int slotIndex;
|
||||||
|
|
||||||
public ClassroomSlotEntry(String date, String time, String course, int studentCount,
|
public ClassroomSlotEntry(String date, String time, String course, int studentCount,
|
||||||
String utilization) {
|
String utilization, int utilizationPercent, int dayIndex, int slotIndex) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.course = course;
|
this.course = course;
|
||||||
this.studentCount = studentCount;
|
this.studentCount = studentCount;
|
||||||
this.utilization = utilization;
|
this.utilization = utilization;
|
||||||
|
this.utilizationPercent = utilizationPercent;
|
||||||
|
this.dayIndex = dayIndex;
|
||||||
|
this.slotIndex = slotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate() {
|
public String getDate() {
|
||||||
@@ -178,5 +237,17 @@ public class ScheduleClassroomController {
|
|||||||
public String getUtilization() {
|
public String getUtilization() {
|
||||||
return utilization;
|
return utilization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getUtilizationPercent() {
|
||||||
|
return utilizationPercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDayIndex() {
|
||||||
|
return dayIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSlotIndex() {
|
||||||
|
return slotIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user