JDatePicker v4.3

com.standbysoft.component.date.swing
Class DefaultMonthModel

java.lang.Object
  extended bycom.standbysoft.component.date.swing.DefaultMonthModel
All Implemented Interfaces:
MonthModel

public class DefaultMonthModel
extends java.lang.Object
implements MonthModel

A default implementation for a MonthModel. It adds a few methods that are not specified in the interface in order to make the specification of month names easier.

The month names are determined using a locale and a format (short or long).

One can also specify custom month names by overriding the getMonthNames() method.


Field Summary
static int MONTH_NAMES_LONG
          Type value indicating that the months' names are long.
static int MONTH_NAMES_SHORT
          Type value indicating that the months' names are short.
 
Constructor Summary
DefaultMonthModel()
          Creates a default month model that uses the default locale.
 
Method Summary
 void addMonthModelListener(MonthModelListener listener)
          Adds an object that listens to changes in this model.
protected  void fireMonthChanged(MonthModelEvent evt)
          DefaultMonthModel subclasses must call this method when the month represented by the model changes.
protected  void fireMonthNamesChanged(MonthModelEvent evt)
          DefaultMonthModel subclasses must call this method when the format for the month names changes.
protected  void fireTodayChanged(MonthModelEvent evt)
          DefaultMonthModel subclasses must call this method when the reference today date changes.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
           
 java.util.Locale getLocale()
          Returns the locale used to detrmine the names of the months.
 int getMonth()
          Returns the month represented by this model.
 java.lang.String[] getMonthNames()
          Returns the names of the months that are determined using the current locale and a format.
 int getMonthNamesFormat()
          Returns the current format used to represent the month names.
 java.util.TimeZone getTimeZone()
          Returns the time zone used to determine whether a date belongs to the month represented by this model or not.
 java.util.Date getToday()
          Returns the today reference date.
 int getYear()
          Returns the year to which the represented month belongs.
 boolean isToday(java.util.Date date)
          Determines whether a specified date matches the today date (the year, month and date fields in fact).
 boolean isTrailingNext(java.util.Date date)
          Determines if a specified date belongs to a following month.
 boolean isTrailingPrevious(java.util.Date date)
          Determines if a specified date belongs to a previous month.
 void removeMonthModelListener(MonthModelListener listener)
          Removes a specified listener from the list of registered listeners.
 void setLocale(java.util.Locale locale)
          Specifies a new locale to change the month names.
 void setMonth(int amonth)
          Specifies a new month to be represented by this model.
 void setMonth(int month, int year)
          Specifies a new month to be represented by this model.
 void setMonthNamesFormat(int format)
          Changes the format for the month names.
 void setTimeZone(java.util.TimeZone timezone)
          Specifies the time zone used to determine whether a date belongs to the month represented by this model or not.
 void setToday(java.util.Date date)
          Specifies a new date to be considered the today date.
 void setYear(int ayear)
          Specifies a new year to which the represented month belongs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MONTH_NAMES_SHORT

public static final int MONTH_NAMES_SHORT
Type value indicating that the months' names are short.

See Also:
Constant Field Values

MONTH_NAMES_LONG

public static final int MONTH_NAMES_LONG
Type value indicating that the months' names are long.

See Also:
Constant Field Values
Constructor Detail

DefaultMonthModel

public DefaultMonthModel()
Creates a default month model that uses the default locale. The names of the months use the MONTH_NAMES_SHORT format and the current month is selected.

Method Detail

getMonthNames

public java.lang.String[] getMonthNames()

Returns the names of the months that are determined using the current locale and a format. This approach should solve most cases and for special needs one can just override it and provide some custom names.

Specified by:
getMonthNames in interface MonthModel
Returns:
names of the months
See Also:
setLocale(Locale), setMonthNamesFormat(int)

setLocale

public void setLocale(java.util.Locale locale)
Specifies a new locale to change the month names.

Parameters:
locale - locale that determines the month names.
See Also:
getMonthNames(), setMonthNamesFormat(int)

getLocale

public java.util.Locale getLocale()
Returns the locale used to detrmine the names of the months.

Returns:
locale used to detrmine the names of the months.
See Also:
setLocale(Locale)

setMonthNamesFormat

public void setMonthNamesFormat(int format)
Changes the format for the month names. These names are determined based on this format and current locale.

Parameters:
format - format used to represent the names. Allowed values are MONTH_NAMES_SHORT and MONTH_NAMES_LONG
See Also:
getMonthNames(), setLocale(Locale)

getMonthNamesFormat

public int getMonthNamesFormat()
Returns the current format used to represent the month names.

Returns:
current format used to represent the month names. It can be MONTH_NAMES_SHORT or MONTH_NAMES_LONG.
See Also:
setMonthNamesFormat(int)

setMonth

public void setMonth(int amonth)
Description copied from interface: MonthModel
Specifies a new month to be represented by this model. The month will be the month of the current year. Only months that belong to the allowed dates interval are valid.

Specified by:
setMonth in interface MonthModel
Parameters:
amonth - new month to be used by this model. The values are Calendar constants like Calendar.JANUARY.
See Also:
MonthModel.getYear(), MonthModel.setMonth(int, int)

setYear

