Skip to content

Commit

Permalink
Merge pull request #120 from tharshita/master
Browse files Browse the repository at this point in the history
Goals tab
  • Loading branch information
beatricetay authored Apr 1, 2020
2 parents e0c0124 + aebd866 commit e2b7c82
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/seedu/recipe/ui/CookedCard.java
Original file line number Diff line number Diff line change
@@ -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<Region> {

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

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);
}
}
51 changes: 51 additions & 0 deletions src/main/java/seedu/recipe/ui/CookedListPanel.java
Original file line number Diff line number Diff line change
@@ -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<Region> {
private static final String FXML = "CookedListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(CookedListPanel.class);

@FXML
private ListView<Record> cookedListView;

public CookedListPanel(ObservableList<Record> 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<Record> {
@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));
}
}
}
}

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/recipe/ui/MainTabPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MainTabPanel extends UiPart<Region> {
private StackPane planningListPanelPlaceholder;

@FXML
private StackPane goalsListPanelPlaceholder;
private StackPane cookedListPanelPlaceholder;

@FXML
private StackPane achievementsListPanelPlaceholder;
Expand All @@ -34,14 +34,14 @@ public class MainTabPanel extends UiPart<Region> {

//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());

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/seedu/recipe/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,7 @@ public class MainWindow extends UiPart<Stage> {
private MainTabPanel mainTabPanel;
private PlanningListPanel planningListPanel;
private RecipeListPanel recipeListPanel;
private RecipeListPanel goalsListPanel;
private CookedListPanel cookedListPanel;
private RecipeListPanel achievementsListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
Expand All @@ -59,7 +60,7 @@ public class MainWindow extends UiPart<Stage> {
private StackPane recipeListPanelPlaceholder;

@FXML
private StackPane goalsListPanelPlaceholder;
private StackPane cookedListPanelPlaceholder;

@FXML
private StackPane achievementsListPanelPlaceholder;
Expand Down Expand Up @@ -134,14 +135,14 @@ void fillInnerParts() {
ObservableList<PlannedRecipe> plannedList = logic.getFilteredPlannedList();
planningListPanel = new PlanningListPanel(plannedList);

//using recipe list as stub for goalslist and achievements, to be edited later todo
ObservableList<Recipe> goalsList = logic.getFilteredRecipeList();
goalsListPanel = new RecipeListPanel(goalsList);
ObservableList<Record> cookedList = logic.getFilteredRecordList();
cookedListPanel = new CookedListPanel(cookedList);

//using recipe list as stub for chievements, to be edited later todo
ObservableList<Recipe> 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();
Expand Down Expand Up @@ -213,7 +214,7 @@ private void handleSwitchTab(Tab tab) {
case GOALS:
showGoalsTab();
break;
case ACHIEVEMENT:
case ACHIEVEMENTS:
showAchievementsTab();
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/recipe/ui/tab/Tab.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public enum Tab {
RECIPES,
PLANNING,
GOALS,
ACHIEVEMENT
ACHIEVEMENTS
}
33 changes: 33 additions & 0 deletions src/main/resources/view/CookedListCard.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>

<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
<HBox spacing="5" alignment="CENTER_LEFT">
<Label fx:id="id" styleClass="cell_big_label">
<minWidth>
<!-- Ensures that the label text is never truncated -->
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
</HBox>
</VBox>
</GridPane>
</HBox>
31 changes: 31 additions & 0 deletions src/main/resources/view/CookedListPanel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.chart.PieChart?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<BorderPane fx:id="borderPane">
<top>
<VBox spacing = "5">
<Label fx:id="cooked" text="Cooked Meals" styleClass="cell_big_label"/>
</VBox>
</top>
<center>
<ListView fx:id="cookedListView" />
</center>
</BorderPane>
<BorderPane fx:id="borderPane2">
<top>
<VBox spacing = "5">
<Label fx:id="graph" text="Goals" styleClass="cell_big_label"/>
</VBox>
</top>
<center>
<PieChart fx:id="graphView" />
</center>
</BorderPane>
</HBox>
4 changes: 2 additions & 2 deletions src/main/resources/view/MainTabPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
</Tab>
<Tab text="Goals">
<content>
<VBox fx:id="goalList" styleClass="pane-with-border" minWidth="340" prefWidth="340"
<VBox fx:id="cookedList" styleClass="pane-with-border" minWidth="340" prefWidth="340"
VBox.vgrow="ALWAYS">
<padding>
<Insets top="5" right="5" bottom="5" left="5"/>
</padding>
<StackPane fx:id="goalsListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
<StackPane fx:id="cookedListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>
</content>
</Tab>
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/view/PlanningDayCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@

</BorderPane>


</VBox>

0 comments on commit e2b7c82

Please sign in to comment.