From 0b285d21f5702d875586de459932b4f420b1b90e Mon Sep 17 00:00:00 2001 From: Dirk Lemmermann Date: Tue, 27 Sep 2022 14:00:22 +0200 Subject: [PATCH] Added a new "hidden" property to Entry. --- .../main/java/com/calendarfx/model/Entry.java | 43 +++++++++++++++---- .../com/calendarfx/view/EntryViewBase.java | 8 ++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CalendarFXView/src/main/java/com/calendarfx/model/Entry.java b/CalendarFXView/src/main/java/com/calendarfx/model/Entry.java index 2854ae4c..d27d1ead 100644 --- a/CalendarFXView/src/main/java/com/calendarfx/model/Entry.java +++ b/CalendarFXView/src/main/java/com/calendarfx/model/Entry.java @@ -74,7 +74,7 @@ * * *

Recurrence

- * + *

* This class supports the industry standard for defining recurring events (RFC * 2445). For recurring events the method {@link #setRecurrenceRule(String)} * must be fed with a valid RRULE string, for example "RRULE:FREQ=DAILY" for an @@ -698,7 +698,8 @@ private void updateRecurrenceEndProperty(String newRecurrence) { try { Recur recur = new Recur<>(newRecurrence.replaceFirst("^RRULE:", "")); setRecurrenceEnd(Objects.requireNonNullElse(recur.getUntil(), LocalDate.MAX)); - } catch (IllegalArgumentException | DateTimeParseException e) { + } catch (IllegalArgumentException | + DateTimeParseException e) { e.printStackTrace(); } } else { @@ -1496,6 +1497,25 @@ private boolean isShowing(Entry entry, LocalDate startDate, LocalDate endDate return Util.intersect(interval.getStartZonedDateTime(), interval.getEndZonedDateTime(), st, et); } + private final BooleanProperty hidden = new SimpleBooleanProperty(this, "hidden", false); + + public final boolean isHidden() { + return hidden.get(); + } + + public final BooleanProperty hiddenProperty() { + return hidden; + } + + /** + * An entry can be made explicityl hidden. + * + * @param hidden true if the entry should not be visible in the calendar + */ + public final void setHidden(boolean hidden) { + this.hidden.set(hidden); + } + private boolean isRecurrenceShowing(Entry entry, ZonedDateTime st, ZonedDateTime et, ZoneId zoneId) { String recurrenceRule = entry.getRecurrenceRule().replaceFirst("^RRULE:", ""); @@ -1580,25 +1600,32 @@ public int hashCode() { @SuppressWarnings("rawtypes") @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Entry other = (Entry) obj; if (id == null) { - if (other.id != null) + if (other.id != null) { return false; - } else if (!id.equals(other.id)) + } + } else if (!id.equals(other.id)) { return false; + } String recId = getRecurrenceId(); String otherRecId = other.getRecurrenceId(); if (recId == null) { return otherRecId == null; - } else return recId.equals(otherRecId); + } + + return recId.equals(otherRecId); } private static final String ENTRY_CATEGORY = "Entry"; diff --git a/CalendarFXView/src/main/java/com/calendarfx/view/EntryViewBase.java b/CalendarFXView/src/main/java/com/calendarfx/view/EntryViewBase.java index 7b89ea6a..42a5dba2 100644 --- a/CalendarFXView/src/main/java/com/calendarfx/view/EntryViewBase.java +++ b/CalendarFXView/src/main/java/com/calendarfx/view/EntryViewBase.java @@ -268,16 +268,24 @@ private void bindEntry(Entry entry) { private void bindVisibility() { Entry entry = getEntry(); T dateControl = getDateControl(); + if (entry != null && dateControl != null) { Calendar calendar = entry.getCalendar(); if (calendar != null) { BooleanBinding binding = Bindings.and(dateControl.getCalendarVisibilityProperty(calendar), Bindings.not(hiddenProperty())); + + binding = binding.and(entry.hiddenProperty().not()); + if (getLayer() != null) { binding = binding.and(Bindings.createBooleanBinding(this::isAssignedLayerVisible, dateControl.visibleLayersProperty())); } if (dateControl instanceof DayViewBase) { + /* + * Day views support editing of an availability calendar. During editing the + * entries might be shown, hidden, or become somewhat transparent. + */ DayViewBase dayView = (DayViewBase) dateControl; binding = binding.and(dayView.editAvailabilityProperty().not().or(dayView.entryViewAvailabilityEditingBehaviourProperty().isEqualTo(AvailabilityEditingEntryBehaviour.HIDE).not()));