lu.tudor.santec.jtimechooser
Class JTimeChooser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by lu.tudor.santec.jtimechooser.JTimeChooser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class JTimeChooser
extends javax.swing.JComponent

Author:
jens.ferring(at)tudor.lu The JTimeChooser is a possibility to let the user set the time by typing, dragging the mouse and / or rotate the mouse wheel.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static java.awt.Color DEFAULT_HIGHLIGHTING_COLOR
           
static java.util.Date MIDNIGHT
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTimeChooser()
          Builds a JTimeChooser initializing the time with 00:00.
JTimeChooser(java.util.Date time)
          Builds a JTimeChooser initializing the time of the given date.
 
Method Summary
 void addTimeChangedListener(TimeChangedListener listener)
          Adds the listener to the list of listener.
 java.util.Calendar getCalendarWithTime(java.util.Calendar calendar)
          Creates a new Calendar with the data of the given Calendar, but replaces the time.
 java.util.Calendar getCalendarWithTime(java.util.Date date)
          Creates a new Calendar with the data of the given Date, but replaces the time.
 java.util.Date getDateWithTime(java.util.Date date)
          Creates a new Date with the data of the given Date, but replaces the time.
 java.lang.String getFormatedDate()
           
 java.lang.String getFormatedDate(java.util.Locale l, int style)
           
 java.lang.String getFormatedDate(java.lang.String pattern)
           
 java.lang.String getFormatedTime()
           
 int getHours()
           
 int getMinutes()
           
 int getSeconds()
           
 javax.swing.JFormattedTextField getTimeField()
           
 boolean isEnabledWithDoubleClick()
          The time field is disabled until it is double clicked.
 boolean isShowIcon()
          Tells whether a small clock is shown or not.
 boolean isShowSeconds()
           
 void removeTimeChangedListener(TimeChangedListener listener)
          Removes the listener of the list of listener
 void setEnabledWithDoubleClick(boolean enabled)
          This functionality disables the time field until it is double clicked.
 void setHighlightingColor(java.awt.Color c)
           
 void setShowIcon(boolean show)
          Defines whether a small clock shall be shown or not.
 void setShowSeconds(boolean showSeconds)
          Defines whether the format of JTimeChooser should show seconds or not.
 void setTime(java.util.Date time)
          You can manually set a new date / time
 void setTimeOnCalendar(java.util.Calendar cal)
          Replaces the time in the given Calendar.
 void setTimeOnDate(java.util.Date date)
          Replaces the time in the given Date.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIDNIGHT

public static final java.util.Date MIDNIGHT

DEFAULT_HIGHLIGHTING_COLOR

public static final java.awt.Color DEFAULT_HIGHLIGHTING_COLOR
Constructor Detail

JTimeChooser

public JTimeChooser()
Builds a JTimeChooser initializing the time with 00:00.


JTimeChooser

public JTimeChooser(java.util.Date time)
Builds a JTimeChooser initializing the time of the given date.

Parameters:
time - this date provides the start value and is modified
Method Detail

getTimeField

public javax.swing.JFormattedTextField getTimeField()
Returns:
The text field that contains the time.

setHighlightingColor

public void setHighlightingColor(java.awt.Color c)
Parameters:
c - Define the Color which is used to highlight the currently selected TimeUnit.

setShowSeconds

public void setShowSeconds(boolean showSeconds)
Defines whether the format of JTimeChooser should show seconds or not.

Parameters:
showSeconds - Shall the seconds be shown?

isShowSeconds

public boolean isShowSeconds()
Returns:
If the seconds are shown or not.

setShowIcon

public void setShowIcon(boolean show)
Defines whether a small clock shall be shown or not. By default it is not shown.

Parameters:
show -

isShowIcon

public boolean isShowIcon()
Tells whether a small clock is shown or not. By default it is not shown.

Returns:

getHours

public int getHours()
Returns:
The number of hours

getMinutes

public int getMinutes()
Returns:
The number of minutes

getSeconds

public int getSeconds()
Returns:
The number of seconds

setTime

public void setTime(java.util.Date time)
You can manually set a new date / time

Parameters:
time - The new date

getFormatedTime

public java.lang.String getFormatedTime()
Returns:
The time as it is in the text field.

getFormatedDate

public java.lang.String getFormatedDate()
Returns:
The date as string, using the short style and the default locale.

getFormatedDate

public java.lang.String getFormatedDate(java.util.Locale l,
                                        int style)
Parameters:
l - The locale to format the date.
style - The style to format the date.
Returns:
The date as string, using the specified style and the specified locale.

getFormatedDate

public java.lang.String getFormatedDate(java.lang.String pattern)
Parameters:
pattern - The pattern to format the date.
Returns:
The date / time as string, using the specified pattern.

setTimeOnDate

public void setTimeOnDate(java.util.Date date)
Replaces the time in the given Date.
This method does NOT change the JTimeChooser!

Parameters:
date - The Date to be changed

setTimeOnCalendar

public void setTimeOnCalendar(java.util.Calendar cal)
Replaces the time in the given Calendar.
This method does NOT change the JTimeChooser!

Parameters:
cal - The Calendar to be changed

getCalendarWithTime

public java.util.Calendar getCalendarWithTime(java.util.Calendar calendar)
Creates a new Calendar with the data of the given Calendar, but replaces the time.
This method does NOT change the JTimeChooser!

Parameters:
calendar - The Calendar, which data is used.
Returns:
A new Calendar with the defined time.

getCalendarWithTime

public java.util.Calendar getCalendarWithTime(java.util.Date date)
Creates a new Calendar with the data of the given Date, but replaces the time.
This method does NOT change the JTimeChooser!

Parameters:
date - The Date, which data is used.
Returns:
A new Calendar with the defined time.

getDateWithTime

public java.util.Date getDateWithTime(java.util.Date date)
Creates a new Date with the data of the given Date, but replaces the time.
This method does NOT change the JTimeChooser!

Parameters:
date - The Date, which data is used.
Returns:
A new Date with the defined time.

addTimeChangedListener

public void addTimeChangedListener(TimeChangedListener listener)
Adds the listener to the list of listener.
The listener are called whenever the time might be changed.

Parameters:
listener - The TimeChangedListener

removeTimeChangedListener

public void removeTimeChangedListener(TimeChangedListener listener)
Removes the listener of the list of listener

Parameters:
listener -

isEnabledWithDoubleClick

public boolean isEnabledWithDoubleClick()
The time field is disabled until it is double clicked. After entering the time it becomes disabled again.

Returns:
true if this functionality is enabled and the field will be disabled after an entry, false if the field is enabled all the time.

setEnabledWithDoubleClick

public void setEnabledWithDoubleClick(boolean enabled)
This functionality disables the time field until it is double clicked. After entering the time it becomes disabled again. The default is value true (disabled and becomes enabled after a double click).

Parameters:
enabled - true to enable this functionality, false to enable the field all the time.