com.ibm.spinner
Class CalendarSpinner

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.ibm.spinner.SpinnerGUI
                                |
                                +--com.ibm.spinner.Spinner
                                      |
                                      +--com.ibm.spinner.CalendarSpinner
Direct Known Subclasses:
DateSpinner, TimeSpinner

public class CalendarSpinner
extends Spinner
implements DateChangedListener

A spinner which displays and spins date/time. The date/time value can be changed by clicking on different subfields and spinning on them. The user can also type in a date string to set the current value.


Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static int DATE
          One kind of caret position.
static java.lang.String FULL
          One kind of date format string.
static int HOUR
          One kind of caret position.
static java.lang.String LONG
          One kind of date format string.
static java.lang.String MEDIUM
          One kind of date format string.
static int MINUTE
          One kind of caret position.
static int MONTH
          One kind of caret position.
static int SECOND
          One kind of caret position.
static java.lang.String SHORT
          One kind of date format string.
static int YEAR
          One kind of caret position.
 
Fields inherited from class com.ibm.spinner.SpinnerGUI
SPIN_HORIZONTAL, SPIN_VERTICAL
 
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
 
Constructor Summary
CalendarSpinner()
          Default constructor which constructs a CalendarSpinner with the time zone set to that of the host, and the formatString property set to the default locale's Dateformat.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Event mothod of ActionListener.
 void addDateChangedListener(DateChangedListener listener)
          Adds a DateChangedListener.
 void dateChanged(DateChangedEvent e)
          Event mothod of DateChangedListener.
 void focusLost(java.awt.event.FocusEvent e)
          Event mothod of FocusListener.
 java.util.Calendar getCalendar()
          Gets the current calendar's six time fields (which are year, month, date, hour, minute, second).
 int getCaretPos()
          Gets the current caret positon of the text field.
 java.util.Date getDate()
          Gets the current date/time stored in the spinner.
 long getDatePartValue()
          Gets the current date part(year, month, day).
 java.lang.String getDateString()
          Gets the current date/time string shown in the entry field.
 int getDay()
          Gets the current day.
 java.lang.String getFormatString()
          Gets the current date/time format string.
 int getFormattingStyle()
          Gets the default formatting styles which can be FULL, LONG, MEDIUM, or SHORT.
 int getHour()
          Gets the current hour.
 java.util.Calendar getMaximum()
          Gets the maximum property of calendar.
 java.util.Calendar getMinimum()
          Gets the minimum property of calendar.
 int getMinute()
          Gets the current minute.
 int getMonth()
          Gets the current month.
 int getSecond()
          Gets the current second.
 java.sql.Date getSQLDate()
          Returns the spinner's current date as an SQL date.
 long getTimePartValue()
          Gets the current time part(hour, minute, second).
 java.lang.String getTimeZone()
          Returns the ID of the spinner's current time zone.
 long getValue()
          Gets the current date/time value.
 int getYear()
          Gets the current year.
 boolean isWrapAssociated()
          Returns true if the spinner's subfields can be wrapped together.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void removeDateChangedListener(DateChangedListener listener)
          Removes a date-changed listener.
 void scrollDown()
          Decrements the date/time subfield that the caret points to.
 void scrollUp()
          Increments the date/time subfield that the caret points to.
 void setCalendar(java.util.Calendar newCalendar)
          Sets the current calendar's six time fields ,which are year, month, date, hour, minute, second the same with the time fields of another calendar.
 void setCaretPos(int newCaretPos)
          Sets the current caret positon of the text field.
 void setDate(java.util.Date date)
          Sets the current date/time.
 void setDateByFields(int year, int month, int day, int hour, int minute, int second)
          Sets the current date/time by time fields.
 void setDatePartValue(long newValue)
          Sets the current date part(year, month, day) by by fields.
 void setDateString(java.lang.String str)
          Sets the current date/time shown in the entry field.
 void setDay(int newDays)
          Sets the current date.
 void setFormatString(java.lang.String newFormatString)
          Sets the user defined pattern string for formatting and parsing date/time in a locale-sensitive manner.
 void setFormattingStyle(int newFormattingStyle)
          Sets the default formatting styles which can be FULL, LONG, MEDIUM, of SHORT.
 void setHour(int newHours)
          Sets the current hour.
 void setMaximum(java.util.Calendar newMaximumCalendar)
          Sets the maximum property of calendar.
 void setMinimum(java.util.Calendar newMinimumCalendar)
          Sets the minimum property of calendar.
 void setMinute(int newMinutes)
          Sets the current minute.
 void setMonth(int newMonths)
          Sets the current month.
 void setSecond(int newSeconds)
          Sets the current second.
 void setTimePartValue(long newValue)
          Sets the current time part(hour, minute, second) by fields.
 void setTimeZone(java.lang.String id)
          Sets the time zone used by the DateFormat class for formatting strings into days.
 void setValue(long newValue)
          Sets the current date/time value.
 void setWrapAssociated(boolean b)
          Sets whether the spinner's subfields can be wrapped together or not.
 void setYear(int newYears)
          Sets the current year.
 
