com.michaelbaranov.microba.calendar

Class CalendarPane

Implemented Interfaces:
CalendarColors

public class CalendarPane
extends MicrobaComponent
implements CalendarColors

A concrete implementation of JComponent. Capable of displaying and selecting dates, much like a real-world calendar.
Author:
Michael Baranov

Field Summary

static String
PROPERTY_NAME_DATE
The name of a "date" property.
static String
PROPERTY_NAME_FOCUS_LOST_BEHAVIOR
The name of a "focusLocatBehavior" property.
static String
PROPERTY_NAME_HOLIDAY_POLICY
The name of a "holidayPolicy" property.
static String
PROPERTY_NAME_LOCALE
The name of a "locale" property.
static String
PROPERTY_NAME_RESOURCES
The name of a "resources" property.
static String
PROPERTY_NAME_SHOW_NONE_BTN
The name of a "showNoneButton" property.
static String
PROPERTY_NAME_SHOW_NUMBER_WEEK
The name of a "resources" property.
static String
PROPERTY_NAME_SHOW_TODAY_BTN
The name of a "showTodayButton" property.
static String
PROPERTY_NAME_STRIP_TIME
The name of a "stripTime" property.
static String
PROPERTY_NAME_STYLE
The name of a "style" property.
static String
PROPERTY_NAME_VETO_POLICY
The name of a "vetoPolicy" property.
static String
PROPERTY_NAME_ZONE
The name of a "zone" property.
static int
STYLE_CLASSIC
A constant for the "style" property.
static int
STYLE_MODERN
A constant for the "style" property.

Constructor Summary

CalendarPane()
Constructor.
CalendarPane(Date initialDate)
Constructor.
CalendarPane(Date initialDate, int style)
Constructor.
CalendarPane(Date initialDate, int style, Locale locale)
Constructor.
CalendarPane(Date initialDate, int style, Locale locale, TimeZone zone)
Constructor.
CalendarPane(int style)
Constructor.

Method Summary

void
addActionListener(ActionListener listener)
Adds an ActionListener listener.
void
addCommitListener(CommitListener listener)
Adds an CommitListener listener.
boolean
commitEdit()
Forces the control to commit current user's edit.
void
commitOrRevert()
Forces the control to commit or revert user's edit depending on the current focus lost behavior as if the focus would be lost.
void
fireActionEvent()
Fires a ActionEvent to all registered listeners.
void
fireCommitEvent(boolean commit)
Fires a CommitEvent to all registered listeners.
Date
getDate()
Returns currently selected date in the control.
int
getFocusLostBehavior()
Returns the focus lost behavior.
HolidayPolicy
getHolidayPolicy()
Returns current holliday policy (model).
Locale
getLocale()
Returns current locale.
CalendarResources
getResources()
Resurns current calendar resources model.
int
getStyle()
Returns current visual style of the control.
String
getUIClassID()
VetoPolicy
getVetoPolicy()
Returns the current veto policy (model).
TimeZone
getZone()
Returns current time zone.
boolean
isShowNoneButton()
Is the none-button visible?

The none-button allows the user to select empty date (null-date, no date).

boolean
isShowNumberOfWeek()
Is the number of every week visible?
boolean
isShowTodayButton()
Is today button visible?

The today button allows the user to quickly select current date.

boolean
isStripTime()
Is time protion of the date automatically striped, based on current locale and ime zone?
void
removeActionListener(ActionListener listener)
Removes an ActionListener listener.
void
removeCommitListener(CommitListener listener)
Removes an CommitListener listener.
void
revertEdit()
Forces the control to revert current user's edit to reflect current control's date.
void
setDate(Date date)
Sets currently selected date to the control.
void
setFocusLostBehavior(int behavior)
Sets the focus lost behaviour.
void
setHolidayPolicy(HolidayPolicy holidayPolicy)
Sets current holliday policy (model) then updates the control to reflect the policy set.
void
setLocale(Locale locale)
Sets current locale.
void
setResources(CalendarResources resources)
Sets current calendar resources model.
void
setShowNoneButton(boolean visible)
Shows or hides the none-button.
void
setShowNumberOfWeek(boolean visible)
Shows or hides the the number of every week.
void
setShowTodayButton(boolean visible)
Shows or hides the today-button.
void
setStripTime(boolean stripTime)
Makes getDate() either strip the time portion of the date, or keep it.
void
setStyle(int style)
Sets the current visual style of the control.
void
setVetoPolicy(VetoPolicy vetoModel)
Sets the current veto policy (model).
void
setZone(TimeZone zone)
Sets current time zone.
static Date
stripTime(Date date, TimeZone zone, Locale locale)
Returns same date as given, but time portion (hours, minutes, seconds, fraction of second) set to zero, based on given locale and time zone.

