Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S1#83 from CFSY/ui
Browse files Browse the repository at this point in the history
Add basic UI for itinerary page
  • Loading branch information
CFSY committed Oct 22, 2022
2 parents f0e9288 + 3237639 commit 296c92a
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/main/java/seedu/waddle/model/item/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public int compare(Item item1, Item item2) {
*/
public Day(int dayNumber) {
this.dayNumber = dayNumber;
this.itemList = new UniqueItemList();
}

/**
Expand Down Expand Up @@ -107,4 +108,8 @@ public int getItemSize() {
public boolean hasItem(Item item) {
return this.itemList.contains(item);
}

public UniqueItemList getItemList() {
return this.itemList;
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/waddle/model/itinerary/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -201,6 +203,16 @@ public Item getItem(MultiIndex index) {
}
}

public ObservableList<ObservableList<Item>> getUnmodifiableItemGroups() {
ObservableList<ObservableList<Item>> itemGroups = FXCollections.observableArrayList();
itemGroups.add(this.unscheduledItemList.asUnmodifiableObservableList());
for (Day day : this.days) {
ObservableList<Item> 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.
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/waddle/storage/JsonAdaptedItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

}
64 changes: 64 additions & 0 deletions src/main/java/seedu/waddle/ui/ItemGroupCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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<Region> {

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

public final ObservableList<Item> 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<Item> itemGroup, int displayedIndex) {
super(FXML);
this.itemGroup = itemGroup;
if (displayedIndex == 0) {
this.id.setText("Wishlist");
} else {
this.id.setText("Day " + displayedIndex);
}
this.itemListPanelPlaceholder.getChildren().add(new ItemListPanel(itemGroup).getRoot());
this.itemListPanelPlaceholder.setMinHeight(UiSizes.ITEM_LIST_MIN_HEIGHT);
}

@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);
}
}
48 changes: 48 additions & 0 deletions src/main/java/seedu/waddle/ui/ItemGroupListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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<ObservableList<Item>> itemGroupListView;

/**
* Creates a {@code ItemListPanel} with the given {@code ObservableList}.
*/
public ItemGroupListPanel(ObservableList<ObservableList<Item>> itemGroups) {
super(FXML);
itemGroupListView.setItems(itemGroups);
itemGroupListView.setCellFactory(listView -> new ItemGroupListPanel.ItemGroupListViewCell());
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Item} using a {@code ItemCard}.
*/
class ItemGroupListViewCell extends ListCell<ObservableList<Item>> {
@Override
protected void updateItem(ObservableList<Item> itemGroup, boolean empty) {
super.updateItem(itemGroup, empty);

if (empty || itemGroup == null) {
setGraphic(null);
setText(null);
} else {
setGraphic(new ItemGroupCard(itemGroup, getIndex()).getRoot());
}
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/waddle/ui/ItemListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ public ItemListPanel(ObservableList<Item> itemList) {
super(FXML);
itemListView.setItems(itemList);
itemListView.setCellFactory(listView -> new ItemListPanel.ItemListViewCell());
itemListView.prefHeightProperty().bind(Bindings.size(itemList).multiply(UiSizes.ITEM_CARD_HEIGHT));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/waddle/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ private CommandResult executeCommand(String commandText) throws CommandException
setListPanel(new ItineraryListPanel(itineraryList));
break;
case WISH:
ObservableList<Item> itemList = StageManager.getInstance().getSelectedItinerary()
.getItemList().asUnmodifiableObservableList();
setListPanel(new ItemListPanel(itemList));
ObservableList<ObservableList<Item>> itemGroups = StageManager.getInstance()
.getSelectedItinerary().getUnmodifiableItemGroups();
setListPanel(new ItemGroupListPanel(itemGroups));
break;
case SCHEDULE:
//TODO: create a ListPanel for Schedule page
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/waddle/ui/UiSizes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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;
}
12 changes: 12 additions & 0 deletions src/main/resources/view/ItemGroupListCard.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>

<VBox VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="id" prefHeight="60.0" text="Label" />
<StackPane fx:id="itemListPanelPlaceholder"/>
</children>
</VBox>
8 changes: 8 additions & 0 deletions src/main/resources/view/ItemGroupListPanel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<ListView fx:id="itemGroupListView" VBox.vgrow="ALWAYS" />
</VBox>
2 changes: 1 addition & 1 deletion src/main/resources/view/ItemListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<VBox alignment="CENTER_LEFT" minHeight="120" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
Expand Down

0 comments on commit 296c92a

Please sign in to comment.