forked from nus-cs2103-AY1718S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY1718S2#105 from Robert-Peng/PetPatien…
…tCard Created PetPatientCard and Panel & Update GUI test
- Loading branch information
Showing
18 changed files
with
682 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/commons/events/ui/PetPatientPanelSelectionChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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; | ||
|
||
/** | ||
* AN UI component that displays the information of a {@code PetPatient} | ||
*/ | ||
public class PetPatientCard extends UiPart<Region> { | ||
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().toString()); | ||
species.setText(petPatient.getSpecies()); | ||
breed.setText(petPatient.getBreed()); | ||
colour.setText(petPatient.getColour()); | ||
bloodType.setText(petPatient.getBloodType()); | ||
ownerNric.setText(petPatient.getOwner().toString()); | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package seedu.address.ui; | ||
|
||
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<Region> { | ||
private static final String FXML = "PetPatientListPanel.fxml"; | ||
private final Logger logger = LogsCenter.getLogger(PetPatientListPanel.class); | ||
|
||
@FXML | ||
private ListView<PetPatientCard> petPatientListView; | ||
|
||
public PetPatientListPanel(ObservableList<PetPatient> petPatientList) { | ||
super(FXML); | ||
setConnections(petPatientList); | ||
registerAsAnEventHandler(this); | ||
} | ||
|
||
private void setConnections(ObservableList<PetPatient> petPatientList) { | ||
ObservableList<PetPatientCard> 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 petPatient 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<PetPatientCard> { | ||
|
||
@Override | ||
protected void updateItem(PetPatientCard petPatient, boolean empty) { | ||
super.updateItem(petPatient, empty); | ||
|
||
if (empty || petPatient == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setGraphic(petPatient.getRoot()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Label?> | ||
<?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.0.141" 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 bottom="5" left="15" right="5" top="5" /> | ||
</padding> | ||
<HBox alignment="CENTER_LEFT" spacing="5"> | ||
<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" styleClass="cell_big_label" text="\$first" /> | ||
</HBox> | ||
<FlowPane fx:id="tags" /> | ||
<Label fx:id="species" styleClass="cell_small_label" text="\$species" /> | ||
<Label fx:id="breed" styleClass="cell_small_label" text="\$breed" /> | ||
<Label fx:id="colour" styleClass="cell_small_label" text="\$colour" /> | ||
<Label fx:id="bloodType" styleClass="cell_small_label" text="\$bloodType" /> | ||
<Label fx:id="ownerNric" styleClass="cell_small_label" text="\$ownerNric" /> | ||
</VBox> | ||
</GridPane> | ||
</HBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="petPatientListView" VBox.vgrow="ALWAYS" /> | ||
</VBox> |
Oops, something went wrong.