From e97f4ea7c60e2a22ab573086e79fe6842426a3b0 Mon Sep 17 00:00:00 2001 From: Robert-Peng Date: Thu, 29 Mar 2018 09:43:13 +0800 Subject: [PATCH 01/11] PetPatientCard --- src/main/java/seedu/address/ui/PetPatientCard.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/seedu/address/ui/PetPatientCard.java diff --git a/src/main/java/seedu/address/ui/PetPatientCard.java b/src/main/java/seedu/address/ui/PetPatientCard.java new file mode 100644 index 000000000000..ae840ccf68fa --- /dev/null +++ b/src/main/java/seedu/address/ui/PetPatientCard.java @@ -0,0 +1,12 @@ +package seedu.address.ui; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import seedu.address.model.petpatient.PetPatient; + +public class PetPatientCard { + +} From 7465e471fc8fd0034f1ccf91cb3b8040f0628d29 Mon Sep 17 00:00:00 2001 From: Robert-Peng Date: Thu, 29 Mar 2018 10:25:45 +0800 Subject: [PATCH 02/11] UPdate --- src/main/java/seedu/address/ui/PetPatientCard.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/ui/PetPatientCard.java b/src/main/java/seedu/address/ui/PetPatientCard.java index ae840ccf68fa..d030772ecb55 100644 --- a/src/main/java/seedu/address/ui/PetPatientCard.java +++ b/src/main/java/seedu/address/ui/PetPatientCard.java @@ -7,6 +7,9 @@ import javafx.scene.layout.Region; import seedu.address.model.petpatient.PetPatient; +/** + * AN UI component that displays the information of a {@code PetPatient} + */ public class PetPatientCard { - + } From 200935cf4f0cdb7f7d442ae1a2593b6ffed1f63d Mon Sep 17 00:00:00 2001 From: Robert-Peng Date: Thu, 29 Mar 2018 12:41:43 +0800 Subject: [PATCH 03/11] Update PatientListCard fxml and PatientListPanel fxml --- .../java/seedu/address/ui/PetPatientCard.java | 81 ++++++++++++++++++- .../seedu/address/ui/PetPatientListPanel.java | 4 + .../resources/view/PetPatientListCard.fxml | 38 +++++++++ .../resources/view/PetPatientListPanel.fxml | 8 ++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/ui/PetPatientListPanel.java create mode 100644 src/main/resources/view/PetPatientListCard.fxml create mode 100644 src/main/resources/view/PetPatientListPanel.fxml diff --git a/src/main/java/seedu/address/ui/PetPatientCard.java b/src/main/java/seedu/address/ui/PetPatientCard.java index d030772ecb55..ae2a2b329733 100644 --- a/src/main/java/seedu/address/ui/PetPatientCard.java +++ b/src/main/java/seedu/address/ui/PetPatientCard.java @@ -10,6 +10,85 @@ /** * AN UI component that displays the information of a {@code PetPatient} */ -public class PetPatientCard { +public class PetPatientCard extends UiPart { + private static final String FXML = "PetPatientListCard.fxml"; + private static final String[] TAG_COLOR_STYLES = + {"teal", "red", "yellow", "blue", "orange", "brown", "green", "pink", + "black", "grey"}; + + public final PetPatient petPatient; + + @FXML + private HBox cardPane; + @FXML + private Label name; + @FXML + private Label id; + @FXML + private Label species; + @FXML + private Label breed; + @FXML + private Label colour; + @FXML + private Label bloodType; + @FXML + private Label ownerNric; + @FXML + private FlowPane tags; + + public PetPatientCard(PetPatient petPatient, int displayedIndex) { + super(FXML); + this.petPatient = petPatient; + id.setText(displayedIndex + ". "); + name.setText(petPatient.getName().fullName); + species.setText(petPatient.getSpecies()); + breed.setText(petPatient.getBreed()); + colour.setText(petPatient.getColour()); + bloodType.setText(petPatient.getBloodType()); + ownerNric.setText(petPatient.getOwner().value); + + createTags(PetPatient); + } + + /** + * Returns the color style for {@code tagName}'s label. + * Solution below adopted from : + * https://github.com/se-edu/addressbook-level4/pull/798/commits/167b3d0b4f7ad34296d2fbf505f9ae71f983f53c + */ + private String getTagColorStyleFor(String tagName) { + // we use the hash code of the tag name to generate a random color, so that the color remain consistent + // between different runs of the program while still making it random enough between tags. + return TAG_COLOR_STYLES[Math.abs(tagName.hashCode()) % TAG_COLOR_STYLES.length]; + } + + /** + * Creates the tag labels for {@code PetPatient}. + */ + private void createTags(PetPatient petPatient) { + petPatient.getTags().forEach(tag -> { + Label tagLabel = new Label(tag.tagName); + tagLabel.getStyleClass().add(getTagColorStyleFor(tag.tagName)); + tags.getChildren().add(tagLabel); + }); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof PetPatientCard)) { + return false; + } + + // state check + PetPatientCard card = (PetPatientCard) other; + return id.getText().equals(card.id.getText()) + && petPatient.equals(card.petPatient); + } } diff --git a/src/main/java/seedu/address/ui/PetPatientListPanel.java b/src/main/java/seedu/address/ui/PetPatientListPanel.java new file mode 100644 index 000000000000..312d5607cbbc --- /dev/null +++ b/src/main/java/seedu/address/ui/PetPatientListPanel.java @@ -0,0 +1,4 @@ +package seedu.address.ui; + +public class PetPatientListPanel { +} diff --git a/src/main/resources/view/PetPatientListCard.fxml b/src/main/resources/view/PetPatientListCard.fxml new file mode 100644 index 000000000000..46fc2e1124b4 --- /dev/null +++ b/src/main/resources/view/PetPatientListCard.fxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/PetPatientListPanel.fxml b/src/main/resources/view/PetPatientListPanel.fxml new file mode 100644 index 000000000000..0ac517133714 --- /dev/null +++ b/src/main/resources/view/PetPatientListPanel.fxml @@ -0,0 +1,8 @@ + + + + + + + + From 78c6a0e78800954b2c8f41d29022cb52cfc03aed Mon Sep 17 00:00:00 2001 From: Robert-Peng Date: Thu, 29 Mar 2018 23:38:13 +0800 Subject: [PATCH 04/11] Update PetPatientListPanel, PetPatientCard and their handlers. --- .../PetPatientPanelSelectionChangedEvent.java | 24 ++++ src/main/java/seedu/address/logic/Logic.java | 4 + .../seedu/address/logic/LogicManager.java | 6 + src/main/java/seedu/address/model/Model.java | 3 + .../seedu/address/model/ModelManager.java | 18 ++- .../java/seedu/address/ui/MainWindow.java | 7 + .../java/seedu/address/ui/PetPatientCard.java | 3 +- .../seedu/address/ui/PetPatientListPanel.java | 86 ++++++++++- src/main/resources/view/MainWindow.fxml | 7 + .../resources/view/PetPatientListPanel.fxml | 2 +- .../guitests/guihandles/MainWindowHandle.java | 7 + .../guihandles/PetPatientCardHandle.java | 96 +++++++++++++ .../guihandles/PetPatientListPanelHandle.java | 136 ++++++++++++++++++ .../logic/commands/AddCommandTest.java | 6 + .../systemtests/AddressBookSystemTest.java | 5 + 15 files changed, 404 insertions(+), 6 deletions(-) create mode 100644 src/main/java/seedu/address/commons/events/ui/PetPatientPanelSelectionChangedEvent.java create mode 100644 src/test/java/guitests/guihandles/PetPatientCardHandle.java create mode 100644 src/test/java/guitests/guihandles/PetPatientListPanelHandle.java diff --git a/src/main/java/seedu/address/commons/events/ui/PetPatientPanelSelectionChangedEvent.java b/src/main/java/seedu/address/commons/events/ui/PetPatientPanelSelectionChangedEvent.java new file mode 100644 index 000000000000..9a6b9eb7591b --- /dev/null +++ b/src/main/java/seedu/address/commons/events/ui/PetPatientPanelSelectionChangedEvent.java @@ -0,0 +1,24 @@ +package seedu.address.commons.events.ui; + +import seedu.address.commons.events.BaseEvent; +import seedu.address.ui.PetPatientCard; + +/** + * Represents a selection change in the PetPatient list Panel + */ +public class PetPatientPanelSelectionChangedEvent extends BaseEvent{ + private final PetPatientCard newSelection; + + public PetPatientPanelSelectionChangedEvent(PetPatientCard newSelection) { + this.newSelection = newSelection; + } + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } + + public PetPatientCard getNewSelection() { + return newSelection; + } +} diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 8b34b862039a..7cd4c922457c 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -5,6 +5,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Person; +import seedu.address.model.petpatient.PetPatient; /** * API of the Logic component @@ -22,6 +23,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the filtered list of petPatients */ + ObservableList getFilteredPetPatientList(); + /** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */ ListElementPointer getHistorySnapshot(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 9f6846bdfc74..b2bdc8e5a38a 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -12,6 +12,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.person.Person; +import seedu.address.model.petpatient.PetPatient; /** * The main LogicManager of the app. @@ -50,6 +51,11 @@ public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } + @Override + public ObservableList getFilteredPetPatientList() { + return model.getFilteredPetPatientList(); + } + @Override public ListElementPointer getHistorySnapshot() { return new ListElementPointer(history.getHistory()); diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index bc444d3816c6..3c7de7909e51 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -52,6 +52,9 @@ void updatePerson(Person target, Person editedPerson) /** Returns an unmodifiable view of the filtered person list */ ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the filtered petPatientList */ + ObservableList getFilteredPetPatientList(); + /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index fd821a741a15..7404746a2712 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -126,6 +126,18 @@ public void updateFilteredPersonList(Predicate predicate) { filteredPersons.setPredicate(predicate); } + //=========== Filtered PetPatient List Accessors ============================================================= + + @Override + public ObservableList getFilteredPetPatientList() { + return FXCollections.unmodifiableObservableList(filteredPetPatients); + } + + @Override + public void updateFilteredPetPatientList(Predicate predicate) { + requireNonNull(predicate); + filteredPetPatients.setPredicate(predicate); + } //=========== Filtered Appointment List Accessors ============================================================= /** @@ -143,11 +155,13 @@ public void updateFilteredAppointmentList(Predicate predicate) { filteredAppointments.setPredicate(predicate); } + /* @Override public void updateFilteredPetPatientList(Predicate predicate) { - requireNonNull(predicate); - filteredPetPatients.setPredicate(predicate); + requireNonNull(predicate); + filteredPetPatients.setPredicate(predicate); } + */ @Override public boolean equals(Object obj) { diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 60cddf9ef523..ab066c5983b0 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -39,6 +39,7 @@ public class MainWindow extends UiPart { private CalendarWindow calendarWindow; //private BrowserPanel browserPanel; private PersonListPanel personListPanel; + private PetPatientListPanel petPatientListPanel; private Config config; private UserPrefs prefs; @@ -54,6 +55,9 @@ public class MainWindow extends UiPart { @FXML private StackPane personListPanelPlaceholder; + @FXML + private StackPane petPatientListPanelPlaceholder; + @FXML private StackPane resultDisplayPlaceholder; @@ -126,6 +130,9 @@ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + petPatientListPanel = new PetPatientListPanel(logic.getFilteredPetPatientList()); + petPatientListPanelPlaceholder.getChildren().add(petPatientListPanel.getRoot()); + ResultDisplay resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); diff --git a/src/main/java/seedu/address/ui/PetPatientCard.java b/src/main/java/seedu/address/ui/PetPatientCard.java index ae2a2b329733..532e71d87331 100644 --- a/src/main/java/seedu/address/ui/PetPatientCard.java +++ b/src/main/java/seedu/address/ui/PetPatientCard.java @@ -48,8 +48,7 @@ public PetPatientCard(PetPatient petPatient, int displayedIndex) { colour.setText(petPatient.getColour()); bloodType.setText(petPatient.getBloodType()); ownerNric.setText(petPatient.getOwner().value); - - createTags(PetPatient); + createTags(petPatient); } /** diff --git a/src/main/java/seedu/address/ui/PetPatientListPanel.java b/src/main/java/seedu/address/ui/PetPatientListPanel.java index 312d5607cbbc..89cdfc593213 100644 --- a/src/main/java/seedu/address/ui/PetPatientListPanel.java +++ b/src/main/java/seedu/address/ui/PetPatientListPanel.java @@ -1,4 +1,88 @@ package seedu.address.ui; -public class PetPatientListPanel { +import java.util.logging.Logger; + +import org.fxmisc.easybind.EasyBind; + +import com.google.common.eventbus.Subscribe; + +import javafx.application.Platform; +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.address.commons.core.LogsCenter; +import seedu.address.commons.events.ui.JumpToListRequestEvent; +import seedu.address.commons.events.ui.PetPatientPanelSelectionChangedEvent; +import seedu.address.model.petpatient.PetPatient; + +/** + * Panel containing list of PetPatients + */ +public class PetPatientListPanel extends UiPart { + private static final String FXML = "PetPatientListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(PersonListPanel.class); + + @FXML + private ListView petPatientListView; + + public PetPatientListPanel(ObservableList petPatientList) { + super(FXML); + setConnections(petPatientList); + registerAsAnEventHandler(this); + } + + private void setConnections(ObservableList petPatientList) { + ObservableList mappedList = EasyBind.map( + petPatientList, (petPatient) -> new PetPatientCard(petPatient, petPatientList.indexOf(petPatient) + 1)); + petPatientListView.setItems(mappedList); + petPatientListView.setCellFactory(listView -> new PetPatientListViewCell()); + setEventHandlerForSelectionChangeEvent(); + } + + private void setEventHandlerForSelectionChangeEvent() { + petPatientListView.getSelectionModel().selectedItemProperty() + .addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + logger.fine("Selection in person list panel changed to : '" + newValue + "'"); + raise(new PetPatientPanelSelectionChangedEvent(newValue)); + } + }); + } + + /** + * Scrolls to the {@code PetPatientCard} at the {@code index} and selects it. + */ + private void scrollTo(int index) { + Platform.runLater(() -> { + petPatientListView.scrollTo(index); + petPatientListView.getSelectionModel().clearAndSelect(index); + }); + } + + @Subscribe + private void handleJumpToListRequestEvent(JumpToListRequestEvent event) { + logger.info(LogsCenter.getEventHandlingLogMessage(event)); + scrollTo(event.targetIndex); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code PetPatientCard}. + */ + class PetPatientListViewCell extends ListCell { + + @Override + protected void updateItem(PetPatientCard petPatient, boolean empty) { + super.updateItem(petPatient, empty); + + if (empty || petPatient == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(petPatient.getRoot()); + } + } + } + } diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 3b038d0e314a..ee68fdb4c6df 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -54,6 +54,13 @@ + + + + + + + diff --git a/src/main/resources/view/PetPatientListPanel.fxml b/src/main/resources/view/PetPatientListPanel.fxml index 0ac517133714..77a393e20301 100644 --- a/src/main/resources/view/PetPatientListPanel.fxml +++ b/src/main/resources/view/PetPatientListPanel.fxml @@ -4,5 +4,5 @@ - + diff --git a/src/test/java/guitests/guihandles/MainWindowHandle.java b/src/test/java/guitests/guihandles/MainWindowHandle.java index 54e880bb1898..9fdd9977a2ab 100644 --- a/src/test/java/guitests/guihandles/MainWindowHandle.java +++ b/src/test/java/guitests/guihandles/MainWindowHandle.java @@ -13,6 +13,7 @@ public class MainWindowHandle extends StageHandle { private final StatusBarFooterHandle statusBarFooter; private final MainMenuHandle mainMenu; private final CalendarPanelHandle calendarPanel; + private final PetPatientListPanelHandle petPatientListPanel; //private final BrowserPanelHandle browserPanel; @@ -25,6 +26,8 @@ public MainWindowHandle(Stage stage) { statusBarFooter = new StatusBarFooterHandle(getChildNode(StatusBarFooterHandle.STATUS_BAR_PLACEHOLDER)); mainMenu = new MainMenuHandle(getChildNode(MainMenuHandle.MENU_BAR_ID)); calendarPanel = new CalendarPanelHandle(getChildNode(CalendarPanelHandle.CALENDARPANEL_ID)); + petPatientListPanel = new PetPatientListPanelHandle( + getChildNode(PetPatientListPanelHandle.PETPATIENT_LIST_VIEW_ID)); //browserPanel = new BrowserPanelHandle(getChildNode(BrowserPanelHandle.BROWSER_ID)); } @@ -52,6 +55,10 @@ public CalendarPanelHandle getCalendarPanel() { return calendarPanel; } + public PetPatientListPanelHandle getPetPatientListPanel() { + return petPatientListPanel; + } + //public BrowserPanelHandle getBrowserPanel() { // return browserPanel; //} diff --git a/src/test/java/guitests/guihandles/PetPatientCardHandle.java b/src/test/java/guitests/guihandles/PetPatientCardHandle.java new file mode 100644 index 000000000000..f419261fbd9d --- /dev/null +++ b/src/test/java/guitests/guihandles/PetPatientCardHandle.java @@ -0,0 +1,96 @@ +package guitests.guihandles; + +import java.util.List; +import java.util.stream.Collectors; + +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.layout.Region; + +/** + * Provides a handle to a petPatient card in the petPatient list panel + */ + +public class PetPatientCardHandle extends NodeHandle{ + private static final String ID_FIELD_ID = "#id"; + private static final String NAME_FIELD_ID = "#name"; + private static final String SPECIES_FIELD_ID = "#species"; + private static final String BREED_FIELD_ID = "#breed"; + private static final String COLOUR_FIELD_ID = "#colour"; + private static final String BLOODTYPE_FIELD_ID = "#bloodType"; + private static final String OWNERNRIC_FIELD_ID = "#ownerNric"; + private static final String TAGS_FIELD_ID = "#tags"; + + private final Label idLabel; + private final Label nameLabel; + private final Label speciesLabel; + private final Label breedLabel; + private final Label colourLabel; + private final Label bloodTypeLabel; + private final Label ownerNricLabel; + private final List