Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display upcoming lesson function #64

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private StudentListPanel studentListPanel;
private ScheduleListPanel scheduleListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

Expand All @@ -45,6 +46,9 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private StackPane studentListPanelPlaceholder;

@FXML
private StackPane scheduleListPanelPlaceholder;

@FXML
private StackPane resultDisplayPlaceholder;

Expand Down Expand Up @@ -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());

Expand Down
67 changes: 67 additions & 0 deletions src/main/java/seedu/address/ui/ScheduleCard.java
Original file line number Diff line number Diff line change
@@ -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<Region> {

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 <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

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<Student, Lesson> 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());
}
}
80 changes: 80 additions & 0 deletions src/main/java/seedu/address/ui/ScheduleListPanel.java
Original file line number Diff line number Diff line change
@@ -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<Region> {
private static final String FXML = "ScheduleListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class);

@FXML
private ListView<Pair<Student, Lesson>> scheduleListView;

/**
* Creates a {@code ScheduleListPanel} with the given {@code ObservableList}.
*/
public ScheduleListPanel(ObservableList<Student> studentList) {
super(FXML);

scheduleListView.setItems(TransformList(studentList));
scheduleListView.setCellFactory(listView -> new ScheduleListViewCell());
}

public ObservableList<Pair<Student, Lesson>> TransformList(ObservableList<Student> studentList) {
List<Pair<Student, Lesson>> scheduleList = new ArrayList<>();
for (Student student : studentList) {
List<Lesson> studentLesson = student.getLessons();
for (Lesson l : studentLesson) {
scheduleList.add(new Pair(student, l));
}
}

Collections.sort(scheduleList, new SortDate());

ObservableList<Pair<Student, Lesson>> 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<Pair<Student, Lesson>> {
@Override
protected void updateItem(Pair<Student, Lesson> 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<Pair<Student, Lesson>> {

@Override
public int compare(Pair<Student, Lesson> o1, Pair<Student, Lesson> o2) {
// TODO: implement your logic here
return o1.getValue().getDate().compareTo(o2.getValue().getDate());
}
}

}
9 changes: 6 additions & 3 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@
</StackPane>
<HBox fx:id="studentListHBox" prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<StackPane fx:id="scheduleBox" alignment="CENTER_LEFT" maxWidth="150.0" prefHeight="500.0" prefWidth="150.0" HBox.hgrow="ALWAYS">
<VBox fx:id="scheduleBox" alignment="CENTER_RIGHT" minWidth="340" prefWidth="340" styleClass="pane-with-border">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<children>
<Label text="Feature coming soon..." />
<StackPane fx:id="scheduleListPanelPlaceholder" VBox.vgrow="ALWAYS" />
</children>
</StackPane>
</VBox>
<VBox fx:id="studentList" alignment="CENTER_RIGHT" minWidth="340" prefWidth="340" styleClass="pane-with-border" HBox.hgrow="ALWAYS">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
Expand Down
45 changes: 45 additions & 0 deletions src/main/resources/view/ScheduleListCard.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>

<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<children>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets bottom="5" left="15" right="5" top="5" />
</padding>
<children>
<HBox alignment="CENTER_LEFT" spacing="5">
<children>
<Label fx:id="id" styleClass="cell_big_label">
<minWidth>
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" styleClass="cell_big_label" text="\$first" />
</children>
</HBox>
<Label fx:id="subject" styleClass="cell_small_label" text="\$subject" />
<Label fx:id="date" styleClass="cell_small_label" text="\$date" />
<Label fx:id="time" styleClass="cell_small_label" text="\$time" />
</children>
</VBox>
</children>
<rowConstraints>
<RowConstraints />
</rowConstraints>
</GridPane>
</children>
</HBox>
10 changes: 10 additions & 0 deletions src/main/resources/view/ScheduleListPanel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ListView fx:id="scheduleListView" VBox.vgrow="ALWAYS" />
</children>
</VBox>
Loading