jmri.implementation
Class AbstractLight

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.implementation.AbstractLight
All Implemented Interfaces:
Serializable, Light, NamedBean
Direct Known Subclasses:
AbstractVariableLight, AcelaLight, LnLight, SerialLight, SerialLight, SerialLight, SerialLight, SerialLight, XNetLight

public abstract class AbstractLight
extends AbstractNamedBean
implements Light, Serializable

Abstract class providing partial implementation of the basic logic of the Light interface.

Light objects require a number of instance variables. Since Light objects are created using the standard JMRI systemName/userName concept, accessor routines are provided for setting and editting these instance variables.

Instance variables are divided into system-independent and system dependent categories. System independent instance variables are defined here, and their accessor routines are implemented here.

This implementation provides a notional implementation of intensity and transitions. The user can set intensity so long as it's at least the max value (default 1.0) or no more than the minimum value (default 0.0). In that case, the setTargetIntensity operations become a setState to ON or OFF. Setting a target intensity between the min and max is an error, because this type of Light does not support a true analog intensity. Transitions never happen, and setting a TransitionTime greater than 0.0 gives an exception.

Since this form of Light does not do variable intensity nor transitions, it stores both CurrentIntensity and TargetIntensity in a single location, forcing them to be the same

Author:
Dave Duchamp Copyright (C) 2004, Ken Cameron Copyright (C) 2008, Bob Jacobsen Copyright (C) 2008
See Also:
Serialized Form

Field Summary
protected  boolean mActive
          System independent operational instance variables (not saved between runs)
protected  Timebase mClock
           
protected  Sensor mControlSensor
           
protected  String mControlSensorName
           
protected  int mControlSensorSense
           
protected  Turnout mControlTurnout
           
protected  String mControlTurnoutName
           
protected  int mControlType
          System independent instance variables (saved between runs)
protected  double mCurrentIntensity
           
protected  boolean mEnabled
           
protected  int mFastClockOffHour
           
protected  int mFastClockOffMin
           
protected  int mFastClockOnHour
           
protected  int mFastClockOnMin
           
protected  boolean mLightOnTimerActive
           
protected  double mMaxIntensity
           
protected  double mMinIntensity
           
protected  PropertyChangeListener mSensorListener
           
protected  int mState
           
protected  PropertyChangeListener mTimebaseListener
           
protected  boolean mTimedActive
           
protected  ActionListener mTimedControlListener
           
protected  Sensor mTimedControlSensor
           
protected  Timer mTimedControlTimer
           
protected  PropertyChangeListener mTimedSensorListener
           
protected  String mTimedSensorName
           
protected  int mTimeOff
           
protected  int mTimeOn
           
protected  int mTimeOnDuration
           
protected  PropertyChangeListener mTurnoutListener
           
protected  int mTurnoutState
           
 
Fields inherited from interface jmri.Light
FAST_CLOCK_CONTROL, INTERMEDIATE, NO_CONTROL, OFF, ON, SENSOR_CONTROL, TIMED_ON_CONTROL, TRANSITIONING, TRANSITIONINGHIGHER, TRANSITIONINGLOWER, TRANSITIONINGTOFULLOFF, TRANSITIONINGTOFULLON, TURNOUT_STATUS_CONTROL
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT, UNKNOWN
 
Constructor Summary
AbstractLight(String systemName)
           
AbstractLight(String systemName, String userName)
           
 
Method Summary
 void activateLight()
          Activates a light by control type.
 void deactivateLight()
          Deactivates a light by control type.
protected  void doNewState(int oldState, int newState)
          Implement the specific change of state needed by hardware
 String getControlSensorName()
          Return the controlling Sensor if there is one, else null
 int getControlSensorSense()
          Return the controlling Sensor Sense.
 String getControlTimedOnSensorName()
          Return the trigger Sensor system name.
 String getControlTurnoutName()
          Return the controlling Turnout if there is one, else null.
 int getControlTurnoutState()
          Return the state of the controlling Turnout that corresponds to this light being ON.
 int getControlType()
          Return the control type of this Light
 double getCurrentIntensity()
          Get the current intensity value.
 boolean getEnabled()
          Get enabled status
 int getFastClockOffHour()
           
 int getFastClockOffMin()
           
 int getFastClockOnHour()
          Return the On/Off Schedule if FAST_CLOCK_CONTROL
 int getFastClockOnMin()
           
 double getMaxIntensity()
          Get the current value of the maxIntensity property.
 double getMinIntensity()
          Get the current value of the minIntensity property.
 int getState()
          Get the current state of the Light's output.
 double getTargetIntensity()
          Get the target intensity value for the current transition, if any.
 int getTimedOnDuration()
          Return the duration (milliseconds) light is to remain ON after it has been triggered.
 double getTransitionTime()
          Get the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.
 boolean isIntensityVariable()
          Check if this object can handle variable intensity.
 boolean isTransitionAvailable()
          Can the Light change it's intensity setting slowly?
 boolean isTransitioning()
          Convenience method for checking if the intensity of the light is currently changing due to a transition.
