From 0d706af0bf8b8baf60ceed4ed063b6db1e9c377f Mon Sep 17 00:00:00 2001 From: Clement Foo Date: Sun, 23 Oct 2022 04:57:52 +0800 Subject: [PATCH 1/3] Add basic UI for itinerary page --- .../java/seedu/waddle/model/item/Day.java | 5 ++ .../waddle/model/itinerary/Itinerary.java | 12 ++++ .../seedu/waddle/storage/JsonAdaptedItem.java | 13 ++-- .../java/seedu/waddle/ui/ItemGroupCard.java | 65 +++++++++++++++++++ .../seedu/waddle/ui/ItemGroupListPanel.java | 49 ++++++++++++++ src/main/java/seedu/waddle/ui/MainWindow.java | 7 +- .../resources/view/ItemGroupListCard.fxml | 12 ++++ .../resources/view/ItemGroupListPanel.fxml | 8 +++ 8 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 src/main/java/seedu/waddle/ui/ItemGroupCard.java create mode 100644 src/main/java/seedu/waddle/ui/ItemGroupListPanel.java create mode 100644 src/main/resources/view/ItemGroupListCard.fxml create mode 100644 src/main/resources/view/ItemGroupListPanel.fxml diff --git a/src/main/java/seedu/waddle/model/item/Day.java b/src/main/java/seedu/waddle/model/item/Day.java index 19fe30a6096..2148ec8803f 100644 --- a/src/main/java/seedu/waddle/model/item/Day.java +++ b/src/main/java/seedu/waddle/model/item/Day.java @@ -27,6 +27,7 @@ public int compare(Item item1, Item item2) { */ public Day(int dayNumber) { this.dayNumber = dayNumber; + this.itemList = new UniqueItemList(); } /** @@ -107,4 +108,8 @@ public int getItemSize() { public boolean hasItem(Item item) { return this.itemList.contains(item); } + + public UniqueItemList getItemList() { + return this.itemList; + } } diff --git a/src/main/java/seedu/waddle/model/itinerary/Itinerary.java b/src/main/java/seedu/waddle/model/itinerary/Itinerary.java index 0ea673c0bae..44ab7e7dae7 100644 --- a/src/main/java/seedu/waddle/model/itinerary/Itinerary.java +++ b/src/main/java/seedu/waddle/model/itinerary/Itinerary.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Objects; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import seedu.waddle.commons.core.index.MultiIndex; import seedu.waddle.logic.commands.exceptions.CommandException; import seedu.waddle.model.item.Day; @@ -201,6 +203,16 @@ public Item getItem(MultiIndex index) { } } + public ObservableList> getUnmodifiableItemGroups() { + ObservableList> itemGroups = FXCollections.observableArrayList(); + itemGroups.add(this.unscheduledItemList.asUnmodifiableObservableList()); + for (Day day : this.days) { + ObservableList itemList = day.getItemList().asUnmodifiableObservableList(); + itemGroups.add(itemList); + } + return FXCollections.unmodifiableObservableList(itemGroups); + } + /** * Returns true if both itineraries have the same identity and data fields. * This defines a stronger notion of equality between two itineraries. diff --git a/src/main/java/seedu/waddle/storage/JsonAdaptedItem.java b/src/main/java/seedu/waddle/storage/JsonAdaptedItem.java index d549a30e7d0..8284f7781b8 100644 --- a/src/main/java/seedu/waddle/storage/JsonAdaptedItem.java +++ b/src/main/java/seedu/waddle/storage/JsonAdaptedItem.java @@ -5,7 +5,7 @@ import seedu.waddle.commons.exceptions.IllegalValueException; import seedu.waddle.model.item.Cost; -import seedu.waddle.model.item.Duration; +//import seedu.waddle.model.item.Duration; import seedu.waddle.model.item.Item; import seedu.waddle.model.item.Priority; @@ -19,7 +19,7 @@ public class JsonAdaptedItem { private final String description; private final String priority; private final String cost; - private final String duration; + //private final String duration; /** * Constructs a {@code JsonAdaptedItem} with the given item details. @@ -32,7 +32,7 @@ public JsonAdaptedItem(@JsonProperty("description") String description, this.description = description; this.priority = priority; this.cost = cost; - this.duration = duration; + //this.duration = duration; } /** @@ -42,7 +42,8 @@ public JsonAdaptedItem(Item source) { description = source.getDescription(); priority = source.getPriority().priority; cost = source.getCost().toString(); - duration = source.getDuration().toString(); + //TODO duration and startTime null error + //duration = source.getDuration().toString(); } /** @@ -74,9 +75,9 @@ public Item toModelType() throws IllegalValueException { final Priority modelPriority = new Priority(priority); final Cost modelCost = new Cost(cost); - final Duration modelDuration = new Duration(duration); + //final Duration modelDuration = new Duration(duration); - return new Item(modelDescription, modelPriority, modelCost, modelDuration); + return new Item(modelDescription, modelPriority, modelCost, null); } } diff --git a/src/main/java/seedu/waddle/ui/ItemGroupCard.java b/src/main/java/seedu/waddle/ui/ItemGroupCard.java new file mode 100644 index 00000000000..7730f360169 --- /dev/null +++ b/src/main/java/seedu/waddle/ui/ItemGroupCard.java @@ -0,0 +1,65 @@ +package seedu.waddle.ui; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; +import seedu.waddle.model.item.Item; + +/** + * An UI component that displays information of a {@code Itinerary}. + */ +public class ItemGroupCard extends UiPart { + + private static final String FXML = "ItemGroupListCard.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 ObservableList itemGroup; + + @FXML + private Label id; + @FXML + private StackPane itemListPanelPlaceholder; + + + /** + * Creates a {@code ItineraryCode} with the given {@code Itinerary} and index to display. + */ + public ItemGroupCard(ObservableList itemGroup, int displayedIndex) { + super(FXML); + this.itemGroup = itemGroup; + if (displayedIndex == 0) { + this.id.setText("Wishlist"); + } else { + this.id.setText("Day " + displayedIndex); + } + System.out.println("SET ITEM GROUP ID"); + this.itemListPanelPlaceholder.getChildren().add(new ItemListPanel(itemGroup).getRoot()); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ItemGroupCard)) { + return false; + } + + // state check + ItemGroupCard card = (ItemGroupCard) other; + return id.getText().equals(card.id.getText()) + && itemGroup.equals(card.itemGroup); + } +} diff --git a/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java b/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java new file mode 100644 index 00000000000..d819f50c8d0 --- /dev/null +++ b/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java @@ -0,0 +1,49 @@ +package seedu.waddle.ui; + +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import seedu.waddle.commons.core.LogsCenter; +import seedu.waddle.model.item.Item; + +/** + * Panel containing the list of Items. + */ +public class ItemGroupListPanel extends ListPanel { + private static final String FXML = "ItemGroupListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(ItemGroupListPanel.class); + + @FXML + private ListView> itemGroupListView; + + /** + * Creates a {@code ItemListPanel} with the given {@code ObservableList}. + */ + public ItemGroupListPanel(ObservableList> itemGroups) { + super(FXML); + itemGroupListView.setItems(itemGroups); + itemGroupListView.setCellFactory(listView -> new ItemGroupListPanel.ItemGroupListViewCell()); + System.out.println("DONE CREATING GROUP LIST PANEL"); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Item} using a {@code ItemCard}. + */ + class ItemGroupListViewCell extends ListCell> { + @Override + protected void updateItem(ObservableList itemGroup, boolean empty) { + super.updateItem(itemGroup, empty); + + if (empty || itemGroup == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new ItemGroupCard(itemGroup, getIndex()).getRoot()); + } + } + } + +} diff --git a/src/main/java/seedu/waddle/ui/MainWindow.java b/src/main/java/seedu/waddle/ui/MainWindow.java index c796d056d2c..627f7d187ec 100644 --- a/src/main/java/seedu/waddle/ui/MainWindow.java +++ b/src/main/java/seedu/waddle/ui/MainWindow.java @@ -207,9 +207,10 @@ private CommandResult executeCommand(String commandText) throws CommandException setListPanel(new ItineraryListPanel(itineraryList)); break; case WISH: - ObservableList itemList = StageManager.getInstance().getSelectedItinerary() - .getItemList().asUnmodifiableObservableList(); - setListPanel(new ItemListPanel(itemList)); + ObservableList> itemGroups = StageManager.getInstance() + .getSelectedItinerary().getUnmodifiableItemGroups(); + System.out.println("GOT UNMODIFIABLE ITEM GROUPS"); + setListPanel(new ItemGroupListPanel(itemGroups)); break; case SCHEDULE: //TODO: create a ListPanel for Schedule page diff --git a/src/main/resources/view/ItemGroupListCard.fxml b/src/main/resources/view/ItemGroupListCard.fxml new file mode 100644 index 00000000000..3d28336d68f --- /dev/null +++ b/src/main/resources/view/ItemGroupListCard.fxml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/src/main/resources/view/ItemGroupListPanel.fxml b/src/main/resources/view/ItemGroupListPanel.fxml new file mode 100644 index 00000000000..7dfa756e7ad --- /dev/null +++ b/src/main/resources/view/ItemGroupListPanel.fxml @@ -0,0 +1,8 @@ + + + + + + + + From 31125c3d5ce515c4a9eab302f04ee48ee7ae665d Mon Sep 17 00:00:00 2001 From: Clement Foo Date: Sun, 23 Oct 2022 06:07:55 +0800 Subject: [PATCH 2/3] Slight change to UI --- src/main/java/seedu/waddle/ui/ItemGroupCard.java | 3 +-- src/main/java/seedu/waddle/ui/ItemGroupListPanel.java | 1 - src/main/java/seedu/waddle/ui/ItemListPanel.java | 2 ++ src/main/java/seedu/waddle/ui/MainWindow.java | 1 - src/main/java/seedu/waddle/ui/UiSizes.java | 6 ++++++ src/main/resources/view/ItemGroupListCard.fxml | 2 +- src/main/resources/view/ItemListCard.fxml | 2 +- 7 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 src/main/java/seedu/waddle/ui/UiSizes.java diff --git a/src/main/java/seedu/waddle/ui/ItemGroupCard.java b/src/main/java/seedu/waddle/ui/ItemGroupCard.java index 7730f360169..83810edd84f 100644 --- a/src/main/java/seedu/waddle/ui/ItemGroupCard.java +++ b/src/main/java/seedu/waddle/ui/ItemGroupCard.java @@ -29,7 +29,6 @@ public class ItemGroupCard extends UiPart { @FXML private StackPane itemListPanelPlaceholder; - /** * Creates a {@code ItineraryCode} with the given {@code Itinerary} and index to display. */ @@ -41,8 +40,8 @@ public ItemGroupCard(ObservableList itemGroup, int displayedIndex) { } else { this.id.setText("Day " + displayedIndex); } - System.out.println("SET ITEM GROUP ID"); this.itemListPanelPlaceholder.getChildren().add(new ItemListPanel(itemGroup).getRoot()); + this.itemListPanelPlaceholder.setMinHeight(UiSizes.ITEM_LIST_MIN_HEIGHT); } @Override diff --git a/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java b/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java index d819f50c8d0..dd422c18a5b 100644 --- a/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java +++ b/src/main/java/seedu/waddle/ui/ItemGroupListPanel.java @@ -26,7 +26,6 @@ public ItemGroupListPanel(ObservableList> itemGroups) { super(FXML); itemGroupListView.setItems(itemGroups); itemGroupListView.setCellFactory(listView -> new ItemGroupListPanel.ItemGroupListViewCell()); - System.out.println("DONE CREATING GROUP LIST PANEL"); } /** diff --git a/src/main/java/seedu/waddle/ui/ItemListPanel.java b/src/main/java/seedu/waddle/ui/ItemListPanel.java index 2855d17779e..b4ac1201409 100644 --- a/src/main/java/seedu/waddle/ui/ItemListPanel.java +++ b/src/main/java/seedu/waddle/ui/ItemListPanel.java @@ -2,6 +2,7 @@ import java.util.logging.Logger; +import javafx.beans.binding.Bindings; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.ListCell; @@ -26,6 +27,7 @@ public ItemListPanel(ObservableList itemList) { super(FXML); itemListView.setItems(itemList); itemListView.setCellFactory(listView -> new ItemListPanel.ItemListViewCell()); + itemListView.prefHeightProperty().bind(Bindings.size(itemList).multiply(UiSizes.ITEM_CARD_HEIGHT)); } /** diff --git a/src/main/java/seedu/waddle/ui/MainWindow.java b/src/main/java/seedu/waddle/ui/MainWindow.java index 627f7d187ec..26551350066 100644 --- a/src/main/java/seedu/waddle/ui/MainWindow.java +++ b/src/main/java/seedu/waddle/ui/MainWindow.java @@ -209,7 +209,6 @@ private CommandResult executeCommand(String commandText) throws CommandException case WISH: ObservableList> itemGroups = StageManager.getInstance() .getSelectedItinerary().getUnmodifiableItemGroups(); - System.out.println("GOT UNMODIFIABLE ITEM GROUPS"); setListPanel(new ItemGroupListPanel(itemGroups)); break; case SCHEDULE: diff --git a/src/main/java/seedu/waddle/ui/UiSizes.java b/src/main/java/seedu/waddle/ui/UiSizes.java new file mode 100644 index 00000000000..63c5bf8d401 --- /dev/null +++ b/src/main/java/seedu/waddle/ui/UiSizes.java @@ -0,0 +1,6 @@ +package seedu.waddle.ui; + +public class UiSizes { + public static final double ITEM_CARD_HEIGHT = 120; + public static final double ITEM_LIST_MIN_HEIGHT = 20; +} diff --git a/src/main/resources/view/ItemGroupListCard.fxml b/src/main/resources/view/ItemGroupListCard.fxml index 3d28336d68f..447553199f8 100644 --- a/src/main/resources/view/ItemGroupListCard.fxml +++ b/src/main/resources/view/ItemGroupListCard.fxml @@ -7,6 +7,6 @@ diff --git a/src/main/resources/view/ItemListCard.fxml b/src/main/resources/view/ItemListCard.fxml index 98303073893..95b0b56d77d 100644 --- a/src/main/resources/view/ItemListCard.fxml +++ b/src/main/resources/view/ItemListCard.fxml @@ -14,7 +14,7 @@ - + From 3237639d1b0dc06aa1a7b6033619bf9a402bbabb Mon Sep 17 00:00:00 2001 From: Clement Foo Date: Sun, 23 Oct 2022 06:26:15 +0800 Subject: [PATCH 3/3] Fix checkstyle --- src/main/java/seedu/waddle/ui/UiSizes.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/seedu/waddle/ui/UiSizes.java b/src/main/java/seedu/waddle/ui/UiSizes.java index 63c5bf8d401..038b595a4cb 100644 --- a/src/main/java/seedu/waddle/ui/UiSizes.java +++ b/src/main/java/seedu/waddle/ui/UiSizes.java @@ -1,5 +1,8 @@ package seedu.waddle.ui; +/** + * Standard sizes for UI elements. + */ public class UiSizes { public static final double ITEM_CARD_HEIGHT = 120; public static final double ITEM_LIST_MIN_HEIGHT = 20;