From face80a60314ee59f59abac6bf02c2f38469f0e2 Mon Sep 17 00:00:00 2001 From: leepoeaik Date: Thu, 4 Apr 2024 02:33:09 +0800 Subject: [PATCH] Add display upcoming lesson function --- .../java/seedu/address/ui/MainWindow.java | 7 ++ .../java/seedu/address/ui/ScheduleCard.java | 67 ++++++++++++++++ .../seedu/address/ui/ScheduleListPanel.java | 80 +++++++++++++++++++ src/main/resources/view/MainWindow.fxml | 9 ++- src/main/resources/view/ScheduleListCard.fxml | 45 +++++++++++ .../resources/view/ScheduleListPanel.fxml | 10 +++ 6 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 src/main/java/seedu/address/ui/ScheduleCard.java create mode 100644 src/main/java/seedu/address/ui/ScheduleListPanel.java create mode 100644 src/main/resources/view/ScheduleListCard.fxml create mode 100644 src/main/resources/view/ScheduleListPanel.fxml diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 1d02bf9d8f1..a4b82bfd906 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -33,6 +33,7 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private StudentListPanel studentListPanel; + private ScheduleListPanel scheduleListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -45,6 +46,9 @@ public class MainWindow extends UiPart { @FXML private StackPane studentListPanelPlaceholder; + @FXML + private StackPane scheduleListPanelPlaceholder; + @FXML private StackPane resultDisplayPlaceholder; @@ -118,6 +122,9 @@ void fillInnerParts() { studentListPanel = new StudentListPanel(logic.getFilteredStudentList()); studentListPanelPlaceholder.getChildren().add(studentListPanel.getRoot()); + scheduleListPanel = new ScheduleListPanel(logic.getFilteredStudentList()); + scheduleListPanelPlaceholder.getChildren().add(scheduleListPanel.getRoot()); + resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); diff --git a/src/main/java/seedu/address/ui/ScheduleCard.java b/src/main/java/seedu/address/ui/ScheduleCard.java new file mode 100644 index 00000000000..fffea799c88 --- /dev/null +++ b/src/main/java/seedu/address/ui/ScheduleCard.java @@ -0,0 +1,67 @@ +package seedu.address.ui; + + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import javafx.util.Pair; +import seedu.address.model.student.Lesson; +import seedu.address.model.student.Student; + +/** + * An UI component that displays information of a {@code Student}. + */ +public class ScheduleCard extends UiPart { + + private static final String FXML = "ScheduleListCard.fxml"; + + /** + * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. + * As a consequence, UI elements' variable names cannot be set to such keywords + * or an exception will be thrown by JavaFX during runtime. + * + * @see The issue on AddressBook level 4 + */ + + public final Lesson lesson; + public final String studentName; + + @FXML + private HBox cardPane; + @FXML + private Label name; + @FXML + private Label id; + @FXML + private Label phone; + @FXML + private Label address; + @FXML + private Label email; + @FXML + private Label subject; + @FXML + private Label date; + @FXML + private Label time; + @FXML + private FlowPane lessons; + @FXML + private Label remark; + + /** + * Creates a {@code StudentCode} with the given {@code Student} and index to display. + */ + public ScheduleCard(Pair pair, int displayedIndex) { + super(FXML); + this.lesson = pair.getValue(); + this.studentName = pair.getKey().getName().toString(); + id.setText(displayedIndex + ". "); + name.setText(studentName); + subject.setText(lesson.getSubject().value); + date.setText(String.valueOf(lesson.getDate())); + time.setText(lesson.getTime().toString()); + } +} diff --git a/src/main/java/seedu/address/ui/ScheduleListPanel.java b/src/main/java/seedu/address/ui/ScheduleListPanel.java new file mode 100644 index 00000000000..f9329673b66 --- /dev/null +++ b/src/main/java/seedu/address/ui/ScheduleListPanel.java @@ -0,0 +1,80 @@ +package seedu.address.ui; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.logging.Logger; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import javafx.util.Pair; +import seedu.address.commons.core.LogsCenter; +import seedu.address.model.student.Lesson; +import seedu.address.model.student.Student; + +/** + * Panel containing the list of students. + */ +public class ScheduleListPanel extends UiPart { + private static final String FXML = "ScheduleListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class); + + @FXML + private ListView> scheduleListView; + + /** + * Creates a {@code ScheduleListPanel} with the given {@code ObservableList}. + */ + public ScheduleListPanel(ObservableList studentList) { + super(FXML); + + scheduleListView.setItems(TransformList(studentList)); + scheduleListView.setCellFactory(listView -> new ScheduleListViewCell()); + } + + public ObservableList> TransformList(ObservableList studentList) { + List> scheduleList = new ArrayList<>(); + for (Student student : studentList) { + List studentLesson = student.getLessons(); + for (Lesson l : studentLesson) { + scheduleList.add(new Pair(student, l)); + } + } + + Collections.sort(scheduleList, new SortDate()); + + ObservableList> observableList = FXCollections.observableList(scheduleList); + return observableList; + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Student} using a {@code StudentCard}. + */ + class ScheduleListViewCell extends ListCell> { + @Override + protected void updateItem(Pair pair, boolean empty) { + super.updateItem(pair, empty); + if (empty || pair == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new ScheduleCard(pair, getIndex() + 1).getRoot()); + } + } + } + + class SortDate implements Comparator> { + + @Override + public int compare(Pair o1, Pair o2) { + // TODO: implement your logic here + return o1.getValue().getDate().compareTo(o2.getValue().getDate()); + } + } + +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index d3fe3f70592..2d2b41595d4 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -69,11 +69,14 @@ - + + + + - - + diff --git a/src/main/resources/view/ScheduleListCard.fxml b/src/main/resources/view/ScheduleListCard.fxml new file mode 100644 index 00000000000..e3478d3c3ab --- /dev/null +++ b/src/main/resources/view/ScheduleListCard.fxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/ScheduleListPanel.fxml b/src/main/resources/view/ScheduleListPanel.fxml new file mode 100644 index 00000000000..732ca2ced1c --- /dev/null +++ b/src/main/resources/view/ScheduleListPanel.fxml @@ -0,0 +1,10 @@ + + + + + + + + + +