JDatePicker v4.3

com.standbysoft.component.date.swing
Class DefaultWeekModel

java.lang.Object
  extended bycom.standbysoft.component.date.swing.DefaultWeekModel
All Implemented Interfaces:
WeekModel

public class DefaultWeekModel
extends java.lang.Object
implements WeekModel

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

The week days names are determined using a locale and a format (short, long or one letter).

One can also specify custom week days names by overriding the getDowNames() method.

Another important feature of this model is that it can compute the week number for a certain date. This means that you can override it to implement your own week numbering scheme although it may probably happen in very few cases.

What is important to know is that you can configure this model to compute the week numbers according to the ISO 8601 standard.


Field Summary
protected  int dow
           
static int DOW_NAMES_LETTER
          Type value indicating that the days of week names are only one letter long.
static int DOW_NAMES_LONG
          Type value indicating that the days of week names are long.
static int DOW_NAMES_SHORT
          Type value indicating that the days of week names are short.
protected  int dowFirst
           
protected  int dowFormat
          The format used to determine the week days names.
protected  java.lang.String[] dowNames
          Contains the actual week days names.
protected  int[] dows
           
protected  boolean dowSelectionAllowed
           
protected  boolean isoWeekNumbersEnabled
           
protected  javax.swing.event.EventListenerList listenerList
          The list where all the registered listeners are stored.
protected  java.util.Locale locale
          The locale used to determine the week days names.
protected  int month
           
protected  int week
           
protected static int[] WEEK_DAYS
          A list with all the Calendar week days that starts with Sunday and ends with Saturday.
protected  boolean weekSelectionAllowed
           
protected  int year
           
 
Fields inherited from interface com.standbysoft.component.date.swing.WeekModel
NO_SELECTED_DOW, NO_SELECTED_MONTH, NO_SELECTED_WEEK, NO_SELECTED_YEAR
 
Constructor Summary
DefaultWeekModel()
          Creates a default week model that uses the default locale.
 
Method Summary
 void addWeekModelListener(WeekModelListener listener)
          Adds an object that listens to changes in this model.
protected  void fireDowChanged(WeekModelEvent evt)
          DefaultWeekModel subclasses must call this method when the selected day of week changes.
protected  void fireDowFirstChanged(WeekModelEvent evt)
          DefaultWeekModel subclasses must call this method when the first day of week changes.
protected  void fireDowNamesChanged(WeekModelEvent evt)
          DefaultWeekModel subclasses must call this method when the names of the days of week change.
protected  void fireWeekChanged(WeekModelEvent evt)
          DefaultWeekModel subclasses must call this method when the selected week changes.
protected  void fireWeekNumbersChanged(WeekModelEvent evt)
          DefaultWeekModel subclasses must call this method when the week numbers numerotation changes.
 int getDowFirst()
          Returns the first day of week.
 java.lang.String[] getDowNames()
          Returns the names of the week days that are determined using the current locale and a format.
