Class DefaultLightControl
- java.lang.Object
-
- jmri.implementation.DefaultLightControl
-
- All Implemented Interfaces:
LightControl
public class DefaultLightControl extends java.lang.Object implements LightControl
Each LightControl object is linked to a specific Light, and provides one of the controls available for switching the Light ON/OFF in response to time or events occurring on the layout.Each LightControl holds the information for one control of the parent Light.
Each Light may have as many controls as desired by the user. It is the user's responsibility to ensure that the various control mechanisms do not conflict with one another.
Available control types are those defined in the Light.java interface. Control types: SENSOR_CONTROL FAST_CLOCK_CONTROL TURNOUT_STATUS_CONTROL TIMED_ON_CONTROL TWO_SENSOR_CONTROL
This file is part of JMRI.JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
_controlSensorSense
protected int
_timeOnDuration
-
Constructor Summary
Constructors Constructor Description DefaultLightControl()
Main constructor methodsDefaultLightControl(Light l)
DefaultLightControl(LightControl lc)
Create a New LightControl from existing, for use when editing a LightControl
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateLightControl()
Activates a Light Control by control type.boolean
areFollowerTimesFaulty(java.util.List<LightControl> compareList)
Check to see if we have the FastClock Follower has unique times for a single Light.void
deactivateLightControl()
Deactivates a LightControl by control type.boolean
equals(java.lang.Object o)
Test if a LightControl is equal to this onejava.lang.String
getControlSensor2Name()
Get the Second Sensor name.java.lang.String
getControlSensorName()
Get the Sensor 1 name for 1 and 2 Sensor Control Types.int
getControlSensorSense()
Get the Sensor State used by the 1 Sensor Controljava.lang.String
getControlTimedOnSensorName()
Get the Timed On Trigger Sensor name.java.lang.String
getControlTurnoutName()
Get the LightControl Turnout Name.int
getControlTurnoutState()
Get the LightControl Turnout Name.int
getControlType()
Get the control type used by the Controljava.lang.String
getDescriptionText(java.lang.String lightName)
Get a Textual Description eg.int
getFastClockOffCombined()
Get the Fast Clock Off Hours and Minutes Combined Convenience method of separate getFastClockOnHour() and getFastClockOnMin()int
getFastClockOffHour()
Get the Fast Clock Off Hour.int
getFastClockOffMin()
Get the Fast Clock Off Minute.int
getFastClockOnCombined()
Get the Fast Clock On Hours and Minutes Combined Convenience method of separate getFastClockOnHour() and getFastClockOnMin()int
getFastClockOnHour()
Get the Fast Clock On Hour.int
getFastClockOnMin()
Get the Fast Clock On Minute.int
getTimedOnDuration()
Get the Timed On Control Durationjava.lang.String
getTimedSensorName()
Get the Timed On Trigger Sensor name.int
hashCode()
boolean
onOffTimesFaulty()
Check to see if we have the FastClock Follower has unique times for a single Light Control.void
setControlSensor2Name(java.lang.String sensorName)
Set Sensor 2 used by the 2 Sensor Control Does NOT update any changelistenersvoid
setControlSensorName(java.lang.String sensorName)
Set Sensor 1 used by the 1 Sensor and 2 Sensor Control Does NOT update any changelisteners If Sensor not present and name not empty, is provided by the SensorManager when #activateLightControl() is calledvoid
setControlSensorSense(int sense)
Set the Sensor State used by the Control Does NOT update any changelistenersvoid
setControlTimedOnSensorName(java.lang.String sensorName)
Set Sensor used by the Timed On Control Does NOT update any changelistenersvoid
setControlTurnout(java.lang.String turnoutName)
Set the Turnout used by the Control Does NOT update any changelistenersvoid
setControlTurnoutState(int state)
Set the Turnout State used by the Control Does NOT update any changelistenersvoid
setControlType(int type)
Set the control type used by the Control Does NOT update any changelistenersvoid
setFastClockControlSchedule(int onHour, int onMin, int offHour, int offMin)
Set a Fast Clock LightControl Schedule.void
setParentLight(Light l)
Set Light to control Does NOT update any changelistenersvoid
setTimedOnDuration(int duration)
Set Duration used by the Timed On Control Does NOT update any changeListenersprotected void
twoSensorChanged()
Internal routine for handling sensor changes for the 2 Sensor Control Type
-
-
-
Field Detail
-
_controlSensorSense
protected int _controlSensorSense
-
_timeOnDuration
protected int _timeOnDuration
-
-
Constructor Detail
-
DefaultLightControl
public DefaultLightControl()
Main constructor methods
-
DefaultLightControl
public DefaultLightControl(Light l)
-
DefaultLightControl
public DefaultLightControl(@Nonnull LightControl lc)
Create a New LightControl from existing, for use when editing a LightControl- Parameters:
lc
- the LightControl to be copied
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
Test if a LightControl is equal to this one- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the LightControl object to be checked- Returns:
- True if the LightControl is equal, else false
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getControlType
public int getControlType()
Get the control type used by the Control- Specified by:
getControlType
in interfaceLightControl
- Returns:
- the Control Type, eg. FAST_CLOCK_CONTROL
-
setControlType
public void setControlType(int type)
Set the control type used by the Control Does NOT update any changelisteners- Specified by:
setControlType
in interfaceLightControl
- Parameters:
type
- the Control Type, eg. FAST_CLOCK_CONTROL
-
setControlSensorName
public void setControlSensorName(java.lang.String sensorName)
Set Sensor 1 used by the 1 Sensor and 2 Sensor Control Does NOT update any changelisteners If Sensor not present and name not empty, is provided by the SensorManager when #activateLightControl() is called- Specified by:
setControlSensorName
in interfaceLightControl
- Parameters:
sensorName
- the Sensor name
-
getControlSensorSense
public int getControlSensorSense()
Get the Sensor State used by the 1 Sensor Control- Specified by:
getControlSensorSense
in interfaceLightControl
- Returns:
- Sensor.ACTIVE or Sensor.INACTIVE
-
getControlSensorName
public java.lang.String getControlSensorName()
Get the Sensor 1 name for 1 and 2 Sensor Control Types.- Specified by:
getControlSensorName
in interfaceLightControl
- Returns:
- If a Sensor is registered, returns the Sensor.getName() else the Sensor Name as set by #setControlSensorName
-
setControlSensorSense
public void setControlSensorSense(int sense)
Set the Sensor State used by the Control Does NOT update any changelisteners- Specified by:
setControlSensorSense
in interfaceLightControl
- Parameters:
sense
- The state to react to, eg. Sensor.ACTIVE or Sensor.INACTIVE
-
getFastClockOnHour
public int getFastClockOnHour()
Get the Fast Clock On Hour.- Specified by:
getFastClockOnHour
in interfaceLightControl
- Returns:
- On Hour value
-
getFastClockOnMin
public int getFastClockOnMin()
Get the Fast Clock On Minute.- Specified by:
getFastClockOnMin
in interfaceLightControl
- Returns:
- On Minute value
-
getFastClockOnCombined
public int getFastClockOnCombined()
Get the Fast Clock On Hours and Minutes Combined Convenience method of separate getFastClockOnHour() and getFastClockOnMin()- Specified by:
getFastClockOnCombined
in interfaceLightControl
- Returns:
- Total combined Minute value
-
getFastClockOffHour
public int getFastClockOffHour()
Get the Fast Clock Off Hour.- Specified by:
getFastClockOffHour
in interfaceLightControl
- Returns:
- Off Hour value
-
getFastClockOffMin
public int getFastClockOffMin()
Get the Fast Clock Off Minute.- Specified by:
getFastClockOffMin
in interfaceLightControl
- Returns:
- Off Minute value
-
getFastClockOffCombined
public int getFastClockOffCombined()
Get the Fast Clock Off Hours and Minutes Combined Convenience method of separate getFastClockOnHour() and getFastClockOnMin()- Specified by:
getFastClockOffCombined
in interfaceLightControl
- Returns:
- Total combined Minute value
-
setFastClockControlSchedule
public void setFastClockControlSchedule(int onHour, int onMin, int offHour, int offMin)
Set a Fast Clock LightControl Schedule.- Specified by:
setFastClockControlSchedule
in interfaceLightControl
- Parameters:
onHour
- Hour the Light should switch OnonMin
- Minute the Light should switch OnoffHour
- Hour the Light should switch OffoffMin
- Minute the Light should switch Off *
-
getControlTurnoutName
public java.lang.String getControlTurnoutName()
Get the LightControl Turnout Name.- Specified by:
getControlTurnoutName
in interfaceLightControl
- Returns:
- The Turnout name
-
setControlTurnout
public void setControlTurnout(java.lang.String turnoutName)
Set the Turnout used by the Control Does NOT update any changelistenersA Turnout of this name is provided by the TurnoutManager on LightControl Initialisation
- Specified by:
setControlTurnout
in interfaceLightControl
- Parameters:
turnoutName
- The Turnout name
-
getControlTurnoutState
public int getControlTurnoutState()
Get the LightControl Turnout Name.- Specified by:
getControlTurnoutState
in interfaceLightControl
- Returns:
- The Turnout name
-
setControlTurnoutState
public void setControlTurnoutState(int state)
Set the Turnout State used by the Control Does NOT update any changelisteners- Specified by:
setControlTurnoutState
in interfaceLightControl
- Parameters:
state
- Turnout state to act on, eg. Turnout.CLOSED or Turnout.THROWN
-
getTimedSensorName
public java.lang.String getTimedSensorName()
Get the Timed On Trigger Sensor name.- Specified by:
getTimedSensorName
in interfaceLightControl
- Returns:
- The Sensor Name as set by #setControlTimedOnSensorName
-
getControlTimedOnSensorName
public java.lang.String getControlTimedOnSensorName()
Get the Timed On Trigger Sensor name.- Specified by:
getControlTimedOnSensorName
in interfaceLightControl
- Returns:
- If a Sensor is registered, returns the Sensor.getName() else the Sensor Name as set by #setControlTimedOnSensorName
-
setControlTimedOnSensorName
public void setControlTimedOnSensorName(java.lang.String sensorName)
Set Sensor used by the Timed On Control Does NOT update any changelisteners- Specified by:
setControlTimedOnSensorName
in interfaceLightControl
- Parameters:
sensorName
- the Sensor name to be used for the On Trigger
-
getTimedOnDuration
public int getTimedOnDuration()
Get the Timed On Control Duration- Specified by:
getTimedOnDuration
in interfaceLightControl
- Returns:
- duration in ms
-
setTimedOnDuration
public void setTimedOnDuration(int duration)
Set Duration used by the Timed On Control Does NOT update any changeListeners- Specified by:
setTimedOnDuration
in interfaceLightControl
- Parameters:
duration
- in ms following the Sensor On Trigger
-
getControlSensor2Name
public java.lang.String getControlSensor2Name()
Get the Second Sensor name. as used in the 2 Sensor Control Group.- Specified by:
getControlSensor2Name
in interfaceLightControl
- Returns:
- If a 2nd Sensor is registered, returns the Sensor.getName() else the 2nd Sensor Name as set by #setControlSensor2Name
-
setControlSensor2Name
public void setControlSensor2Name(java.lang.String sensorName)
Set Sensor 2 used by the 2 Sensor Control Does NOT update any changelisteners- Specified by:
setControlSensor2Name
in interfaceLightControl
- Parameters:
sensorName
- the Sensor 2 name
-
setParentLight
public void setParentLight(Light l)
Set Light to control Does NOT update any changelisteners- Specified by:
setParentLight
in interfaceLightControl
- Parameters:
l
- the Light object to control
-
getDescriptionText
public java.lang.String getDescriptionText(java.lang.String lightName)
Get a Textual Description eg. Light Control TestLight ON when TestSensor is Active eg. Light Control ON at 14:00, OFF at 15:00.- Specified by:
getDescriptionText
in interfaceLightControl
- Parameters:
lightName
- the Light Name, can be empty.- Returns:
- An I18N full-text description of thiscontrol
-
activateLightControl
public void activateLightControl()
Activates a Light Control by control type. This method tests the control type, and set up a control mechanism, appropriate for the control type. Adds PropertyChangeListeners to Sensors / Turnout / Fast Clock as necessary- Specified by:
activateLightControl
in interfaceLightControl
-
twoSensorChanged
protected void twoSensorChanged()
Internal routine for handling sensor changes for the 2 Sensor Control Type
-
onOffTimesFaulty
public boolean onOffTimesFaulty()
Check to see if we have the FastClock Follower has unique times for a single Light Control.Hour / Minute combination must be unique for each Light to avoid flicker.
- Specified by:
onOffTimesFaulty
in interfaceLightControl
- Returns:
- true if the clock on time equals the off time, otherwise false.
-
areFollowerTimesFaulty
public boolean areFollowerTimesFaulty(java.util.List<LightControl> compareList)
Check to see if we have the FastClock Follower has unique times for a single Light.Hour / Minute combination must be unique for each Light to avoid flicker.
- Specified by:
areFollowerTimesFaulty
in interfaceLightControl
- Parameters:
compareList
- the ArrayList of other Light Controls to compare against- Returns:
- true if there are multiple exact same times
-
deactivateLightControl
public void deactivateLightControl()
Deactivates a LightControl by control type. This method tests the control type, and deactivates the control mechanism, appropriate for the control type.- Specified by:
deactivateLightControl
in interfaceLightControl
-
-