jmri.jmrit.simpleclock
Class SimpleTimebase

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.jmrit.simpleclock.SimpleTimebase
All Implemented Interfaces:
Serializable, 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.

Author:
Bob Jacobsen Copyright (C) 2004, 2007 Dave Duchamp - 2007 additions/revisions for handling one hardware clock
See Also:
Serialized Form

Field Summary
 
Fields inherited from class jmri.implementation.AbstractNamedBean
mSystemName, mUserName
 
Fields inherited from interface jmri.Timebase
ANALOG_CLOCK, LCD_CLOCK, NIXIE_CLOCK, NONE
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT, UNKNOWN
 
Constructor Summary
SimpleTimebase()
           
 
Method Summary
 void addMinuteChangeListener(PropertyChangeListener l)
          Request a call-back when the minutes place of the time changes.
 void addPropertyChangeListener(PropertyChangeListener l)
          Request a call-back when the bound Rate or Run property changes.
 void dispose()
          Remove references to and from this object, so that it can eventually be garbage-collected.
protected  void firePropertyChange(String p, Object old, Object n)
           
 boolean getCorrectHardware()
           
 boolean getInternalMaster()
           
 boolean getIsInitialized()
           
 String getMasterName()
           
 double getRate()
          Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source.
 boolean getRun()
           
 int getStartClockOption()
           
 boolean getStartSetTime()
           
 boolean getStartStopped()
           
 Date getStartTime()
           
 int getState()
          Provide generic access to internal state.
 boolean getSynchronize()
           
 Date getTime()
           
 void initializeClock()
           
 void initializeHardwareClock()
          Method to initialize hardware clock at start up Note: This method is always called at start up after all options have been set.
 void removeMinuteChangeListener(PropertyChangeListener l)
          Remove a request for call-back when the minutes place of the time changes.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a request for a call-back when a bound property changes.
 void set12HourDisplay(boolean display, boolean update)
          Set 12 or 24 hour display option
 void setCorrectHardware(boolean correct, boolean update)
           
 void setInternalMaster(boolean master, boolean update)
           
 void setMasterName(String name)
           
 void setRate(double factor)
          Set fast clock rate factor
 void setRun(boolean run)
           
 void setStartClockOption(int option)
           
 void setStartSetTime(boolean set, Date time)
           
 void setStartStopped(boolean stopped)
           
 void setState(int s)
          Provide generic access to internal state.
 void setSynchronize(boolean synchronize, boolean update)
           
 void setTime(Date d)
          Set the current time
 boolean use12HourDisplay()
           
 double userGetRate()
          This method is used by Setup Fast Clock when an external change in fast clock rate occurs because of the peculiar way some hardware clocks attempt to synchronize with the JMRI fast clock.
 void userSetRate(double factor)
          Used when the user changes fast clock rate in Setup Fast Clock and by hardware ClockControl implementations that fiddle with the fast clock rate to synchronize
 void userSetTime(Date d)
          Special method for when the user changes fast clock time in Setup Fast Clock.
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, setComment, setProperty, setUserName, updateListenerRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, setComment, setProperty, setUserName, updateListenerRef
 

Constructor Detail

SimpleTimebase

public SimpleTimebase()
Method Detail

getTime

public Date getTime()
Specified by:
getTime in interface Timebase

setTime

public void setTime(Date d)
Description copied from interface: Timebase
Set the current time

Specified by:
setTime in interface Timebase

userSetTime

public void userSetTime(Date d)
Description copied from interface: Timebase
Special method for when the user changes fast clock time in Setup Fast Clock.

Specified by:
userSetTime in interface Timebase

setRun

public void setRun(boolean run)
Specified by:
setRun in interface Timebase

getRun

public boolean getRun()
Specified by:
getRun in interface Timebase

setRate

public void setRate(double factor)
Description copied from interface: Timebase
Set fast clock rate factor

Specified by:
setRate in interface Timebase

userSetRate

public void userSetRate(double factor)
Description copied from interface: Timebase
Used when the user changes fast clock rate in Setup Fast Clock and by hardware ClockControl implementations that fiddle with the fast clock rate to synchronize

Specified by:
userSetRate in interface Timebase

getRate

public double getRate()
Description copied from interface: Timebase
Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source. Use "userGetRate" if you want the real clock rate instead.

Specified by:
getRate in interface Timebase

userGetRate