protected  java.lang.String[] getDowNames(int format, java.util.Locale locale)
          Returns the names of the week days.
 int getDowNamesFormat()
          Returns the current format used to represent the week days names.
 int[] getDows()
          Returns the days of week starting with the first day of week.
 java.util.Locale getLocale()
          Returns the locale used to determine the names of the week days.
 int getSelectedDow()
          Returns the day of week selected by this model.
 int getSelectedMonth()
          Returns the month to which the selected day of week belongs.
 int getSelectedWeek()
          Returns the number of the selected week from current year.
 int getSelectedYear()
          Returns the year to which the selected week belongs.
 int getWeekNumber(java.util.Date date, java.util.TimeZone timezone)
          Returns the week number for a certain date using the Calendar.WEEK_OF_YEAR field value.
 boolean isDowSelectionAllowed()
          Determines whether days of week may be selected.
 boolean isWeekNumberISOFormatEnabled()
          Determines whether ISO week numbering is enabled.
 boolean isWeekSelectionAllowed()
          Determines whether weeks of year may be selected.
 void removeWeekModelListener(WeekModelListener listener)
          Removes a specified listener from the list of registered listeners.
 void setDowFirst(int day)
          Specifies the first day of week.
 void setDowNamesFormat(int format)
          Changes the format for the week days names.
 void setDowSelectionAllowed(boolean allowed)
          Specifies whether days of week may be selected.
 void setLocale(java.util.Locale locale)
          Specifies a new locale to change the week days names.
 void setSelectedDow(int month, int dow)
          Specifies the day of week that is selected by this model.
 void setSelectedWeek(int year, int week)
          Selects a week from a specified year.
 void setWeekNumberISOFormatEnabled(boolean enabled)
          Specifies whether weeks are numbered according to the ISO 8601 standard which defines the numeric representations of date and time.
 void setWeekSelectionAllowed(boolean allowed)
          Specifies whether weeks of year may be selected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOW_NAMES_SHORT

public static final int DOW_NAMES_SHORT
Type value indicating that the days of week names are short.

See Also:
Constant Field Values

DOW_NAMES_LONG

public static final int DOW_NAMES_LONG
Type value indicating that the days of week names are long.

See Also:
Constant Field Values

DOW_NAMES_LETTER

public static final int DOW_NAMES_LETTER
Type value indicating that the days of week names are only one letter long.

See Also:
Constant Field Values

listenerList

protected javax.swing.event.EventListenerList listenerList
The list where all the registered listeners are stored.


WEEK_DAYS

protected static int[] WEEK_DAYS
A list with all the Calendar week days that starts with Sunday and ends with Saturday.


dow

protected int dow

month

protected int month

week

protected int week

year

protected int year

dowFirst

protected int dowFirst

dows

protected int[] dows

dowFormat

protected int dowFormat
The format used to determine the week days names. It can be one of DOW_NAMES_SHORT, DOW_NAMES_LONG or DOW_NAMES_LETTER.


locale

protected java.util.Locale locale
The locale used to determine the week days names.


dowNames

protected java.lang.String[] dowNames
Contains the actual week days names.


dowSelectionAllowed

protected boolean dowSelectionAllowed

weekSelectionAllowed

protected boolean weekSelectionAllowed

isoWeekNumbersEnabled

protected boolean isoWeekNumbersEnabled
Constructor Detail

DefaultWeekModel

public DefaultWeekModel()
Creates a default week model that uses the default locale. The names of the week days use the DOW_NAMES_SHORT format and no week or day of week is selected.

Method Detail

getDowNames

public java.lang.String[] getDowNames()

Returns the names of the week days 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:
getDowNames in interface WeekModel
Returns:
names of the week days
See Also:
setLocale(Locale), setDowNamesFormat(int)

getDowNames

protected java.lang.String[] getDowNames(int format,
                                         java.util.Locale locale)
                                  throws java.lang.IllegalArgumentException
Returns the names of the week days. This method computes the names of the days of week using a certain format and locale. In case one wants to provide additional formats, one should just extend this class and override this method to handle them.

Parameters:
format - available formats are short, long and one letter
locale - locale
Returns:
returns the names of the week days as a String array. The name of a week day can be accessed using as array index a Calendar constant like Calendar.SUNDAY.
Throws:
java.lang.IllegalArgumentException - if the format is not valid

setDowNamesFormat

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

Parameters:
format - format used to represent the names. Allowed values are DOW_NAMES_SHORT, DOW_NAMES_LONG and DOW_NAMES_LETTER
See Also:
getDowNames(), setLocale(Locale)

getDowNamesFormat

public int getDowNamesFormat()
Returns the current format used to represent the week days names.

Returns:
current format used to represent the week days names. It can be DOW_NAMES_SHORT, DOW_NAMES_LONG or DOW_NAMES_LETTER.
See Also:
setDowNamesFormat(int)

