diff --git a/src/main/java/seedu/recipe/logic/parser/SwitchCommandParser.java b/src/main/java/seedu/recipe/logic/parser/SwitchCommandParser.java index c4e4589794c..d8fbfb4c9ee 100644 --- a/src/main/java/seedu/recipe/logic/parser/SwitchCommandParser.java +++ b/src/main/java/seedu/recipe/logic/parser/SwitchCommandParser.java @@ -28,6 +28,10 @@ public SwitchCommand parse(String args) throws ParseException { return new SwitchCommand(Tab.RECIPES); } else if (specifiedTab.equals("planning")) { return new SwitchCommand(Tab.PLANNING); + } else if (specifiedTab.equals("goals")) { + return new SwitchCommand(Tab.GOALS); + } else if (specifiedTab.equals("achievements")) { + return new SwitchCommand(Tab.ACHIEVEMENTS); } else { throw new ParseException( String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, SwitchCommand.MESSAGE_USAGE)); diff --git a/src/main/java/seedu/recipe/ui/CookedCard.java b/src/main/java/seedu/recipe/ui/CookedCard.java new file mode 100644 index 00000000000..540dfa93aa6 --- /dev/null +++ b/src/main/java/seedu/recipe/ui/CookedCard.java @@ -0,0 +1,63 @@ +package seedu.recipe.ui; + +import java.io.IOException; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import seedu.recipe.model.cooked.Record; + +/** + * An UI component that displays information of a {@code Recipe}. + */ +public class CookedCard extends UiPart { + + private static final String FXML = "CookedListCard.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 Record record; + private final String styleIngredientsAndSteps = "-fx-font-size: 11pt;\n" + + "-fx-font-family: \"Segoe UI\";\n" + + "-fx-text-fill: #FFFFFF;\n"; + + @FXML + private HBox cardPane; + @FXML + private Label name; + @FXML + private Label id; + + public CookedCard(Record record, int displayedIndex) throws IOException { + super(FXML); + this.record = record; + id.setText(displayedIndex + ". "); + name.setText(record.getName().fullName); + name.setWrapText(true); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof CookedCard)) { + return false; + } + + // state check + CookedCard card = (CookedCard) other; + return id.getText().equals(card.id.getText()) + && record.equals(card.record); + } +} diff --git a/src/main/java/seedu/recipe/ui/CookedListPanel.java b/src/main/java/seedu/recipe/ui/CookedListPanel.java new file mode 100644 index 00000000000..4a56b550a9b --- /dev/null +++ b/src/main/java/seedu/recipe/ui/CookedListPanel.java @@ -0,0 +1,51 @@ +package seedu.recipe.ui; + +import java.io.IOException; +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.recipe.commons.core.LogsCenter; +import seedu.recipe.commons.util.StringUtil; +import seedu.recipe.model.cooked.Record; + +/** + * Panel containing the list of recipes. + */ +public class CookedListPanel extends UiPart { + private static final String FXML = "CookedListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(CookedListPanel.class); + + @FXML + private ListView cookedListView; + + public CookedListPanel(ObservableList recordList) { + super(FXML); + cookedListView.setItems(recordList); + cookedListView.setCellFactory(listView -> new RecordListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Recipe} using a {@code RecipeCard}. + */ + class RecordListViewCell extends ListCell { + @Override + protected void updateItem(Record record, boolean empty) { + super.updateItem(record, empty); + if (empty || record == null) { + setGraphic(null); + setText(null); + } else { + try { + setGraphic(new CookedCard(record, getIndex() + 1).getRoot()); + } catch (IOException e) { + logger.warning("Failed to load : " + StringUtil.getDetails(e)); + } + } + } + } + +} diff --git a/src/main/java/seedu/recipe/ui/MainTabPanel.java b/src/main/java/seedu/recipe/ui/MainTabPanel.java index fcf0d387dbe..99577927b17 100644 --- a/src/main/java/seedu/recipe/ui/MainTabPanel.java +++ b/src/main/java/seedu/recipe/ui/MainTabPanel.java @@ -23,7 +23,7 @@ public class MainTabPanel extends UiPart { private StackPane planningListPanelPlaceholder; @FXML - private StackPane goalsListPanelPlaceholder; + private StackPane cookedListPanelPlaceholder; @FXML private StackPane achievementsListPanelPlaceholder; @@ -34,14 +34,14 @@ public class MainTabPanel extends UiPart { //TODO: change last argument's RecipeListPanel to AchievementsListPanel once class is created public MainTabPanel(RecipeListPanel recipeListPanel, PlanningListPanel planningListPanel, - RecipeListPanel goalsListPanel, RecipeListPanel achievementsListPanel) { + CookedListPanel cookedListPanel, RecipeListPanel achievementsListPanel) { super(FXML); recipeListPanelPlaceholder.getChildren().add(recipeListPanel.getRoot()); planningListPanelPlaceholder.getChildren().add(planningListPanel.getRoot()); - goalsListPanelPlaceholder.getChildren().add(goalsListPanel.getRoot()); + cookedListPanelPlaceholder.getChildren().add(cookedListPanel.getRoot()); achievementsListPanelPlaceholder.getChildren().add(achievementsListPanel.getRoot()); diff --git a/src/main/java/seedu/recipe/ui/MainWindow.java b/src/main/java/seedu/recipe/ui/MainWindow.java index c8a49a090f1..644b9db87f0 100644 --- a/src/main/java/seedu/recipe/ui/MainWindow.java +++ b/src/main/java/seedu/recipe/ui/MainWindow.java @@ -17,6 +17,7 @@ import seedu.recipe.logic.commands.CommandResult; import seedu.recipe.logic.commands.exceptions.CommandException; import seedu.recipe.logic.parser.exceptions.ParseException; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.plan.PlannedRecipe; import seedu.recipe.model.recipe.Recipe; import seedu.recipe.ui.tab.Tab; @@ -38,7 +39,7 @@ public class MainWindow extends UiPart { private MainTabPanel mainTabPanel; private PlanningListPanel planningListPanel; private RecipeListPanel recipeListPanel; - private RecipeListPanel goalsListPanel; + private CookedListPanel cookedListPanel; private RecipeListPanel achievementsListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -59,7 +60,7 @@ public class MainWindow extends UiPart { private StackPane recipeListPanelPlaceholder; @FXML - private StackPane goalsListPanelPlaceholder; + private StackPane cookedListPanelPlaceholder; @FXML private StackPane achievementsListPanelPlaceholder; @@ -134,14 +135,14 @@ void fillInnerParts() { ObservableList plannedList = logic.getFilteredPlannedList(); planningListPanel = new PlanningListPanel(plannedList); - //using recipe list as stub for goalslist and achievements, to be edited later todo - ObservableList goalsList = logic.getFilteredRecipeList(); - goalsListPanel = new RecipeListPanel(goalsList); + ObservableList cookedList = logic.getFilteredRecordList(); + cookedListPanel = new CookedListPanel(cookedList); + //using recipe list as stub for chievements, to be edited later todo ObservableList achievementsList = logic.getFilteredRecipeList(); achievementsListPanel = new RecipeListPanel(achievementsList); - mainTabPanel = new MainTabPanel(recipeListPanel, planningListPanel, goalsListPanel, achievementsListPanel); + mainTabPanel = new MainTabPanel(recipeListPanel, planningListPanel, cookedListPanel, achievementsListPanel); mainTabPanelPlaceholder.getChildren().add(mainTabPanel.getRoot()); resultDisplay = new ResultDisplay(); @@ -213,7 +214,7 @@ private void handleSwitchTab(Tab tab) { case GOALS: showGoalsTab(); break; - case ACHIEVEMENT: + case ACHIEVEMENTS: showAchievementsTab(); break; default: diff --git a/src/main/java/seedu/recipe/ui/tab/Tab.java b/src/main/java/seedu/recipe/ui/tab/Tab.java index 127eb2e4715..12654b6c39a 100644 --- a/src/main/java/seedu/recipe/ui/tab/Tab.java +++ b/src/main/java/seedu/recipe/ui/tab/Tab.java @@ -7,5 +7,5 @@ public enum Tab { RECIPES, PLANNING, GOALS, - ACHIEVEMENT + ACHIEVEMENTS } diff --git a/src/main/resources/view/CookedListCard.fxml b/src/main/resources/view/CookedListCard.fxml new file mode 100644 index 00000000000..a9ad1f9dede --- /dev/null +++ b/src/main/resources/view/CookedListCard.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/CookedListPanel.fxml b/src/main/resources/view/CookedListPanel.fxml new file mode 100644 index 00000000000..3071dc43d37 --- /dev/null +++ b/src/main/resources/view/CookedListPanel.fxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + +
+ +
+
+ + + + + +
+ +
+
+
diff --git a/src/main/resources/view/MainTabPanel.fxml b/src/main/resources/view/MainTabPanel.fxml index 7509c853393..d142c32c9e7 100644 --- a/src/main/resources/view/MainTabPanel.fxml +++ b/src/main/resources/view/MainTabPanel.fxml @@ -33,12 +33,12 @@ - - + diff --git a/src/main/resources/view/PlanningDayCard.fxml b/src/main/resources/view/PlanningDayCard.fxml index 20baea4ae8e..3e800c2575d 100644 --- a/src/main/resources/view/PlanningDayCard.fxml +++ b/src/main/resources/view/PlanningDayCard.fxml @@ -16,5 +16,4 @@ -