Top Description Inners Fields Constructors Methods
com.calendarfx.model

public Class Calendar<T>

extends Object
implements EventTarget
Class Inheritance
All Implemented Interfaces
javafx.event.EventTarget
Type Parameters
<T>
the type of the (optional) user object
Imports
com.calendarfx.view.DateControl, javafx.beans.property.BooleanProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.collections.FXCollections, .ObservableList, javafx.event.Event, .EventDispatchChain, .EventHandler, .EventTarget, net.fortuna.ical4j.model.Recur, java.time.Duration, .Instant, .LocalDate, .LocalTime, .ZoneId, .ZonedDateTime, java.time.format.DateTimeParseException, java.util.ArrayList, .Collection, .Collections, .HashMap, .Iterator, .List, .Map

A calendar is responsible for storing calendar entries. It provides methods for adding, removing, and querying entries. A calendar also defines a visual style / color theme that will be used throughout the UI controls. Calendars fire events whenever entries are added or removed. Calendars are grouped together inside a CalendarSource. These calendar sources are then added to DateControl#getCalendarSources().

Example

    // create the calendar and listen to all changes
    Calendar calendar = new Calendar("Home");
    calendar.addEventHandler(CalendarEvent.ANY, evt -> handleEvent(evt));

    // create the calendar source and attach the calendar
    CalendarSource source = new CalendarSource("Online Calendars");
    source.getCalendars().add(calendar);

    // attach the source to the date control / calendar view.
    CalendarView view = new CalendarView();
    view.getCalendarSources().add(source);
    

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Calendar.Style

Predefined visual styles for calendars.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private final ObservableList<EventHandler<CalendarEvent>>
private boolean
private final IntervalTree<Entry<?>>
private final ObjectProperty<Duration>
private final ObjectProperty<Duration>
private final StringProperty
private final BooleanProperty
private final StringProperty
private final StringProperty
private final ObjectProperty<T>

Constructor Summary

AccessConstructor and Description
public
Calendar()

Constructs a new calendar.

public
Calendar(String
the name of the calendar
name
,
T
an optional user object
userObject
)

Constructs a new calendar with the given name.

public
Calendar(String
the name of the calendar
name
)

Constructs a new calendar with the given name.

Method Summary

Modifier and TypeMethod and Description
public final void
addEntries(Entry<?>...
the entries to add
entries
)

Adds the given entries to the calendar.

public final void
addEntries(Collection<Entry<?>>
the collection of entries to add
entries
)

Adds the given entries to the calendar.

public final void
addEntries(Iterator<Entry<?>>
the entries to add
entries
)

Adds the entries returned by the iterator to the calendar.

public final void
addEntries(Iterable<Entry<?>>
the entries to add
entries
)

Adds the entries returned by the iterable to the calendar.

public final void
addEntry(Entry<?>
the entry to add
entry
)

Adds the given entry to the calendar.

private void
addEntryToResult(Map<LocalDate, List<Entry<?>>> result, Entry<?> entry, LocalDate startDate, LocalDate endDate)

public final void
addEventHandler(EventHandler<CalendarEvent>
the event handler to add
l
)

Adds an event handler for calendar events.

public final EventDispatchChain
buildEventDispatchChain(EventDispatchChain
the initial chain to build from
givenTail
)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Construct an event dispatch chain for this target.

private Interval
calculateSourceBoundsFromRecurrenceBounds(Entry<?> source, Entry<?> recurrence, Interval oldInterval)

public final void
clear()

Removes all entries from the calendar.

private Map<LocalDate, List<Entry<?>>>
doGetEntries(LocalDate startDate, LocalDate endDate, ZoneId zoneId)

public final Map<LocalDate, List<Entry<?>>>

Returns:

a map filled with list of entries for given days
findEntries
(LocalDate
the start of the time interval
startDate
,
LocalDate
the end of the time interval
endDate
,
ZoneId
the time zone for which to find entries
zoneId
)

Queries the calendar for all entries within the time interval defined by the start date and end date.

public List<Entry<?>>

Returns:

a list of entries that match the search
findEntries
(String
the search text
searchText
)

Queries the calendar for entries that match the given search text.

public final void
fireEvent(CalendarEvent
the event to fire
evt
)

Fires the given calendar event to all event handlers currently registered with this calendar.

public final Instant

Returns:

An instant representing the earliest time, can be null if no entries are contained.
getEarliestTimeUsed
()

Gets the earliest time used by this calendar, that means the start of the first entry stored.

public final Instant

Returns:

An instant representing the latest time, can be null if no entries are contained.
getLatestTimeUsed
()

Gets the latest time used by this calendar, that means the end of the last entry stored.

public final Duration

Returns:

the look ahead duration
getLookAheadDuration
()

Returns the value of lookAheadDurationProperty().

public final Duration

Returns:

the look back duration
getLookBackDuration
()

Returns the value of lookBackDurationProperty().

public final String

Returns:

the name of the calendar
getName
()

Returns the value of nameProperty().

public final String

Returns:

the short name of the calendar
getShortName
()

Returns the value of shortNameProperty().

public final String

Returns:

the current calendar style
getStyle
()

Returns the value of styleProperty().

public final T
pack-priv final void
impl_addEntry(Entry<?> entry)

pack-priv final void
public final boolean

Returns:

true if the calendar can not be edited by the user
isReadOnly
()

Returns the value of readOnlyProperty().

public final ObjectProperty<Duration>

Returns:

the look ahead duration
lookAheadDurationProperty
()

Stores a time duration used for the entry search functionality of this calendar.

public final ObjectProperty<Duration>

Returns:

the look back duration
lookBackDurationProperty
()

Stores a time duration used for the entry search functionality of this calendar.

public final StringProperty

Returns:

the property used for storing the calendar name
nameProperty
()

A property used to store the name of the calendar.

public final BooleanProperty

Returns:

true if the calendar is read-only (default is false)
readOnlyProperty
()

A property used to control if the calendar is read-only or not.

public final void
removeEntries(Entry<?>...
the entries to remove
entries
)

Removes the given entries from the calendar.

public final void
removeEntries(Collection<Entry<?>>
the collection of entries to remove
entries
)

Removes the given entries from the calendar.

public final void
removeEntries(Iterator<Entry<?>>
the entries to remove
entries
)

Removes the entries returned by the iterator from the calendar.

public final void
removeEntries(Iterable<Entry<?>>
the entries to add
entries
)

Adds the entries returned by the iterable to the calendar.

public final void
removeEntry(Entry<?>
the entry to remove
entry
)

Removes the given entry from the calendar.

public final void
removeEventHandler(EventHandler<CalendarEvent>
the event handler to remove
l
)

Removes an event handler from the calendar.

public final void
setLookAheadDuration(Duration
the look ahead duration
duration
)

Sets the value of lookAheadDurationProperty().

public final void
setLookBackDuration(Duration
the look back duration
duration
)

Sets the value of lookBackDurationProperty().

public final void
setName(String
the new name for the calendar
name
)

Sets the value of nameProperty().

public final void
setReadOnly(boolean
the calendar can not be edited by the user if true
readOnly
)

Sets the value of readOnlyProperty().

public final void
setShortName(String
the new short name for the calendar
name
)

Sets the value of shortNameProperty().

public final void
setStyle(Calendar.Style
the calendar style
style
)

Sets the value of styleProperty() based on one of the predefined styles (see also the enum Style).

public final void
setStyle(String
the calendar style
stylePrefix
)

Sets the value of styleProperty().

public final void
setUserObject(T userObject)

public final StringProperty

Returns:

the property used for storing the calendar short name
shortNameProperty
()

A property used to store the short name of the calendar.

public final void
startBatchUpdates()

Tells the calendar that the application will perform a large number of changes.

public final void
stopBatchUpdates()

Tells the calendar that the application is done making big changes.

public final StringProperty

Returns:

the visual calendar style
styleProperty
()

A property used to store the visual style that will be used for the calendar in the UI.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
public final ObjectProperty<T>

Returns:

a user object
userObjectProperty
()

An (optional) user object that can be used to link this calendar to the source of its data or the business object that it represents.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

batchUpdatesback to summary
private boolean batchUpdates
dirtyback to summary
private boolean dirty
eventHandlersback to summary
private final ObservableList<EventHandler<CalendarEvent>> eventHandlers
fireEventsback to summary
private boolean fireEvents
intervalTreeback to summary
private final IntervalTree<Entry<?>> intervalTree
lookAheadDurationback to summary
private final ObjectProperty<Duration> lookAheadDuration
lookBackDurationback to summary
private final ObjectProperty<Duration> lookBackDuration
nameback to summary
private final StringProperty name
readOnlyback to summary
private final BooleanProperty readOnly
shortNameback to summary
private final StringProperty shortName
styleback to summary
private final StringProperty style
userObjectback to summary
private final ObjectProperty<T> userObject