Methods inherited from class com.ibm.spinner.Spinner
addChangeListener, addSpinnerErrorEventListener, isWrap, removeChangeListener, removeSpinnerErrorEventListener, setWrap
 
Methods inherited from class com.ibm.spinner.SpinnerGUI
focusGained, getColumns, getDecrButtonArrowColor, getIncrButtonArrowColor, getMaximumSize, getMinimumSize, getOrientation, getPreferredSize, isEditable, isEnabled, keyTyped, mouseClicked, mouseEntered, mouseExited, mousePressed, setBackground, setColumns, setDecrButtonArrowColor, setEditable, setEnabled, setFont, setForeground, setIncrButtonArrowColor, setOpaque, setOrientation
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, setLayout, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, createImage, createImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FULL

public static java.lang.String FULL
One kind of date format string.

LONG

public static java.lang.String LONG
One kind of date format string.

MEDIUM

public static java.lang.String MEDIUM
One kind of date format string.

SHORT

public static java.lang.String SHORT
One kind of date format string.

YEAR

public static final int YEAR
One kind of caret position.

MONTH

public static final int MONTH
One kind of caret position.

DATE

public static final int DATE
One kind of caret position.

HOUR

public static final int HOUR
One kind of caret position.

MINUTE

public static final int MINUTE
One kind of caret position.

SECOND

public static final int SECOND
One kind of caret position.
Constructor Detail

CalendarSpinner

public CalendarSpinner()
Default constructor which constructs a CalendarSpinner with the time zone set to that of the host, and the formatString property set to the default locale's Dateformat.
Method Detail

setWrapAssociated

public void setWrapAssociated(boolean b)
Sets whether the spinner's subfields can be wrapped together or not.
Parameters:
b - if true, the subfields can be wrapped together.

isWrapAssociated

public boolean isWrapAssociated()
Returns true if the spinner's subfields can be wrapped together.
Returns:
if the wrapAssociated is true, the subfields can be wrapped together.

setTimeZone

public void setTimeZone(java.lang.String id)
Sets the time zone used by the DateFormat class for formatting strings into days.
Parameters:
id - A time zone ID. For instance, the time zone ID for the Pacific Standard Time zone is "PST".

getTimeZone

public java.lang.String getTimeZone()
Returns the ID of the spinner's current time zone.
Returns:
The ID of current time zone

setCaretPos

public void setCaretPos(int newCaretPos)
Sets the current caret positon of the text field.
Parameters:
newCaretPos - the sub-field number of the text

getCaretPos

public int getCaretPos()
Gets the current caret positon of the text field.
Returns:
The caret position

setCalendar

public void setCalendar(java.util.Calendar newCalendar)
Sets the current calendar's six time fields ,which are year, month, date, hour, minute, second the same with the time fields of another calendar. But the timeZone of the current calendar is not changed.
Parameters:
newCalendar - the calendar whose time fields will be used to change the current one.
Throws:
java.lang.IllegalArgumentException - exception

getCalendar

public java.util.Calendar getCalendar()
Gets the current calendar's six time fields (which are year, month, date, hour, minute, second).
Returns:
The calendar of the current CalendarSpinner.

setDateString

public void setDateString(java.lang.String str)
Sets the current date/time shown in the entry field.
Parameters:
str - The new date/time string.

getDateString

public java.lang.String getDateString()
Gets the current date/time string shown in the entry field.
Returns:
The current date/time string.

setDate

public void setDate(java.util.Date date)
Sets the current date/time.
Parameters:
date - the new date/time.

getDate

public java.util.Date getDate()
Gets the current date/time stored in the spinner.
Returns:
an instance of java.util.Date that represents the date/time stored by this spinner

setFormatString

public void setFormatString(java.lang.String newFormatString)
Sets the user defined pattern string for formatting and parsing date/time in a locale-sensitive manner.
Parameters:
newFormatString - the new formatting string.

getFormatString

public java.lang.String getFormatString()
Gets the current date/time format string.
Returns:
The current format string.

setFormattingStyle