public void setYear(int ayear)
Description copied from interface: MonthModel
Specifies a new year to which the represented month belongs. Only years that belong to the allowed dates interval are valid.

Specified by:
setYear in interface MonthModel
Parameters:
ayear - year to which the represented month belongs.
See Also:
MonthModel.setMonth(int, int)

setMonth

public void setMonth(int month,
                     int year)
Description copied from interface: MonthModel
Specifies a new month to be represented by this model. The month will be the month of the current year. Only months that belong to the allowed dates interval are valid.

Specified by:
setMonth in interface MonthModel
Parameters:
month - new month to be used by this model. The values are Calendar constants like Calendar.JANUARY
year - year to which the represented month belongs
See Also:
MonthModel.setMonth(int), MonthModel.setYear(int)

getMonth

public int getMonth()
Description copied from interface: MonthModel
Returns the month represented by this model.

Specified by:
getMonth in interface MonthModel
Returns:
month represented by this model as a Calendar constant like Calendar.JANUARY.
See Also:
MonthModel.getYear()

getYear

public int getYear()
Description copied from interface: MonthModel
Returns the year to which the represented month belongs.

Specified by:
getYear in interface MonthModel
Returns:
the year to which the represented month belongs.
See Also:
MonthModel.getMonth()

isTrailingPrevious

public boolean isTrailingPrevious(java.util.Date date)
Description copied from interface: MonthModel
Determines if a specified date belongs to a previous month. For instance if the current month is January 2000, then December 23 1999 is a previous trailing date.

Specified by:
isTrailingPrevious in interface MonthModel
Parameters:
date - date that is tested if it is previous to this month
Returns:
true if the date is before the first date of this month; false otherwise.

isTrailingNext

public boolean isTrailingNext(java.util.Date date)
Description copied from interface: MonthModel
Determines if a specified date belongs to a following month. For instance if the current month is January 2000, then February 11 2000 is a next trailing date.

Specified by:
isTrailingNext in interface MonthModel
Parameters:
date - date that is tested if it is after this month
Returns:
true if the date is after the last date of this month; false otherwise.

isToday

public boolean isToday(java.util.Date date)
Description copied from interface: MonthModel
Determines whether a specified date matches the today date (the year, month and date fields in fact).

Specified by:
isToday in interface MonthModel
Parameters:
date - date that is tested
Returns:
true if the date matches the today date; false otherwise.

setToday

public void setToday(java.util.Date date)
Description copied from interface: MonthModel

Specifies a new date to be considered the today date. This date is particularly important for the date renderer and the JMonthView component which uses a label to display the today date.

Although setting the today date might seem a little weird, it makes sense if the application runs for a few days. Specifying the today date might be done automatically by a timer thread. In fact, JMonth uses such a thread to do it automatically.

When the today date changes, all interested listeners are notified via a MonthModelListener.todayChanged(MonthModelEvent) event.

Specified by:
setToday in interface MonthModel
Parameters:
date - new date that will be the today reference
See Also:
MonthModel.isToday(Date)

getToday

public java.util.Date getToday()
Description copied from interface: MonthModel
Returns the today reference date.

Specified by:
getToday in interface MonthModel
Returns:
today reference date.
See Also:
MonthModel.setToday(Date)

addMonthModelListener

public void addMonthModelListener(MonthModelListener listener)
Description copied from interface: MonthModel
Adds an object that listens to changes in this model.

Specified by:
addMonthModelListener in interface MonthModel
Parameters:
listener - the listener object that is informed about changes in this model

removeMonthModelListener

public void removeMonthModelListener(MonthModelListener listener)
Description copied from interface: MonthModel
Removes a specified listener from the list of registered listeners.

Specified by:
removeMonthModelListener in interface MonthModel
Parameters:
listener - the listener to be removed

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)

fireMonthNamesChanged

protected void fireMonthNamesChanged(MonthModelEvent evt)
DefaultMonthModel subclasses must call this method when the format for the month names changes.


fireMonthChanged

protected void fireMonthChanged(MonthModelEvent evt)
DefaultMonthModel subclasses must call this method when the month represented by the model changes.


fireTodayChanged

protected void fireTodayChanged(MonthModelEvent evt)
DefaultMonthModel subclasses must call this method when the reference today date changes.


setTimeZone

public void setTimeZone(java.util.TimeZone timezone)
Description copied from interface: MonthModel
Specifies the time zone used to determine whether a date belongs to the month represented by this model or not. This property is used internally by the date components to synchronize their time zone with this model so that it can determine if a date is before or after this month or if it is the today date.

Specified by:
setTimeZone in interface MonthModel
Parameters:
timezone - new time zone

getTimeZone

public java.util.TimeZone getTimeZone()
Description copied from interface: MonthModel
Returns the time zone used to determine whether a date belongs to the month represented by this model or not.

Specified by:
getTimeZone in interface MonthModel
Returns:
time zone used to determine whether a date belongs to the month represented by this model or not
See Also:
MonthModel.setTimeZone(TimeZone)

JDatePicker v4.3

Visit www.jdatepicker.com for further information or send us your suggestions.

Copyright © 2003-2007 Stand By Soft Ltd. All Rights Reserved.