forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #81 from Justinhoejj/branch-BirthdayReminder
Modify UI for birthday reminder. Resolves #80
- Loading branch information
Showing
7 changed files
with
181 additions
and
7 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
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,63 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Region; | ||
import seedu.address.model.person.Birthday; | ||
import seedu.address.model.person.Person; | ||
|
||
public class BirthdayReminderCard extends UiPart<Region> { | ||
private static final String FXML = "BirthdayReminderListCard.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 Person person; | ||
|
||
@javafx.fxml.FXML | ||
private HBox cardPane; | ||
@FXML | ||
private Label name; | ||
@FXML | ||
private Label phone; | ||
@FXML | ||
private Label birthday; | ||
|
||
/** | ||
* Creates a {@code PersonCode} with the given {@code Person} and index to display. | ||
*/ | ||
public BirthdayReminderCard(Person person) { | ||
super(FXML); | ||
this.person = person; | ||
name.setText(person.getFullName()); | ||
phone.setText(person.getPhoneNumber()); | ||
Optional<Birthday> possibleBirthday = person.getBirthday(); | ||
assert possibleBirthday.isPresent(); | ||
birthday.setText(possibleBirthday.map(Birthday::display).get()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof PersonCard)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
PersonCard card = (PersonCard) other; | ||
return person.equals(card.person); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/ui/BirthdayReminderListPanel.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,46 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javafx.collections.ObservableList; | ||
import javafx.scene.control.ListCell; | ||
import javafx.scene.control.ListView; | ||
import javafx.scene.layout.Region; | ||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.model.person.Person; | ||
|
||
public class BirthdayReminderListPanel extends UiPart<Region> { | ||
private static final String FXML = "BirthdayReminderListPanel.fxml"; | ||
private final Logger logger = LogsCenter.getLogger(BirthdayReminderListPanel.class); | ||
|
||
@javafx.fxml.FXML | ||
private ListView<Person> birthdayReminderListView; | ||
|
||
/** | ||
* Creates a {@code BirthdayReminderListPanel} with the given {@code ObservableList}. | ||
*/ | ||
public BirthdayReminderListPanel(ObservableList<Person> personList) { | ||
super(FXML); | ||
birthdayReminderListView.setItems(personList); | ||
birthdayReminderListView.setCellFactory(listView -> new BirthdayReminderListViewCell()); | ||
} | ||
|
||
/** | ||
* Custom {@code ListCell} that displays the birthday reminder for a {@code Person} | ||
* using a {@code BirthdayReminderCard}. | ||
*/ | ||
class BirthdayReminderListViewCell extends ListCell<Person> { | ||
@Override | ||
protected void updateItem(Person person, boolean empty) { | ||
super.updateItem(person, empty); | ||
|
||
if (empty || person == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setGraphic(new BirthdayReminderCard(person).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,33 @@ | ||
<?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.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> | ||
<Label fx:id="birthday" styleClass="cell_small_label" text="\$birthday" /> | ||
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" /> | ||
</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="birthdayReminderListView" VBox.vgrow="ALWAYS" /> | ||
</VBox> |
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