public void setFormattingStyle(int newFormattingStyle)
Sets the default formatting styles which can be FULL, LONG, MEDIUM, of SHORT.
Parameters:
newFormattingStyle - the default formatting style.

getFormattingStyle

public int getFormattingStyle()
Gets the default formatting styles which can be FULL, LONG, MEDIUM, or SHORT.
Returns:
an integer representing of the default formatting styles

setYear

public void setYear(int newYears)
Sets the current year.
Parameters:
newYears - The year as an int.

getYear

public int getYear()
Gets the current year.
Returns:
The current year as an int.

setMonth

public void setMonth(int newMonths)
Sets the current month.
Parameters:
newMonths - The month values are 0-11, e.g. 1 for January, 12 for December.

getMonth

public int getMonth()
Gets the current month.
Returns:
The current month as an int.

setDay

public void setDay(int newDays)
Sets the current date.
Parameters:
newDays - The date as an int.

getDay

public int getDay()
Gets the current day.
Returns:
The current day as an int.

setHour

public void setHour(int newHours)
Sets the current hour.
Parameters:
newHours - The hour as an int.

getHour

public int getHour()
Gets the current hour.
Returns:
hours The hour as an int.

setMinute

public void setMinute(int newMinutes)
Sets the current minute.
Parameters:
newMinutes - The minute as an int.

getMinute

public int getMinute()
Gets the current minute.
Returns:
minutes The minute as an int.

setSecond

public void setSecond(int newSeconds)
Sets the current second.
Parameters:
newSeconds - The second as an int.

getSecond

public int getSecond()
Gets the current second.
Returns:
The second as an int.

setValue

public void setValue(long newValue)
Sets the current date/time value.
Parameters:
newValue - The new date/time value as a long.

getValue

public long getValue()
Gets the current date/time value.
Returns:
current value as a long.

setMinimum

public void setMinimum(java.util.Calendar newMinimumCalendar)
Sets the minimum property of calendar.
Parameters:
newMinimum - The minimum as a Calendar.

getMinimum

public java.util.Calendar getMinimum()
Gets the minimum property of calendar.
Returns:
The minimum as a Calendar.

setMaximum

public void setMaximum(java.util.Calendar newMaximumCalendar)
Sets the maximum property of calendar.
Parameters:
newMaximumCalendar - The maximum as a Calendar.

getMaximum

public java.util.Calendar getMaximum()
Gets the maximum property of calendar.
Returns:
The maximum as a Calendar.

getSQLDate

public java.sql.Date getSQLDate()
Returns the spinner's current date as an SQL date.
Returns:
an instance of java.sql.Date that represents the date stored by the spinner.

setDatePartValue

public void setDatePartValue(long newValue)
Sets the current date part(year, month, day) by by fields.
Parameters:
newValue - The date part value as a long.

getDatePartValue

public long getDatePartValue()
Gets the current date part(year, month, day).
Returns:
The date part value as a long.

setTimePartValue

public void setTimePartValue(long newValue)
Sets the current time part(hour, minute, second) by fields.
Parameters:
newValue - The time part value as a long.

getTimePartValue

public long getTimePartValue()
Gets the current time part(hour, minute, second).
Returns:
The time part value as a long.

setDateByFields

public void setDateByFields(int year,
                            int month,
                            int day,
                            int hour,
                            int minute,
                            int second)
Sets the current date/time by time fields.
Parameters:
year - The year as an int.
month - The month as an int. Month values are 0-11, e.g. 0 for January, 11 for December.
day - The day as an int.
hour - The hour as an int.
minute - The minute as an int.
second - The second as an int.

addDateChangedListener

public void addDateChangedListener(DateChangedListener listener)
Adds a DateChangedListener.
Parameters:
listener - The listener to add.

removeDateChangedListener

public void removeDateChangedListener(DateChangedListener listener)
Removes a date-changed listener.
Parameters:
listener - The listener to remove.

scrollUp

public void scrollUp()
Increments the date/time subfield that the caret points to.
Overrides:
scrollUp in class Spinner

scrollDown

public void scrollDown()
Decrements the date/time subfield that the caret points to.
Overrides:
scrollDown in class Spinner

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Overrides:
mouseReleased in class SpinnerGUI

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Overrides:
keyReleased in class SpinnerGUI

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Overrides:
keyPressed in class Spinner

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Event mothod of ActionListener.
Overrides:
actionPerformed in class Spinner

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Event mothod of FocusListener.
Overrides:
focusLost in class SpinnerGUI

dateChanged

public void dateChanged(DateChangedEvent e)
Event mothod of DateChangedListener.
Specified by:
dateChanged in interface DateChangedListener