Class SimpleTimebase
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.jmrit.simpleclock.SimpleTimebase
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>,PropertyChangeProvider,NamedBean,Timebase
public class SimpleTimebase extends AbstractNamedBean implements Timebase
Provide basic Timebase implementation from system clock.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.DuplicateSystemNameException
-
Nested classes/interfaces inherited from interface jmri.Timebase
Timebase.ClockInitialRunState
-
-
Field Summary
Fields Modifier and Type Field Description static doubleMAXIMUM_RATEprotected SystemConnectionMemomemostatic doubleMINIMUM_RATE-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWN
-
Fields 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 Constructor Description SimpleTimebase(InternalSystemConnectionMemo memo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMinuteChangeListener(java.beans.PropertyChangeListener l)Request a callback when the minutes place of the time changes.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add aPropertyChangeListenerto the listener list.voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Add aPropertyChangeListenerfor a specific property.voiddispose()Stops Timer.java.lang.StringgetBeanType()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.Timebase.ClockInitialRunStategetClockInitialRunState()Get the Clock Initial Run State ENUM.booleangetCorrectHardware()Get if should correct Hardware clocks.booleangetInternalMaster()Get internalMaster field.booleangetIsInitialized()java.lang.StringgetMasterName()Get the Master Clock Name.java.beans.PropertyChangeListener[]getMinuteChangeListeners()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.booleangetSetRateAtStart()Get if to Set Rate at Start option checked.booleangetShowStopButton()Get if to show a Stop / Resume button next to the clock.intgetStartClockOption()Get the Start Clock Type.doublegetStartRate()Get the startup clock speed rate.booleangetStartSetTime()Get if to use a set start time.java.util.DategetStartTime()Get the Clock Start Time.intgetState()Implementation returns 0 .booleangetSynchronize()Get if clock should synchronise with Time base.java.util.DategetTime()Get the current time.(package private) voidhandleAlarm(java.awt.event.ActionEvent e)Handle an "alarm", which is used to count off minutes.(package private) voidinit()voidinitializeClock()The following method should only be invoked at start up.voidinitializeHardwareClock()Initialize hardware clock at start up after all options are set up.voidremoveMinuteChangeListener(java.beans.PropertyChangeListener l)Remove a request for callback when the minutes place of the time changes.voidset12HourDisplay(boolean display, boolean update)Set 12 or 24 hour display option.voidsetClockInitialRunState(Timebase.ClockInitialRunState state)Set 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(java.lang.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, java.util.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.voidsetTime(java.time.Instant i)Set the current time.voidsetTime(java.util.Date d)Set the current time.(package private) voidstartAlarm()Start the minute alarm ticking, if it isnt already.(package private) voidupdateMemory(double factor)(package private) voidupdateMemory(java.util.Date date)booleanuse12HourDisplay()Get 12 or 24 hour display option.doubleuserGetRate()Get 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(java.util.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, vetoableChange
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods 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, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
MINIMUM_RATE
public static final double MINIMUM_RATE
- See Also:
- Constant Field Values
-
MAXIMUM_RATE
public static final double MAXIMUM_RATE
- See Also:
- Constant Field Values
-
memo
protected final SystemConnectionMemo memo
-
-
Constructor Detail
-
SimpleTimebase
public SimpleTimebase(InternalSystemConnectionMemo memo)
-
-
Method Detail
-
init
final void init()
-
getBeanType
public java.lang.String 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
public java.util.Date getTime()
Get the current time.
-
setTime
public void setTime(java.util.Date d)
Set the current time.
-
setTime
public void setTime(java.time.Instant i)
Set the current time.
-
userSetTime
public void userSetTime(java.util.Date d)
Set the current time and force a synchronization with the DCC system.- Specified by:
userSetTimein interfaceTimebase- Parameters:
d- the new time
-
setRun
public void setRun(boolean run)
Set if Timebase is running.
-
getRun
public boolean getRun()
Get if Timebase is running.
-
setRate
public void setRate(double factor) throws TimebaseRateException
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
public void userSetRate(double factor) throws TimebaseRateException
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
public double 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
public double 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
public void setInternalMaster(boolean master, boolean update)
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
public boolean 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
public void setMasterName(java.lang.String name)
Set the Master Clock Name.- Specified by:
setMasterNamein interfaceTimebase- Parameters:
name- master clock name.
-
getMasterName
public java.lang.String getMasterName()
Get the Master Clock Name.- Specified by:
getMasterNamein interfaceTimebase- Returns:
- master clock name.
-
setSynchronize
public void setSynchronize(boolean synchronize, boolean update)
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
public boolean getSynchronize()
Get if clock should synchronise with Time base.- Specified by:
getSynchronizein interfaceTimebase- Returns:
- true if should synchronise hardware clocks.
-
setCorrectHardware
public void setCorrectHardware(boolean correct, boolean update)
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
public boolean getCorrectHardware()
Get if should correct Hardware clocks.- Specified by:
getCorrectHardwarein interfaceTimebase- Returns:
- true to correct, else false.
-
set12HourDisplay
public void set12HourDisplay(boolean display, boolean update)
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
public boolean 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
public void setClockInitialRunState(Timebase.ClockInitialRunState state)
Set the Clock Initial Run State ENUM.- Specified by:
setClockInitialRunStatein interfaceTimebase- Parameters:
state- Initial state.
-
getClockInitialRunState
public Timebase.ClockInitialRunState getClockInitialRunState()
Get the Clock Initial Run State ENUM.- Specified by:
getClockInitialRunStatein interfaceTimebase- Returns:
- Initial state.
-
setShowStopButton
public void setShowStopButton(boolean displayed)
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
public boolean 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
public void setStartSetTime(boolean set, java.util.Date time)
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
public boolean getStartSetTime()
Get if to use a set start time.- Specified by:
getStartSetTimein interfaceTimebase- Returns:
- true if using set start time.
-
setStartRate
public void setStartRate(double factor)
Set the start clock speed rate.- Specified by:
setStartRatein interfaceTimebase- Parameters:
factor- start clock speed factor.
-
getStartRate
public double getStartRate()
Get the startup clock speed rate.- Specified by:
getStartRatein interfaceTimebase- Returns:
- startup clock speed rate factor.
-
setSetRateAtStart
public void setSetRateAtStart(boolean set)
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
public boolean 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
public java.util.Date getStartTime()
Get the Clock Start Time.- Specified by:
getStartTimein interfaceTimebase- Returns:
- Clock Start Time.
-
setStartClockOption
public void setStartClockOption(int option)
Set the Start Clock type Option.- Specified by:
setStartClockOptionin interfaceTimebase- Parameters:
option- Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
-
getStartClockOption
public int getStartClockOption()
Get the Start Clock Type.- Specified by:
getStartClockOptionin interfaceTimebase- Returns:
- Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
-
initializeClock
public void 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
public void 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
public boolean getIsInitialized()
- Specified by:
getIsInitializedin interfaceTimebase- Returns:
- true if call to initialize Hardware Clock has occurred
-
dispose
public void 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
void handleAlarm(java.awt.event.ActionEvent e)
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
void updateMemory(java.util.Date date)
-
updateMemory
void updateMemory(double factor)
-
addMinuteChangeListener
public void addMinuteChangeListener(java.beans.PropertyChangeListener l)
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
public void removeMinuteChangeListener(java.beans.PropertyChangeListener l)
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
public java.beans.PropertyChangeListener[] 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
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from class:AbstractNamedBeanAdd aPropertyChangeListenerto the listener list.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
addPropertyChangeListenerin classAbstractNamedBean- Parameters:
listener- The PropertyChangeListener to be added
-
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
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
public void setState(int s) throws JmriException
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
public int 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.
-
-