jmri.implementation
Class AbstractLight

Show UML class diagram
java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.implementation.AbstractLight
All Implemented Interfaces:
Serializable, Light, NamedBean
Direct Known Subclasses:
AbstractVariableLight, AcelaLight, JMRIClientLight, JsonClientLight, LnLight, NceLight, SerialLight, SerialLight, SerialLight, SerialLight, SerialLight, XBeeLight, XNetLight

public abstract class AbstractLight
extends AbstractNamedBean
implements Light, Serializable

Abstract class providing partial implementation of the 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.

Each Light may have one or more control mechanisms, of the types defined in the Light interface. A Light may also not have any control mechanisms defined.

Information for each control mechanism is held in LightControl objects, which also implement the logic for control. A list of LightControls, if any, is kept here, and activation and deactivation of LightControls is through this module.

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

See Also:
Serialized Form

Field Summary
protected  ArrayList<LightControl> lightControlList
          System independent instance variables (saved between runs)
protected  boolean mActive
          System independent operational instance variables (not saved between runs)
protected  double mCurrentIntensity
           
protected  boolean mEnabled
           
protected  double mMaxIntensity
           
protected  double mMinIntensity
           
protected  int mState
           
 
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, log, mSystemName, mUserName, parameters, pcs, register
 
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, TWO_SENSOR_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 activating all its LightControl objects.
 void addLightControl(LightControl c)
           
 void clearLightControls()
          LightControl management methods
 void deactivateLight()
          Deactivates a light by deactivating each of its LightControl objects.
protected  void doNewState(int oldState, int newState)
          Implement the specific change of state needed by hardware
 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.
 double getCurrentIntensity()
          Get the current intensity value.
 boolean getEnabled()
          Get enabled status
 ArrayList<LightControl> getLightControlList()
           
 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.
 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 setEnabled(boolean v)
          Set enabled status
 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 setTransitionTime(double minutes)
          Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.
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, addPropertyChangeListener, dispose, firePropertyChange, getComment, getDisplayName, getFullyFormattedDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, removeProperty, removePropertyChangeListener, setComment, setProperty, setUserName, updateListenerRef, vetoableChange
 
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, addPropertyChangeListener, dispose, getComment, getDisplayName, getFullyFormattedDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, removeProperty, removePropertyChangeListener, setComment, setProperty, setUserName, updateListenerRef, vetoableChange
 

Field Detail

lightControlList

protected ArrayList<LightControl> lightControlList
System independent instance variables (saved between runs)


mMaxIntensity

protected double mMaxIntensity

mMinIntensity

protected double mMinIntensity

mActive

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


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

getBeanType

public String getBeanType()
Description copied from interface: NamedBean
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 interface NamedBean
Returns:
a string of the bean type, eg Turnout, Sensor etc

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

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

activateLight

public void activateLight()
Activates a light activating all its LightControl objects.

Specified by:
activateLight in interface Light

deactivateLight

public void deactivateLight()
Deactivates a light by deactivating each of its LightControl objects.

Specified by:
deactivateLight in interface Light

clearLightControls

public void clearLightControls()
LightControl management methods

Specified by:
clearLightControls in interface Light

addLightControl

public void addLightControl(LightControl c)
Specified by:
addLightControl in interface Light

getLightControlList

public ArrayList<LightControl> getLightControlList()
Specified by:
getLightControlList in interface Light


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