de.jaret.util.ui.datechooser
Class DateChooser

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by de.jaret.util.ui.datechooser.DateChooser
All Implemented Interfaces:
IDateChooserListener, java.util.EventListener, org.eclipse.swt.events.FocusListener, org.eclipse.swt.graphics.Drawable, org.eclipse.swt.internal.SWTEventListener

public class DateChooser
extends org.eclipse.swt.widgets.Composite
implements org.eclipse.swt.events.FocusListener, IDateChooserListener

A date field with an attached datechooser in a combobox style. The date chooser used is

Version:
$Id: DateChooser.java 871 2009-08-17 20:35:34Z kliem $
Author:
Peter Kliem
See Also:
The popup is displayed using a shell. The creation of the shell and the chooserpanel is lazy. The control offers three strategies for dealing with unparsable input in the textfield: KEEP_AND_MARK: keep the unparsable input, do not modify the date value and mark the field. This is the default behaviour allowing the user to step back and correct the input without slowing down the input process. RESET_TO_LASTVALID: reset the input to the last valid date entered or given RESET_TO_NULL: reset the value to null The DateFieldCombo features

Field Summary
protected  DateChooserPanel _chooserPanel
          DateChooserPanel in the dropdown.
protected  java.util.Date _date
          the date value manipulated by the control.
protected  java.text.DateFormat _dateformat
          dateformat used to format the date in the textfield.
protected  IAdditionalDayInformationProvider _dayInformationProvider
          Provier for additional day information.
protected  org.eclipse.swt.widgets.Button _dropdownButton
          dropdown button.
protected  org.eclipse.swt.widgets.Shell _dropDownShell
          shell for the drop down.
protected  boolean _dropped
          dropped state.
protected  boolean _editable
          if true: editable.
protected  IFieldIdentifier _fieldIdentifier
          FieldIdentifier used for field rolling.
protected  boolean _hasValidInput
          true if th einput is valid.
protected  de.jaret.util.date.holidayenumerator.HolidayEnumerator _holidayEnumerator
          Enumerator for identifying holidays.
protected  int _invalidInputBehaviour
          behaviour on invalid input.
protected  java.util.List<IDateChooserListener> _listenerList
          listener list of interestedlisteners.
protected  java.util.Locale _locale
          locale used by the control.
protected  org.eclipse.swt.widgets.Text _textField
          text field widgets used.
protected  TimeChooser _timeChooser
          timechooser to sync time of the handled date with.
static int KEEP_AND_MARK
          Invalid input behaviour: keep the textual input and mark the field.
static org.eclipse.swt.graphics.Color MARKER_COLOR
          Color used to mark invalid input.
protected static int MOUSEWHEEL_DIVISOR
          divisor for the mousewheel ticks.
static int RESET_TO_LASTVALID
          Invalid input behaviour: reset the date to the last valid input.
static int RESET_TO_NULL
          Invalid input behaviour: reset the date to null.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
DateChooser(org.eclipse.swt.widgets.Composite parent, int style)
          Constructor using the default locale.
DateChooser(org.eclipse.swt.widgets.Composite parent, int style, java.util.Locale locale)
          Constructor for the datefieldcombo.
 
Method Summary
 void addDateChooserListener(IDateChooserListener listener)
          Add a DateChooserListener to be informed about changes.
 void choosingCanceled()
          Called when the user decided not to choose any date.
 void clearSelection()
          Clear selection on the textfield.
 void copy()
          Copy operation of the textfield.
 void cut()
          Cut operation of the textfield.
 void dateChosen(java.util.Date date)
          Called when the user selected a date.
 void dateIntermediateChange(java.util.Date date)
          Called on intermediate changes in the date chooser.
protected  void fireChoosingCanceled()
          Inform listeners that the choosing has been cancelled.
protected  void fireDateChosen(java.util.Date date)
          Inform listeners that a date has been chosen.
protected  void fireInputInvalid()
          Inform listeners that the current input has become invalid.
protected  void fireIntermediateChange(java.util.Date date)
          Inform listeners about an intermediate change of the date.
 void focusGained(org.eclipse.swt.events.FocusEvent evt)
           On gaining focus on the textfield, select its content.
 void focusLost(org.eclipse.swt.events.FocusEvent evt)
           On loosing focus validate the input and check whether the focus will be going to the dropdown.
 boolean forceFocus()
           The textfield will get the focus.
 IAdditionalDayInformationProvider getAdditionalDayInformationProvider()
          Retrieve the additional information provider.
 java.util.Date getDate()
          Retrieve the current selected date.
 DateChooserPanel getDateChooserPanel()
          Return the chooser panel used by the DateChooser.
 java.text.DateFormat getDateFormat()
          Retrieve the used dateformat.
