forked from nus-cs2103-AY1819S2/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-AY1819S2#82 from yonggqiii/MASTER
Created files necessary for event viewing in UI
- Loading branch information
Showing
9 changed files
with
349 additions
and
2 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
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,70 @@ | ||
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.event.Event; | ||
|
||
/** | ||
* A UI component that displays information of a {@code Event}. | ||
*/ | ||
public class EventCard extends UiPart<Region> { | ||
|
||
private static final String FXML = "EventListCard.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 Event event; | ||
|
||
@FXML | ||
private HBox cardPane; | ||
@FXML | ||
private Label name; | ||
@FXML | ||
private Label id; | ||
@FXML | ||
private Label venue; | ||
@FXML | ||
private Label startDateTime; | ||
@FXML | ||
private Label endDateTime; | ||
@FXML | ||
private FlowPane persons; | ||
|
||
public EventCard(Event event, int displayedIndex) { | ||
super(FXML); | ||
this.event = event; | ||
id.setText(displayedIndex + ". "); | ||
name.setText(event.getName().fullName); | ||
venue.setText(event.getVenue().value); | ||
startDateTime.setText(event.getStartDateTime().value); | ||
endDateTime.setText(event.getEndDateTime().value); | ||
event.getPersons().forEach(person -> persons.getChildren().add(new Label(person.getName().fullName))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EventCard)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
EventCard card = (EventCard) other; | ||
return id.getText().equals(card.id.getText()) | ||
&& event.equals(card.event); | ||
} | ||
} |
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,86 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javafx.beans.value.ObservableValue; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.Region; | ||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.model.event.Event; | ||
|
||
/** | ||
* The person info display person info | ||
*/ | ||
public class EventInfo extends UiPart<Region> { | ||
|
||
public static final String FXML = "EventInfo.fxml"; | ||
public static final String DEFAULT_DESCRIPTION = "This is a default description"; | ||
|
||
@FXML | ||
private Label titleNameLabel; | ||
@FXML | ||
private Label nameLabel; | ||
@FXML | ||
private Label venueLabel; | ||
@FXML | ||
private Label tagLabel; | ||
@FXML | ||
private Label startsOnLabel; | ||
@FXML | ||
private Label endsOnLabel; | ||
@FXML | ||
private Label descriptionLabel; | ||
|
||
/** | ||
* 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> | ||
*/ | ||
|
||
private final Logger logger = LogsCenter.getLogger(getClass()); | ||
|
||
|
||
public EventInfo(ObservableValue<Event> selectedEvent) { | ||
super(FXML); | ||
showEventDetails(null); | ||
// Load person page when selected person changes. | ||
selectedEvent.addListener((observable, oldValue, newValue) -> | ||
showEventDetails(newValue)); | ||
} | ||
|
||
/** | ||
* Fills all text fields to show details about the event. | ||
* If the specified event is null, all text fields are cleared. | ||
* | ||
* @param event the event or null | ||
*/ | ||
private void showEventDetails(Event event) { | ||
if (event != null) { | ||
// Fill the labels with info from the person object. | ||
titleNameLabel.setText(event.getName().toString()); | ||
nameLabel.setText(event.getName().toString()); | ||
venueLabel.setText(event.getVenue().toString()); | ||
startsOnLabel.setText(event.getStartDateTime().toString()); | ||
endsOnLabel.setText(event.getEndDateTime().toString()); | ||
tagLabel.setText(event.getLabel().toString()); | ||
descriptionLabel.setText(DEFAULT_DESCRIPTION); | ||
|
||
} else { | ||
// Event is null, remove all the text. | ||
nameLabel.setText(""); | ||
venueLabel.setText(""); | ||
startsOnLabel.setText(""); | ||
endsOnLabel.setText(""); | ||
tagLabel.setText(""); | ||
descriptionLabel.setText(DEFAULT_DESCRIPTION); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
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,71 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.logging.Logger; | ||
|
||
import javafx.beans.value.ObservableValue; | ||
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.model.event.Event; | ||
|
||
/** | ||
* Panel containing the list of events. | ||
*/ | ||
public class EventListPanel extends UiPart<Region> { | ||
private static final String FXML = "EventListPanel.fxml"; | ||
private final Logger logger = LogsCenter.getLogger(PersonListPanel.class); | ||
|
||
@FXML | ||
private ListView<Event> eventListView; | ||
|
||
public EventListPanel(ObservableList<Event> eventList, ObservableValue<Event> selectedEvent, | ||
Consumer<Event> onSelectedEventChange) { | ||
super(FXML); | ||
eventListView.setItems(eventList); | ||
eventListView.setCellFactory(listView -> new EventListViewCell()); | ||
eventListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { | ||
logger.fine("Selection in person list panel changed to : '" + newValue + "'"); | ||
onSelectedEventChange.accept(newValue); | ||
}); | ||
selectedEvent.addListener((observable, oldValue, newValue) -> { | ||
logger.fine("Selected person changed to: " + newValue); | ||
|
||
// Don't modify selection if we are already selecting the selected person, | ||
// otherwise we would have an infinite loop. | ||
if (Objects.equals(eventListView.getSelectionModel().getSelectedItem(), newValue)) { | ||
return; | ||
} | ||
|
||
if (newValue == null) { | ||
eventListView.getSelectionModel().clearSelection(); | ||
} else { | ||
int index = eventListView.getItems().indexOf(newValue); | ||
eventListView.scrollTo(index); | ||
eventListView.getSelectionModel().clearAndSelect(index); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Custom {@code ListCell} that displays the graphics of a {@code Event} using am {@code EventCard}. | ||
*/ | ||
class EventListViewCell extends ListCell<Event> { | ||
@Override | ||
protected void updateItem(Event event, boolean empty) { | ||
super.updateItem(event, empty); | ||
|
||
if (empty || event == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setGraphic(new EventCard(event, getIndex() + 1).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.image.ImageView?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.ColumnConstraints?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.RowConstraints?> | ||
|
||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1"> | ||
<children> | ||
<GridPane layoutX="44.0" layoutY="187.0" prefHeight="209.0" prefWidth="406.0"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> | ||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> | ||
</columnConstraints> | ||
<rowConstraints> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
</rowConstraints> | ||
<children> | ||
<Label text="Name" /> | ||
<Label text="Venue" GridPane.rowIndex="1" /> | ||
<Label text="Starts on" GridPane.rowIndex="2" /> | ||
<Label fx:id="nameLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" /> | ||
<Label fx:id="venueLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" /> | ||
<Label fx:id="startsOnLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" /> | ||
<Label text="Ends on" GridPane.rowIndex="3" /> | ||
<Label fx:id="endsOnLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" /> | ||
<Label text="Description" GridPane.rowIndex="5" /> | ||
<Label fx:id="descriptionLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" /> | ||
<Label text="Labels" GridPane.rowIndex="4" /> | ||
<Label fx:id="tagLabel" styleClass="label-bright" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" /> | ||
</children> | ||
</GridPane> | ||
<Label fx:id="titleNameLabel" layoutX="264.0" layoutY="89.0" styleClass="label-bright" text="Name" /> | ||
</children> | ||
</AnchorPane> | ||
|
Oops, something went wrong.