Field Details

PROPERTY_NAME_DATE

public static final String PROPERTY_NAME_DATE
The name of a "date" property.

PROPERTY_NAME_FOCUS_LOST_BEHAVIOR

public static final String PROPERTY_NAME_FOCUS_LOST_BEHAVIOR
The name of a "focusLocatBehavior" property.

PROPERTY_NAME_HOLIDAY_POLICY

public static final String PROPERTY_NAME_HOLIDAY_POLICY
The name of a "holidayPolicy" property.

PROPERTY_NAME_LOCALE

public static final String PROPERTY_NAME_LOCALE
The name of a "locale" property.

PROPERTY_NAME_RESOURCES

public static final String PROPERTY_NAME_RESOURCES
The name of a "resources" property.

PROPERTY_NAME_SHOW_NONE_BTN

public static final String PROPERTY_NAME_SHOW_NONE_BTN
The name of a "showNoneButton" property.

PROPERTY_NAME_SHOW_NUMBER_WEEK

public static final String PROPERTY_NAME_SHOW_NUMBER_WEEK
The name of a "resources" property.

PROPERTY_NAME_SHOW_TODAY_BTN

public static final String PROPERTY_NAME_SHOW_TODAY_BTN
The name of a "showTodayButton" property.

PROPERTY_NAME_STRIP_TIME

public static final String PROPERTY_NAME_STRIP_TIME
The name of a "stripTime" property.

PROPERTY_NAME_STYLE

public static final String PROPERTY_NAME_STYLE
The name of a "style" property.

PROPERTY_NAME_VETO_POLICY

public static final String PROPERTY_NAME_VETO_POLICY
The name of a "vetoPolicy" property.

PROPERTY_NAME_ZONE

public static final String PROPERTY_NAME_ZONE
The name of a "zone" property.

STYLE_CLASSIC

public static final int STYLE_CLASSIC
A constant for the "style" property.
Field Value:
32

STYLE_MODERN

public static final int STYLE_MODERN
A constant for the "style" property.
Field Value:
16

Constructor Details

CalendarPane

public CalendarPane()
Constructor.

CalendarPane

public CalendarPane(Date initialDate)
Constructor.

CalendarPane

public CalendarPane(Date initialDate,
                    int style)
Constructor.

CalendarPane

public CalendarPane(Date initialDate,
                    int style,
                    Locale locale)
Constructor.

CalendarPane

public CalendarPane(Date initialDate,
                    int style,
                    Locale locale,
                    TimeZone zone)
Constructor.

CalendarPane

public CalendarPane(int style)
Constructor.

Method Details

addActionListener

public void addActionListener(ActionListener listener)
Adds an ActionListener listener.
Parameters:
listener - a listener to add
See Also:
ActionListener

addCommitListener

public void addCommitListener(CommitListener listener)
Adds an CommitListener listener.
Parameters:
listener - a listener to add
See Also:
CommitListener

commitEdit

public boolean commitEdit()
Forces the control to commit current user's edit. The opertaion may fail because the date in the control may be restricted by current veto policy. If successfull, the current date of the control may change, a CommitEvent is fired.
Returns:
true if successful, false otherwise

commitOrRevert

public void commitOrRevert()
Forces the control to commit or revert user's edit depending on the current focus lost behavior as if the focus would be lost.

fireActionEvent

public void fireActionEvent()
Fires a ActionEvent to all registered listeners.
See Also:
ActionEvent, ActionListener

fireCommitEvent

public void fireCommitEvent(boolean commit)
Fires a CommitEvent to all registered listeners.
Parameters:
commit - true to indicate commit, false to indicate revert
See Also:
CommitEvent, CommitListener

getDate

public Date getDate()
Returns:
currently selected date

getFocusLostBehavior

public int getFocusLostBehavior()
Returns the focus lost behavior. Possible values are:
  • JFormattedTextField.COMMIT
  • JFormattedTextField.COMMIT_OR_REVERT
  • JFormattedTextField.REVERT
  • JFormattedTextField.PERSIST
Original meaning preserved.
Returns:
the focus lost behavior constant
See Also:
JFormattedTextField

getHolidayPolicy

public HolidayPolicy getHolidayPolicy()
Returns current holliday policy (model).

The policy is used to query holliday dates and holliday descriptions.

Returns:
current holliday policy or null if none set
See Also:
HolidayPolicy

getLocale

public Locale getLocale()
Returns current locale.
Returns:
current locale

getResources

public CalendarResources getResources()
Resurns current calendar resources model.

The model is used to query localized resources for the control.

Returns:
current calendar resources model
See Also:
CalendarResources

getStyle

public int getStyle()
Returns current visual style of the control.
Returns:
current visual style constant.

