Class AbstractLight
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.AbstractLight
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>
,PropertyChangeProvider
,DigitalIO
,Light
,NamedBean
- Direct Known Subclasses:
AbstractVariableLight
,AcelaLight
,CbusLight
,DCCppLight
,IpocsLight
,JMRIClientLight
,LnLight
,NceLight
,OlcbLight
,SerialLight
,SerialLight
,SerialLight
,SerialLight
,SerialLight
,XBeeLight
,XNetLight
public abstract class AbstractLight extends AbstractNamedBean implements Light
Abstract class providing partial implementation 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 editing 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<LightControl>
lightControlList
System independent instance variables (saved between runs).protected boolean
mActive
protected double
mCurrentIntensity
System independent operational instance variables (not saved between runs).protected boolean
mEnabled
protected double
mMaxIntensity
protected double
mMinIntensity
protected int
mState
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.Light
FAST_CLOCK_CONTROL, INTERMEDIATE, NO_CONTROL, SENSOR_CONTROL, TIMED_ON_CONTROL, TRANSITIONING, TRANSITIONINGHIGHER, TRANSITIONINGLOWER, TRANSITIONINGTOFULLOFF, TRANSITIONINGTOFULLON, TURNOUT_STATUS_CONTROL, TWO_SENSOR_CONTROL
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description AbstractLight(java.lang.String systemName)
AbstractLight(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateLight()
Activate a light activating all its LightControl objects.void
addLightControl(LightControl c)
Add a LightControl to this Light.void
clearLightControls()
Clears (removes) all LightControl objects for this lightvoid
deactivateLight()
Deactivate a light by deactivating each of its LightControl objects.java.lang.String
describeState(int state)
Provide human-readable, localized version of state value.protected void
doNewState(int oldState, int newState)
Implement the specific change of state needed by hardware.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.boolean
getEnabled()
Get enabled status.java.util.List<LightControl>
getLightControlList()
int
getState()
Get the current state of the Light's output.java.util.List<NamedBeanUsageReport>
getUsageReport(NamedBean bean)
Get a list of references for the specified bean.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
setState(int newState)
Handle a request for a state change.-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, dispose, 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.Light
getCommandedState, getKnownState, isConsistentState, requestUpdateFromLayout, setCommandedState
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, dispose, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
lightControlList
protected java.util.List<LightControl> lightControlList
System independent instance variables (saved between runs).
-
mMaxIntensity
protected double mMaxIntensity
-
mMinIntensity
protected double mMinIntensity
-
mCurrentIntensity
protected double mCurrentIntensity
System independent operational instance variables (not saved between runs).
-
mActive
protected boolean mActive
-
mEnabled
protected boolean mEnabled
-
mState
protected int mState
-
-
Constructor Detail
-
AbstractLight
public AbstractLight(java.lang.String systemName, java.lang.String userName)
-
AbstractLight
public AbstractLight(java.lang.String systemName)
-
-
Method Detail
-
getBeanType
public java.lang.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 interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
describeState
@Nonnull public java.lang.String describeState(int state)
Description copied from class:AbstractNamedBean
Provide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Specified by:
describeState
in interfaceNamedBean
- Overrides:
describeState
in classAbstractNamedBean
- Parameters:
state
- the state to describe- Returns:
- the state in localized form
-
getEnabled
public boolean getEnabled()
Get enabled status.- Specified by:
getEnabled
in interfaceLight
- Returns:
- enabled status
-
setEnabled
public void setEnabled(boolean v)
Set enabled status.- Specified by:
setEnabled
in interfaceLight
- Parameters:
v
- status to set
-
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. Ignores any outputDelay setting for connection.
-
notifyTargetIntensityChange
protected void notifyTargetIntensityChange(double intensity)
Change the stored target intensity value and do notification, but don't change anything in the hardware.- Parameters:
intensity
- intensity value
-
notifyStateChange
protected void notifyStateChange(int oldState, int newState)
Change the stored state value and do notification, but don't change anything in the hardware.- Parameters:
oldState
- old valuenewState
- new value
-
doNewState
protected void doNewState(int oldState, int newState)
Implement the specific change of state needed by hardware.- Parameters:
oldState
- old statenewState
- new state
-
getState
public int getState()
Description copied from interface:Light
Get the current state of the Light's output.
-
activateLight
public void activateLight()
Activate a light activating all its LightControl objects.- Specified by:
activateLight
in interfaceLight
-
deactivateLight
public void deactivateLight()
Deactivate a light by deactivating each of its LightControl objects.- Specified by:
deactivateLight
in interfaceLight
-
clearLightControls
public void clearLightControls()
Description copied from interface:Light
Clears (removes) all LightControl objects for this light- Specified by:
clearLightControls
in interfaceLight
-
addLightControl
public void addLightControl(LightControl c)
Add a LightControl to this Light.Duplicates are considered the same, hence not added
- Specified by:
addLightControl
in interfaceLight
- Parameters:
c
- the light control to add.
-
getLightControlList
public java.util.List<LightControl> getLightControlList()
- Specified by:
getLightControlList
in interfaceLight
- Returns:
- a list of all LightControls
-
getUsageReport
public java.util.List<NamedBeanUsageReport> getUsageReport(NamedBean bean)
Description copied from interface:NamedBean
Get a list of references for the specified bean.- Specified by:
getUsageReport
in interfaceNamedBean
- Parameters:
bean
- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
-