com.sas.util
Class DateTimeMonitor

com.sas.util.DateTimeMonitor
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.lang.ObjectDataInterface, com.sas.lang.StringDataInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, com.sas.PublicClonable, AlarmListener, com.sas.util.TimeIntervals, com.sas.ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
CurrentDate, CurrentTime

public class DateTimeMonitor
implements AlarmListener, com.sas.util.TimeIntervals

DateTimeMonitor is a text model that updates itself with the current date and time at regular intervals. The default interval is one second.

The time zone with which the date format is recreated on deserialization will be the current local default time zone, not the time zone in use when the DateTimeMonitor was serialized. This makes sense in most applications. Subclasses can change this explicitly calling dateTimeFormat.setTimeZone(tz) in their private readObject() method.

Properties

Name interval
Type long
Default value TimeIntervals.ONE_SECOND
Short description update interval
Description interval between updates, in milliseconds
Name dateTime
Type java.util.Calendar
Default value a calendar representing the current time
Short description the current time
Description the current time, as of the last update
Name format
Type java.text.DateFormat
Default value java.text.DateFormat.getDateTimeInstance()
Short description format
Description date time formatter

See Also:
Serialized Form

Field Summary
protected  Alarm alarm
          Internal Alarm, used to update the Date and text at regular intervals.
protected  java.util.Date date
          The current date, updated at regular intervals.
protected  java.text.DateFormat dateTimeFormat
          The DateFormat used to format the current date at regular intervals.
static java.util.TimeZone defaultTimeZone
          The default time zone.
static java.lang.String RB_KEY
           
 
Fields inherited from interface com.sas.util.TimeIntervals
ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK
 
Constructor Summary
DateTimeMonitor()
          Default constructor.
DateTimeMonitor(java.text.DateFormat dateTimeFormat)
          Custom constructor for non-Locale default date format.
DateTimeMonitor(java.text.DateFormat dateTimeFormat, java.util.Calendar calendar)
          Deprecated. the calendar parameter is no longer used. Use DateTimeMonitor(DateFormat) or DateTimeMonitor(dateTimeFormat, long delay, long interval)
DateTimeMonitor(java.text.DateFormat dateTimeFormat, java.util.Calendar calendar, long delay, long interval)
          Deprecated. the calendar parameter is no longer used. Use DateTimeMonitor(dateTimeFormat, long delay, long interval)
DateTimeMonitor(java.text.DateFormat dateTimeFormat, long delay, long interval)
          Custom constructor for non-Locale default date format.
DateTimeMonitor(int format)
          Custom constructor for a default date format and default calendar.
DateTimeMonitor(java.lang.String format)
          Custom constructor for default date format
 
Method Summary
 void fireAlarm(AlarmEvent event)
          Handle an AlarmEvent from the internal alarm.
 java.util.Date getDateTime()
          Return the date/time as it was last monitored.
protected  long getDelay()
          Return the time delay before the monitor updates.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 java.text.DateFormat getFormat()
          Return the format property
 long getInterval()
          Return the interval at which the monitor updates the date/time and text properties.
 boolean isAlarmRunning()
          Returns a boolean indicating whether the alarm is running
protected  Alarm newAlarm(long delay, long interval)
           
 void setFormat(java.text.DateFormat format)
          Replace the date/time format.
 void setInterval(long interval)
          Set the update interval.
 void start()
          Restart the date/time monitor.
 void stop()
          Stop the date/time monitor.
 void update()
          Update the date time monitor after the time interval has expired.
 void validateObject()
          Validate/initialize the object after deserialization.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

dateTimeFormat

protected transient java.text.DateFormat dateTimeFormat
The DateFormat used to format the current date at regular intervals.


date

protected transient java.util.Date date
The current date, updated at regular intervals.


alarm

protected Alarm alarm
Internal Alarm, used to update the Date and text at regular intervals.


defaultTimeZone

public static java.util.TimeZone defaultTimeZone
The default time zone.

Constructor Detail

DateTimeMonitor

public DateTimeMonitor()
Default constructor. Create a DateMonitor object which updates its text attribute when the date changes, using the default Locale specific date format.


DateTimeMonitor

public DateTimeMonitor(java.text.DateFormat dateTimeFormat,
                       java.util.Calendar calendar)
Deprecated. the calendar parameter is no longer used. Use DateTimeMonitor(DateFormat) or DateTimeMonitor(dateTimeFormat, long delay, long interval)

Custom constructor for non-Locale default date format and calendar.

Parameters:
dateTimeFormat - a date format with which the date is rendered. Note that you probably want to set the timezone on this formatter with format.setTimeZone(DateTimeMonitor.defaultTimeZone); before using the dateTimeFormat.
calendar - a calendar with which time values are obtained

DateTimeMonitor

public DateTimeMonitor(java.text.DateFormat dateTimeFormat)
Custom constructor for non-Locale default date format.

Parameters:
dateTimeFormat - a date format with which the date is rendered. Note that you probably want to set the timezone on this formatter with format.setTimeZone(DateTimeMonitor.defaultTimeZone); before using the dateTimeFormat.

DateTimeMonitor

public DateTimeMonitor(int format)
Custom constructor for a default date format and default calendar.

Parameters:
format - one of DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, or DateFormat.FULL The current time zone is applied to the format.

DateTimeMonitor

public DateTimeMonitor(java.text.DateFormat dateTimeFormat,
                       java.util.Calendar calendar,
                       long delay,
                       long interval)
Deprecated. the calendar parameter is no longer used. Use DateTimeMonitor(dateTimeFormat, long delay, long interval)

Custom constructor for non-Locale default date format and calendar.

Parameters:
dateTimeFormat - a date format with which the date is rendered. Note that you probably want to set the timezone on this formatter with format.setTimeZone(DateTimeMonitor.defaultTimeZone); before using the dateTimeFormat.
calendar - a calendar with which time values are obtained
delay - how much time to delay before starting updates. if delay == -1, use getDelay()
interval - how much time to pause between updates. if interval == -1, use getInterval()

DateTimeMonitor

public DateTimeMonitor(java.text.DateFormat dateTimeFormat,
                       long delay,
                       long interval)
Custom constructor for non-Locale default date format.

Parameters:
dateTimeFormat - a date format with which the date is rendered. Note that you probably want to set the timezone on this formatter with format.setTimeZone(DateTimeMonitor.defaultTimeZone); before using the dateTimeFormat.
delay - how much time to delay before starting updates. if delay == -1, use getDelay()
interval - how much time to pause between updates. if interval == -1, use getInterval()

DateTimeMonitor

public DateTimeMonitor(java.lang.String format)
Custom constructor for default date format

Parameters:
format - A format string used to construct a SimpleDateFormat object which is used to format the date and time. The default time zone is used.
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

newAlarm

protected Alarm newAlarm(long delay,
                         long interval)

getFormat

public java.text.DateFormat getFormat()
Return the format property

Returns:
the current date/time formatter

setFormat

public void setFormat(java.text.DateFormat format)
Replace the date/time format.

Parameters:
dateTimeFormat - a date/time format with which the monitored date/time value is formatted into the text property. Note that you probably want to set the timezone on this formatter with format.setTimeZone(DateTimeMonitor.defaultTimeZone); before using the dateTimeFormat.

getDelay

protected long getDelay()
Return the time delay before the monitor updates. The default is DateTimeMonitor.ONE_SECOND

Returns:
the time delay before the monitor updates.

getInterval

public long getInterval()
Return the interval at which the monitor updates the date/time and text properties.

Returns:
the update interval.

setInterval

public void setInterval(long interval)
Set the update interval.

Parameters:
interval - the amount of time between updates, such as DateTimeMonitor.ONE_SECOND

getDateTime

public java.util.Date getDateTime()
Return the date/time as it was last monitored.

Returns:
the last monitored date time value.

fireAlarm

public void fireAlarm(AlarmEvent event)
Handle an AlarmEvent from the internal alarm.

Specified by:
fireAlarm in interface AlarmListener
Parameters:
event - the alarm event.

update

public void update()
Update the date time monitor after the time interval has expired. The intrnal date has already been updated. This updates the text.


stop

public void stop()
Stop the date/time monitor. It will no longer send PropertyChangeEvents, until started again.


start

public void start()
Restart the date/time monitor. It will again send PropertyChangeEvents, until stopped.


isAlarmRunning

public boolean isAlarmRunning()
Returns a boolean indicating whether the alarm is running


validateObject

public void validateObject()
Validate/initialize the object after deserialization.

Specified by:
validateObject in interface java.io.ObjectInputValidation
Overrides:
validateObject in class com.sas.Component
See Also:
ComponentInterfaceSupport.validateObject(com.sas.ComponentInterface)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.