setLocale

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

Parameters:
locale - locale that determines the week days names.
See Also:
getDowNames(), setDowNamesFormat(int)

getLocale

public java.util.Locale getLocale()
Returns the locale used to determine the names of the week days.

Returns:
locale used to determine the names of the week days.
See Also:
setLocale(Locale)

getSelectedMonth

public int getSelectedMonth()
Description copied from interface: WeekModel
Returns the month to which the selected day of week belongs.

Specified by:
getSelectedMonth in interface WeekModel
Returns:
month to which the selected dow belongs or WeekModel.NO_SELECTED_MONTH if no dow is selected.
See Also:
WeekModel.NO_SELECTED_MONTH, WeekModel.getSelectedDow(), WeekModel.setSelectedDow(int, int)

getSelectedDow

public int getSelectedDow()
Description copied from interface: WeekModel
Returns the day of week selected by this model. Accepted values when a day is selected are the calendar constants: Calendar.SUNDAY, Calendar.MONDAY, etc. If no day of week is selected, then the method will return WeekModel.NO_SELECTED_DOW.

Specified by:
getSelectedDow in interface WeekModel
Returns:
day of week selected by this model.
See Also:
WeekModel.setSelectedDow(int, int), WeekModel.NO_SELECTED_DOW

setSelectedDow

public void setSelectedDow(int month,
                           int dow)
Description copied from interface: WeekModel
Specifies the day of week that is selected by this model.

Specified by:
setSelectedDow in interface WeekModel
Parameters:
dow - day of week that is selected (Calendar.SUNDAY, Calendar.MONDAY, etc) or WeekModel.NO_SELECTED_DOW if no date should be selected
month - month to which the dow belongs
See Also:
WeekModel.NO_SELECTED_DOW, WeekModel.NO_SELECTED_MONTH

getDowFirst

public int getDowFirst()
Description copied from interface: WeekModel
Returns the first day of week.

Specified by:
getDowFirst in interface WeekModel
Returns:
the first day of week.
See Also:
WeekModel.setDowFirst(int)

setDowFirst

public void setDowFirst(int day)
Description copied from interface: WeekModel
Specifies the first day of week.

Specified by:
setDowFirst in interface WeekModel
Parameters:
day - day of week that is a java.util.Calendar constant like Calendar.MONDAY

getDows

public int[] getDows()
Description copied from interface: WeekModel
Returns the days of week starting with the first day of week.

Specified by:
getDows in interface WeekModel
Returns:
the days of week in order, starting with the first day of week. The values are values like Calendar.MONDAY.
See Also:
WeekModel.getDowFirst()

getSelectedWeek

public int getSelectedWeek()
Description copied from interface: WeekModel
Returns the number of the selected week from current year.

Specified by:
getSelectedWeek in interface WeekModel
Returns:
number of the selected week or WeekModel.NO_SELECTED_WEEK if no week is selected.
See Also:
WeekModel.NO_SELECTED_WEEK, WeekModel.getSelectedYear(), WeekModel.setSelectedWeek(int, int)

getSelectedYear

public int getSelectedYear()
Description copied from interface: WeekModel
Returns the year to which the selected week belongs.

Specified by:
getSelectedYear in interface WeekModel
Returns:
year to which the selected week belongs or WeekModel.NO_SELECTED_YEAR if no year is selected.
See Also:
WeekModel.NO_SELECTED_YEAR, WeekModel.getSelectedWeek(), WeekModel.setSelectedWeek(int, int)

setSelectedWeek

public void setSelectedWeek(int year,
                            int week)
Description copied from interface: WeekModel
Selects a week from a specified year.

Specified by:
setSelectedWeek in interface WeekModel
Parameters:
year - specified year
week - specified week
See Also:
WeekModel.NO_SELECTED_WEEK, WeekModel.NO_SELECTED_YEAR

isDowSelectionAllowed

