Skip to content

Commit

Permalink
Merge pull request #81 from Justinhoejj/branch-BirthdayReminder
Browse files Browse the repository at this point in the history
Modify UI for birthday reminder. Resolves #80
  • Loading branch information
Justinhoejj authored Oct 19, 2021
2 parents c632900 + a37b8e1 commit 7e817fa
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public Name getName() {
return name;
}

public String getFullName() {
return name.fullName;
}

public String getPhoneNumber() {
return phone.value;
}

public Phone getPhone() {
return phone;
}
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/seedu/address/ui/BirthdayReminderCard.java
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 src/main/java/seedu/address/ui/BirthdayReminderListPanel.java
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());
}
}
}

}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public class MainWindow extends UiPart<Stage> {
private Logic logic;

// Independent Ui parts residing in this Ui container
private BirthdayReminderListPanel birthdayReminderListPanel;
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

@FXML
private StackPane birthdayReminderListPanelPlaceholder;

@FXML
private StackPane commandBoxPlaceholder;

Expand Down Expand Up @@ -121,6 +125,9 @@ void fillInnerParts() {

CommandBox commandBox = new CommandBox(this::executeCommand);
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());

birthdayReminderListPanel = new BirthdayReminderListPanel(logic.getFilteredPersonList());
birthdayReminderListPanelPlaceholder.getChildren().add(birthdayReminderListPanel.getRoot());
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/main/resources/view/BirthdayReminderListCard.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.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>
8 changes: 8 additions & 0 deletions src/main/resources/view/BirthdayReminderListPanel.fxml
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>
23 changes: 16 additions & 7 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<?import javafx.scene.layout.VBox?>

<fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
title="Address App" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
title="Address App" minWidth="550" minHeight="600" onCloseRequest="#handleExit">
<icons>
<Image url="@/images/address_book_32.png" />
</icons>
Expand Down Expand Up @@ -47,12 +47,21 @@
</padding>
</StackPane>

<VBox fx:id="personList" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>
<SplitPane VBox.vgrow="ALWAYS" dividerPositions="0.66">
<VBox fx:id="personList" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>

<VBox fx:id="birthdayReminderList" styleClass="pane-with-border" maxWidth="550" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="birthdayReminderListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>
</SplitPane>

<StackPane fx:id="statusbarPlaceholder" VBox.vgrow="NEVER" />
</VBox>
Expand Down

0 comments on commit 7e817fa

Please sign in to comment.