getUIClassID

public String getUIClassID()

getVetoPolicy

public VetoPolicy getVetoPolicy()
Returns the current veto policy (model).

The policy is used to veto dates in the control.

Returns:
current veto policy or null if none set
See Also:
VetoPolicy

getZone

public TimeZone getZone()
Returns current time zone.
Returns:
current time zone

isShowNoneButton

public boolean isShowNoneButton()
Is the none-button visible?

The none-button allows the user to select empty date (null-date, no date).

Returns:
true if the none-button is visible, false otherwise

isShowNumberOfWeek

public boolean isShowNumberOfWeek()
Is the number of every week visible?
Returns:
true if the number of every week is visible, false otherwise

isShowTodayButton

public boolean isShowTodayButton()
Is today button visible?

The today button allows the user to quickly select current date.

Returns:
true if the today button is visible, false otherwise

isStripTime

public boolean isStripTime()
Is time protion of the date automatically striped, based on current locale and ime zone?
Returns:
true if getDate() returns a stripped date, false otherwise

removeActionListener

public void removeActionListener(ActionListener listener)
Removes an ActionListener listener.
Parameters:
listener - a listener to remove
See Also:
ActionListener

removeCommitListener

public void removeCommitListener(CommitListener listener)
Removes an CommitListener listener.
Parameters:
listener - a listener to remove
See Also:
CommitListener

revertEdit

public void revertEdit()
Forces the control to revert current user's edit to reflect current control's date. The current date of the control may change, a CommitEvent is fired.

setDate

public void setDate(Date date)
            throws PropertyVetoException
Sets currently selected date to the control.

The given date is checked against the current VetoPolicy. If the check is passed, the date is transferred to the control and the control is updated to display the date.

A PropertyChangeEvent may be fired, an ActionEvent may be fired.

Parameters:
date - the date to set

setFocusLostBehavior

public void setFocusLostBehavior(int behavior)
Sets the focus lost behaviour. Possible values are:
  • JFormattedTextField.COMMIT
  • JFormattedTextField.COMMIT_OR_REVERT
  • JFormattedTextField.REVERT
  • JFormattedTextField.PERSIST
Original meaning preserved.
Parameters:
behavior - the focus lost behavior constant
See Also:
JFormattedTextField

setHolidayPolicy

public void setHolidayPolicy(HolidayPolicy holidayPolicy)
Sets current holliday policy (model) then updates the control to reflect the policy set.

The policy is used to query holliday dates and holiday descriptions.

Parameters:
holidayPolicy - a holliday policy to set. May be null
See Also:
VetoPolicy

setLocale

public void setLocale(Locale locale)
Sets current locale.

The locale is used to construct internal Calendar instances and affects visual representation of the control.

Parameters:
locale - the locale to set

setResources

public void setResources(CalendarResources resources)
Sets current calendar resources model.

The model is used to query localized resources for the control.

Parameters:
resources - a calendar resources model to set. Should not be null
See Also:
CalendarResources

setShowNoneButton

public void setShowNoneButton(boolean visible)
Shows or hides the none-button.

The none-button allows the user to select empty date (null-date, no date).

Parameters:
visible - true to show the none-button false to hide

setShowNumberOfWeek

public void setShowNumberOfWeek(boolean visible)
Shows or hides the the number of every week.

The number of week is based on the current locale for the component.

Parameters:
visible - true to show the the number of every week false to hide

setShowTodayButton

public void setShowTodayButton(boolean visible)
Shows or hides the today-button.

The today-button allows the user to quickly select current date.

Parameters:
visible - true to show the today-button false to hide

setStripTime

public void setStripTime(boolean stripTime)
Makes getDate() either strip the time portion of the date, or keep it.
Parameters:
stripTime - true to strip time, false to keep time

setStyle

public void setStyle(int style)
Sets the current visual style of the control.

The control is then updated to reflect the new style.

Parameters:
style - the style to set

setVetoPolicy

public void setVetoPolicy(VetoPolicy vetoModel)
Sets the current veto policy (model).

The policy is used to veto dates in the control.

Parameters:
vetoModel - a veto policy to set. May be null

setZone

public void setZone(TimeZone zone)
Parameters:
zone - the time zone to set

stripTime

public static Date stripTime(Date date,
                             TimeZone zone,
                             Locale locale)
Returns same date as given, but time portion (hours, minutes, seconds, fraction of second) set to zero, based on given locale and time zone. Utility method.

Examle:
Fri Sep 29 15:57:23 EEST 2006 -> Fri Sep 29 00:00:00 EEST 2006

Parameters:
date - date to strip time from
zone - time zone to get zero fields in
locale - locale to base the calendar on
Returns:
stripped date