Skip to content

Commit

Permalink
Merge pull request #100 from jasmoon/master
Browse files Browse the repository at this point in the history
Add Task Panel
  • Loading branch information
Kyomian authored Mar 28, 2018
2 parents c12c401 + c45c180 commit c446288
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 11 deletions.
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;
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/EventListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void setEventHandlerForSelectionChangeEvent() {
eventListView.getSelectionModel().selectedItemProperty()
.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
logger.fine("Selection in activity list panel changed to : '" + newValue + "'");
logger.fine("Selection in event list panel changed to : '" + newValue + "'");
raise(new EventPanelSelectionChangedEvent(newValue));
}
});
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MainWindow extends UiPart<Stage> {
private Logic logic;

// Independent Ui parts residing in this Ui container
private ActivityListPanel activityListPanel;
private TaskListPanel taskListPanel;
private Config config;
private EventListPanel eventListPanel;
private UserPrefs prefs;
Expand All @@ -49,7 +49,7 @@ public class MainWindow extends UiPart<Stage> {
private MenuItem helpMenuItem;

@FXML
private StackPane activityListPanelPlaceholder;
private StackPane taskListPanelPlaceholder;

@FXML
private StackPane eventListPanelPlaceholder;
Expand Down Expand Up @@ -119,10 +119,10 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
activityListPanel = new ActivityListPanel(logic.getFilteredActivitiesList());
activityListPanelPlaceholder.getChildren().add(activityListPanel.getRoot());

//@@author jasmoon
taskListPanel = new TaskListPanel(logic.getFilteredTaskList());
taskListPanelPlaceholder.getChildren().add(taskListPanel.getRoot());

eventListPanel = new EventListPanel(logic.getFilteredEventList());
eventListPanelPlaceholder.getChildren().add(eventListPanel.getRoot());

Expand Down Expand Up @@ -185,10 +185,6 @@ private void handleExit() {
raise(new ExitAppRequestEvent());
}

public ActivityListPanel getActivityListPanel() {
return this.activityListPanel;
}

@Subscribe
private void handleShowHelpEvent(ShowHelpRequestEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/ui/TaskCard.java
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);
}
}
89 changes: 89 additions & 0 deletions src/main/java/seedu/address/ui/TaskListPanel.java
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());
}
}
}

}
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<items>
<VBox fx:id="personList" prefWidth="100.0" styleClass="VBox" VBox.vgrow="ALWAYS">
<children>
<StackPane id="taskListPanelPlaceholder" fx:id="activityListPanelPlaceholder"
<StackPane id="taskListPanelPlaceholder" fx:id="taskListPanelPlaceholder"
prefHeight="150.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="8.0" left="30.0" right="30.0" top="10.0"/>
Expand Down
36 changes: 36 additions & 0 deletions src/main/resources/view/TaskListCard.fxml
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>
9 changes: 9 additions & 0 deletions src/main/resources/view/TaskListPanel.fxml
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>

0 comments on commit c446288

Please sign in to comment.