de.jaret.util.ui.datechooser
Class TimeChooser

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.TimeChooser
All Implemented Interfaces:
IDateChooserListener, java.util.EventListener, org.eclipse.swt.events.FocusListener, org.eclipse.swt.graphics.Drawable, org.eclipse.swt.internal.SWTEventListener

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

A time field with an attached timechooser in a combobox style.

Version:
$Id: TimeChooser.java 587 2007-10-14 12:32:10Z olk $
Author:
Peter Kliem

Field Summary
protected  TimeChooserPanel _chooserPanel
          TimeChooserPanel in the dropdown.
protected  java.util.Date _date
          the date value manipulated by the control.
protected  DateChooser _dateChooser
          date chooser to synchronize the date with.
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 the current niput is valid.
protected  int _invalidInputBehaviour
          behaviour on invalid input.
protected  java.util.List<IDateChooserListener> _listenerList
          listener list of interestedlisteners.
protected  org.eclipse.swt.widgets.Text _textField
          text field widgets used.
protected  java.text.NumberFormat _twoDigitNF
          number format for time formating.
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.
static int RESET_TO_LASTVALID
          Invalid input behaviour: reset the date to the last valid input.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
TimeChooser(org.eclipse.swt.widgets.Composite parent, int style)
          Constructor for the time chooser.
 
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.
protected  java.lang.String formatTime(java.util.Date date)
          Format the time in the date as a String.
 java.util.Date getDate()
          Retrieve the current selected time (as the time in the date).
 DateChooser getDateChooser()
          Retrieve a date chooser that has been set for synchronizing the date part of the returned date.
protected  java.util.Date getDateInternal()
          Retrieve internal date field without adaption by a possible set datechooser.
 IFieldIdentifier getFieldIdentifier()
           
 int getInvalidInputBehaviour()
           
 org.eclipse.swt.widgets.Text getTextField()
          Access to the embedded textfield widget.
 TimeChooserPanel getTimeChooserPanel()
          Return the chooser panel used by the DateChooser.
 void inputInvalid()
          Called when the user input becomes invalid.
 boolean isDropped()
          Check whether the drop down is dropped down.
 boolean isEditable()
           
 boolean isEnabled()
           
 boolean isSelectAllOnFocusGained()
           
 boolean isTextfieldMouseWheelEnable()
          Retrieve state of mousewheel support on textfield.
 void onDispose()
          dispose has to take care of some additional disposals.
protected  java.util.Date parseTime(java.lang.String text, java.util.Date date)
          Parse an input string in the format hh:mm and set this time to the given date.
 void paste()
          Paste operation of the textfield.
 void remDateChooserListener(IDateChooserListener listener)
          Remove a DateChooserListener.
 void selectAll()
          Select the text fields contents.
 void setDate(java.util.Date date)
          Set the date.
 void setDateChooser(DateChooser dateChooser)
          Set a date chooser that supplies the date part for any returned date (as long as the datechooser provides a date).
 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 setInvalidInputBehaviour(int invalidInputBehaviour)
           
 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.
 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

MARKER_COLOR

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


_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.


_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 TimeChooserPanel _chooserPanel
TimeChooserPanel in the dropdown.


_fieldIdentifier

protected IFieldIdentifier _fieldIdentifier
FieldIdentifier used for field rolling.


_twoDigitNF

protected java.text.NumberFormat _twoDigitNF
number format for time formating.


_dateChooser

protected DateChooser _dateChooser
date chooser to synchronize the date with.


_hasValidInput

protected boolean _hasValidInput
true if the current niput is valid.

Constructor Detail

TimeChooser

public TimeChooser(org.eclipse.swt.widgets.Composite parent,
                   int style)
Constructor for the time chooser.

Parameters:
parent - Composite parent
style - style
Method Detail

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 time (as the time in the date). If a datechooser is set the date part will be taken from the date chooser.

Returns:
Returns the time in a date.

getDateInternal

protected java.util.Date getDateInternal()
Retrieve internal date field without adaption by a possible set datechooser.

Returns:
date

setDate

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

Parameters:
date - The date to set.

formatTime

protected java.lang.String formatTime(java.util.Date date)
Format the time in the date as a String.

Parameters:
date - date containing the time
Returns:
String hh:mm

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

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

parseTime

protected java.util.Date parseTime(java.lang.String text,
                                   java.util.Date date)
Parse an input string in the format hh:mm and set this time to the given date.

Parameters:
text - text to parse
date - date to aply the parsed time to
Returns:
date with time of the parsed string or null to indicate a parse error

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

getTimeChooserPanel

public TimeChooserPanel getTimeChooserPanel()
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

getDateChooser

public DateChooser getDateChooser()
Retrieve a date chooser that has been set for synchronizing the date part of the returned date.

Returns:
date chooser or null

setDateChooser

public void setDateChooser(DateChooser dateChooser)
Set a date chooser that supplies the date part for any returned date (as long as the datechooser provides a date).

Parameters:
dateChooser - date chooser to sync with


Copyright © 2012. All Rights Reserved.