protected  void notifyStateChange(int oldState, int newState)
          Change the stored state value and do notification, but don't change anything in the hardware
protected  void notifyTargetIntensityChange(double intensity)
          Change the stored target intensity value and do notification, but don't change anything in the hardware
 void setControlSensor(String sensorName)
          Set the controlling Sensor if there is one, else null
 void setControlSensorSense(int sense)
          Set the controlling Sensor Sense.
 void setControlTimedOnSensor(String sensorName)
          Set the trigger Sensor system name.
 void setControlTurnout(String turnoutName)
          Set the controlling Turnout.
 void setControlTurnoutState(int ts)
          Set the state of the controlling Turnout that corresponds to this light being ON.
 void setControlType(int controlType)
          Set the control type of this Light
 void setEnabled(boolean v)
          Set enabled status
 void setFastClockControlSchedule(int onHour, int onMin, int offHour, int offMin)
          Set the On/Off Schedule if FAST_CLOCK_CONTROL
 void setMaxIntensity(double intensity)
          Set the value of the maxIntensity property.
 void setMinIntensity(double intensity)
          Set the value of the minIntensity property.
 void setState(int newState)
          Handle a request for a state change.
 void setTargetIntensity(double intensity)
          Set the intended new intensity value for the Light.
 void setTimedOnDuration(int duration)
          Set the duration (milliseconds) light is to remain ON after it has been triggered.
 void setTransitionTime(double minutes)
          Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.
 void updateClockControlLight()
          Updates the status of a Light under FAST_CLOCK_CONTROL.
protected  void updateIntensityHigh(double intensity)
          Method for further implementation of setTargetIntensity at or above the maximum Does not change state.
protected  void updateIntensityIntermediate(double intensity)
          Method for further implementation of setTargetIntensity between min and max Does not change state.
protected  void updateIntensityLow(double intensity)
          Method for further implementation of setTargetIntensity at or below the minimum.
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, dispose, firePropertyChange, getComment, getDisplayName, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getSystemName, getUserName, removePropertyChangeListener, setComment, setProperty, setUserName
 
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, dispose, getComment, getDisplayName, getNumPropertyChangeListeners, getProperty, getSystemName, getUserName, removePropertyChangeListener, setComment, setProperty, setUserName
 

Field Detail

mControlType

protected int mControlType
System independent instance variables (saved between runs)


mControlSensorSense

protected int mControlSensorSense

mControlSensorName

protected String mControlSensorName

mFastClockOnHour

protected int mFastClockOnHour

mFastClockOnMin

protected int mFastClockOnMin

mFastClockOffHour

protected int mFastClockOffHour

mFastClockOffMin

protected int mFastClockOffMin

mControlTurnoutName

protected String mControlTurnoutName

mTurnoutState

protected int mTurnoutState

mTimedSensorName

protected String mTimedSensorName

mTimeOnDuration

protected int mTimeOnDuration

mMaxIntensity

protected double mMaxIntensity

mMinIntensity

protected double mMinIntensity

mActive

protected boolean mActive
System independent operational instance variables (not saved between runs)


mControlSensor

protected Sensor mControlSensor

mSensorListener

protected PropertyChangeListener mSensorListener

mTimebaseListener

protected PropertyChangeListener mTimebaseListener

mClock

protected Timebase mClock

mTimeOn

protected int mTimeOn

mTimeOff

protected int mTimeOff

mControlTurnout

protected Turnout mControlTurnout

mTurnoutListener

protected PropertyChangeListener mTurnoutListener

mTimedActive

protected boolean mTimedActive

mTimedControlSensor

protected Sensor mTimedControlSensor

mTimedSensorListener

protected PropertyChangeListener mTimedSensorListener

mTimedControlTimer

protected Timer mTimedControlTimer

mTimedControlListener

protected ActionListener mTimedControlListener

mLightOnTimerActive

protected boolean mLightOnTimerActive

mEnabled

protected boolean mEnabled

mCurrentIntensity

protected double mCurrentIntensity