public boolean isDowSelectionAllowed()
Description copied from interface: WeekModel
Determines whether days of week may be selected.

Specified by:
isDowSelectionAllowed in interface WeekModel
Returns:
true if days of week may be selected and false otherwise
See Also:
WeekModel.setDowSelectionAllowed(boolean)

setDowSelectionAllowed

public void setDowSelectionAllowed(boolean allowed)
Description copied from interface: WeekModel
Specifies whether days of week may be selected. A day of week may be selected from a JMonth component if the respective day is clicked in the header.

Specified by:
setDowSelectionAllowed in interface WeekModel
Parameters:
allowed - if true, one may click on a day of week to select it.

isWeekSelectionAllowed

public boolean isWeekSelectionAllowed()
Description copied from interface: WeekModel
Determines whether weeks of year may be selected.

Specified by:
isWeekSelectionAllowed in interface WeekModel
Returns:
true if weeks of week may be selected and false otherwise
See Also:
WeekModel.setWeekSelectionAllowed(boolean)

setWeekSelectionAllowed

public void setWeekSelectionAllowed(boolean allowed)
Description copied from interface: WeekModel
Specifies whether weeks of year may be selected. A week of year may be selected from a JMonth component if the respective week number is clicked.

Specified by:
setWeekSelectionAllowed in interface WeekModel
Parameters:
allowed - if true, one may click on a week of year to select it.

getWeekNumber

public int getWeekNumber(java.util.Date date,
                         java.util.TimeZone timezone)

Returns the week number for a certain date using the Calendar.WEEK_OF_YEAR field value. The week number calculation considers the locale and first day of week settings.

If ISO week numbering is enabled, then the week number will be computed according to the standard.

Specified by:
getWeekNumber in interface WeekModel
Parameters:
date - date for which the week number is computed
timezone - time zone used with the date to extract the week number
Returns:
week number for the specified date
See Also:
setWeekNumberISOFormatEnabled(boolean)

setWeekNumberISOFormatEnabled

public void setWeekNumberISOFormatEnabled(boolean enabled)

Specifies whether weeks are numbered according to the ISO 8601 standard which defines the numeric representations of date and time.

The standard defines the week 01 of a year as the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January. In other words, the first week of a new year is the week that has the majority of its days in the new year.

Parameters:
enabled - true if week numbers should follow the standard and false otherwise
See Also:
getWeekNumber(Date,TimeZone)

isWeekNumberISOFormatEnabled

public boolean isWeekNumberISOFormatEnabled()
Determines whether ISO week numbering is enabled.

Returns:
true if enabled and false otherwise
See Also:
setWeekNumberISOFormatEnabled(boolean)

addWeekModelListener

public void addWeekModelListener(WeekModelListener listener)
Description copied from interface: WeekModel
Adds an object that listens to changes in this model.

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

removeWeekModelListener

public void removeWeekModelListener(WeekModelListener listener)
Description copied from interface: WeekModel
Removes a specified listener from the list of registered listeners.

Specified by:
removeWeekModelListener in interface WeekModel
Parameters:
listener - the listener to be removed

fireWeekChanged

protected void fireWeekChanged(WeekModelEvent evt)
DefaultWeekModel subclasses must call this method when the selected week changes.


fireDowNamesChanged

protected void fireDowNamesChanged(WeekModelEvent evt)
DefaultWeekModel subclasses must call this method when the names of the days of week change.


fireDowFirstChanged

protected void fireDowFirstChanged(WeekModelEvent evt)
DefaultWeekModel subclasses must call this method when the first day of week changes.


fireDowChanged

protected void fireDowChanged(WeekModelEvent evt)
DefaultWeekModel subclasses must call this method when the selected day of week changes.


fireWeekNumbersChanged

protected void fireWeekNumbersChanged(WeekModelEvent evt)
DefaultWeekModel subclasses must call this method when the week numbers numerotation changes.


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.