Skip to content

Commit

Permalink
Another fix for duplicate entries in DayView with scrolling enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed May 8, 2020
1 parent f2a423b commit d05787d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
Expand Up @@ -79,17 +79,17 @@ public Node getPanel(Stage stage) {
for (int i = 0; i < 1; i++) {
CalendarSource source = new CalendarSource("Default");

Calendar calendar1 = new HelloDayViewCalendar();
Calendar calendar1 = new HelloDayViewCalendar("cal1");
calendar1.setStyle(Style.STYLE1);
source.getCalendars().add(calendar1);

// Calendar calendar2 = new HelloDayViewCalendar();
// calendar2.setStyle(Style.STYLE2);
// source.getCalendars().add(calendar2);
//
// Calendar calendar3 = new HelloDayViewCalendar();
// calendar3.setStyle(Style.STYLE3);
// source.getCalendars().add(calendar3);
Calendar calendar2 = new HelloDayViewCalendar("cal2");
calendar2.setStyle(Style.STYLE2);
source.getCalendars().add(calendar2);

Calendar calendar3 = new HelloDayViewCalendar("cal3");
calendar3.setStyle(Style.STYLE3);
source.getCalendars().add(calendar3);

String resource = "Resource " + (i + 1);
resourceCalendarView.getResources().add(resource);
Expand Down Expand Up @@ -137,20 +137,20 @@ protected Class<?> getJavaDocClass() {

class HelloDayViewCalendar extends Calendar {

public HelloDayViewCalendar() {
// createEntries(LocalDate.now().minusDays(2));
// createEntries(LocalDate.now().minusDays(1));
public HelloDayViewCalendar(String name) {
setName(name);
createEntries(LocalDate.now().minusDays(2));
createEntries(LocalDate.now().minusDays(1));
createEntries(LocalDate.now());
// createEntries(LocalDate.now().plusDays(1));
// createEntries(LocalDate.now().plusDays(2));
createEntries(LocalDate.now().plusDays(1));
createEntries(LocalDate.now().plusDays(2));
}

private void createEntries(LocalDate startDate) {
for (int j = 0; j < 1; j++) {
for (int j = 0; j < 5 + (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(startDate);
entry.changeEndDate(startDate);
entry.setRecurrenceRule("RRULE:FREQ=DAILY");

entry.setTitle("Entry " + (j + 1));

Expand Down
Expand Up @@ -897,7 +897,7 @@ public String getLoaderName() {
@Override
public LocalDate getLoadStartDate() {
if (getSkinnable().isScrollingEnabled()) {
return getSkinnable().getScrollTime().toLocalDate();
return getSkinnable().getScrollTime().toLocalDate().minusDays(1);
}

return getSkinnable().getDate();
Expand Down
Expand Up @@ -61,12 +61,12 @@ public void add(EntryViewBase<?> entryView, DayView dayView, double contentWidth
if (clusterRange == null) {
clusterRange = new Range();
clusterRange.title = "Cluster Range";
clusterRange.y1 = Double.MAX_VALUE;
clusterRange.y2 = Double.MIN_VALUE;
clusterRange.y1 = entryRange.y1;
clusterRange.y2 = entryRange.y2;
} else {
clusterRange.y1 = Math.min(clusterRange.y1, entryRange.y1);
clusterRange.y2 = Math.max(clusterRange.y2, entryRange.y2);
}

clusterRange.y1 = Math.min(clusterRange.y1, entryRange.y1);
clusterRange.y2 = Math.max(clusterRange.y2, entryRange.y2);
}

public boolean intersects(EntryViewBase<?> entryView, DayView dayView, double contentWidth) {
Expand All @@ -86,7 +86,13 @@ public boolean intersects(EntryViewBase<?> entryView, DayView dayView, double co
entryRange.y2 = dayView.getHeight();
}

return entryRange.y1 < clusterRange.y2 && entryRange.y2 > clusterRange.y1;
boolean inter = entryRange.y1 < clusterRange.y2 && entryRange.y2 > clusterRange.y1;

if (inter && entryView.getEntry().getTitle().equals("Entry 1 of cal1")) {
System.out.println("stop");
}

return inter;
}

public List<Placement> resolve(DayView dayView, double contentWidth) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ static class Range {

@Override
public String toString() {
return "entry = " + title + ", y1 = " + y1 + ", y2 = " + y2;
return "title = " + title + ", y1 = " + y1 + ", y2 = " + y2;
}
}

Expand Down

0 comments on commit d05787d

Please sign in to comment.