From 1f34404efec69af20053ca58173ad03c7c602315 Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 12:27:31 +0800 Subject: [PATCH 1/7] Add fxml and refactor code to update UI --- src/main/java/ezschedule/logic/Logic.java | 10 +-- .../java/ezschedule/logic/LogicManager.java | 10 +-- .../logic/commands/ShowNextCommand.java | 2 +- src/main/java/ezschedule/model/Model.java | 17 +++-- .../java/ezschedule/model/ModelManager.java | 28 +++++--- .../ezschedule/model/ReadOnlyScheduler.java | 2 +- src/main/java/ezschedule/model/Scheduler.java | 23 +------ src/main/java/ezschedule/ui/MainWindow.java | 10 +++ src/main/java/ezschedule/ui/ShowNextCard.java | 65 +++++++++++++++++++ .../java/ezschedule/ui/ShowNextPanel.java | 49 ++++++++++++++ src/main/resources/view/MainWindow.fxml | 18 +++-- src/main/resources/view/ShowNextCard.fxml | 39 +++++++++++ src/main/resources/view/ShowNextPanel.fxml | 10 +++ .../logic/commands/AddCommandTest.java | 11 +++- 14 files changed, 239 insertions(+), 55 deletions(-) create mode 100644 src/main/java/ezschedule/ui/ShowNextCard.java create mode 100644 src/main/java/ezschedule/ui/ShowNextPanel.java create mode 100644 src/main/resources/view/ShowNextCard.fxml create mode 100644 src/main/resources/view/ShowNextPanel.fxml diff --git a/src/main/java/ezschedule/logic/Logic.java b/src/main/java/ezschedule/logic/Logic.java index c8a764f1855..ce9e82328a2 100644 --- a/src/main/java/ezschedule/logic/Logic.java +++ b/src/main/java/ezschedule/logic/Logic.java @@ -33,11 +33,6 @@ public interface Logic { */ ReadOnlyScheduler getScheduler(); - /** - * Returns an unmodifiable view of the upcoming list of events - */ - ObservableList getUpcomingEventList(); - /** * Returns an unmodifiable view of the list of events */ @@ -48,6 +43,11 @@ public interface Logic { */ ObservableList getFilteredEventList(); + /** + * Returns an unmodifiable view of the upcoming list of events + */ + ObservableList getUpcomingEventList(); + /** * Updates the filtered list of events */ diff --git a/src/main/java/ezschedule/logic/LogicManager.java b/src/main/java/ezschedule/logic/LogicManager.java index 2662e814a1c..c9ccbee50cf 100644 --- a/src/main/java/ezschedule/logic/LogicManager.java +++ b/src/main/java/ezschedule/logic/LogicManager.java @@ -60,11 +60,6 @@ public ReadOnlyScheduler getScheduler() { return model.getScheduler(); } - @Override - public ObservableList getUpcomingEventList() { - return model.getUpcomingEventList(); - } - @Override public ObservableList getEventList() { return model.getEventList(); @@ -75,6 +70,11 @@ public ObservableList getFilteredEventList() { return model.getFilteredEventList(); } + @Override + public ObservableList getUpcomingEventList() { + return model.getUpcomingEventList(); + } + @Override public void updateFilteredEventList(Predicate predicate) { model.updateFilteredEventList(predicate); diff --git a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java index 818174647cc..809b66411f2 100644 --- a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java +++ b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java @@ -29,7 +29,7 @@ public ShowNextCommand(UpcomingEventPredicate predicate) { @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - model.updateFilteredEventList(predicate); + model.updateUpcomingEventList(predicate); return new CommandResult( String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getFilteredEventList().size())); } diff --git a/src/main/java/ezschedule/model/Model.java b/src/main/java/ezschedule/model/Model.java index f77109601d0..8c815ea9aa0 100644 --- a/src/main/java/ezschedule/model/Model.java +++ b/src/main/java/ezschedule/model/Model.java @@ -85,11 +85,6 @@ public interface Model { */ void setEvent(Event target, Event editedEvent); - /** - * Returns an unmodifiable view of the upcoming event list - */ - ObservableList getUpcomingEventList(); - /** * Returns an unmodifiable view of the event list */ @@ -101,10 +96,22 @@ public interface Model { */ ObservableList getFilteredEventList(); + /** + * Returns an unmodifiable view of the upcoming event list + */ + ObservableList getUpcomingEventList(); + /** * Updates the filter of the filtered event list to filter by the given {@code predicate}. * * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredEventList(Predicate predicate); + + /** + * Updates the filter of the upcoming event list to filter by the given {@code predicate}. + * + * @throws NullPointerException if {@code predicate} is null. + */ + void updateUpcomingEventList(Predicate predicate); } diff --git a/src/main/java/ezschedule/model/ModelManager.java b/src/main/java/ezschedule/model/ModelManager.java index 61189292904..ea886c31a54 100644 --- a/src/main/java/ezschedule/model/ModelManager.java +++ b/src/main/java/ezschedule/model/ModelManager.java @@ -10,6 +10,7 @@ import ezschedule.commons.core.GuiSettings; import ezschedule.commons.core.LogsCenter; import ezschedule.model.event.Event; +import ezschedule.model.event.UpcomingEventPredicate; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; @@ -17,11 +18,15 @@ * Represents the in-memory model of the scheduler data. */ public class ModelManager implements Model { + + public static final int DISPLAY_UPCOMING_COUNT = 1; private static final Logger logger = LogsCenter.getLogger(ModelManager.class); private final Scheduler scheduler; private final UserPrefs userPrefs; private final FilteredList filteredEvents; + private final FilteredList upcomingEvents; + /** * Initializes a ModelManager with the given scheduler and userPrefs. @@ -34,6 +39,7 @@ public ModelManager(ReadOnlyScheduler scheduler, ReadOnlyUserPrefs userPrefs) { this.scheduler = new Scheduler(scheduler); this.userPrefs = new UserPrefs(userPrefs); filteredEvents = new FilteredList<>(this.scheduler.getEventList()); + upcomingEvents = new FilteredList<>(this.scheduler.getEventList()); } public ModelManager() { @@ -118,15 +124,6 @@ public void setEvent(Event target, Event editedEvent) { //=========== Event List Accessors ============================================================= - /** - * Returns an unmodifiable view of the list of {@code Event} backed by the internal list of - * {@code scheduler} - */ - @Override - public ObservableList getUpcomingEventList() { - return scheduler.getUpcomingEvents(); - } - /** * Returns an unmodifiable view of the list of {@code Event} backed by the internal list of * {@code scheduler} @@ -141,12 +138,25 @@ public ObservableList getFilteredEventList() { return filteredEvents; } + @Override + public ObservableList getUpcomingEventList() { + UpcomingEventPredicate predicate = new UpcomingEventPredicate(DISPLAY_UPCOMING_COUNT); + upcomingEvents.setPredicate(predicate); + return upcomingEvents; + } + @Override public void updateFilteredEventList(Predicate predicate) { requireNonNull(predicate); filteredEvents.setPredicate(predicate); } + @Override + public void updateUpcomingEventList(Predicate predicate) { + requireNonNull(predicate); + upcomingEvents.setPredicate(predicate); + } + @Override public boolean equals(Object obj) { // short circuit if same object diff --git a/src/main/java/ezschedule/model/ReadOnlyScheduler.java b/src/main/java/ezschedule/model/ReadOnlyScheduler.java index 6ee1942e753..4697397b715 100644 --- a/src/main/java/ezschedule/model/ReadOnlyScheduler.java +++ b/src/main/java/ezschedule/model/ReadOnlyScheduler.java @@ -4,7 +4,7 @@ import javafx.collections.ObservableList; /** - * Unmodifiable view of an scheduler + * Unmodifiable view of the scheduler */ public interface ReadOnlyScheduler { diff --git a/src/main/java/ezschedule/model/Scheduler.java b/src/main/java/ezschedule/model/Scheduler.java index 29562f2ec45..82940e0bcdf 100644 --- a/src/main/java/ezschedule/model/Scheduler.java +++ b/src/main/java/ezschedule/model/Scheduler.java @@ -6,21 +6,17 @@ import ezschedule.model.event.Event; import ezschedule.model.event.UniqueEventList; -import ezschedule.model.event.UpcomingEventPredicate; import javafx.collections.ObservableList; -import javafx.collections.transformation.FilteredList; /** * Wraps all data at the scheduler level * Duplicates are not allowed (by .isSameEvent comparison) */ public class Scheduler implements ReadOnlyScheduler { - private static final int DISPLAY_UPCOMING_COUNT = 1; - private static final UpcomingEventPredicate predicate = new UpcomingEventPredicate(DISPLAY_UPCOMING_COUNT); private final UniqueEventList events; - private FilteredList upcomingEvents; + // private FilteredList upcomingEvents; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -38,7 +34,6 @@ public class Scheduler implements ReadOnlyScheduler { * Listeners are attached in here. */ public Scheduler() { - upcomingEvents = new FilteredList<>(getEventList()); // Attach a listener to auto-sort events in chronological order events.addListChangeListener(c -> { @@ -48,12 +43,6 @@ public Scheduler() { } } }); - - events.addListChangeListener(c -> { - while (c.next()) { /* Do nothing */ } - upcomingEvents.setPredicate(predicate); - }); - } /** @@ -126,17 +115,7 @@ public void removeEvent(Event key) { events.remove(key); } - /** - * Returns the list of upcoming {@code Event} - * - * @return - */ - public FilteredList getUpcomingEvents() { - return upcomingEvents; - } - //// util methods - @Override public String toString() { return events.asUnmodifiableObservableList().size() + " events"; diff --git a/src/main/java/ezschedule/ui/MainWindow.java b/src/main/java/ezschedule/ui/MainWindow.java index 40264fc8ab7..d2108ea12af 100644 --- a/src/main/java/ezschedule/ui/MainWindow.java +++ b/src/main/java/ezschedule/ui/MainWindow.java @@ -33,6 +33,7 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private EventListPanel eventListPanel; + private ShowNextPanel showNextPanel; private ResultDisplay resultDisplay; @FXML @@ -46,6 +47,8 @@ public class MainWindow extends UiPart { @FXML private StackPane statusbarPlaceholder; @FXML + private StackPane showNextPlaceholder; + @FXML private StackPane calendarPlaceholder; /** @@ -121,6 +124,9 @@ void fillInnerParts() { CommandBox commandBox = new CommandBox(this::executeCommand); commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); + showNextPanel = new ShowNextPanel(logic.getUpcomingEventList()); + showNextPlaceholder.getChildren().add(showNextPanel.getRoot()); + Calendar calendar = new Calendar(logic.getEventList(), logic::updateFilteredEventList); calendarPlaceholder.getChildren().add(calendar.getRoot()); } @@ -169,6 +175,10 @@ public EventListPanel getEventListPanel() { return eventListPanel; } + public ShowNextPanel getShowPanel() { + return showNextPanel; + } + /** * Executes the command and returns the result. * diff --git a/src/main/java/ezschedule/ui/ShowNextCard.java b/src/main/java/ezschedule/ui/ShowNextCard.java new file mode 100644 index 00000000000..1708fd90521 --- /dev/null +++ b/src/main/java/ezschedule/ui/ShowNextCard.java @@ -0,0 +1,65 @@ +package ezschedule.ui; + +import ezschedule.model.event.Event; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; + +/** + * A UI component that displays information of a {@code Event}. + */ +public class ShowNextCard extends UiPart { + + private static final String FXML = "ShowNextCard.fxml"; + + public final Event event; + + @FXML + private HBox cardPane; + @FXML + private Label name; + @FXML + private Label completed; + @FXML + private Label id; + @FXML + private Label date; + @FXML + private Label startTime; + @FXML + private Label endTime; + + /** + * Creates a {@code EventCode} with the given {@code Event} and index to display. + */ + public ShowNextCard(Event event, int displayedIndex) { + super(FXML); + this.event = event; + + id.setText(displayedIndex + ". "); + name.setText(event.getName().fullName); + completed.setText(event.getCompletedStatus()); + date.setText("Date: " + event.getDate().toString()); + startTime.setText("Start Time: " + event.getStartTime().toString()); + endTime.setText("End Time: " + event.getEndTime().toString()); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ShowNextCard)) { + return false; + } + + // state check + ShowNextCard card = (ShowNextCard) other; + return id.getText().equals(card.id.getText()) + && event.equals(card.event); + } +} diff --git a/src/main/java/ezschedule/ui/ShowNextPanel.java b/src/main/java/ezschedule/ui/ShowNextPanel.java new file mode 100644 index 00000000000..83e75fc9127 --- /dev/null +++ b/src/main/java/ezschedule/ui/ShowNextPanel.java @@ -0,0 +1,49 @@ +package ezschedule.ui; + +import java.util.logging.Logger; + +import ezschedule.commons.core.LogsCenter; +import ezschedule.model.event.Event; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; + +/** + * Panel containing the list of upcoming events. + */ +public class ShowNextPanel extends UiPart { + + private static final String FXML = "ShowNextPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(ShowNextPanel.class); + + @FXML + private ListView showNextListView; + + /** + * Creates a {@code EventListPanel} with the given {@code ObservableList}. + */ + public ShowNextPanel(ObservableList eventList) { + super(FXML); + showNextListView.setItems(eventList); + showNextListView.setCellFactory(listView -> new ShowNextPanel.ShowNextViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Event} using a {@code EventCard}. + */ + class ShowNextViewCell extends ListCell { + @Override + protected void updateItem(Event event, boolean empty) { + super.updateItem(event, empty); + + if (empty || event == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new ShowNextCard(event, getIndex() + 1).getRoot()); + } + } + } +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 67b37672546..a3db57457c9 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -46,10 +46,20 @@ - - - - + + + + + + + + + + + + + +
diff --git a/src/main/resources/view/ShowNextCard.fxml b/src/main/resources/view/ShowNextCard.fxml new file mode 100644 index 00000000000..1c306c14d3c --- /dev/null +++ b/src/main/resources/view/ShowNextCard.fxml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/ShowNextPanel.fxml b/src/main/resources/view/ShowNextPanel.fxml new file mode 100644 index 00000000000..15183d946da --- /dev/null +++ b/src/main/resources/view/ShowNextPanel.fxml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/src/test/java/ezschedule/logic/commands/AddCommandTest.java b/src/test/java/ezschedule/logic/commands/AddCommandTest.java index 5776560be99..8d499cabbd5 100644 --- a/src/test/java/ezschedule/logic/commands/AddCommandTest.java +++ b/src/test/java/ezschedule/logic/commands/AddCommandTest.java @@ -144,17 +144,17 @@ public void setEvent(Event target, Event editedEvent) { } @Override - public ObservableList getUpcomingEventList() { + public ObservableList getEventList() { throw new AssertionError("This method should not be called."); } @Override - public ObservableList getEventList() { + public ObservableList getFilteredEventList() { throw new AssertionError("This method should not be called."); } @Override - public ObservableList getFilteredEventList() { + public ObservableList getUpcomingEventList() { throw new AssertionError("This method should not be called."); } @@ -162,6 +162,11 @@ public ObservableList getFilteredEventList() { public void updateFilteredEventList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override + public void updateUpcomingEventList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } } /** From 78e26365c625c757a157ad59780a0ea0cb43d95d Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 13:43:05 +0800 Subject: [PATCH 2/7] Update show next UI to not show completed events --- .../java/ezschedule/logic/commands/DeleteCommand.java | 10 +++++----- .../ezschedule/logic/commands/ShowNextCommand.java | 2 +- src/main/java/ezschedule/model/ModelManager.java | 5 +---- src/main/java/ezschedule/model/Scheduler.java | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/ezschedule/logic/commands/DeleteCommand.java b/src/main/java/ezschedule/logic/commands/DeleteCommand.java index 1b6b39ab9c3..463f0397b14 100644 --- a/src/main/java/ezschedule/logic/commands/DeleteCommand.java +++ b/src/main/java/ezschedule/logic/commands/DeleteCommand.java @@ -18,9 +18,9 @@ public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Deletes the event identified by the index number used in the displayed event list.\n" - + "Parameters: INDEX (must be a positive integer)\n" - + "Example: " + COMMAND_WORD + " 1"; + + ": Deletes the event identified by the index number used in the displayed event list.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; public static final String MESSAGE_DELETE_EVENT_SUCCESS = "Deleted Event: %1$s"; @@ -47,7 +47,7 @@ public CommandResult execute(Model model) throws CommandException { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof DeleteCommand // instanceof handles nulls - && targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check + || (other instanceof DeleteCommand // instanceof handles nulls + && targetIndex.equals(((DeleteCommand) other).targetIndex)); // state check } } diff --git a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java index 809b66411f2..30e37c2ba81 100644 --- a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java +++ b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java @@ -31,7 +31,7 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); model.updateUpcomingEventList(predicate); return new CommandResult( - String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getFilteredEventList().size())); + String.format(Messages.MESSAGE_EVENTS_LISTED_OVERVIEW, model.getUpcomingEventList().size())); } @Override diff --git a/src/main/java/ezschedule/model/ModelManager.java b/src/main/java/ezschedule/model/ModelManager.java index ea886c31a54..29174e2a91e 100644 --- a/src/main/java/ezschedule/model/ModelManager.java +++ b/src/main/java/ezschedule/model/ModelManager.java @@ -19,7 +19,6 @@ */ public class ModelManager implements Model { - public static final int DISPLAY_UPCOMING_COUNT = 1; private static final Logger logger = LogsCenter.getLogger(ModelManager.class); private final Scheduler scheduler; @@ -27,7 +26,6 @@ public class ModelManager implements Model { private final FilteredList filteredEvents; private final FilteredList upcomingEvents; - /** * Initializes a ModelManager with the given scheduler and userPrefs. */ @@ -40,6 +38,7 @@ public ModelManager(ReadOnlyScheduler scheduler, ReadOnlyUserPrefs userPrefs) { this.userPrefs = new UserPrefs(userPrefs); filteredEvents = new FilteredList<>(this.scheduler.getEventList()); upcomingEvents = new FilteredList<>(this.scheduler.getEventList()); + updateUpcomingEventList(new UpcomingEventPredicate(1)); } public ModelManager() { @@ -140,8 +139,6 @@ public ObservableList getFilteredEventList() { @Override public ObservableList getUpcomingEventList() { - UpcomingEventPredicate predicate = new UpcomingEventPredicate(DISPLAY_UPCOMING_COUNT); - upcomingEvents.setPredicate(predicate); return upcomingEvents; } diff --git a/src/main/java/ezschedule/model/Scheduler.java b/src/main/java/ezschedule/model/Scheduler.java index 82940e0bcdf..8b61f73d93d 100644 --- a/src/main/java/ezschedule/model/Scheduler.java +++ b/src/main/java/ezschedule/model/Scheduler.java @@ -16,8 +16,6 @@ public class Scheduler implements ReadOnlyScheduler { private final UniqueEventList events; - // private FilteredList upcomingEvents; - /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication * between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html From cdd0bb8e4ee354bf2c66180e1f60b4c49646c1cd Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 14:14:21 +0800 Subject: [PATCH 3/7] Add persistent show next count and auto refresh upon add/edit/delete --- .../java/ezschedule/model/ModelManager.java | 3 +++ .../model/event/UpcomingEventPredicate.java | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/ezschedule/model/ModelManager.java b/src/main/java/ezschedule/model/ModelManager.java index 29174e2a91e..7a77734b9a7 100644 --- a/src/main/java/ezschedule/model/ModelManager.java +++ b/src/main/java/ezschedule/model/ModelManager.java @@ -107,18 +107,21 @@ public boolean hasEventAtTime(Event event) { @Override public void deleteEvent(Event target) { scheduler.removeEvent(target); + updateUpcomingEventList(new UpcomingEventPredicate()); } @Override public void addEvent(Event event) { scheduler.addEvent(event); updateFilteredEventList(PREDICATE_SHOW_ALL_EVENTS); + updateUpcomingEventList(new UpcomingEventPredicate()); } @Override public void setEvent(Event target, Event editedEvent) { requireAllNonNull(target, editedEvent); scheduler.setEvent(target, editedEvent); + updateUpcomingEventList(new UpcomingEventPredicate()); } //=========== Event List Accessors ============================================================= diff --git a/src/main/java/ezschedule/model/event/UpcomingEventPredicate.java b/src/main/java/ezschedule/model/event/UpcomingEventPredicate.java index 50434d02790..6a387271e31 100644 --- a/src/main/java/ezschedule/model/event/UpcomingEventPredicate.java +++ b/src/main/java/ezschedule/model/event/UpcomingEventPredicate.java @@ -8,10 +8,22 @@ */ public class UpcomingEventPredicate implements Predicate { - private int upcomingCount; + private static int upcomingCount; + private int count; + /** + * Constructor for UpcomingEventPredicate to reuse the given count. + */ + public UpcomingEventPredicate() { + count = upcomingCount; + } + + /** + * Constructor for UpcomingEventPredicate with given count. + */ public UpcomingEventPredicate(int count) { upcomingCount = count; + this.count = count; } // Events should be in chronological order @@ -21,13 +33,13 @@ public boolean test(Event event) { return false; } - return upcomingCount-- > 0; + return count-- > 0; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof UpcomingEventPredicate // instanceof handles nulls - && upcomingCount == ((UpcomingEventPredicate) other).upcomingCount); // state check + && count == ((UpcomingEventPredicate) other).count); // state check } } From 33f07c3ea457f644e1fc11b89d2cd3dcde47a969 Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 14:24:13 +0800 Subject: [PATCH 4/7] Add UI to show how many next event it is currently displaying --- src/main/java/ezschedule/ui/ShowNextPanel.java | 6 ++++++ src/main/resources/view/ShowNextPanel.fxml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ezschedule/ui/ShowNextPanel.java b/src/main/java/ezschedule/ui/ShowNextPanel.java index 83e75fc9127..930b156c422 100644 --- a/src/main/java/ezschedule/ui/ShowNextPanel.java +++ b/src/main/java/ezschedule/ui/ShowNextPanel.java @@ -4,8 +4,10 @@ import ezschedule.commons.core.LogsCenter; import ezschedule.model.event.Event; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.Region; @@ -18,6 +20,8 @@ public class ShowNextPanel extends UiPart { private static final String FXML = "ShowNextPanel.fxml"; private final Logger logger = LogsCenter.getLogger(ShowNextPanel.class); + @FXML + private Label showNextLabel; @FXML private ListView showNextListView; @@ -26,6 +30,8 @@ public class ShowNextPanel extends UiPart { */ public ShowNextPanel(ObservableList eventList) { super(FXML); + eventList.addListener( + (ListChangeListener) c -> showNextLabel.setText("Next " + eventList.size() + " Event")); showNextListView.setItems(eventList); showNextListView.setCellFactory(listView -> new ShowNextPanel.ShowNextViewCell()); } diff --git a/src/main/resources/view/ShowNextPanel.fxml b/src/main/resources/view/ShowNextPanel.fxml index 15183d946da..faedb8e5fb2 100644 --- a/src/main/resources/view/ShowNextPanel.fxml +++ b/src/main/resources/view/ShowNextPanel.fxml @@ -5,6 +5,6 @@ - From 11bac82a03776fa3d664baddd6bb41152dcdb014 Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 14:39:22 +0800 Subject: [PATCH 5/7] Fix show next event number on start --- src/main/resources/view/ShowNextPanel.fxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/view/ShowNextPanel.fxml b/src/main/resources/view/ShowNextPanel.fxml index faedb8e5fb2..9566f374ca6 100644 --- a/src/main/resources/view/ShowNextPanel.fxml +++ b/src/main/resources/view/ShowNextPanel.fxml @@ -5,6 +5,6 @@ - From b4a5f83ade479ebd8ac5f1079e9c0cfa515c3de5 Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 21:00:34 +0800 Subject: [PATCH 6/7] Remove the use of magic number --- src/main/java/ezschedule/model/Model.java | 6 ++++++ src/main/java/ezschedule/model/ModelManager.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ezschedule/model/Model.java b/src/main/java/ezschedule/model/Model.java index 8c815ea9aa0..c3649148e65 100644 --- a/src/main/java/ezschedule/model/Model.java +++ b/src/main/java/ezschedule/model/Model.java @@ -5,6 +5,7 @@ import ezschedule.commons.core.GuiSettings; import ezschedule.model.event.Event; +import ezschedule.model.event.UpcomingEventPredicate; import javafx.collections.ObservableList; /** @@ -16,6 +17,11 @@ public interface Model { */ Predicate PREDICATE_SHOW_ALL_EVENTS = unused -> true; + /** + * {@code Predicate} that always evaluate to true + */ + Predicate PREDICATE_SHOW_NEXT_FIRST_EVENT = new UpcomingEventPredicate(1); + /** * Returns the user prefs. */ diff --git a/src/main/java/ezschedule/model/ModelManager.java b/src/main/java/ezschedule/model/ModelManager.java index 7a77734b9a7..dd35b752e09 100644 --- a/src/main/java/ezschedule/model/ModelManager.java +++ b/src/main/java/ezschedule/model/ModelManager.java @@ -38,7 +38,7 @@ public ModelManager(ReadOnlyScheduler scheduler, ReadOnlyUserPrefs userPrefs) { this.userPrefs = new UserPrefs(userPrefs); filteredEvents = new FilteredList<>(this.scheduler.getEventList()); upcomingEvents = new FilteredList<>(this.scheduler.getEventList()); - updateUpcomingEventList(new UpcomingEventPredicate(1)); + updateUpcomingEventList(PREDICATE_SHOW_NEXT_FIRST_EVENT); } public ModelManager() { From dd6425d61ef8b2faa3806393dcf9de36a70b77e2 Mon Sep 17 00:00:00 2001 From: JrmCkh Date: Tue, 28 Mar 2023 21:11:51 +0800 Subject: [PATCH 7/7] Remove magic number --- .../java/ezschedule/logic/commands/ShowNextCommand.java | 1 + .../java/ezschedule/logic/parser/ShowNextCommandParser.java | 4 +++- src/main/java/ezschedule/model/Model.java | 6 ------ src/main/java/ezschedule/model/ModelManager.java | 3 ++- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java index 30e37c2ba81..89f335d0067 100644 --- a/src/main/java/ezschedule/logic/commands/ShowNextCommand.java +++ b/src/main/java/ezschedule/logic/commands/ShowNextCommand.java @@ -14,6 +14,7 @@ public class ShowNextCommand extends Command { public static final String COMMAND_WORD = "next"; + public static final int SHOW_UPCOMING_COUNT_ONE = 1; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Display upcoming events." + "\nCan be used without any parameters." diff --git a/src/main/java/ezschedule/logic/parser/ShowNextCommandParser.java b/src/main/java/ezschedule/logic/parser/ShowNextCommandParser.java index a58dd23f3cd..c60d371dd91 100644 --- a/src/main/java/ezschedule/logic/parser/ShowNextCommandParser.java +++ b/src/main/java/ezschedule/logic/parser/ShowNextCommandParser.java @@ -1,5 +1,7 @@ package ezschedule.logic.parser; +import static ezschedule.logic.commands.ShowNextCommand.SHOW_UPCOMING_COUNT_ONE; + import ezschedule.commons.core.Messages; import ezschedule.logic.commands.ShowNextCommand; import ezschedule.logic.parser.exceptions.ParseException; @@ -20,7 +22,7 @@ public class ShowNextCommandParser implements Parser { public ShowNextCommand parse(String userInput) throws ParseException { // No argument provided, just show the next one if (userInput.isBlank()) { - return new ShowNextCommand(new UpcomingEventPredicate(1)); + return new ShowNextCommand(new UpcomingEventPredicate(SHOW_UPCOMING_COUNT_ONE)); } try { diff --git a/src/main/java/ezschedule/model/Model.java b/src/main/java/ezschedule/model/Model.java index c3649148e65..8c815ea9aa0 100644 --- a/src/main/java/ezschedule/model/Model.java +++ b/src/main/java/ezschedule/model/Model.java @@ -5,7 +5,6 @@ import ezschedule.commons.core.GuiSettings; import ezschedule.model.event.Event; -import ezschedule.model.event.UpcomingEventPredicate; import javafx.collections.ObservableList; /** @@ -17,11 +16,6 @@ public interface Model { */ Predicate PREDICATE_SHOW_ALL_EVENTS = unused -> true; - /** - * {@code Predicate} that always evaluate to true - */ - Predicate PREDICATE_SHOW_NEXT_FIRST_EVENT = new UpcomingEventPredicate(1); - /** * Returns the user prefs. */ diff --git a/src/main/java/ezschedule/model/ModelManager.java b/src/main/java/ezschedule/model/ModelManager.java index dd35b752e09..1f8444d26ee 100644 --- a/src/main/java/ezschedule/model/ModelManager.java +++ b/src/main/java/ezschedule/model/ModelManager.java @@ -1,6 +1,7 @@ package ezschedule.model; import static ezschedule.commons.util.CollectionUtil.requireAllNonNull; +import static ezschedule.logic.commands.ShowNextCommand.SHOW_UPCOMING_COUNT_ONE; import static java.util.Objects.requireNonNull; import java.nio.file.Path; @@ -38,7 +39,7 @@ public ModelManager(ReadOnlyScheduler scheduler, ReadOnlyUserPrefs userPrefs) { this.userPrefs = new UserPrefs(userPrefs); filteredEvents = new FilteredList<>(this.scheduler.getEventList()); upcomingEvents = new FilteredList<>(this.scheduler.getEventList()); - updateUpcomingEventList(PREDICATE_SHOW_NEXT_FIRST_EVENT); + updateUpcomingEventList(new UpcomingEventPredicate(SHOW_UPCOMING_COUNT_ONE)); } public ModelManager() {