protected  java.util.Date getDateInternal()
          Retrieve the current date without syncing with a time chooser.
 IFieldIdentifier getFieldIdentifier()
           
 de.jaret.util.date.holidayenumerator.HolidayEnumerator getHolidayEnumerator()
          Retrieve he holiday enumerator used.
 int getInvalidInputBehaviour()
           
 org.eclipse.swt.widgets.Text getTextField()
          Access to the embedded textfield widget.
 TimeChooser getTimeChooser()
          Get the timechooser set for time synchronization.
 void inputInvalid()
          Called when the user input becomes invalid.
 boolean isDropped()
          Check whether the drop down is dropped down.
 boolean isEditable()
           
 boolean isEnabled()
           
 boolean isOneClickSelection()
          Get the oneClick property of the date chooser panel.
 boolean isSelectAllOnFocusGained()
           
 boolean isTextfieldMouseWheelEnable()
          Retrieve state of mousewheel support on textfield.
 void onDispose()
          dispose has to take care of some additional disposals.
 void paste()
          Paste operation of the textfield.
 void remDateChooserListener(IDateChooserListener listener)
          Remove a DateChooserListener.
 void selectAll()
          Select the text fields contents.
 void setAdditionalDayInformationProvider(IAdditionalDayInformationProvider dayInformationProvider)
          Set an additional information provider for days.
 void setDate(java.util.Date date)
          Set the date.
 void setDateFormat(java.text.DateFormat dateformat)
          Set the dateformat used to parse and format the date in the text field.
 void setDropped(boolean dropped)
          Set the state of the dropdown.
 void setEditable(boolean editable)
          Set the editable state.
 void setEnabled(boolean enabled)
          Set the enabled state of the widget.
 void setFieldIdentifier(IFieldIdentifier fieldIdentifier)
           
 boolean setFocus()
           The textfield will get the focus.
 void setHolidayEnumerator(de.jaret.util.date.holidayenumerator.HolidayEnumerator holidayEnumerator)
          Set a HolidayEnumerator for marking holidays in the day panel.
 void setInvalidInputBehaviour(int invalidInputBehaviour)
           
 void setOneClickSelection(boolean oneClick)
          Set the onClick property of the date chooser panel.
 void setSelectAllOnFocusGained(boolean selectAllOnFocusGained)
           
 void setSelection(int pos)
          Set the selection on the textfield.
 void setText(java.lang.String text)
          Set the input in the textfield direct.
 void setTextfieldMouseWheelEnable(boolean mouseWheelEnable)
          Enable/Disable mousewheel for rolling on text field.
 void setTimeChooser(TimeChooser timeChooser)
          Set a timechoser to synchronize the time of the chosen date with.
 boolean validateInput()
          Validate the input currently present in the textfield.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEEP_AND_MARK

public static final int KEEP_AND_MARK
Invalid input behaviour: keep the textual input and mark the field.

See Also:
Constant Field Values

RESET_TO_LASTVALID

public static final int RESET_TO_LASTVALID
Invalid input behaviour: reset the date to the last valid input.

See Also:
Constant Field Values

RESET_TO_NULL

public static final int RESET_TO_NULL
Invalid input behaviour: reset the date to null.

See Also:
Constant Field Values

MARKER_COLOR

public static final org.eclipse.swt.graphics.Color MARKER_COLOR
Color used to mark invalid input.


MOUSEWHEEL_DIVISOR

protected static final int MOUSEWHEEL_DIVISOR
divisor for the mousewheel ticks.

See Also:
Constant Field Values

_invalidInputBehaviour

protected int _invalidInputBehaviour
behaviour on invalid input.


_editable

protected boolean _editable
if true: editable.


_listenerList

protected java.util.List<IDateChooserListener> _listenerList
listener list of interestedlisteners.


_date

protected java.util.Date _date
the date value manipulated by the control.


_dateformat

protected java.text.DateFormat _dateformat
dateformat used to format the date in the textfield.


_locale

protected java.util.Locale _locale
locale used by the control.


_textField

protected org.eclipse.swt.widgets.Text _textField
text field widgets used.


_dropdownButton

protected org.eclipse.swt.widgets.Button _dropdownButton
dropdown button.


_dropDownShell

protected org.eclipse.swt.widgets.Shell _dropDownShell
shell for the drop down.


_dropped

protected boolean _dropped
dropped state.


_chooserPanel

protected DateChooserPanel _chooserPanel
DateChooserPanel in the dropdown.


