DESY ACOP Beans Home

com.cosylab.gui.components
Class SimpleDateSelector

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.cosylab.gui.components.SimpleDateSelector
All Implemented Interfaces:
PropertyEditor, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class SimpleDateSelector
extends javax.swing.JComponent
implements PropertyEditor

This class provides user-friendly entry of dates. The component consists of three combo boxes containing year, month and day values. All values are validated and always display a valid date. This is then provided by getDate and setDate methods. User can listen to PropertyChangeEvent to get notifications when a date was changed When setting or getting the date from or to java.util.Date class, only YEAR, MONTH and DAY_OF_MONTH properties are set.

Version:
$id$
Author:
Ales Pucelj
See Also:
GregorianCalendar class is used to calculate the dates. Since only the number of years is unlimited, it is set to 20 by default, allowing years 2000 through 2019 inclusively to be chosen. This can, however, be modified., Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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 com.cosylab.gui.property.editors.PropertyEditor
PROPERTY_VALUE_NAME
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SimpleDateSelector()
          Default constructor for SimpleDateSelector.
SimpleDateSelector(java.util.Date date)
          Constructor for SimpleDateSelector.
SimpleDateSelector(java.util.Date date, int fromYear, int yearRange)
          Constructor for SimpleDateSelector.
SimpleDateSelector(int fromYear, int yearRange)
          Constructor for SimpleDateSelector.
SimpleDateSelector(int day, int month, int year)
          Constructor for SimpleDateSelector.
SimpleDateSelector(int day, int month, int year, int fromYear, int yearRange)
          Constructor for SimpleDateSelector.
 
Method Summary
 java.util.Date getDate()
          Returns the currently selected date as java.util.Date.
 int getDay()
          Returns number of the selected day in current month, starting with 1.
 java.lang.String getDescription()
          Returns the description for this editor.
 int getMonth()
          Returns the index of the currently selected month starting with 1.
 int getNumberOfYears()
          Returns the number of year to display in the year selector.
 java.lang.Object getPropertyValue()
          Returns the value contained in this editor.
 int getStartingYear()
          Returns the starting year to display in the year selector.
 int getYear()
          Returns the currently selected year.
static void main(java.lang.String[] args)
          Run test applet.
 void setCompactView(boolean compact)
           
 void setDate(java.util.Date date)
          Sets the date to display.
 void setDay(int day)
          Sets the day to the specified index.
 void setDescription(java.lang.String description)
           
 void setEnabled(boolean how)
          Sets the enabled state of this component.
 void setLabelsVisible(boolean visible)
          Shows / hides the Year/Month/Day labels
 void setMonth(int month)
          Sets the currently selected month.
 void setNumberOfYears(int range)
          Sets the number of years to display in the year selector.
 boolean setPropertyValue(java.lang.Object value)
          PropertyEditor should set the value specified and display it accordingly.
 void setStartingYear(int from)
          Sets the starting year to be displayed in the year selector.
 void setYear(int year)
          Sets the currently selected year.
 void setYearRange(int from, int range)
          Sets new available year range.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.cosylab.gui.property.editors.PropertyEditor
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

SimpleDateSelector

public SimpleDateSelector()
Default constructor for SimpleDateSelector.


SimpleDateSelector

public SimpleDateSelector(java.util.Date date)
Constructor for SimpleDateSelector.

Parameters:
date - Date Initial date to set.

SimpleDateSelector

public SimpleDateSelector(java.util.Date date,
                          int fromYear,
                          int yearRange)
Constructor for SimpleDateSelector.

Parameters:
date - Date Initial date to set.
fromYear - int Initial starting year.
yearRange - int Number of years to allow.

SimpleDateSelector

public SimpleDateSelector(int fromYear,
                          int yearRange)
Constructor for SimpleDateSelector.

Parameters:
fromYear - int Initial starting year.
yearRange - int Number of years to allow.

SimpleDateSelector

public SimpleDateSelector(int day,
                          int month,
                          int year)
Constructor for SimpleDateSelector.

Parameters:
day - int
month - int
year - int