mState

protected int mState
Constructor Detail

AbstractLight

public AbstractLight(String systemName,
                     String userName)

AbstractLight

public AbstractLight(String systemName)
Method Detail

getEnabled

public boolean getEnabled()
Get enabled status

Specified by:
getEnabled in interface Light

setEnabled

public void setEnabled(boolean v)
Set enabled status

Specified by:
setEnabled in interface Light

isIntensityVariable

public boolean isIntensityVariable()
Check if this object can handle variable intensity.

Specified by:
isIntensityVariable in interface Light
Returns:
false, as this abstract class does not implement variable intensity. See e.g. AbstractVariableLight for an abstract implementation of variable intensity.

setTargetIntensity

public void setTargetIntensity(double intensity)
Set the intended new intensity value for the Light.

Bound property between 0 and 1.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Values at or below the minIntensity property will result in the Light going to the OFF state immediately. Values at or above the maxIntensity property will result in the Light going to the ON state immediately.

All others result in an exception, instead of the INTERMEDIATE state, because this class does not implement analog intensity

Specified by:
setTargetIntensity in interface Light
Throws:
IllegalArgumentException - when intensity is less than 0.0 or more than 1.0
IllegalArgumentException - when intensity is more than MinIntensity and less than MaxIntensity

updateIntensityLow

protected void updateIntensityLow(double intensity)
Method for further implementation of setTargetIntensity at or below the minimum.

Does not change state.


updateIntensityIntermediate

protected void updateIntensityIntermediate(double intensity)
Method for further implementation of setTargetIntensity between min and max

Does not change state.


updateIntensityHigh

protected void updateIntensityHigh(double intensity)
Method for further implementation of setTargetIntensity at or above the maximum

Does not change state.


getCurrentIntensity

public double getCurrentIntensity()
Get the current intensity value. If the Light is currently transitioning, this may be either an intermediate or final value.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Specified by:
getCurrentIntensity in interface Light

getTargetIntensity

public double getTargetIntensity()
Get the target intensity value for the current transition, if any. If the Light is not currently transitioning, this is the current intensity value.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Bound property

Specified by:
getTargetIntensity in interface Light

setMaxIntensity

public void setMaxIntensity(double intensity)
Set the value of the maxIntensity property.

Bound property between 0 and 1.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Specified by:
setMaxIntensity in interface Light
Throws:
IllegalArgumentException - when intensity is less than 0.0 or more than 1.0
IllegalArgumentException - when intensity is not greater than the current value of the minIntensity property

getMaxIntensity

public double getMaxIntensity()
Get the current value of the maxIntensity property.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Specified by:
getMaxIntensity in interface Light

setMinIntensity

public void setMinIntensity(double intensity)
Set the value of the minIntensity property.

Bound property between 0 and 1.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Specified by:
setMinIntensity in interface Light
Throws:
IllegalArgumentException - when intensity is less than 0.0 or more than 1.0
IllegalArgumentException - when intensity is not less than the current value of the maxIntensity property

getMinIntensity

public double getMinIntensity()
Get the current value of the minIntensity property.

A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.

Specified by:
getMinIntensity in interface Light

isTransitionAvailable

public boolean isTransitionAvailable()
Can the Light change it's intensity setting slowly?

If true, this Light supports a non-zero value of the transitionTime property, which controls how long the Light will take to change from one intensity level to another.

Unbound property

Specified by:
isTransitionAvailable in interface Light

setTransitionTime

public void setTransitionTime(double minutes)
Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.

This class does not implement transitions, so this property cannot be set from zero.

Bound property

Specified by:
setTransitionTime in interface Light
Throws:
IllegalArgumentException - if minutes is not 0.0

getTransitionTime

public double getTransitionTime()
Get the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.

Specified by:
getTransitionTime in interface Light
Returns:
0.0 if the output intensity transition is instantaneous

isTransitioning

public boolean isTransitioning()
Convenience method for checking if the intensity of the light is currently changing due to a transition.

Bound property so that listeners can conveniently learn when the transition is over.

Specified by:
isTransitioning in interface Light

getControlType

public int getControlType()
Return the control type of this Light

Specified by:
getControlType in interface Light

setControlType

public void setControlType(int controlType)
Set the control type of this Light

Specified by:
setControlType in interface Light

getControlSensorName

public String getControlSensorName()
Return the controlling Sensor if there is one, else null

Specified by:
getControlSensorName in interface Light

setControlSensor

public void setControlSensor(String sensorName)
Set the controlling Sensor if there is one, else null