Constructor Detail

Calendarback to summary
public Calendar()

Constructs a new calendar.

Calendarback to summary
public Calendar(String name, T userObject)

Constructs a new calendar with the given name.

Parameters
name:String

the name of the calendar

userObject:T

an optional user object

Calendarback to summary
public Calendar(String name)

Constructs a new calendar with the given name.

Parameters
name:String

the name of the calendar

Method Detail

addEntriesback to summary
public final void addEntries(Entry<?>... entries)

Adds the given entries to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Entry<?>[]

the entries to add

addEntriesback to summary
public final void addEntries(Collection<Entry<?>> entries)

Adds the given entries to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Collection<Entry<?>>

the collection of entries to add

addEntriesback to summary
public final void addEntries(Iterator<Entry<?>> entries)

Adds the entries returned by the iterator to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Iterator<Entry<?>>

the entries to add

addEntriesback to summary
public final void addEntries(Iterable<Entry<?>> entries)

Adds the entries returned by the iterable to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Iterable<Entry<?>>

the entries to add

addEntryback to summary
public final void addEntry(Entry<?> entry)

Adds the given entry to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entry:Entry<?>

the entry to add

addEntryToResultback to summary
private void addEntryToResult(Map<LocalDate, List<Entry<?>>> result, Entry<?> entry, LocalDate startDate, LocalDate endDate)
addEventHandlerback to summary
public final void addEventHandler(EventHandler<CalendarEvent> l)

Adds an event handler for calendar events. Handlers will be called when an entry gets added, removed, changes, etc.

Parameters
l:EventHandler<CalendarEvent>

the event handler to add

buildEventDispatchChainback to summary
public final EventDispatchChain buildEventDispatchChain(EventDispatchChain givenTail)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Doc from javafx.event.EventTarget.buildEventDispatchChain.

Construct an event dispatch chain for this target. The event dispatch chain contains event dispatchers which might be interested in processing of events targeted at this EventTarget. This event target is not automatically added to the chain, so if it wants to process events, it needs to add an EventDispatcher for itself to the chain.

In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target.

The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain.

The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain.

Parameters
givenTail:EventDispatchChain

the initial chain to build from

Returns:EventDispatchChain

the resulting event dispatch chain for this target

Annotations
@Override
calculateSourceBoundsFromRecurrenceBoundsback to summary
private Interval calculateSourceBoundsFromRecurrenceBounds(Entry<?> source, Entry<?> recurrence, Interval oldInterval)
clearback to summary
public final void clear()

Removes all entries from the calendar. Fires an CalendarEvent#CALENDAR_CHANGED event.

doGetEntriesback to summary
private Map<LocalDate, List<Entry<?>>> doGetEntries(LocalDate startDate, LocalDate endDate, ZoneId zoneId)
Annotations
@SuppressWarnings:rawtypes, unchecked
findEntriesback to summary
public final Map<LocalDate, List<Entry<?>>> findEntries(LocalDate startDate, LocalDate endDate, ZoneId zoneId)

Queries the calendar for all entries within the time interval defined by the start date and end date.

Parameters
startDate:LocalDate

the start of the time interval

endDate:LocalDate

the end of the time interval

zoneId:ZoneId

the time zone for which to find entries

Returns:Map<LocalDate, List<Entry<?>>>

a map filled with list of entries for given days

findEntriesback to summary
public List<Entry<?>> findEntries(String searchText)

Queries the calendar for entries that match the given search text. The method can be overridden to implement custom find / search strategies.

Parameters
searchText:String

the search text

Returns:List<Entry<?>>

a list of entries that match the search

See Also
Entry#matches(String)
fireEventback to summary
public final void fireEvent(CalendarEvent evt)

Fires the given calendar event to all event handlers currently registered with this calendar.

Parameters
evt:CalendarEvent

the event to fire

getEarliestTimeUsedback to summary
public final Instant getEarliestTimeUsed()

Gets the earliest time used by this calendar, that means the start of the first entry stored.

Returns:Instant

An instant representing the earliest time, can be null if no entries are contained.

