forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from leepoeaik/update-displayUpcomingLessons
Add display upcoming lesson function
- Loading branch information
Showing
6 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |