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 double
MAXIMUM_RATE
protected SystemConnectionMemo
memo
static double
MINIMUM_RATE
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
Fields inherited from interface jmri.Timebase
ANALOG_CLOCK, LCD_CLOCK, NIXIE_CLOCK, NONE, PRAGOTRON_CLOCK
-
-
Constructor Summary
Constructors Constructor Description SimpleTimebase(InternalSystemConnectionMemo memo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMinuteChangeListener(java.beans.PropertyChangeListener l)
Request a callback when the minutes place of the time changes.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add aPropertyChangeListener
to the listener list.void
addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Add aPropertyChangeListener
for a specific property.void
dispose()
Stops Timer.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.Timebase.ClockInitialRunState
getClockInitialRunState()
Get the Clock Initial Run State ENUM.boolean
getCorrectHardware()
Get if should correct Hardware clocks.boolean
getInternalMaster()
Get internalMaster field.boolean
getIsInitialized()
java.lang.String
getMasterName()
Get the Master Clock Name.java.beans.PropertyChangeListener[]
getMinuteChangeListeners()
Get the list of minute change listeners.double
getRate()
Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source.boolean
getRun()
Get if Timebase is running.boolean
getSetRateAtStart()
Get if to Set Rate at Start option checked.boolean
getShowStopButton()
Get if to show a Stop / Resume button next to the clock.int
getStartClockOption()
Get the Start Clock Type.double
getStartRate()
Get the startup clock speed rate.boolean
getStartSetTime()
Get if to use a set start time.java.util.Date
getStartTime()
Get the Clock Start Time.int
getState()
Implementation returns 0 .boolean
getSynchronize()
Get if clock should synchronise with Time base.java.util.Date
getTime()
Get the current time.(package private) void
handleAlarm(java.awt.event.ActionEvent e)
Handle an "alarm", which is used to count off minutes.(package private) void
init()
void
initializeClock()
The following method should only be invoked at start up.void
initializeHardwareClock()
Initialize hardware clock at start up after all options are set up.void
removeMinuteChangeListener(java.beans.PropertyChangeListener l)
Remove a request for callback when the minutes place of the time changes.void
set12HourDisplay(boolean display, boolean update)
Set 12 or 24 hour display option.void
setClockInitialRunState(Timebase.ClockInitialRunState state)
Set the Clock Initial Run State ENUM.void
setCorrectHardware(boolean correct, boolean update)
If update true, calls initializeHardwareClock.void
setInternalMaster(boolean master, boolean update)
Set internalMaster and update fields.void
setMasterName(java.lang.String name)
Set the Master Clock Name.void
setRate(double factor)
Set fast clock rate.void
setRun(boolean run)
Set if Timebase is running.void
setSetRateAtStart(boolean set)
Set Set Rate at Start option.void
setShowStopButton(boolean displayed)
Set if to show a Stop / Resume button next to the clock.void
setStartClockOption(int option)
Set the Start Clock type Option.void
setStartRate(double factor)
Set the start clock speed rate.void
setStartSetTime(boolean set, java.util.Date time)
Set time at start up option, and start up time.void
setState(int s)
Implementation does nothing.void
setSynchronize(boolean synchronize, boolean update)
Set if clock should synchronise.void
setTime(java.time.Instant i)
Set the current time.void
setTime(java.util.Date d)
Set the current time.(package private) void
startAlarm()
Start the minute alarm ticking, if it isnt already.(package private) void
updateMemory(double factor)
(package private) void
updateMemory(java.util.Date date)
boolean
use12HourDisplay()
Get 12 or 24 hour display option.double
userGetRate()
Get the true fast clock rate even if the master timebase rate has been modified by a hardware clock.void
userSetRate(double factor)
Set fast clock rate and force a synchronization with the DCC hardware.void
userSetTime(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, 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:
getBeanType
in 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:
userSetTime
in 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:
setRate
in 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:
userSetRate
in 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:
userGetRate
in interfaceTimebase
- Returns:
- the rate
-
setInternalMaster
public void setInternalMaster(boolean master, boolean update)
Set internalMaster and update fields.- Specified by:
setInternalMaster
in 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:
getInternalMaster
in 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:
setMasterName
in interfaceTimebase
- Parameters:
name
- master clock name.
-
getMasterName
public java.lang.String getMasterName()
Get the Master Clock Name.- Specified by:
getMasterName
in interfaceTimebase
- Returns:
- master clock name.
-
setSynchronize
public void setSynchronize(boolean synchronize, boolean update)
Set if clock should synchronise.- Specified by:
setSynchronize
in 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:
getSynchronize
in 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:
setCorrectHardware
in 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:
getCorrectHardware
in interfaceTimebase
- Returns:
- true to correct, else false.
-
set12HourDisplay
public void set12HourDisplay(boolean display, boolean update)
Set 12 or 24 hour display option.- Specified by:
set12HourDisplay
in 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:
use12HourDisplay
in 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:
setClockInitialRunState
in interfaceTimebase
- Parameters:
state
- Initial state.
-
getClockInitialRunState
public Timebase.ClockInitialRunState getClockInitialRunState()
Get the Clock Initial Run State ENUM.- Specified by:
getClockInitialRunState
in interfaceTimebase
- Returns:
- Initial state.
-
setShowStopButton
public void setShowStopButton(boolean displayed)
Set if to show a Stop / Resume button next to the clock.- Specified by:
setShowStopButton
in 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:
getShowStopButton
in 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:
setStartSetTime
in 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:
getStartSetTime
in interfaceTimebase
- Returns:
- true if using set start time.
-
setStartRate
public void setStartRate(double factor)
Set the start clock speed rate.- Specified by:
setStartRate
in interfaceTimebase
- Parameters:
factor
- start clock speed factor.
-
getStartRate
public double getStartRate()
Get the startup clock speed rate.- Specified by:
getStartRate
in interfaceTimebase
- Returns:
- startup clock speed rate factor.
-
setSetRateAtStart
public void setSetRateAtStart(boolean set)
Set Set Rate at Start option.- Specified by:
setSetRateAtStart
in 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:
getSetRateAtStart
in 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:
getStartTime
in interfaceTimebase
- Returns:
- Clock Start Time.
-
setStartClockOption
public void setStartClockOption(int option)
Set the Start Clock type Option.- Specified by:
setStartClockOption
in interfaceTimebase
- Parameters:
option
- Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
-
getStartClockOption
public int getStartClockOption()
Get the Start Clock Type.- Specified by:
getStartClockOption
in 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:
initializeClock
in 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:
initializeHardwareClock
in interfaceTimebase
-
getIsInitialized
public boolean getIsInitialized()
- Specified by:
getIsInitialized
in 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:
addMinuteChangeListener
in 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:
removeMinuteChangeListener
in 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:
getMinuteChangeListeners
in interfaceTimebase
- Returns:
- the list of listeners
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from class:AbstractNamedBean
Add aPropertyChangeListener
to the listener list.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeProvider
- Overrides:
addPropertyChangeListener
in classAbstractNamedBean
- Parameters:
listener
- The PropertyChangeListener to be added
-
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
Description copied from class:AbstractNamedBean
Add aPropertyChangeListener
for a specific property.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeProvider
- Overrides:
addPropertyChangeListener
in 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:
setState
in 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.
-
-