_holidayEnumerator

protected de.jaret.util.date.holidayenumerator.HolidayEnumerator _holidayEnumerator
Enumerator for identifying holidays.


_dayInformationProvider

protected IAdditionalDayInformationProvider _dayInformationProvider
Provier for additional day information.


_fieldIdentifier

protected IFieldIdentifier _fieldIdentifier
FieldIdentifier used for field rolling.


_timeChooser

protected TimeChooser _timeChooser
timechooser to sync time of the handled date with.


_hasValidInput

protected boolean _hasValidInput
true if th einput is valid.

Constructor Detail

DateChooser

public DateChooser(org.eclipse.swt.widgets.Composite parent,
                   int style,
                   java.util.Locale locale)
Constructor for the datefieldcombo.

Parameters:
parent - Composite parent
style - style
locale - locale to be used

DateChooser

public DateChooser(org.eclipse.swt.widgets.Composite parent,
                   int style)
Constructor using the default locale.

Parameters:
parent - Composite parent
style - style
Method Detail

getDateFormat

public java.text.DateFormat getDateFormat()
Retrieve the used dateformat.

Returns:
the dateformat used to format and parse the date.

setDateFormat

public void setDateFormat(java.text.DateFormat dateformat)
Set the dateformat used to parse and format the date in the text field. Default is the MEDIUM style DateInstance for the given locale.

Parameters:
dateformat - dateformat to use.

onDispose

public void onDispose()
dispose has to take care of some additional disposals.


isDropped

public boolean isDropped()
Check whether the drop down is dropped down.

Returns:
true if the dropdow is dropped down

setDropped

public void setDropped(boolean dropped)
Set the state of the dropdown.

Parameters:
dropped - if true the dropdowbn will be displayed.

getDate

public java.util.Date getDate()
Retrieve the current selected date. Corrects the time from a time chooser if set.

Returns:
Returns the date.

getDateInternal

protected java.util.Date getDateInternal()
Retrieve the current date without syncing with a time chooser.

Returns:
current selected date

setDate

public void setDate(java.util.Date date)
Set the date.

Parameters:
date - The date to set.

setText

public void setText(java.lang.String text)
Set the input in the textfield direct.

Parameters:
text - new text of the textfield

selectAll

public void selectAll()
Select the text fields contents.


setSelection

public void setSelection(int pos)
Set the selection on the textfield.

Parameters:
pos - position

clearSelection

public void clearSelection()
Clear selection on the textfield.


cut

public void cut()
Cut operation of the textfield.


copy

public void copy()
Copy operation of the textfield.


paste

public void paste()
Paste operation of the textfield.


setFocus

public boolean setFocus()
The textfield will get the focus.

Overrides:
setFocus in class org.eclipse.swt.widgets.Composite

forceFocus

public boolean forceFocus()
The textfield will get the focus.

Overrides:
forceFocus in class org.eclipse.swt.widgets.Control

getTextField

public org.eclipse.swt.widgets.Text getTextField()
Access to the embedded textfield widget.

Returns:
the textfield

getHolidayEnumerator

public de.jaret.util.date.holidayenumerator.HolidayEnumerator getHolidayEnumerator()
Retrieve he holiday enumerator used.

Returns:
the holiday enumerator

setHolidayEnumerator

public void setHolidayEnumerator(de.jaret.util.date.holidayenumerator.HolidayEnumerator holidayEnumerator)
Set a HolidayEnumerator for marking holidays in the day panel. A value of null is valid indicating no HolidayEnumerator to be used.

Parameters:
holidayEnumerator - HolidayEnumerator to be used.

getAdditionalDayInformationProvider

public IAdditionalDayInformationProvider getAdditionalDayInformationProvider()
Retrieve the additional information provider.

Returns:
the additional information provider

setAdditionalDayInformationProvider

public void setAdditionalDayInformationProvider(IAdditionalDayInformationProvider dayInformationProvider)
Set an additional information provider for days.

Parameters:
dayInformationProvider - the information provider

dateChosen

public void dateChosen(java.util.Date date)
Called when the user selected a date. If a date has been chosen in the panel, close dropdaown, selection finished.

Specified by:
dateChosen in interface IDateChooserListener
Parameters:
date - chosen date

choosingCanceled

public void choosingCanceled()
Called when the user decided not to choose any date. Propagate cancelling.

Specified by:
choosingCanceled in interface IDateChooserListener

dateIntermediateChange

public void dateIntermediateChange(java.util.Date date)
Called on intermediate changes in the date chooser. Do an update on the textfield.

