public class Calendar extends Container implements ActionSource
Date widget for selecting a date/time value.
To localize strings for month names use the values "Calendar.Month" using the
3 first characters of the month name in the resource localization e.g.
"Calendar.Jan
", "Calendar.Feb
" etc...
To localize strings for day names use the values "Calendar.Day" in the
resource localization e.g. "Calendar.Sunday
",
"Calendar.Monday
" etc...
Note that we recommend using the Picker
class which is superior when running on the device for most use cases.
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR
Constructor and Description |
---|
Calendar()
Constructs a calendar with the current date and time
|
Calendar(Image leftArrowImage,
Image rightArrowImage)
Constructs a calendar with the current date and time with left and right
images set
|
Calendar(long time)
Creates a new instance of Calendar set to the given date based on time
since epoch (the java.util.Date convention)
|
Calendar(long time,
TimeZone tmz)
Creates a new instance of Calendar set to the given date based on time
since epoch (the java.util.Date convention)
|
Calendar(long time,
TimeZone tmz,
Image leftArrowImage,
Image rightArrowImage)
Creates a new instance of Calendar set to the given date based on time
since epoch (the java.util.Date convention)
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener l)
Fires when a change is made to the month view of this component
|
void |
addDataChangedListener(DataChangedListener l)
Allows tracking selection changes in the calendar in real time
|
void |
addDataChangeListener(DataChangedListener l)
Deprecated.
use #addDataChangedListener(DataChangedListener) instead
|
void |
addDayActionListener(ActionListener l)
Adds an ActionListener to the day buttons.
|
void |
addMonthChangedListener(ActionListener l)
Fires when a new month is selected
|
protected void |
bindDayListener(Component cmp,
ActionListener l)
Since a day may be any component type, developers should override this
method to add support for binding the click listener to the given
component.
|
protected Button |
createDay()
Deprecated.
override
createDayComponent() instead |
protected Component |
createDayComponent()
Creates a day within the Calendar, this method is protected allowing
Calendar to be subclassed to replace the rendering logic of individual
day buttons.
|
protected Label |
createDayTitle(int day)
This method creates the Day title Component for the Month View
|
Date |
getCurrentDate()
Returns the currently viewed date (as opposed to the selected date)
|
Date |
getDate()
Return the date object matching the current selection
|
protected String |
getDayText(Component cmp)
Since a day may be any component type, developers should override this
method to add support for removing the click listener from the given
component.
|
Style |
getMonthViewSelectedStyle()
Gets the selected style of the month view component within the calendar
|
Style |
getMonthViewUnSelectedStyle()
Gets the un selected style of the month view component within the
calendar
|
long |
getSelectedDay()
Returns the time for the current calendar.
|
Collection<Date> |
getSelectedDays()
Gets the dates selected on the calendar or null if no date is selected
|
String |
getSelectedDaysUIID() |
TimeZone |
getTimeZone()
Gets the Calendar timezone
|
void |
highlightDate(Date date,
String uiid)
Highlights a date on the calendar using the supplied uiid.
|
void |
highlightDates(Collection<Date> dates,
String uiid)
Highlights dates on the calendar using the supplied uiid.
|
boolean |
isChangesSelectedDateEnabled()
This flag determines if selected date can be changed by selecting an
alternative date
|
boolean |
isMultipleSelectionEnabled()
If true multiple days can be selected on a calendar and
"
getSelectedDays() " will return the dates selected |
boolean |
isTwoDigitMode()
When set to true days will be rendered as 2 digits with 0 preceding
single digit days
|
void |
removeActionListener(ActionListener l)
Fires when a change is made to the month view of this component
|
void |
removeDataChangedListener(DataChangedListener l)
Allows tracking selection changes in the calendar in real time
|
void |
removeDataChangeListener(DataChangedListener l)
Deprecated.
use #removeDataChangedListener(DataChangedListener) instead
|
void |
removeDayActionListener(ActionListener l)
Removes ActionListener from day buttons
|
void |
removeMonthChangedListener(ActionListener l)
Fires when a new month is selected
|
void |
setChangesSelectedDateEnabled(boolean changesSelectedDateEnabled)
This flag determines if selected date can be changed by selecting an
alternative date
|
void |
setCurrentDate(Date d)
Sets the Calendar view on the given date, only the the month and year are
being considered.
|
void |
setDate(Date d)
Sets the current date in the view and the selected date to be the same.
|
protected void |
setDayEnabled(Component cmp,
boolean enable)
Since a day may be any component type, developers should override this
method to add support for enabling or disabling the right component.
|
protected void |
setDayText(Component cmp,
String text)
Since a day may be any component type, developers should override this
method to add support for setting the displayed string.
|
protected void |
setDayUIID(Component cmp,
String uiid)
Since a day may be any component type, developers should override this
method to add support for setting the right component's UIID.
|
void |
setMonthViewSelectedStyle(Style s)
Sets the selected style of the month view component within the calendar
|
void |
setMonthViewUnSelectedStyle(Style s)
Sets the un selected style of the month view component within the
calendar
|
void |
setMultipleSelectionEnabled(boolean multipleSelectionEnabled)
When set to true multiple days can be selected on a calendar and
"
getSelectedDays() " will return the dates selected |
void |
setSelectedDate(Date d)
This method sets the Calendar selected day
|
void |
setSelectedDays(Collection<Date> selectedDays)
Sets the dates to be selected on the calendar
|
void |
setSelectedDays(Collection<Date> selectedDays,
String uiid)
Sets the dates to be selected on the calendar with a custom uiid.
|
void |
setSelectedDaysUIID(String uiid)
Sets the selectedDays UIID to the given uiid.
|
void |
setTimeZone(TimeZone tmz)
Sets the Calendar timezone, if not specified Calendar will use the
default timezone
|
void |
setTwoDigitMode(boolean twoDigitMode)
When set to true days will be rendered as 2 digits with 0 preceding
single digit days
|
void |
setYearRange(int minYear,
int maxYear)
Sets the Calendar min and max years
|
void |
unHighlightDate(Date date)
Un-highlights dates on the calendar by removing the highlighting uiid.
|
void |
unHighlightDates(Collection<Date> dates)
Un-highlights dates on the calendar by removing the highlighting uiid.
|
protected void |
updateButtonDayDate(Button dayButton,
int currentMonth,
int day)
Deprecated.
override the method that accepts a generic component
|
protected void |
updateButtonDayDate(Button dayButton,
int year,
int currentMonth,
int day)
Deprecated.
override the method that accepts a generic component
|
protected void |
updateButtonDayDate(Component dayButton,
int currentMonth,
int day)
This method updates the Button day.
|
protected void |
updateButtonDayDate(Component dayButton,
int year,
int currentMonth,
int day)
This method updates the Button day.
|
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintBackground, paintBorderBackground, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
public Calendar(long time)
time
- time since epochpublic Calendar()
public Calendar(long time, TimeZone tmz)
time
- time since epochtmz
- a reference timezonepublic Calendar(Image leftArrowImage, Image rightArrowImage)
leftArrowImage
- an image for calendar left arrowrightArrowImage
- an image for calendar right arrowpublic Calendar(long time, TimeZone tmz, Image leftArrowImage, Image rightArrowImage)
time
- time since epochtmz
- a reference timezoneleftArrowImage
- an image for calendar left arrowrightArrowImage
- an image for calendar right arrowpublic long getSelectedDay()
public Date getDate()
public void setDate(Date d)
d
- new datepublic void setYearRange(int minYear, int maxYear)
minYear
- the min yearmaxYear
- the max yearpublic void setSelectedDate(Date d)
d
- the selected daypublic void setCurrentDate(Date d)
d
- the date to set the calendar view on.public Date getCurrentDate()
public void setTimeZone(TimeZone tmz)
tmz
- the timezonepublic TimeZone getTimeZone()
public void setMonthViewSelectedStyle(Style s)
s
- style for the month viewpublic void setMonthViewUnSelectedStyle(Style s)
s
- style for the month viewpublic Style getMonthViewSelectedStyle()
public Style getMonthViewUnSelectedStyle()
public void addActionListener(ActionListener l)
addActionListener
in interface ActionSource
l
- listener to addpublic void removeActionListener(ActionListener l)
removeActionListener
in interface ActionSource
l
- listener to removepublic void addMonthChangedListener(ActionListener l)
l
- listener to addpublic void removeMonthChangedListener(ActionListener l)
l
- listener to removepublic void addDayActionListener(ActionListener l)
Calendar.addActionListener
and will only fire when an active day
is selected.l
- listener to addpublic void removeDayActionListener(ActionListener l)
l
- listener to removepublic void addDataChangedListener(DataChangedListener l)
l
- listener to addpublic void removeDataChangedListener(DataChangedListener l)
l
- listener to removepublic void addDataChangeListener(DataChangedListener l)
l
- listener to addpublic void removeDataChangeListener(DataChangedListener l)
l
- listener to removepublic void setChangesSelectedDateEnabled(boolean changesSelectedDateEnabled)
changesSelectedDateEnabled
- if true pressing on a date will cause
the selected date to be changed to the pressed onepublic boolean isChangesSelectedDateEnabled()
protected Button createDay()
createDayComponent()
insteadprotected Label createDayTitle(int day)
day
- the relevant day values are 0-6 where 0 is Sunday.protected void updateButtonDayDate(Component dayButton, int year, int currentMonth, int day)
dayButton
- the button to be updatedyear
- the current yearcurrentMonth
- the current monthday
- the new button dayprotected void updateButtonDayDate(Component dayButton, int currentMonth, int day)
dayButton
- the button to be updatedcurrentMonth
- the current monthday
- the new button dayprotected void updateButtonDayDate(Button dayButton, int year, int currentMonth, int day)
dayButton
- the button to be updatedyear
- the current yearcurrentMonth
- the current monthday
- the new button dayprotected void updateButtonDayDate(Button dayButton, int currentMonth, int day)
dayButton
- the button to be updatedcurrentMonth
- the current monthday
- the new button daypublic boolean isTwoDigitMode()
public void setTwoDigitMode(boolean twoDigitMode)
twoDigitMode
- the twoDigitMode to setpublic Collection<Date> getSelectedDays()
public void setSelectedDays(Collection<Date> selectedDays)
selectedDays
- the multipleDateSelection to setpublic void setSelectedDays(Collection<Date> selectedDays, String uiid)
CalendarMultipleDay
", call this method without the
"uiid
parameter"selectedDays
- the multipleDateSelection to setuiid
- a custom uiid to be used in the dates selectedpublic String getSelectedDaysUIID()
public void setSelectedDaysUIID(String uiid)
uiid
- the uiid to change topublic void highlightDate(Date date, String uiid)
date
- the date to be highlighteduiid
- a custom uiid to be used in highlighting the datepublic void highlightDates(Collection<Date> dates, String uiid)
dates
- the dates to be highlighteduiid
- a custom uiid to be used in highlighting the datespublic void unHighlightDates(Collection<Date> dates)
selectedDaysUIID
uiid will be applied to any of the dates that
are part of selectedDays
)dates
- the dates to be un-highlightedpublic void unHighlightDate(Date date)
selectedDaysUIID
uiid will be applied to the date if it is part
of selectedDays
)date
- the date to be un-highlightedpublic boolean isMultipleSelectionEnabled()
getSelectedDays()
" will return the dates selectedpublic void setMultipleSelectionEnabled(boolean multipleSelectionEnabled)
getSelectedDays()
" will return the dates selectedmultipleSelectionEnabled
- the multipleSelectionEnabled to setprotected Component createDayComponent()
protected void bindDayListener(Component cmp, ActionListener l)
l
- listener interfacecmp
- day component returned by createDayComponent()protected void setDayText(Component cmp, String text)
text
- the text set the component tocmp
- day component returned by createDayComponent()protected String getDayText(Component cmp)
cmp
- day component returned by createDayComponentprotected void setDayUIID(Component cmp, String uiid)
cmp
- day component returned by createDayComponent()uiid
- the text set the component toprotected void setDayEnabled(Component cmp, boolean enable)
cmp
- day component returned by createDayComponent()enable
- the text set the component to