com.miginfocom.calendar.spinner
Class DateSpinnerGroup

java.lang.Object
  extended by com.miginfocom.calendar.spinner.DateSpinnerGroup
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.ChangeListener
Direct Known Subclasses:
DateGroupConnectorBean

public class DateSpinnerGroup
extends java.lang.Object
implements javax.swing.event.ChangeListener, java.io.Serializable

A number of date spinners (of type, or subtypes of, AbstractDateSpinner or JSpinner (with a SpinnerDateModel set)) that are interconnected so they all are changed if one is changed. They all always represents the same date, and only one date/time (not a range).

Note! Due to Sun Bug id 5067114 JSpinners with JFormattedFields that doesn't contain a year part can't be grouped since they always revert to the year 1970 and that will cause the whole group to revert to 1970. This pretty much rules out using JSpinners until this bug is fixed.

See Also:
Serialized Form

Constructor Summary
DateSpinnerGroup()
          JaveBean constructor.
DateSpinnerGroup(javax.swing.JComponent[] spinners)
          Constructor for default time zone and Locale
DateSpinnerGroup(javax.swing.JComponent[] spinners, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor
 
Method Summary
 void addDateChangeListener(DateChangeListener listener)
          Adds the listener, if it isn't already in the list.
 void addDateChangeListener(DateChangeListener listener, boolean asWeakRef)
          Adds the listener, if it isn't already in the list.
 void addSpinner(javax.swing.JComponent spinner)
          Adds the spinner to the spinners that will be synchronized to have the same date.
protected  boolean fireDateChange(java.util.Date oldDate, java.util.Date newDate)
          Fires a date change event to the listeners
 int getBoundaryAlignment()
          Property: When the boundary is expanded and set from the date from the spinner this alignment is check to know if the extra dates should be before or after the date.
 int getBoundaryCount()
          Property: The number of "boudary" that should be the size.
 int getBoundaryType()
          Property: The type of boundary to expand the date set in the date spinners to.
 DateAreaContainer getConnectedDateArea()
          Property: The date area which should have its visible date range change when a date spinner connected to this groupd changes.
 java.util.Date getDate()
          Property: The date that all spinner should have.
 int getExpandCount()
          Property: After the boundary is set it can be expanded by for instance two weeks or five days.
 int getExpandField()
          Property: After the boundary is set it can be expanded by for instance "two weeks" or "five days".
 java.util.Date getMaxDate()
          The maximum date that can be set on the group or null if no boudary is set.
 java.util.Date getMinDate()
          The minimum date that can be set on the group or null if no boudary is set.
 javax.swing.JComponent[] getSpinners()
          Returns the spinners.
 void removeDateChangeListener(DateChangeListener l)
           
 void removeSpinner(javax.swing.JComponent spinner)
          Removes the spinner from the spinners that will be synchronized to have the same date.
 void setBoundaryAlignment(int align)
          Property: When the boundary is expanded and set from the date from the spinner this alignment is check to know if the extra dates should be before or after the date.
 void setBoundaryCount(int count)
          Property: The number of "boudary" that should be the size.
 void setBoundaryType(int rangeType)
          Property: The type of boundary to expand the date set in the date spinners to.
 void setConnectedDateArea(DateAreaContainer container)
          Property: The date area which should have its visible date range change when a date spinner connected to this groupd changes.
 void setDate(java.util.Date date)
          Property: The date that all spinner should have.
 void setExpandCount(int count)
          Property: After the boundary is set it can be expanded by for instance two weeks or five days.
 void setExpandField(int field)
          Property: After the boundary is set it can be expanded by for instance "two weeks" or "five days".
 void setMaxDate(java.util.Date date)
          The maximum date that can be set on the group or null if no boudary is set.
 void setMinDate(java.util.Date date)
          The minimum date that can be set on the group or null if no boudary is set.
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateSpinnerGroup

public DateSpinnerGroup()
JaveBean constructor.


DateSpinnerGroup

public DateSpinnerGroup(javax.swing.JComponent[] spinners)
Constructor for default time zone and Locale

Parameters:
spinners - The spinners to keep in sync with each other. Not null and elements not null. Can only be of type (or subtypes of) AbstractDateSpinner or JSpinner (With a SpinnerDateModel set)

Note! Due to Sun Bug id 5067114 JSpinners with JFormattedFields that doesn't contain a year part can't be grouped since the always revert to the year 1970 and that will cause the whole ground to revert to 1970. This prettu much rules out using JSpinners until this bug is fixed.


DateSpinnerGroup

public DateSpinnerGroup(javax.swing.JComponent[] spinners,
                        java.util.TimeZone timeZone,
                        java.util.Locale locale)
Constructor

Parameters:
spinners - The spinners to keep in sync with each other. Not null and elements not null. Can only be of type (or subtypes of) AbstractDateSpinner or JSpinner (With a SpinnerDateModel set)

Note! Due to Sun Bug id 5067114 JSpinners with JFormattedFields that doesn't contain a year part can't be grouped since the always revert to the year 1970 and that will cause the whole ground to revert to 1970. This prettu much rules out using JSpinners until this bug is fixed.

timeZone - The time zone that if != null will be used in the fired DateChangeEvents.
locale - The locale that if != null will be used in the fired DateChangeEvents.
Method Detail

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

addSpinner

public void addSpinner(javax.swing.JComponent spinner)
Adds the spinner to the spinners that will be synchronized to have the same date.

Parameters:
spinner - The spinner. Not null.

getConnectedDateArea

public DateAreaContainer getConnectedDateArea()
Property: The date area which should have its visible date range change when a date spinner connected to this groupd changes.

Returns:
The connected date area or null if unconnected.

setConnectedDateArea

public void setConnectedDateArea(DateAreaContainer container)
Property: The date area which should have its visible date range change when a date spinner connected to this groupd changes.

Parameters:
container - The connected date area or null if unconnected.

getBoundaryAlignment

public int getBoundaryAlignment()
Property: When the boundary is expanded and set from the date from the spinner this alignment is check to know if the extra dates should be before or after the date.

Returns:
The current alignment. Defaults to: MutableDateRange.ALIGN_START
See Also:
DateRange.setSize(int, int, int)

setBoundaryAlignment

public void setBoundaryAlignment(int align)
Property: When the boundary is expanded and set from the date from the spinner this alignment is check to know if the extra dates should be before or after the date.

Parameters:
align - The new alignment. Default is: MutableDateRange.ALIGN_START
See Also:
DateRange.setSize(int, int, int)

getBoundaryCount

public int getBoundaryCount()
Property: The number of "boudary" that should be the size. E.g. "4" years.

Returns:
The current count. Defaults to 1.

setBoundaryCount

public void setBoundaryCount(int count)
Property: The number of "boudary" that should be the size. E.g. "4" years.

Parameters:
count - The new count. Defaults is 1.

getBoundaryType

public int getBoundaryType()
Property: The type of boundary to expand the date set in the date spinners to. E.g. a year or week.

Returns:
The current boundary type. Defaults to DateRangeI.RANGE_TYPE_WEEK

setBoundaryType

public void setBoundaryType(int rangeType)
Property: The type of boundary to expand the date set in the date spinners to. E.g. a year or week.

Parameters:
rangeType - The new boundary type. Default is DateRangeI.RANGE_TYPE_WEEK

getExpandField

public int getExpandField()
Property: After the boundary is set it can be expanded by for instance "two weeks" or "five days". This is the type of what to expand.

Returns:
The current count. Defaults to Calendar.WEEK_OF_YEAR

setExpandField

public void setExpandField(int field)
Property: After the boundary is set it can be expanded by for instance "two weeks" or "five days". This is the type of what to expand.

Parameters:
field - The new type. Default is Calendar.WEEK_OF_YEAR

getExpandCount

public int getExpandCount()
Property: After the boundary is set it can be expanded by for instance two weeks or five days. This is the number of what to expand.

Returns:
The current count. Defaults to 0.

setExpandCount

public void setExpandCount(int count)
Property: After the boundary is set it can be expanded by for instance two weeks or five days. This is the number of what to expand.

Parameters:
count - The new count. Default is 0.

removeSpinner

public void removeSpinner(javax.swing.JComponent spinner)
Removes the spinner from the spinners that will be synchronized to have the same date. Currently AbstractDateSpinner sub classes and JSpinner classes are handled.

Parameters:
spinner - The spinner to remove.

getDate

public java.util.Date getDate()
Property: The date that all spinner should have.

Returns:
The date that all spinner should have. Only null if no spinner or date has ever been set.

setDate

public void setDate(java.util.Date date)
Property: The date that all spinner should have.

Parameters:
date - The new date that all spinner should get. Never null.

getMinDate

public java.util.Date getMinDate()
The minimum date that can be set on the group or null if no boudary is set. Dates outside the boundary will be set to the boundary.

Returns:
The current value. Might be null.

setMinDate

public void setMinDate(java.util.Date date)
The minimum date that can be set on the group or null if no boudary is set. Dates outside the boundary will be set to the boundary.

Parameters:
date - The new value. Might be null.

getMaxDate

public java.util.Date getMaxDate()
The maximum date that can be set on the group or null if no boudary is set. Dates outside the boundary will be set to the boundary.

Returns:
The current value. Might be null.

setMaxDate

public void setMaxDate(java.util.Date date)
The maximum date that can be set on the group or null if no boudary is set. Dates outside the boundary will be set to the boundary.

Parameters:
date - The new value. Might be null.

getSpinners

public javax.swing.JComponent[] getSpinners()
Returns the spinners.

Returns:
The spinners.

addDateChangeListener

public void addDateChangeListener(DateChangeListener listener)
Adds the listener, if it isn't already in the list. Will be notified when the date chagned. Old and new value will be correct, but as a range that doesnät span time. Use start date of the range though.

Parameters:
listener - The listener. Not null.

addDateChangeListener

public void addDateChangeListener(DateChangeListener listener,
                                  boolean asWeakRef)
Adds the listener, if it isn't already in the list. Will be notified when the date chagned. Old and new value will be correct, but as a range that doesnät span time. Use start date of the range though.

Parameters:
listener - The listener. Not null.
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removeDateChangeListener

public void removeDateChangeListener(DateChangeListener l)

fireDateChange

protected boolean fireDateChange(java.util.Date oldDate,
                                 java.util.Date newDate)
Fires a date change event to the listeners

Parameters:
oldDate - The old range or null if not applicable.
newDate - The new range or null if there was no new range.
Returns:
If there was any listeners registered and the ignore events wasnät turned on.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.