SimpleDateSelector

public SimpleDateSelector(int day,
                          int month,
                          int year,
                          int fromYear,
                          int yearRange)
Constructor for SimpleDateSelector.

Parameters:
day - int
month - int
year - int
fromYear - int
yearRange - int
Method Detail

getDate

public java.util.Date getDate()
Returns the currently selected date as java.util.Date. Creation date:

Returns:
java.util.Date

getDay

public int getDay()
Returns number of the selected day in current month, starting with 1.

Returns:
int

getMonth

public int getMonth()
Returns the index of the currently selected month starting with 1.

Returns:
int

getYear

public int getYear()
Returns the currently selected year.

Returns:
int

getNumberOfYears

public int getNumberOfYears()
Returns the number of year to display in the year selector.

Returns:
int

getStartingYear

public int getStartingYear()
Returns the starting year to display in the year selector. No year lower than this can be selected by the user or set using setDate method.

Returns:
int

setDate

public void setDate(java.util.Date date)
Sets the date to display.

Parameters:
date - java.util.Date

setDay

public void setDay(int day)
Sets the day to the specified index. To ensure compatibility with java.util.Calendar class, first day of month is specified as 1. If the day set is outside allowed range, the value will be set to the nearest allowed value.

Parameters:
day - int

setLabelsVisible

public void setLabelsVisible(boolean visible)
Shows / hides the Year/Month/Day labels

Parameters:
visible - the visibility value

setMonth

public void setMonth(int month)
Sets the currently selected month. January has the index of 0.

Parameters:
month - int

setYear

public void setYear(int year)
Sets the currently selected year. Years are specified absolutely, although only years between startingYear and numberOfYears will be displayed. If the year is not within this range, the closest value will be set.

Parameters:
year - int

setEnabled

public void setEnabled(boolean how)
Sets the enabled state of this component. If the component is disabled, all the combo boxes are also disabled.

Overrides:
setEnabled in class javax.swing.JComponent
Parameters:
how - boolean

setStartingYear

public void setStartingYear(int from)
Sets the starting year to be displayed in the year selector. Only the years between startingYear and startingYear+numberOfYears inclusively can be selected by the user or by calling the setDate method.

Parameters:
from - int

setNumberOfYears

public void setNumberOfYears(int range)
Sets the number of years to display in the year selector. User can only select the years shown in the year selector.

Parameters:
range - int

setYearRange

public void setYearRange(int from,
                         int range)
Sets new available year range.

Parameters:
from - int
range - int

getPropertyValue

public java.lang.Object getPropertyValue()
Description copied from interface: PropertyEditor
Returns the value contained in this editor. To provide generic approach, value must be contained within Object, primitive types should be wrapped within appropriate classes (int - Integer). Return value of null should be used only to indicate, the value contained within this editor is invalid.

Specified by:
getPropertyValue in interface PropertyEditor
Returns:
Object

setPropertyValue

public boolean setPropertyValue(java.lang.Object value)
Description copied from interface: PropertyEditor
PropertyEditor should set the value specified and display it accordingly. Return value show whether the value could be set. Return value should be true only, it the editor was able to set and display value. If the value parameter does not match the editors expected type, is null or has invalid value, return value should be false.

Specified by:
setPropertyValue in interface PropertyEditor
Parameters:
value - Value to set
Returns:
boolean Indicates whether set was successful.

getDescription

public java.lang.String getDescription()
Description copied from interface: PropertyEditor
Returns the description for this editor. This description will be used to describe the component in the GUI. Its actual implementation depends on the implementing class.

If editor is unable to display the description, it must return null. This will allow for automatic creation of description and properly wrap the methods. If editor can display description but its value has not yet been defined, this method should return empty string.

Specified by:
getDescription in interface PropertyEditor
Returns:
String

setDescription

public void setDescription(java.lang.String description)
Specified by:
setDescription in interface PropertyEditor

setCompactView

public void setCompactView(boolean compact)

main

public static void main(java.lang.String[] args)
Run test applet.

Parameters:
args - command line parameters


Copyright © 2010. All Rights Reserved.