getLatestTimeUsedback to summary
public final Instant getLatestTimeUsed()

Gets the latest time used by this calendar, that means the end of the last entry stored.

Returns:Instant

An instant representing the latest time, can be null if no entries are contained.

getLookAheadDurationback to summary
public final Duration getLookAheadDuration()

Returns the value of lookAheadDurationProperty().

Returns:Duration

the look ahead duration

getLookBackDurationback to summary
public final Duration getLookBackDuration()

Returns the value of lookBackDurationProperty().

Returns:Duration

the look back duration

getNameback to summary
public final String getName()

Returns the value of nameProperty().

Returns:String

the name of the calendar

getShortNameback to summary
public final String getShortName()

Returns the value of shortNameProperty().

Returns:String

the short name of the calendar

getStyleback to summary
public final String getStyle()

Returns the value of styleProperty().

Returns:String

the current calendar style

getUserObjectback to summary
public final T getUserObject()
impl_addEntryback to summary
pack-priv final void impl_addEntry(Entry<?> entry)
impl_removeEntryback to summary
pack-priv final void impl_removeEntry(Entry<?> entry)
isReadOnlyback to summary
public final boolean isReadOnly()

Returns the value of readOnlyProperty().

Returns:boolean

true if the calendar can not be edited by the user

lookAheadDurationPropertyback to summary
public final ObjectProperty<Duration> lookAheadDurationProperty()

Stores a time duration used for the entry search functionality of this calendar. The look ahead and the look back durations limit the search to the time interval [now - lookBackDuration, now + lookAheadDuration]. The default value of this property is 730 days (2 years).

Returns:ObjectProperty<Duration>

the look ahead duration

See Also
findEntries(String)
lookBackDurationPropertyback to summary
public final ObjectProperty<Duration> lookBackDurationProperty()

Stores a time duration used for the entry search functionality of this calendar. The look ahead and the look back durations limit the search to the time interval [now - lookBackDuration, now + lookAheadDuration]. The default value of this property is 730 days (2 years).

Returns:ObjectProperty<Duration>

the look back duration

See Also
findEntries(String)
namePropertyback to summary
public final StringProperty nameProperty()

A property used to store the name of the calendar.

Returns:StringProperty

the property used for storing the calendar name

readOnlyPropertyback to summary
public final BooleanProperty readOnlyProperty()

A property used to control if the calendar is read-only or not.

Returns:BooleanProperty

true if the calendar is read-only (default is false)

removeEntriesback to summary
public final void removeEntries(Entry<?>... entries)

Removes the given entries from the calendar. This is basically just a convenience method as the actual work of removing an entry from a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Entry<?>[]

the entries to remove

removeEntriesback to summary
public final void removeEntries(Collection<Entry<?>> entries)

Removes the given entries from the calendar. This is basically just a convenience method as the actual work of removing an entry from a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Collection<Entry<?>>

the collection of entries to remove

removeEntriesback to summary
public final void removeEntries(Iterator<Entry<?>> entries)

Removes the entries returned by the iterator from the calendar. This is basically just a convenience method as the actual work of removing an entry from a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Iterator<Entry<?>>

the entries to remove

removeEntriesback to summary
public final void removeEntries(Iterable<Entry<?>> entries)

Adds the entries returned by the iterable to the calendar. This is basically just a convenience method as the actual work of adding an entry to a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entries:Iterable<Entry<?>>

the entries to add

removeEntryback to summary
public final void removeEntry(Entry<?> entry)

Removes the given entry from the calendar. This is basically just a convenience method as the actual work of removing an entry from a calendar is done inside Entry#setCalendar(Calendar).

Parameters
entry:Entry<?>

the entry to remove

removeEventHandlerback to summary
public final void removeEventHandler(EventHandler<CalendarEvent> l)

Removes an event handler from the calendar.

Parameters
l:EventHandler<CalendarEvent>

the event handler to remove

setLookAheadDurationback to summary
public final void setLookAheadDuration(Duration duration)

Sets the value of lookAheadDurationProperty().

Parameters
duration:Duration

the look ahead duration

setLookBackDurationback to summary
public final void setLookBackDuration(Duration duration)

Sets the value of lookBackDurationProperty().

Parameters
duration:Duration

the look back duration

setNameback to summary
public final void setName(String name)

Sets the value of nameProperty().

Parameters
name:String

the new name for the calendar