public double userGetRate()
Description copied from interface: Timebase
This method is used by Setup Fast Clock when an external change in fast clock rate occurs because of the peculiar way some hardware clocks attempt to synchronize with the JMRI fast clock. This call will return the "true" rate even if the master Timebase rate has been fiddled by a hardware clock.

Specified by:
userGetRate in interface Timebase

setInternalMaster

public void setInternalMaster(boolean master,
                              boolean update)
Specified by:
setInternalMaster in interface Timebase

getInternalMaster

public boolean getInternalMaster()
Specified by:
getInternalMaster in interface Timebase

setMasterName

public void setMasterName(String name)
Specified by:
setMasterName in interface Timebase

getMasterName

public String getMasterName()
Specified by:
getMasterName in interface Timebase

setSynchronize

public void setSynchronize(boolean synchronize,
                           boolean update)
Specified by:
setSynchronize in interface Timebase

getSynchronize

public boolean getSynchronize()
Specified by:
getSynchronize in interface Timebase

setCorrectHardware

public void setCorrectHardware(boolean correct,
                               boolean update)
Specified by:
setCorrectHardware in interface Timebase

getCorrectHardware

public boolean getCorrectHardware()
Specified by:
getCorrectHardware in interface Timebase

set12HourDisplay

public void set12HourDisplay(boolean display,
                             boolean update)
Description copied from interface: Timebase
Set 12 or 24 hour display option

Specified by:
set12HourDisplay in interface Timebase
Parameters:
display - true if a 12-hour display is requested, false for 24-hour display

use12HourDisplay

public boolean use12HourDisplay()
Specified by:
use12HourDisplay in interface Timebase

setStartStopped

public void setStartStopped(boolean stopped)
Specified by:
setStartStopped in interface Timebase

getStartStopped

public boolean getStartStopped()
Specified by:
getStartStopped in interface Timebase

setStartSetTime

public void setStartSetTime(boolean set,
                            Date time)
Specified by:
setStartSetTime in interface Timebase

getStartSetTime

public boolean getStartSetTime()
Specified by:
getStartSetTime in interface Timebase

getStartTime

public Date getStartTime()
Specified by:
getStartTime in interface Timebase

setStartClockOption

public void setStartClockOption(int option)
Specified by:
setStartClockOption in interface Timebase

getStartClockOption

public int getStartClockOption()
Specified by:
getStartClockOption in interface Timebase

initializeClock

public void initializeClock()
Specified by:
initializeClock in interface Timebase

initializeHardwareClock

public void initializeHardwareClock()
Method to initialize hardware clock at start up Note: This method is always called at start up after all options have been set. It should be ignored if there is no communication with a hardware clock.

Specified by:
initializeHardwareClock in interface Timebase

getIsInitialized

public boolean getIsInitialized()
Specified by:
getIsInitialized in interface Timebase
Returns:
true if call to initialize Hardware Clock has occurred

firePropertyChange

protected void firePropertyChange(String p,
                                  Object old,
                                  Object n)
Overrides:
firePropertyChange in class AbstractNamedBean

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Request a call-back when the bound Rate or Run property changes.

Not yet implemented.

Specified by:
addPropertyChangeListener in interface NamedBean
Specified by:
addPropertyChangeListener in interface Timebase
Overrides:
addPropertyChangeListener in class AbstractNamedBean

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove a request for a call-back when a bound property changes.

Not yet implemented.

Specified by:
removePropertyChangeListener in interface NamedBean
Specified by:
removePropertyChangeListener in interface Timebase
Overrides:
removePropertyChangeListener in class AbstractNamedBean

dispose

public void dispose()
Remove references to and from this object, so that it can eventually be garbage-collected.

Specified by:
dispose in interface NamedBean
Specified by:
dispose in interface Timebase
Overrides:
dispose in class AbstractNamedBean

addMinuteChangeListener

public void addMinuteChangeListener(PropertyChangeListener l)
Request a call-back when the minutes place of the time changes.

Specified by:
addMinuteChangeListener in interface Timebase

removeMinuteChangeListener

public void removeMinuteChangeListener(PropertyChangeListener l)
Remove a request for call-back when the minutes place of the time changes.

Specified by:
removeMinuteChangeListener in interface Timebase

setState

public void setState(int s)
              throws JmriException
Description copied from interface: NamedBean
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 provided to make Jython script access easier to read.

Specified by:
setState in interface NamedBean
Throws:
JmriException - general error when cant do the needed operation

getState

public int getState()
Description copied from interface: NamedBean
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 provided to make Jython script access easier to read.

Specified by:
getState in interface NamedBean


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads