Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues regarding the Drag and Drop of the entry at the start and end of it #37

Merged
merged 10 commits into from
Sep 12, 2018
93 changes: 25 additions & 68 deletions CalendarFXView/src/main/java/com/calendarfx/view/DateControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@

package com.calendarfx.view;

import static java.time.DayOfWeek.SATURDAY;
import static java.time.DayOfWeek.SUNDAY;
import static java.util.Objects.requireNonNull;
import static javafx.scene.input.ContextMenuEvent.CONTEXT_MENU_REQUESTED;

import java.text.MessageFormat;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

import org.controlsfx.control.PopOver;
import org.controlsfx.control.PopOver.ArrowLocation;
import org.controlsfx.control.PropertySheet.Item;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.CalendarSource;
import com.calendarfx.model.Entry;
Expand All @@ -24,6 +48,7 @@
import com.calendarfx.view.page.DayPage;
import com.calendarfx.view.popover.DatePopOver;
import com.calendarfx.view.popover.EntryPopOverContentPane;

import impl.com.calendarfx.view.ViewHelper;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
Expand Down Expand Up @@ -59,31 +84,6 @@
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.util.Callback;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.PopOver.ArrowLocation;
import org.controlsfx.control.PropertySheet.Item;

import java.text.MessageFormat;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

import static java.time.DayOfWeek.SATURDAY;
import static java.time.DayOfWeek.SUNDAY;
import static java.util.Objects.requireNonNull;
import static javafx.scene.control.SelectionMode.MULTIPLE;
import static javafx.scene.input.ContextMenuEvent.CONTEXT_MENU_REQUESTED;
import static javafx.scene.input.MouseButton.PRIMARY;

/**
* The superclass for all controls that are showing calendar information. This
Expand Down Expand Up @@ -425,7 +425,6 @@ protected DateControl() {

addEventFilter(MouseEvent.MOUSE_PRESSED, evt -> {
maybeHidePopOvers();
performSelection(evt);
});
}

Expand Down Expand Up @@ -462,48 +461,6 @@ public final void refreshData() {
getBoundDateControls().forEach(DateControl::refreshData);
}

private void performSelection(MouseEvent evt) {
if ((evt.getButton().equals(PRIMARY) || evt.isPopupTrigger()) && evt.getClickCount() == 1) {

Entry<?> entry;
EntryViewBase<?> view = null;

if (evt.getTarget() instanceof EntryViewBase) {
view = (EntryViewBase<?>) evt.getTarget();
}

if (view == null) {
return;
}

String disableFocusHandlingKey = "disable-focus-handling"; //$NON-NLS-1$

view.getProperties().put(disableFocusHandlingKey, true);
view.requestFocus();

entry = view.getEntry();

if (entry != null) {

if (!isMultiSelect(evt) && !getSelections().contains(entry)) {
clearSelection();
}

if (isMultiSelect(evt) && getSelections().contains(entry)) {
getSelections().remove(entry);
} else if (!getSelections().contains(entry)) {
getSelections().add(entry);
}
}

view.getProperties().remove(disableFocusHandlingKey);

}
}

private boolean isMultiSelect(MouseEvent evt) {
return (evt.isShiftDown() || evt.isShortcutDown()) && getSelectionMode().equals(MULTIPLE);
}

/**
* Creates a new calendar source that will be added to the list of calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@

package com.calendarfx.view;

import static java.util.Objects.requireNonNull;
import static javafx.scene.control.SelectionMode.MULTIPLE;
import static javafx.scene.input.MouseButton.PRIMARY;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Optional;

import org.controlsfx.control.PropertySheet;
import org.controlsfx.control.PropertySheet.Item;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.view.DateControl.EntryContextMenuParameter;
import com.calendarfx.view.DateControl.EntryDetailsParameter;

import javafx.animation.ScaleTransition;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
Expand All @@ -45,14 +57,6 @@
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import javafx.util.Duration;
import org.controlsfx.control.PropertySheet;
import org.controlsfx.control.PropertySheet.Item;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

/**
* The base class for all views that are representing calendar entries. There
Expand Down Expand Up @@ -212,6 +216,8 @@ protected EntryViewBase(Entry<?> entry) {
boolean contains = selections.contains(entry);
selected.set(contains);
});

addEventHandler(MouseEvent.MOUSE_PRESSED, this::performSelection);

bindEntry(entry);
}
Expand Down Expand Up @@ -953,4 +959,30 @@ public String getCategory() {

return items;
}

private void performSelection(MouseEvent evt) {
if ((evt.getButton().equals(PRIMARY) || evt.isPopupTrigger()) && evt.getClickCount() == 1) {
String disableFocusHandlingKey = "disable-focus-handling";
getProperties().put(disableFocusHandlingKey, true);
requestFocus();

DateControl control = getDateControl();

if (!isMultiSelect(evt) && !control.getSelections().contains(entry)) {
control.clearSelection();
}

if(isMultiSelect(evt) && control.getSelections().contains(entry))
control.deselect(entry);
else if (!control.getSelections().contains(entry))
control.getSelections().add(entry);

getProperties().remove(disableFocusHandlingKey);
}
}

private boolean isMultiSelect(MouseEvent evt) {
return (evt.isShiftDown() || evt.isShortcutDown()) && getDateControl().getSelectionMode().equals(MULTIPLE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

package impl.com.calendarfx.view;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Objects;
import java.util.logging.Logger;

import com.calendarfx.model.Calendar;
import com.calendarfx.model.Entry;
import com.calendarfx.model.Interval;
import com.calendarfx.util.LoggingDomain;
import com.calendarfx.view.DateControl;
import com.calendarfx.view.DayEntryView;
Expand All @@ -28,20 +35,13 @@
import com.calendarfx.view.EntryViewBase;
import com.calendarfx.view.VirtualGrid;
import com.calendarfx.view.WeekView;

import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Objects;
import java.util.logging.Logger;

public class DayViewEditController {

private static final Logger LOGGER = LoggingDomain.EDITING;
Expand Down Expand Up @@ -275,65 +275,67 @@ private void mouseDragged(MouseEvent evt) {
}

switch (dragMode) {
case START_TIME:
switch (handle) {
case TOP:
changeStartTime(evt);
break;
case BOTTOM:
changeStartTime(evt);
break;
case CENTER:
break;
}
case START_TIME:
switch (handle) {
case TOP:
case BOTTOM:
changeStartTime(evt);
break;
case END_TIME:
switch (handle) {
case TOP:
changeEndTime(evt);
break;
case BOTTOM:
changeEndTime(evt);
break;
case CENTER:
break;
}
case CENTER:
break;
case START_AND_END_TIME:
changeStartAndEndTime(evt);
}
break;
case END_TIME:
switch (handle) {
case TOP:
case BOTTOM:
changeEndTime(evt);
break;
case CENTER:
break;
}
break;
case START_AND_END_TIME:
changeStartAndEndTime(evt);
break;
}
}

private void changeStartTime(MouseEvent evt) {
LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();
LocalDateTime time = grid(locationTime);

if (evt.getX() > dayView.getWidth() || evt.getX() < 0) {
time = LocalDateTime.of(entry.getStartDate(), time.toLocalTime());
}

LOGGER.finer("changing start time, time = " + time); //$NON-NLS-1$

DraggedEntry draggedEntry = dayView.getDraggedEntry();

if (isMinimumDuration(entry, entry.getEndAsLocalDateTime(), locationTime)) {

Interval interval = draggedEntry.getInterval();
if (isMinimumDuration(entry, entry.getEndAsLocalDateTime(),
locationTime)) {

LocalDate startDate = interval.getStartDate();
LocalDate endDate = interval.getEndDate();
LocalDate startDate;
LocalDate endDate;

LocalTime startTime;
LocalTime endTime;

if (locationTime.isAfter(entry.getEndAsLocalDateTime())) {
if (time.isAfter(entry.getEndAsLocalDateTime())) {
startTime = entry.getEndTime();
startDate = entry.getEndDate();
endTime = time.toLocalTime();
endDate = time.toLocalDate();
} else {
startDate = time.toLocalDate();
startTime = time.toLocalTime();
endTime = entry.getEndTime();
endDate = entry.getEndDate();
}

LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);
LOGGER.finer("new interval: sd = " + startDate + ", st = "
+ startTime + ", ed = " + endDate + ", et = " + endTime);

draggedEntry.setInterval(startDate, startTime, endDate, endTime);

Expand All @@ -345,33 +347,39 @@ private void changeEndTime(MouseEvent evt) {
LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();
LocalDateTime time = grid(locationTime);

LOGGER.finer("changing end time, time = " + time); //$NON-NLS-1$

DraggedEntry draggedEntry = dayView.getDraggedEntry();

if (isMinimumDuration(entry, entry.getStartAsLocalDateTime(), locationTime)) {
if (evt.getX() > dayView.getWidth() || evt.getX() < 0) {
time = LocalDateTime.of(entry.getEndDate(), time.toLocalTime());
}

Interval interval = draggedEntry.getInterval();
LOGGER.finer("changing end time, time = " + time); //$NON-NLS-1$

if (isMinimumDuration(entry, entry.getStartAsLocalDateTime(),
locationTime)) {

LOGGER.finer("dragged entry: " + draggedEntry.getInterval());

LocalDate startDate = interval.getStartDate();
LocalDate endDate = interval.getEndDate();
LocalDate startDate;
LocalDate endDate;

LocalTime startTime;
LocalTime endTime;

if (locationTime.isBefore(entry.getStartAsLocalDateTime())) {
if (time.isBefore(entry.getStartAsLocalDateTime())) {
endTime = entry.getStartTime();
endDate = entry.getStartDate();
startTime = time.toLocalTime();
startDate = time.toLocalDate();
} else {
startTime = entry.getStartTime();
startDate = entry.getStartDate();
endTime = time.toLocalTime();
endDate = time.toLocalDate();
}

LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);
LOGGER.finer("new interval: sd = " + startDate + ", st = "
+ startTime + ", ed = " + endDate + ", et = " + endTime);

draggedEntry.setInterval(startDate, startTime, endDate, endTime);

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ Property files used for logging.
### tutorial

Getting started files.