Class SimpleTimebase
- All Implemented Interfaces:
Comparable<NamedBean>,PropertyChangeProvider,NamedBean,Timebase
This implementation provides for the internal clock and for one hardware clock. A number of hooks and comments are provided below for implementing multiple hardware clocks should that ever be done.
The setTimeValue member is the fast time when the clock started. The startAtTime member is the wall-clock time when the clock was started. Together, those can be used to calculate the current fast time.
The pauseTime member is used to indicate that the Timebase was paused. If non-null, it indicates the current fast time when the clock was paused.
-
Nested Class Summary
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameExceptionNested classes/interfaces inherited from interface jmri.Timebase
Timebase.ClockInitialRunState -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleprotected final SystemConnectionMemostatic final doubleFields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, registerFields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWNFields inherited from interface jmri.Timebase
ANALOG_CLOCK, LCD_CLOCK, NIXIE_CLOCK, NONE, PRAGOTRON_CLOCK, PROPERTY_CHANGE_MINUTES, PROPERTY_CHANGE_RATE, PROPERTY_CHANGE_RUN, PROPERTY_CHANGE_TIME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRequest a callback when the minutes place of the time changes.voidAdd aPropertyChangeListenerto the listener list.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Add aPropertyChangeListenerfor a specific property.voiddispose()Stops Timer.For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.Get the Clock Initial Run State ENUM.booleanGet if should correct Hardware clocks.booleanGet internalMaster field.booleanGet the Master Clock Name.Get the list of minute change listeners.doublegetRate()Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source.booleangetRun()Get if Timebase is running.booleanGet if to Set Rate at Start option checked.booleanGet if to show a Stop / Resume button next to the clock.intGet the Start Clock Type.doubleGet the startup clock speed rate.booleanGet if to use a set start time.Get the Clock Start Time.intgetState()Implementation returns 0 .booleanGet if clock should synchronise with Time base.getTime()Get the current time.(package private) voidHandle an "alarm", which is used to count off minutes.(package private) final voidinit()voidThe following method should only be invoked at start up.voidInitialize hardware clock at start up after all options are set up.voidRemove a request for callback when the minutes place of the time changes.voidset12HourDisplay(boolean display, boolean update) Set 12 or 24 hour display option.voidSet the Clock Initial Run State ENUM.voidsetCorrectHardware(boolean correct, boolean update) If update true, calls initializeHardwareClock.voidsetInternalMaster(boolean master, boolean update) Set internalMaster and update fields.voidsetMasterName(String name) Set the Master Clock Name.voidsetRate(double factor) Set fast clock rate.voidsetRun(boolean run) Set if Timebase is running.voidsetSetRateAtStart(boolean set) Set Set Rate at Start option.voidsetShowStopButton(boolean displayed) Set if to show a Stop / Resume button next to the clock.voidsetStartClockOption(int option) Set the Start Clock type Option.voidsetStartRate(double factor) Set the start clock speed rate.voidsetStartSetTime(boolean set, Date time) Set time at start up option, and start up time.voidsetState(int s) Implementation does nothing.voidsetSynchronize(boolean synchronize, boolean update) Set if clock should synchronise.voidSet the current time.voidSet the current time.(package private) voidStart the minute alarm ticking, if it isnt already.(package private) voidupdateMemory(double factor) (package private) voidupdateMemory(Date date) booleanGet 12 or 24 hour display option.doubleGet the true fast clock rate even if the master timebase rate has been modified by a hardware clock.voiduserSetRate(double factor) Set fast clock rate and force a synchronization with the DCC hardware.voiduserSetTime(Date d) Set the current time and force a synchronization with the DCC system.Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChangeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChangeMethods inherited from interface jmri.beans.PropertyChangeProvider
getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
MINIMUM_RATE
- See Also:
-
MAXIMUM_RATE
- See Also:
-
memo
-
-
Constructor Details
-
SimpleTimebase
-
-
Method Details
-
init
-
getBeanType
For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.- Specified by:
getBeanTypein interfaceNamedBean- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
getTime
Get the current time. -
setTime
Set the current time. -
setTime
Set the current time. -
userSetTime
Set the current time and force a synchronization with the DCC system.- Specified by:
userSetTimein interfaceTimebase- Parameters:
d- the new time
-
setRun
Set if Timebase is running. -
getRun
Get if Timebase is running. -
setRate
Set fast clock rate.- Specified by:
setRatein interfaceTimebase- Parameters:
factor- the fast clock rate- Throws:
TimebaseRateException- if the implementation can not use the requested rate
-
userSetRate
Set fast clock rate and force a synchronization with the DCC hardware.- Specified by:
userSetRatein interfaceTimebase- Parameters:
factor- the fast clock rate- Throws:
TimebaseRateException- if the implementation can not use the requested rate
-
getRate
Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source. UseTimebase.userGetRate()if you want the real clock rate instead. -
userGetRate
Get the true fast clock rate even if the master timebase rate has been modified by a hardware clock. External changes in fast clock rate occur because of the peculiar way some hardware clocks attempt to synchronize with the JMRI fast clock.- Specified by:
userGetRatein interfaceTimebase- Returns:
- the rate, e.g. 1.0 runs at the same rate as real clocks, 2.0 at twice the speed.
-
setInternalMaster
Set internalMaster and update fields.- Specified by:
setInternalMasterin interfaceTimebase- Parameters:
master- true if fast clock time is derived from internal computer clock, false if derived from hardware clock.update- true to send update, else false.
-
getInternalMaster
Get internalMaster field.- Specified by:
getInternalMasterin interfaceTimebase- Returns:
- true if fast clock time is derived from internal computer clock, false if derived from hardware clock
-
setMasterName
Set the Master Clock Name.- Specified by:
setMasterNamein interfaceTimebase- Parameters:
name- master clock name.
-
getMasterName
Get the Master Clock Name.- Specified by:
getMasterNamein interfaceTimebase- Returns:
- master clock name.
-
setSynchronize
Set if clock should synchronise.- Specified by:
setSynchronizein interfaceTimebase- Parameters:
synchronize- set true to synchronise hardware clocks with Time base.update- set true to update clock when function called.
-
getSynchronize
Get if clock should synchronise with Time base.- Specified by:
getSynchronizein interfaceTimebase- Returns:
- true if should synchronise hardware clocks.
-
setCorrectHardware
If update true, calls initializeHardwareClock. Set if should correct or update hardware.- Specified by:
setCorrectHardwarein interfaceTimebase- Parameters:
correct- set true to correct hardware clocks.update- set true to update clock when function called.
-
getCorrectHardware
Get if should correct Hardware clocks.- Specified by:
getCorrectHardwarein interfaceTimebase- Returns:
- true to correct, else false.
-
set12HourDisplay
Set 12 or 24 hour display option.- Specified by:
set12HourDisplayin interfaceTimebase- Parameters:
display- true for a 12-hour display; false for a 24-hour displayupdate- true to update clock when function called.
-
use12HourDisplay
Get 12 or 24 hour display option.- Specified by:
use12HourDisplayin interfaceTimebase- Returns:
- true for a 12-hour display; false for a 24-hour display
-
setClockInitialRunState
Set the Clock Initial Run State ENUM.- Specified by:
setClockInitialRunStatein interfaceTimebase- Parameters:
state- Initial state.
-
getClockInitialRunState
Get the Clock Initial Run State ENUM.- Specified by:
getClockInitialRunStatein interfaceTimebase- Returns:
- Initial state.
-
setShowStopButton
Set if to show a Stop / Resume button next to the clock.- Specified by:
setShowStopButtonin interfaceTimebase- Parameters:
displayed- true if to display, else false.
-
getShowStopButton
Get if to show a Stop / Resume button next to the clock.- Specified by:
getShowStopButtonin interfaceTimebase- Returns:
- true if to display, else false.
-
setStartSetTime
Set time at start up option, and start up time.- Specified by:
setStartSetTimein interfaceTimebase- Parameters:
set- true for set time at startup, else false.time- startup time.
-
getStartSetTime
Get if to use a set start time.- Specified by:
getStartSetTimein interfaceTimebase- Returns:
- true if using set start time.
-
setStartRate
Set the start clock speed rate.- Specified by:
setStartRatein interfaceTimebase- Parameters:
factor- start clock speed factor.
-
getStartRate
Get the startup clock speed rate.- Specified by:
getStartRatein interfaceTimebase- Returns:
- startup clock speed rate factor.
-
setSetRateAtStart
Set Set Rate at Start option.- Specified by:
setSetRateAtStartin interfaceTimebase- Parameters:
set- If true, the rate at startup will be set to the value of getStartRate().
-
getSetRateAtStart
Get if to Set Rate at Start option checked.- Specified by:
getSetRateAtStartin interfaceTimebase- Returns:
- If true, the rate at startup should be set to the value of getStartRate()
-
getStartTime
Get the Clock Start Time.- Specified by:
getStartTimein interfaceTimebase- Returns:
- Clock Start Time.
-
setStartClockOption
Set the Start Clock type Option.- Specified by:
setStartClockOptionin interfaceTimebase- Parameters:
option- Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
-
getStartClockOption
Get the Start Clock Type.- Specified by:
getStartClockOptionin interfaceTimebase- Returns:
- Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
-
initializeClock
The following method should only be invoked at start up. Initialise the clock. Should only be invoked at start up.- Specified by:
initializeClockin interfaceTimebase
-
initializeHardwareClock
Initialize hardware clock at start up after all options are set up.Note: This method is always called at start up. It should be ignored if there is no communication with a hardware clock
- Specified by:
initializeHardwareClockin interfaceTimebase
-
getIsInitialized
- Specified by:
getIsInitializedin interfaceTimebase- Returns:
- true if call to initialize Hardware Clock has occurred
-
dispose
Stops Timer. Deactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
-
startAlarm
void startAlarm()Start the minute alarm ticking, if it isnt already. -
handleAlarm
Handle an "alarm", which is used to count off minutes.Listeners will be notified if the hours or minutes changed since the last time.
- Parameters:
e- Event which triggered this
-
updateMemory
-
updateMemory
-
addMinuteChangeListener
Request a callback when the minutes place of the time changes. This is the same as callingPropertyChangeProvider.addPropertyChangeListener(String, PropertyChangeListener)with the propertyNameminutes.- Specified by:
addMinuteChangeListenerin interfaceTimebase- Parameters:
l- the listener to receive the callback
-
removeMinuteChangeListener
Remove a request for callback when the minutes place of the time changes. This is the same as callingPropertyChangeProvider.removePropertyChangeListener(String, PropertyChangeListener)with the propertyNameminutes.- Specified by:
removeMinuteChangeListenerin interfaceTimebase- Parameters:
l- the listener to receive the callback
-
getMinuteChangeListeners
Get the list of minute change listeners. This is the same as callingPropertyChangeProvider.getPropertyChangeListeners(String)with the propertyNameminutes.- Specified by:
getMinuteChangeListenersin interfaceTimebase- Returns:
- the list of listeners
-
addPropertyChangeListener
Description copied from class:AbstractNamedBeanAdd aPropertyChangeListenerto the listener list.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
addPropertyChangeListenerin classAbstractNamedBean- Parameters:
listener- The PropertyChangeListener to be added
-
addPropertyChangeListener
Description copied from class:AbstractNamedBeanAdd aPropertyChangeListenerfor a specific property.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
addPropertyChangeListenerin classAbstractNamedBean- Parameters:
propertyName- The name of the property to listen on.listener- The PropertyChangeListener to be added
-
setState
Implementation does nothing. Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.
- Specified by:
setStatein interfaceNamedBean- Parameters:
s- the state- Throws:
JmriException- general error when setting the state fails
-
getState
Implementation returns 0 . Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.
-