Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Commit

Permalink
Add a prototype calendar, using jfxtras library (nus-cs2103-AY1819S1#57)
Browse files Browse the repository at this point in the history
* Add a prototype calendar, using jfxtras library

CalendarDisplay: The new class that extends UiPart

add the calendarDisplay to the MainWIndow

* merge calendarDisplay UI into existing ui
rename CalendarEvent.getDescription to CalendarEvent.getDescriptionObject
add functionality so ui will update when user updates calendarEvents
fix calendar losing focus on toggling view
  • Loading branch information
pangjiahao authored and bryanwongweiheng committed Oct 28, 2018
1 parent 7f8eb8a commit 77a3635
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 14 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies {

compile 'com.joestelmach:natty:0.13'
compile 'me.xdrop:fuzzywuzzy:1.1.10'
compile group: 'org.jfxtras', name: 'jfxtras-agenda', version: '9.0-r1-SNAPSHOT'

implementation group: 'org.controlsfx', name: 'controlsfx', version: '8.40.11'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static CalendarEvent createEditedCalendarEvent(CalendarEvent calendarEve

Title updatedName = editCalendarEventDescriptor.getTitle().orElse(calendarEventToEdit.getTitle());
Description updatedDescription =
editCalendarEventDescriptor.getDescription().orElse(calendarEventToEdit.getDescription());
editCalendarEventDescriptor.getDescription().orElse(calendarEventToEdit.getDescriptionObject());

DateTime updatedStart = editCalendarEventDescriptor.getStart().orElse(calendarEventToEdit.getStart());
DateTime updatedEnd = editCalendarEventDescriptor.getEnd().orElse(calendarEventToEdit.getEnd());
Expand Down
77 changes: 73 additions & 4 deletions src/main/java/seedu/address/model/calendarevent/CalendarEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.time.LocalDateTime;
import java.time.temporal.Temporal;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import jfxtras.scene.control.agenda.Agenda;
import seedu.address.model.tag.Tag;

/**
* Represents a Calendar Event in the scheduler.
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class CalendarEvent {
public class CalendarEvent extends Agenda.AppointmentImplLocal {

// Identity fields
private final Title title;
Expand All @@ -24,6 +28,8 @@ public class CalendarEvent {
private final DateTimeInfo dateTimeInfo;
private final Set<Tag> tags = new HashSet<>();

private boolean isWholeDay;

/**
* Every field must be present and not null.
*/
Expand All @@ -34,13 +40,76 @@ public CalendarEvent(Title title, Description description, DateTimeInfo dateTime
this.dateTimeInfo = dateTimeInfo;
this.venue = venue;
this.tags.addAll(tags);

// Appointment variables
this.isWholeDay = false;
}

public Title getTitle() {
return title;
}

public Description getDescription() {
@Override
public Boolean isWholeDay() {
return false;
}

@Override
public void setWholeDay(Boolean b) {
this.isWholeDay = b;
}

@Override
public String getSummary() {
return null;
}

@Override
public void setSummary(String s) {

}

@Override
public String getDescription() {
return description.toString();
}

@Override
public void setDescription(String s) {

}

@Override
public String getLocation() {
return this.venue.toString();
}

@Override
public void setLocation(String s) {

}

// TODO: set up appointment groups
@Override
public Agenda.AppointmentGroup getAppointmentGroup() {
return null;
}

@Override
public void setAppointmentGroup(Agenda.AppointmentGroup s) {

}

public LocalDateTime getStartLocalDateTime() {
return this.dateTimeInfo.start.localDateTime;
}

@Override
public LocalDateTime getEndLocalDateTime() {
return this.dateTimeInfo.end.localDateTime;
}

public Description getDescriptionObject() {
return description;
}

Expand Down Expand Up @@ -95,7 +164,7 @@ public boolean equals(Object other) {

CalendarEvent otherCalendarEvent = (CalendarEvent) other;
return otherCalendarEvent.getTitle().equals(getTitle())
&& otherCalendarEvent.getDescription().equals(getDescription())
&& otherCalendarEvent.getDescriptionObject().equals(getDescriptionObject())
&& otherCalendarEvent.getStart().equals(getStart())
&& otherCalendarEvent.getEnd().equals(getEnd())
&& otherCalendarEvent.getVenue().equals(getVenue())
Expand All @@ -114,7 +183,7 @@ public String toString() {
builder.append(" Title: ")
.append(getTitle())
.append(" Description: ")
.append(getDescription())
.append(getDescriptionObject())
.append(" Start Date & Time: ")
.append(getStart())
.append(" End Date & Time: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public XmlAdaptedCalendarEvent(String title, String description, String start, S
*/
public XmlAdaptedCalendarEvent(CalendarEvent source) {
title = source.getTitle().value;
description = source.getDescription().value;
description = source.getDescriptionObject().value;
start = source.getStart().toInputFormat();
end = source.getEnd().toInputFormat();
venue = source.getVenue().value;
Expand Down
197 changes: 197 additions & 0 deletions src/main/java/seedu/address/ui/CalendarDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package seedu.address.ui;

import static javafx.scene.input.KeyEvent.KEY_PRESSED;

import java.time.LocalDateTime;
import java.util.logging.Logger;

import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import jfxtras.internal.scene.control.skin.agenda.AgendaDaySkin;
import jfxtras.internal.scene.control.skin.agenda.AgendaWeekSkin;
import jfxtras.scene.control.agenda.Agenda;

import jfxtras.scene.control.agenda.Agenda.Appointment;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.calendarevent.CalendarEvent;


/**
* The Ui component that is responsible for displaying a List of CalendarEvents to the user
*/
public class CalendarDisplay extends UiPart<Region> {
private static final String FXML = "CalendarDisplay.fxml";
private final Logger logger = LogsCenter.getLogger(CalendarDisplay.class);

private ObservableList<CalendarEvent> calendarEventList;

private Agenda agenda;

// keeps track of which week calendar is showing
private LocalDateTime currentDateTime = LocalDateTime.now()
.withHour(0).withMinute(0).withSecond(0).withNano(0);

@FXML
private VBox calendarDisplayBox;

public CalendarDisplay(ObservableList<CalendarEvent> calendarEventList) {
super(FXML);
// registerAsAnEventHandler(this); // I don't think this is needed as of now

this.calendarEventList = calendarEventList;
initAgenda(); // set up agenda internally
setConnections(calendarEventList);
setControls();
}

/**
* Starts up the internal Agenda Object
* Prevents the user from interacting directly with the calendar display
*/
private void initAgenda() {
agenda = new Agenda();

// register actionCallBack, to be executed when user double click on appointment
agenda.actionCallbackProperty().set(new Callback<Appointment, Void>() {
@Override
public Void call(Appointment param) {
// can add more functionality here
logger.info("User double clicked on " + param.toString());
return null;
}
});

// disable allowing user to create appointments by clicking on screen
agenda.setAppointmentChangedCallback(null);

// disable dragging appointments around
agenda.setAllowDragging(false);

// set the week for calendar to display
agenda.setDisplayedLocalDateTime(currentDateTime);

// show 1 week
agenda.setSkin(new AgendaWeekSkin(agenda));

// add agenda to the VBox area
calendarDisplayBox.getChildren().add(agenda);
}

/**
* Passes agenda the list of CalendarEvents to display
* @param calendarEventList
*/
private void setConnections(ObservableList<CalendarEvent> calendarEventList) {
// populate the calendar by adding all the events to the calendar
agenda.appointments().addAll(calendarEventList);

// TODO: fix weird add/remove all items bug for first command
this.calendarEventList.addListener(new ListChangeListener<CalendarEvent>() {
@Override
public void onChanged(Change<? extends CalendarEvent> c) {
while (c.next()) {
if (c.wasRemoved()) {
for (CalendarEvent removedEvent : c.getRemoved()) {
agenda.appointments().remove(removedEvent);
System.out.println("REMOVED: " + removedEvent.getTitle());
}
}
if (c.wasAdded()) {
for (CalendarEvent addedEvent : c.getAddedSubList()) {
agenda.appointments().add(addedEvent);
System.out.println("ADDED: " + addedEvent.getTitle());
}
}
}
}
});
}

/**
* Temporary convienience method to test navigation
* The calendarDisplay must be in focus for this to work, i.e. must click on the calendar
* TODO: get help with the down key problem
*/
public void setControls() {
agenda.addEventFilter(KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.T) { // toggle between day and week view
logger.info("Toggle Pressed");
if (agenda.getSkin() instanceof AgendaDaySkin) {
setViewToWeeklyView();
} else if (agenda.getSkin() instanceof AgendaWeekSkin) {
setViewToDailyView();
}
agenda.requestFocus();
} else if (event.getCode() == KeyCode.LEFT) {
logger.info("LEFT arrow Pressed");
if (agenda.getSkin() instanceof AgendaDaySkin) {
displayPreviousDay();
} else if (agenda.getSkin() instanceof AgendaWeekSkin) {
displayPreviousWeek();
}
} else if (event.getCode() == KeyCode.RIGHT) {
logger.info("RIGHT arrow Pressed");
if (agenda.getSkin() instanceof AgendaDaySkin) {
displayNextDay();
} else if (agenda.getSkin() instanceof AgendaWeekSkin) {
displayNextWeek();
}
}
}
});
}

/**
* Toggle the view
*/
public void setViewToWeeklyView() {
agenda.setSkin(new AgendaWeekSkin(agenda)); // skin for viewing by week
}

/**
* Toggle the view
*/
public void setViewToDailyView() {
agenda.setSkin(new AgendaDaySkin(agenda)); // skin for viewing by day
}
/**
* Navigation method
*/
public void displayNextWeek() {
currentDateTime = currentDateTime.plusDays(7);
agenda.setDisplayedLocalDateTime(currentDateTime);
}

/**
* Navigation method
*/
public void displayPreviousWeek() {
currentDateTime = currentDateTime.minusDays(7);
agenda.setDisplayedLocalDateTime(currentDateTime);
}

/**
* Navigation method
*/
public void displayNextDay() {
currentDateTime = currentDateTime.plusDays(1);
agenda.setDisplayedLocalDateTime(currentDateTime);
}

/**
* Navigation method
*/
public void displayPreviousDay() {
currentDateTime = currentDateTime.minusDays(1);
agenda.setDisplayedLocalDateTime(currentDateTime);
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/CalendarEventCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CalendarEventCard(CalendarEvent calendarEvent, int displayedIndex) {
this.calendarEvent = calendarEvent;
id.setText(displayedIndex + ". ");
title.setText(calendarEvent.getTitle().value);
description.setText(calendarEvent.getDescription().value);
description.setText(calendarEvent.getDescriptionObject().value);
venue.setText(calendarEvent.getVenue().value);
// TODO add start date and end date (remember to update fxml file)
calendarEvent.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
Expand Down
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 @@ -36,6 +36,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private BrowserPanel browserPanel;
private CalendarDisplay calendarDisplay;
private CalendarPanel calendarPanel;
private Config config;
private UserPrefs prefs;
Expand All @@ -47,6 +48,9 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private StackPane resultDisplayPlaceholder;

@FXML
private StackPane calendarDisplayPlaceholder;

@FXML
private StackPane commandBoxPlaceholder;

Expand Down Expand Up @@ -127,6 +131,9 @@ void fillInnerParts() {
TaskListPanel taskListPanel = new TaskListPanel();
taskListPanelPlaceholder.getChildren().add(taskListPanel.getRoot());

calendarDisplay = new CalendarDisplay(logic.getFilteredCalendarEventList());
calendarDisplayPlaceholder.getChildren().add(calendarDisplay.getRoot());

DayMonthYearPanel dayMonthYearPanel = new DayMonthYearPanel(logic.getFilteredCalendarEventList());
dayMonthYearPanelPlaceholder.getChildren().add(dayMonthYearPanel.getRoot());

Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/view/CalendarDisplay.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.layout.*?>
<StackPane styleClass="stack-pane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:id="calendarDisplayBox">

</VBox>
</StackPane>
Loading

0 comments on commit 77a3635

Please sign in to comment.