Specified by:
setControlSensor in interface Light

getControlSensorSense

public int getControlSensorSense()
Return the controlling Sensor Sense. This is the state of the controlling Sensor that corresponds to this Light being ON.

Specified by:
getControlSensorSense in interface Light

setControlSensorSense

public void setControlSensorSense(int sense)
Set the controlling Sensor Sense. This is the state of the controlling Sensor that corresponds to this Light being ON. If 'sense' does not correspond to one of the allowed states of a Sensor, this call is ignored.

Specified by:
setControlSensorSense in interface Light

getFastClockOnHour

public int getFastClockOnHour()
Return the On/Off Schedule if FAST_CLOCK_CONTROL

Specified by:
getFastClockOnHour in interface Light

getFastClockOnMin

public int getFastClockOnMin()
Specified by:
getFastClockOnMin in interface Light

getFastClockOffHour

public int getFastClockOffHour()
Specified by:
getFastClockOffHour in interface Light

getFastClockOffMin

public int getFastClockOffMin()
Specified by:
getFastClockOffMin in interface Light

setFastClockControlSchedule

public void setFastClockControlSchedule(int onHour,
                                        int onMin,
                                        int offHour,
                                        int offMin)
Set the On/Off Schedule if FAST_CLOCK_CONTROL

Specified by:
setFastClockControlSchedule in interface Light

getControlTurnoutName

public String getControlTurnoutName()
Return the controlling Turnout if there is one, else null.

Specified by:
getControlTurnoutName in interface Light

setControlTurnout

public void setControlTurnout(String turnoutName)
Set the controlling Turnout. This is the Turnout whose state controls the ON and OFF of this Light.

Specified by:
setControlTurnout in interface Light

getControlTurnoutState

public int getControlTurnoutState()
Return the state of the controlling Turnout that corresponds to this light being ON.

Specified by:
getControlTurnoutState in interface Light

setControlTurnoutState

public void setControlTurnoutState(int ts)
Set the state of the controlling Turnout that corresponds to this light being ON. If 'ts' is not a valid state for a turnout, this call is ignored.

Specified by:
setControlTurnoutState in interface Light

getControlTimedOnSensorName

public String getControlTimedOnSensorName()
Return the trigger Sensor system name. This is the Sensor which triggers the Timed ON state of the light when it moves from inactive to active.

Specified by:
getControlTimedOnSensorName in interface Light

setControlTimedOnSensor

public void setControlTimedOnSensor(String sensorName)
Set the trigger Sensor system name. This is the Sensor which triggers the Timed ON state of the light when it moves from inactive to active.

Specified by:
setControlTimedOnSensor in interface Light

getTimedOnDuration

public int getTimedOnDuration()
Return the duration (milliseconds) light is to remain ON after it has been triggered.

Specified by:
getTimedOnDuration in interface Light

setTimedOnDuration

public void setTimedOnDuration(int duration)
Set the duration (milliseconds) light is to remain ON after it has been triggered.

Specified by:
setTimedOnDuration in interface Light

setState

public void setState(int newState)
Handle a request for a state change. For these lights, ON and OFF just transition immediately between MinIntensity and MaxIntensity

Specified by:
setState in interface Light
Specified by:
setState in interface NamedBean

notifyTargetIntensityChange

protected void notifyTargetIntensityChange(double intensity)
Change the stored target intensity value and do notification, but don't change anything in the hardware


notifyStateChange

protected void notifyStateChange(int oldState,
                                 int newState)
Change the stored state value and do notification, but don't change anything in the hardware


doNewState

protected void doNewState(int oldState,
                          int newState)
Implement the specific change of state needed by hardware


getState

public int getState()
Description copied from interface: Light
Get the current state of the Light's output.

Specified by:
getState in interface Light
Specified by:
getState in interface NamedBean

updateClockControlLight

public void updateClockControlLight()
Updates the status of a Light under FAST_CLOCK_CONTROL. This method is called every FastClock minute.


activateLight

public void activateLight()
Activates a light by control type. This method tests the control type, and set up a control mechanism, appropriate for the control type. Some lights, e.g. signal head lights, are controlled by the signal head, so no activation is needed here.

Specified by:
activateLight in interface Light

deactivateLight

public void deactivateLight()
Deactivates a light by control type. This method tests the control type, and deactivates the control mechanism, appropriate for the control type. Some lights, e.g. signal head lights, are controlled by the signal head, so no deactivation is needed here.

Specified by:
deactivateLight in interface Light


Copyright © 1997 - 2009 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