setReadOnlyback to summary
public final void setReadOnly(boolean readOnly)

Sets the value of readOnlyProperty().

Parameters
readOnly:boolean

the calendar can not be edited by the user if true

setShortNameback to summary
public final void setShortName(String name)

Sets the value of shortNameProperty().

Parameters
name:String

the new short name for the calendar

setStyleback to summary
public final void setStyle(Calendar.Style style)

Sets the value of styleProperty() based on one of the predefined styles (see also the enum Style). The image below shows how the styles appear in the UI. Styles

Parameters
style:Calendar.Style

the calendar style

setStyleback to summary
public final void setStyle(String stylePrefix)

Sets the value of styleProperty().

Parameters
stylePrefix:String

the calendar style

setUserObjectback to summary
public final void setUserObject(T userObject)
shortNamePropertyback to summary
public final StringProperty shortNameProperty()

A property used to store the short name of the calendar.

Returns:StringProperty

the property used for storing the calendar short name

startBatchUpdatesback to summary
public final void startBatchUpdates()

Tells the calendar that the application will perform a large number of changes. While batch updates in progress the calendar will stop to fire events. To finish this mode the application has to call stopBatchUpdates().

stopBatchUpdatesback to summary
public final void stopBatchUpdates()

Tells the calendar that the application is done making big changes. Invoking this method will trigger a calendar event of type CalendarEvent#CALENDAR_CHANGED which will then force an update of the views.

stylePropertyback to summary
public final StringProperty styleProperty()

A property used to store the visual style that will be used for the calendar in the UI. A style can be any arbitrary name. The style will be used as a prefix to find the styles in the stylesheet. For examples please search the standard framework stylesheet for the predefined styles "style1-", "style2-", etc.

Returns:StringProperty

the visual calendar style

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateRecurrenceSourceEntryback to summary
private void updateRecurrenceSourceEntry(CalendarEvent evt, Entry<T> source)
Annotations
@SuppressWarnings:rawtypes, unchecked
userObjectPropertyback to summary
public final ObjectProperty<T> userObjectProperty()

An (optional) user object that can be used to link this calendar to the source of its data or the business object that it represents.

Returns:ObjectProperty<T>

a user object

com.calendarfx.model back to summary

public final Enum Calendar.Style

extends Enum<Calendar.Style>
Class Inheritance

Predefined visual styles for calendars. The actual CSS settings for these styles can be found in the framework stylesheet, prefixed with "style1-", "style2-", etc. The picture below shows the colors used for the various styles. Styles
See Also
Calendar#setStyle(Style)

Field Summary

Modifier and TypeField and Description
public static final Calendar.Style
STYLE1

Default style "1".

public static final Calendar.Style
STYLE2

Default style "2".

public static final Calendar.Style
STYLE3

Default style "3".

public static final Calendar.Style
STYLE4

Default style "4".

public static final Calendar.Style
STYLE5

Default style "5".

public static final Calendar.Style
STYLE6

Default style "6".

public static final Calendar.Style
STYLE7

Default style "7".

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Calendar.Style

Returns:

a style, guaranteed to be non-null
getStyle
(int
the ordinal value for which to return a style
ordinal
)

Returns a style for the given ordinal.

public static Calendar.Style
public static Calendar.Style[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

STYLE1back to summary
public static final Calendar.Style STYLE1

Default style "1".

STYLE2back to summary
public static final Calendar.Style STYLE2

Default style "2".

STYLE3back to summary
public static final Calendar.Style STYLE3

Default style "3".

STYLE4back to summary
public static final Calendar.Style STYLE4

Default style "4".

STYLE5back to summary
public static final Calendar.Style STYLE5

Default style "5".

STYLE6back to summary
public static final Calendar.Style STYLE6

Default style "6".

STYLE7back to summary
public static final Calendar.Style STYLE7

Default style "7".

Constructor Detail

Styleback to summary
private Style()

Method Detail

getStyleback to summary
public static Calendar.Style getStyle(int ordinal)

Returns a style for the given ordinal. This method is implemented with a roll over strategy: the final ordinal value is the given ordinal value modulo the number of elements in this enum.

Parameters
ordinal:int

the ordinal value for which to return a style

Returns:Calendar.Style

a style, guaranteed to be non-null

valueOfback to summary
public static Calendar.Style valueOf(String name)
valuesback to summary
public static Calendar.Style[] values()