Specified by:
dateIntermediateChange in interface IDateChooserListener
Parameters:
date - current date selection

inputInvalid

public void inputInvalid()
Called when the user input becomes invalid. Do nothing.

Specified by:
inputInvalid in interface IDateChooserListener

focusGained

public void focusGained(org.eclipse.swt.events.FocusEvent evt)
On gaining focus on the textfield, select its content. If the datechooser does not already own the focus, notify other listeners.

Specified by:
focusGained in interface org.eclipse.swt.events.FocusListener

focusLost

public void focusLost(org.eclipse.swt.events.FocusEvent evt)
On loosing focus validate the input and check whether the focus will be going to the dropdown. In latter case do not notify other listeners.

Specified by:
focusLost in interface org.eclipse.swt.events.FocusListener

validateInput

public boolean validateInput()
Validate the input currently present in the textfield. Resets a mark if set and handles input behaviour for invalid inputs.

Returns:
true if valid

getInvalidInputBehaviour

public int getInvalidInputBehaviour()
Returns:
Returns the invalidInputBehaviour.

setInvalidInputBehaviour

public void setInvalidInputBehaviour(int invalidInputBehaviour)
Parameters:
invalidInputBehaviour - The invalidInputBehaviour to set.

isEditable

public boolean isEditable()
Returns:
Returns the editable state.

setEditable

public void setEditable(boolean editable)
Set the editable state. If set to false the textfiled be set to editable(false) and the dropdown will be disabled.

Parameters:
editable - The editable state to be set.

isEnabled

public boolean isEnabled()
Overrides:
isEnabled in class org.eclipse.swt.widgets.Control
Returns:
the enabled state of the widget.

setEnabled

public void setEnabled(boolean enabled)
Set the enabled state of the widget.

Overrides:
setEnabled in class org.eclipse.swt.widgets.Control
Parameters:
enabled - the enabled state to set

setOneClickSelection

public void setOneClickSelection(boolean oneClick)
Set the onClick property of the date chooser panel.

Parameters:
oneClick - if set to true a single click will selct the date.

isOneClickSelection

public boolean isOneClickSelection()
Get the oneClick property of the date chooser panel.

Returns:
true if a single click will select the date

getDateChooserPanel

public DateChooserPanel getDateChooserPanel()
Return the chooser panel used by the DateChooser.

Returns:
DateChooserPanel used by the date chooser.

addDateChooserListener

public void addDateChooserListener(IDateChooserListener listener)
Add a DateChooserListener to be informed about changes.

Parameters:
listener - the DateChooserListener to be added

remDateChooserListener

public void remDateChooserListener(IDateChooserListener listener)
Remove a DateChooserListener.

Parameters:
listener - the DateChooserListener to be removed

fireDateChosen

protected void fireDateChosen(java.util.Date date)
Inform listeners that a date has been chosen.

Parameters:
date - chosen date

fireIntermediateChange

protected void fireIntermediateChange(java.util.Date date)
Inform listeners about an intermediate change of the date.

Parameters:
date - current date

fireChoosingCanceled

protected void fireChoosingCanceled()
Inform listeners that the choosing has been cancelled.


fireInputInvalid

protected void fireInputInvalid()
Inform listeners that the current input has become invalid.


isSelectAllOnFocusGained

public boolean isSelectAllOnFocusGained()
Returns:
Returns the selectAllOnFocusGained.

setSelectAllOnFocusGained

public void setSelectAllOnFocusGained(boolean selectAllOnFocusGained)
Parameters:
selectAllOnFocusGained - The selectAllOnFocusGained to set.

getFieldIdentifier

public IFieldIdentifier getFieldIdentifier()
Returns:
Returns the fieldIdentifier.

setFieldIdentifier

public void setFieldIdentifier(IFieldIdentifier fieldIdentifier)
Parameters:
fieldIdentifier - The fieldIdentifier to set.

isTextfieldMouseWheelEnable

public boolean isTextfieldMouseWheelEnable()
Retrieve state of mousewheel support on textfield.

Returns:
true if enabled

setTextfieldMouseWheelEnable

public void setTextfieldMouseWheelEnable(boolean mouseWheelEnable)
Enable/Disable mousewheel for rolling on text field. Default is true.

Parameters:
mouseWheelEnable - true for enable

getTimeChooser

public TimeChooser getTimeChooser()
Get the timechooser set for time synchronization.

Returns:
timechooser or null

setTimeChooser

public void setTimeChooser(TimeChooser timeChooser)
Set a timechoser to synchronize the time of the chosen date with.

Parameters:
timeChooser - time chooser


Copyright © 2012. All Rights Reserved.