com.toedter.calendar

Class JDateChooser

Implemented Interfaces:
ActionListener, ChangeListener, PropertyChangeListener

public class JDateChooser
extends JPanel
implements ActionListener, PropertyChangeListener, ChangeListener

A date chooser containig a date spinner and a button, that makes a JCalendar visible for choosing a date.
Version:
1.2.2
Author:
Kai Toedter

Field Summary

protected JButton
calendarButton
protected String
dateFormatString
protected boolean
dateSelected
protected JSpinner
dateSpinner
protected JSpinner.DateEditor
editor
protected boolean
isInitialized
protected JCalendar
jcalendar
protected Date
lastSelectedDate
protected SpinnerDateModel
model
protected JPopupMenu
popup
protected boolean
startEmpty

Constructor Summary

JDateChooser()
Creates a new JDateChooser object.
JDateChooser(ImageIcon icon)
Creates a new JDateChooser object.
JDateChooser(String dateFormatString, boolean startEmpty)
Creates a new JDateChooser object with given date format string.
JDateChooser(boolean startEmpty)
Creates a new JDateChooser object.
JDateChooser(JCalendar jcalendar)
Creates a new JDateChooser object from a given JCalendar.
JDateChooser(JCalendar jcalendar, String dateFormatString, boolean startEmpty, ImageIcon icon)
Creates a new JDateChooser.

Method Summary

void
actionPerformed(ActionEvent e)
Called when the jalendar button was pressed.
Date
getDate()
Returns the date.
String
getDateFormatString()
Gets the date format string.
SpinnerDateModel
getModel()
Return the SpinnerDateModel associated with this control.
String
getName()
Returns "JDateChooser".
JSpinner
getSpinner()
Return this controls JSpinner control.
void
propertyChange(PropertyChangeEvent evt)
Listens for a "date" property change or a "day" property change event from the JCalendar.
void
setDate(Date date)
Sets the date.
void
setDateFormatString(String dateFormatString)
Sets the date format string.
void
setLocale(Locale l)
Sets the locale.
void
setModel(SpinnerDateModel mdl)
Set the SpinnerDateModel for this control.
void
stateChanged(ChangeEvent e)
Fires property "date" changes, recting on the spinner's state changes.
void
updateUI()
Updates the UI of itself and the popup.

Field Details

calendarButton

protected JButton calendarButton

dateFormatString

protected String dateFormatString

dateSelected

protected boolean dateSelected

dateSpinner

protected JSpinner dateSpinner

editor

protected JSpinner.DateEditor editor

isInitialized

protected boolean isInitialized

jcalendar

protected JCalendar jcalendar

lastSelectedDate

protected Date lastSelectedDate

model

protected SpinnerDateModel model

popup

protected JPopupMenu popup

startEmpty

protected boolean startEmpty

Constructor Details

JDateChooser

public JDateChooser()
Creates a new JDateChooser object.

JDateChooser

public JDateChooser(ImageIcon icon)
Creates a new JDateChooser object.
Parameters:
icon - the new icon

JDateChooser

public JDateChooser(String dateFormatString,
                    boolean startEmpty)
Creates a new JDateChooser object with given date format string. The default date format string is "MMMMM d, yyyy".
Parameters:
dateFormatString - the date format string
startEmpty - true, if the date field should be empty

JDateChooser

public JDateChooser(boolean startEmpty)
Creates a new JDateChooser object.
Parameters:
startEmpty - true, if the date field should be empty

JDateChooser

public JDateChooser(JCalendar jcalendar)
Creates a new JDateChooser object from a given JCalendar.
Parameters:
jcalendar - the JCalendar

JDateChooser

public JDateChooser(JCalendar jcalendar,
                    String dateFormatString,
                    boolean startEmpty,
                    ImageIcon icon)
Creates a new JDateChooser.
Parameters:
jcalendar - the jcalendar or null
dateFormatString - the date format string or null (then "MMMMM d, yyyy" is used)
startEmpty - true, if the date field should be empty
icon - the icon or null (then an internal icon is used)

Method Details

actionPerformed

public void actionPerformed(ActionEvent e)
Called when the jalendar button was pressed.
Parameters:
e - the action event

getDate

public Date getDate()
Returns the date.
Returns:
the current date

getDateFormatString

public String getDateFormatString()
Gets the date format string.
Returns:
Returns the dateFormatString.

getModel

public SpinnerDateModel getModel()
Return the SpinnerDateModel associated with this control.
Returns:
the SpinnerDateModel

getName

public String getName()
Returns "JDateChooser".
Returns:
the name value

getSpinner

public JSpinner getSpinner()
Return this controls JSpinner control.
Returns:
the JSpinner control

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Listens for a "date" property change or a "day" property change event from the JCalendar. Updates the dateSpinner and closes the popup.
Parameters:
evt - the event

setDate

public void setDate(Date date)
Sets the date. Fires the property change "date".
Parameters:
date - the new date.

setDateFormatString

public void setDateFormatString(String dateFormatString)
Sets the date format string. E.g "MMMMM d, yyyy" will result in "July 21, 2004" if this is the selected date and locale is English.
Parameters:
dateFormatString - The dateFormatString to set.

setLocale

public void setLocale(Locale l)
Sets the locale.
Parameters:
l - The new locale value

setModel

public void setModel(SpinnerDateModel mdl)
Set the SpinnerDateModel for this control. This method allows the JDateChooser control to be used with some persistence frameworks (ie. Oracle ADF) to bind the control to the database Date value.
Parameters:
mdl - the SpinnerDateModel

stateChanged

public void stateChanged(ChangeEvent e)
Fires property "date" changes, recting on the spinner's state changes.
Parameters:
e - the change event

updateUI

public void updateUI()
Updates the UI of itself and the popup.

Copyright B) 1999 - 2004 Kai Toedter.