public class DateChooser
extends org.eclipse.swt.widgets.Composite
Calendar is composed of a header and a grid for date selection. The header display the current month and year, and the two buttons for navigation (previous and next month). An optional footer display the today date.
Features:
To know which dates have been selected in the calendar, there is two means :
getSelectedDate()
method returns the currently
selected date (single selection). The getSelectedDates()
returns a list of all selected dates (multi selection).CalendarListener
to the calendar. This listener
will be notified of selection. event.data
contain the
selection if in single selection mode.Keyboard navigation :
Modifier and Type | Class and Description |
---|---|
protected class |
DateChooser.Cell
Defines a grid cell.
|
protected class |
DateChooser.DateChooserLayout
Calendar grid specific layout.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoChangeOnAdjacent
If true, change the current month if an adjacent day is clicked
|
protected boolean |
autoSelectOnFooter
If true, the today date is automatically selected on footer selection event
|
protected java.util.Date |
beginInterval
Begin date of selection interval
|
static java.lang.String |
BUNDLE_NAME
Bundle name constant
|
protected org.eclipse.swt.widgets.Label |
currentMonth
Label for the display of current month and year (corresponding to curDate)
|
protected java.util.Calendar |
currentMonthCal
Date of 1st day of the currently displayed month
|
protected DateChooser.Cell[] |
days
Days numbers cells
|
protected org.eclipse.swt.widgets.Composite |
daysPanel
Panel for display of day numbers
|
protected java.text.SimpleDateFormat |
df1
Format for the display of month and year in the header
|
protected java.text.DateFormat |
df2
Format for the today date in the footer
|
protected java.util.Date |
endInterval
End date of selection interval
|
protected org.eclipse.swt.widgets.Listener |
filter
Listener for external events
|
protected int |
firstDayIndex
Index in the grid of the first day of displayed month
|
protected int |
firstDayOfWeek
Index of the first day of week
|
protected int |
focusIndex
Index of the focus in the days numbers grid
|
protected boolean |
footerVisible
Flag to set footer visible or not
|
static int |
GRID_FULL |
static int |
GRID_LINES |
static int |
GRID_NONE |
protected DateChooser.DateChooserLayout |
gridLayout
Layout of the grid
|
protected org.eclipse.swt.widgets.Composite |
gridPanel
Grid panel
|
protected int |
gridVisible
Flag to set grid visible or not
|
protected boolean |
hasFocus
Flag indicating if the calendar has the focus
|
protected static int |
HEADER_SPACING
Header spacing constant
|
protected org.eclipse.swt.widgets.Label[] |
headers
Grid headers, displaying weekday names
|
protected org.eclipse.swt.widgets.Composite |
headersPanel
Panel for display of weekday names
|
protected org.eclipse.swt.widgets.Listener |
listener
Listener for all internal events
|
protected java.util.Locale |
locale
Locale used for localized names and formats
|
protected int |
minimalDaysInFirstWeek
Minimal number of days in the first week
|
protected org.eclipse.swt.widgets.Composite |
monthPanel
Month header panel
|
protected org.eclipse.swt.widgets.Menu |
monthsMenu
Popup menu for month selection
|
protected boolean |
multi
Multi selection flag
|
protected boolean |
navigationEnabled
Flag to set navigation enabled or not
|
protected org.eclipse.swt.widgets.Button |
nextMonth
Navigation button for next month
|
protected static int |
NOFOCUS
Value to use when there is none internal widget having the focus
|
protected org.eclipse.swt.widgets.Button |
prevMonth
Navigation button for previous month
|
protected java.util.ResourceBundle |
resources
Resources bundle
|
protected java.util.List<java.util.Date> |
selection
Selection
|
protected DateChooserTheme |
theme
Calendar theme
|
protected java.util.Calendar |
todayCal
The today date
|
protected org.eclipse.swt.widgets.Label |
todayLabel
Today label of the footer
|
protected DateChooser.Cell[] |
weeks
Weeks numbers cells
|
protected org.eclipse.swt.widgets.Composite |
weeksPanel
Panel for display of week numbers
|
protected boolean |
weeksVisible
Flag to set weeks numbers visible or not
|
Constructor and Description |
---|
DateChooser(org.eclipse.swt.widgets.Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value
describing its behavior and appearance.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelectionListener(org.eclipse.swt.events.SelectionListener lsnr)
Adds the listener to the collection of listeners who will
be notified when the receiver's selection changes, by sending
it one of the messages defined in the
SelectionListener
interface. |
protected void |
buttonsEvent(org.eclipse.swt.widgets.Event event)
Manages navigation buttons events.
|
protected void |
calendarEvent(org.eclipse.swt.widgets.Event event)
Manages event at the calendar level.
|
protected void |
changeCurrentMonth(int add)
Displays a new month in the grid.
|
void |
clearSelection()
Clears the selection.
|
protected void |
clearSelection(boolean refresh)
Clears the selection.
|
void |
dispose()
Disposes of the operating system resources associated with the receiver
and all its descendants.
|
protected void |
footerEvent(org.eclipse.swt.widgets.Event event)
Manages events on the footer label.
|
boolean |
forceFocus()
Forces the receiver to have the keyboard focus, causing all keyboard events
to be delivered to it.
|
java.util.Date |
getCurrentMonth()
Returns the current displayed month.
|
int |
getFirstDayOfWeek()
Gets what the first day of the week is.
|
int |
getGridVisible()
Returns the grid visibility status.
|
int |
getMinimalDaysInFirstWeek()
Gets what the minimal days required in the first week of the year are.
|
java.util.Date |
getSelectedDate()
Returns the selected date.
|
java.util.Collection<java.util.Date> |
getSelectedDates()
Returns all the selected dates.
|
java.util.Date |
getTodayDate()
Returns the today date.
|
protected void |
gridEvent(org.eclipse.swt.widgets.Event event)
Manages events at the grid level.
|
boolean |
isAutoChangeOnAdjacent()
Returns the autoChangeOnAdjacent mode.
|
boolean |
isAutoSelectOnFooter()
Returns the autoSelectOnFooter mode.
|
boolean |
isDateSelected(java.util.Date date)
Returns
true if the given date is selected, else returns
false . |
boolean |
isFocusControl()
Returns
true if the receiver has the user-interface focus,
and false otherwise. |
boolean |
isFooterVisible()
Returns true if footer is visible.
|
boolean |
isGridVisible()
Deprecated.
|
boolean |
isNavigationEnabled()
Returns true if navigation is enabled.
|
boolean |
isWeeksVisible()
Returns true if weeks numbers are visible.
|
protected void |
menuEvent(org.eclipse.swt.widgets.Event event)
Manages all events of the contextual menu on the month label of the header.
|
protected void |
notifySelection()
Sends selection event to the listeners.
|
void |
removeSelectedDate(java.util.Date d)
Removes the given date from the selection.
|
void |
removeSelectionListener(org.eclipse.swt.events.SelectionListener lsnr)
Removes the listener from the collection of listeners who will
be notified when the receiver's selection changes.
|
void |
setAutoChangeOnAdjacent(boolean autoChangeOnAdjacent)
Sets to
true to enable the automatic change of current month
when an adjacent day is clicked in the grid. |
void |
setAutoSelectOnFooter(boolean autoselectOnFooter)
Set the autoSelectOnFooter mode.
|
void |
setCurrentMonth(java.util.Date month)
Sets a new month to display.
|
void |
setFirstDayOfWeek(int firstDayOfWeek)
Sets what the first day of the week is.
|
boolean |
setFocus()
Causes the receiver to have the keyboard focus,
such that all keyboard events will be delivered to it.
|
void |
setFocusOnDate(java.util.Date date)
Sets the focus on the given date.
|
void |
setFocusOnToday(boolean autoselect)
Sets the focus on the today date.
|
void |
setFont(org.eclipse.swt.graphics.Font font)
Sets the font that the receiver will use to paint textual information to
the font specified by the argument, or to the default font for that kind
of control if the argument is null.
|
void |
setFooterVisible(boolean footerVisible)
Sets the footer visible or not.
|
void |
setGridVisible(boolean gridVisible)
Deprecated.
|
void |
setGridVisible(int gridVisible)
Sets the grid visible or not.
|
void |
setLayout(org.eclipse.swt.widgets.Layout layout)
Sets the layout which is associated with the receiver to be
the argument which may be null.
|
void |
setLocale(java.util.Locale locale)
Sets a new locale to use for calendar.
|
void |
setMinimalDaysInFirstWeek(int minimalDaysInFirstWeek)
Sets what the minimal days required in the first week of the year are; For
example, if the first week is defined as one that contains the first day
of the first month of a year, call this method with value 1.
|
void |
setNavigationEnabled(boolean navigationEnabled)
Sets the header's navigation buttons visible or not.
|
void |
setSelectedDate(java.util.Date date)
Sets the selected date.
|
void |
setTheme(DateChooserTheme theme)
Sets the theme to apply to the calendar.
|
void |
setTodayDate(java.util.Date today)
Sets the today date.
|
void |
setWeeksVisible(boolean weeksVisible)
Sets the weeks numbers visible or not.
|
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
addDisposeListener, addListener, checkWidget, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
public static final java.lang.String BUNDLE_NAME
protected static final int HEADER_SPACING
protected static final int NOFOCUS
public static final int GRID_NONE
public static final int GRID_LINES
public static final int GRID_FULL
protected boolean multi
protected java.util.List<java.util.Date> selection
protected java.util.Date beginInterval
protected java.util.Date endInterval
protected boolean autoSelectOnFooter
protected org.eclipse.swt.widgets.Composite monthPanel
protected org.eclipse.swt.widgets.Button prevMonth
protected org.eclipse.swt.widgets.Label currentMonth
protected org.eclipse.swt.widgets.Button nextMonth
protected org.eclipse.swt.widgets.Menu monthsMenu
protected org.eclipse.swt.widgets.Composite gridPanel
protected DateChooser.DateChooserLayout gridLayout
protected org.eclipse.swt.widgets.Composite headersPanel
protected org.eclipse.swt.widgets.Label[] headers
protected org.eclipse.swt.widgets.Composite daysPanel
protected DateChooser.Cell[] days
protected org.eclipse.swt.widgets.Composite weeksPanel
protected DateChooser.Cell[] weeks
protected int firstDayIndex
protected org.eclipse.swt.widgets.Label todayLabel
protected java.util.Locale locale
protected java.text.SimpleDateFormat df1
protected java.text.DateFormat df2
protected int firstDayOfWeek
protected int minimalDaysInFirstWeek
protected java.util.ResourceBundle resources
protected java.util.Calendar currentMonthCal
protected java.util.Calendar todayCal
protected DateChooserTheme theme
protected int gridVisible
protected boolean weeksVisible
protected boolean footerVisible
protected boolean navigationEnabled
protected boolean autoChangeOnAdjacent
protected org.eclipse.swt.widgets.Listener listener
protected org.eclipse.swt.widgets.Listener filter
protected boolean hasFocus
protected int focusIndex
public DateChooser(org.eclipse.swt.widgets.Composite parent, int style)
The calendar is initialized by default with the default Locale, and the current date for today and selected date attributes.
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to constructpublic void addSelectionListener(org.eclipse.swt.events.SelectionListener lsnr)
SelectionListener
interface.
widgetSelected
is called when the dates selection changes.
lsnr
- the listener which should be notifiedSelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
protected void buttonsEvent(org.eclipse.swt.widgets.Event event)
event
- eventprotected void calendarEvent(org.eclipse.swt.widgets.Event event)
event
- eventprotected void changeCurrentMonth(int add)
add
- delta from the current monthpublic void clearSelection()
protected void clearSelection(boolean refresh)
refresh
- true to refresh display, else falsepublic void dispose()
dispose
in class org.eclipse.swt.widgets.Widget
Widget.dispose()
protected void footerEvent(org.eclipse.swt.widgets.Event event)
event
- eventpublic boolean forceFocus()
forceFocus
in class org.eclipse.swt.widgets.Control
true
if the control got focus, and false
if it was unable to.public java.util.Date getCurrentMonth()
public int getFirstDayOfWeek()
public int getGridVisible()
public int getMinimalDaysInFirstWeek()
public java.util.Date getSelectedDate()
null
.public java.util.Collection<java.util.Date> getSelectedDates()
If the calendar is in single selection mode, it is preferable to use
getSelectedDate
that returns a Date value.
public java.util.Date getTodayDate()
protected void gridEvent(org.eclipse.swt.widgets.Event event)
event
- eventpublic boolean isAutoChangeOnAdjacent()
public boolean isAutoSelectOnFooter()
public boolean isDateSelected(java.util.Date date)
true
if the given date is selected, else returns
false
.date
- true
if selected, else false
.public boolean isFocusControl()
true
if the receiver has the user-interface focus,
and false
otherwise.isFocusControl
in class org.eclipse.swt.widgets.Control
Control.isFocusControl()
public boolean isFooterVisible()
true
if footer visible, else false
@Deprecated public boolean isGridVisible()
public boolean isNavigationEnabled()
public boolean isWeeksVisible()
protected void menuEvent(org.eclipse.swt.widgets.Event event)
event
- eventprotected void notifySelection()
public void removeSelectedDate(java.util.Date d)
d
- date to removepublic void removeSelectionListener(org.eclipse.swt.events.SelectionListener lsnr)
lsnr
- the listener which should no longer be notifiedSelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void setAutoChangeOnAdjacent(boolean autoChangeOnAdjacent)
true
to enable the automatic change of current month
when an adjacent day is clicked in the grid.
This mode is true
by default.
autoChangeOnAdjacent
- true / falsepublic void setAutoSelectOnFooter(boolean autoselectOnFooter)
false
by default.autoselectOnFooter
- true /falsepublic void setCurrentMonth(java.util.Date month)
month
- New monthpublic void setFirstDayOfWeek(int firstDayOfWeek)
This method allows to change the default first day of the week set
from the locale. It must be called after setLocale()
.
firstDayOfWeek
- the given first day of the week.public boolean setFocus()
setFocus
in class org.eclipse.swt.widgets.Composite
true
if the control got focus, and false
if it was unable to.public void setFocusOnDate(java.util.Date date)
date
- date to set the focus onpublic void setFocusOnToday(boolean autoselect)
autoselect
- true to select automatically the today date, else falsepublic void setFont(org.eclipse.swt.graphics.Font font)
The new font is applied to all elements (labels) composing the calendar. The width of cells is adjusted.
setFont
in class org.eclipse.swt.widgets.Control
font
- the new font (or null)public void setFooterVisible(boolean footerVisible)
footerVisible
- true
to set footer visible, else false
@Deprecated public void setGridVisible(boolean gridVisible)
gridVisible
- true
to set grid visible, else false
public void setGridVisible(int gridVisible)
gridVisible
- grid visibility flagpublic void setLayout(org.eclipse.swt.widgets.Layout layout)
Note : No Layout can be set on this Control because it already manages the size and position of its children.
setLayout
in class org.eclipse.swt.widgets.Composite
layout
- the receiver's new layout or nullpublic void setLocale(java.util.Locale locale)
locale
- new locale (must not be null)public void setMinimalDaysInFirstWeek(int minimalDaysInFirstWeek)
This method allows to change the default value set from the locale.
It must be called after setLocale()
.
minimalDaysInFirstWeek
- the given minimal days required in the first week of the year.public void setNavigationEnabled(boolean navigationEnabled)
navigationEnabled
- true if enabled, false elsepublic void setSelectedDate(java.util.Date date)
date
- new selected date (must not be null)public void setTheme(DateChooserTheme theme)
theme
- new theme (must not be null)public void setTodayDate(java.util.Date today)
By default the today date is initialized to the current system date. But it can be needed to adjust it for specifics needs.
today
- today date (must not be null)public void setWeeksVisible(boolean weeksVisible)
weeksVisible
- true
to set weeks visible, else false