forked from nus-cs2103-AY1718S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #100 from jasmoon/master
Add Task Panel
- Loading branch information
Showing
8 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/seedu/address/commons/events/ui/TaskPanelSelectionChangedEvent.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,28 @@ | ||
//@@author jasmoon | ||
package seedu.address.commons.events.ui; | ||
|
||
import seedu.address.commons.events.BaseEvent; | ||
import seedu.address.ui.TaskCard; | ||
|
||
/** | ||
* Represents a selection change in the Task List Panel | ||
*/ | ||
public class TaskPanelSelectionChangedEvent extends BaseEvent { | ||
|
||
|
||
private final TaskCard newSelection; | ||
|
||
public TaskPanelSelectionChangedEvent(TaskCard newSelection) { | ||
this.newSelection = newSelection; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
public TaskCard 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//@@author jasmoon | ||
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.activity.Task; | ||
|
||
/** | ||
* An UI component that displays information of a {@code Task}. | ||
*/ | ||
public class TaskCard extends UiPart<Region> { | ||
|
||
private static final String FXML = "TaskListCard.fxml"; | ||
|
||
public final Task task; | ||
|
||
@FXML | ||
private HBox cardPane; | ||
@FXML | ||
private Label name; | ||
@FXML | ||
private Label id; | ||
@FXML | ||
private Label dateTime; | ||
@FXML | ||
private Label remark; | ||
@FXML | ||
private FlowPane tags; | ||
|
||
public TaskCard(Task task, int displayedIndex) { | ||
super(FXML); | ||
this.task = task; | ||
id.setText(displayedIndex + ". "); | ||
name.setText(task.getName().fullName); | ||
dateTime.setText(task.getDateTime().toString()); | ||
remark.setText(task.getRemark().value); | ||
task.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof TaskCard)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
TaskCard card = (TaskCard) other; | ||
return id.getText().equals(card.id.getText()) | ||
&& task.equals(card.task); | ||
} | ||
} |
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,89 @@ | ||
//@@author jasmoon | ||
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.TaskPanelSelectionChangedEvent; | ||
import seedu.address.model.activity.Task; | ||
|
||
/** | ||
* Panel containing the list of activities. | ||
*/ | ||
public class TaskListPanel extends UiPart<Region> { | ||
private static final String FXML = "TaskListPanel.fxml"; | ||
private final Logger logger = LogsCenter.getLogger(TaskListPanel.class); | ||
|
||
@FXML | ||
private ListView<TaskCard> taskListView; | ||
|
||
public TaskListPanel(ObservableList<Task> taskList) { | ||
super(FXML); | ||
setConnections(taskList); | ||
registerAsAnEventHandler(this); | ||
} | ||
|
||
private void setConnections(ObservableList<Task> taskList) { | ||
ObservableList<TaskCard> mappedList = EasyBind.map( | ||
taskList, (activity) -> new TaskCard(activity, taskList.indexOf(activity) + 1)); | ||
taskListView.setItems(mappedList); | ||
taskListView.setCellFactory(listView -> new TaskListViewCell()); | ||
setEventHandlerForSelectionChangeEvent(); | ||
} | ||
|
||
private void setEventHandlerForSelectionChangeEvent() { | ||
taskListView.getSelectionModel().selectedItemProperty() | ||
.addListener((observable, oldValue, newValue) -> { | ||
if (newValue != null) { | ||
logger.fine("Selection in task list panel changed to : '" + newValue + "'"); | ||
raise(new TaskPanelSelectionChangedEvent(newValue)); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Scrolls to the {@code TaskCard} at the {@code index} and selects it. | ||
*/ | ||
private void scrollTo(int index) { | ||
Platform.runLater(() -> { | ||
taskListView.scrollTo(index); | ||
taskListView.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 TaskCard}. | ||
*/ | ||
class TaskListViewCell extends ListCell<TaskCard> { | ||
|
||
@Override | ||
protected void updateItem(TaskCard activity, boolean empty) { | ||
super.updateItem(activity, empty); | ||
|
||
if (empty || activity == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setGraphic(activity.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,36 @@ | ||
<?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?> | ||
|
||
<!--@@author jasmoon--> | ||
<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> | ||
<FlowPane fx:id="tags" /> | ||
<Label fx:id="dateTime" styleClass="cell_small_label" text="\$dateTime" /> | ||
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" /> | ||
</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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.ListView?> | ||
<?import javafx.scene.layout.VBox?> | ||
|
||
<!-- @@author jasmoon --> | ||
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> | ||
<ListView fx:id="taskListView" VBox.vgrow="ALWAYS" /> | ||
</VBox> |