jmri
Class DefaultConditional

java.lang.Object
  extended by jmri.AbstractNamedBean
      extended by jmri.DefaultConditional
All Implemented Interfaces:
Serializable, Conditional, NamedBean

public class DefaultConditional
extends AbstractNamedBean
implements Conditional, Serializable

Class providing the basic logic of the Conditional interface.

Author:
Dave Duchamp Copyright (C) 2007
See Also:
Serialized Form

Field Summary
protected  int[] actionData
           
protected  int[] actionDelay
           
protected  String[] actionName
           
protected  int[] actionOption
           
protected  String[] actionString
           
protected  int[] actionType
           
protected  int currentState
           
protected  ActionListener[] mDelayListener
           
protected  Timer[] mDelayTimer
           
protected  boolean[] mDelayTimerActive
           
protected  int numStateVariables
          Operational instance variables (not saved between runs)
protected  Sound[] snd
           
protected  String[] varDataString
           
protected  String[] varName
           
protected  int[] varNum1
           
protected  int[] varNum2
           
protected  int[] varOperator
          Persistant instance variables (saved between runs)
protected  boolean[] varTriggersCalculation
           
protected  int[] varType
           
 
Fields inherited from interface jmri.Conditional
ACTION_CANCEL_SENSOR_TIMERS, ACTION_CANCEL_TURNOUT_TIMERS, ACTION_CLEAR_SIGNAL_HELD, ACTION_COPY_MEMORY, ACTION_DELAYED_SENSOR, ACTION_DELAYED_TURNOUT, ACTION_DISABLE_LOGIX, ACTION_ENABLE_LOGIX, ACTION_LOCK_TURNOUT, ACTION_NONE, ACTION_OPTION_ON_CHANGE, ACTION_OPTION_ON_CHANGE_TO_FALSE, ACTION_OPTION_ON_CHANGE_TO_TRUE, ACTION_PLAY_SOUND, ACTION_RESET_DELAYED_SENSOR, ACTION_RESET_DELAYED_TURNOUT, ACTION_RUN_SCRIPT, ACTION_SET_FAST_CLOCK_TIME, ACTION_SET_LIGHT, ACTION_SET_MEMORY, ACTION_SET_SENSOR, ACTION_SET_SIGNAL_APPEARANCE, ACTION_SET_SIGNAL_DARK, ACTION_SET_SIGNAL_HELD, ACTION_SET_SIGNAL_LIT, ACTION_SET_TURNOUT, ACTION_START_FAST_CLOCK, ACTION_STOP_FAST_CLOCK, ACTION_TRIGGER_ROUTE, FALSE, MAX_STATE_VARIABLES, NUM_ACTION_TYPES, NUM_STATE_VARIABLE_TYPES, OPERATOR_AND, OPERATOR_AND_NOT, OPERATOR_NONE, OPERATOR_NOT, TRUE, TYPE_CONDITIONAL_FALSE, TYPE_CONDITIONAL_TRUE, TYPE_FAST_CLOCK_RANGE, TYPE_LIGHT_OFF, TYPE_LIGHT_ON, TYPE_MEMORY_EQUALS, TYPE_SENSOR_ACTIVE, TYPE_SENSOR_INACTIVE, TYPE_SIGNAL_HEAD_DARK, TYPE_SIGNAL_HEAD_FLASHGREEN, TYPE_SIGNAL_HEAD_FLASHRED, TYPE_SIGNAL_HEAD_FLASHYELLOW, TYPE_SIGNAL_HEAD_GREEN, TYPE_SIGNAL_HEAD_HELD, TYPE_SIGNAL_HEAD_LIT, TYPE_SIGNAL_HEAD_RED, TYPE_SIGNAL_HEAD_YELLOW, TYPE_TURNOUT_CLOSED, TYPE_TURNOUT_THROWN, UNKNOWN
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT
 
Constructor Summary
DefaultConditional(String systemName)
           
DefaultConditional(String systemName, String userName)
           
 
Method Summary
 int calculate(boolean logixEnabled)
          Calculate this Conditional, triggering either or both actions if the user specified conditions are met, and the Logix is enabled.
 void cancelSensorTimer(String sname)
          Stop a sensor timer if one is actively delaying setting of the specified sensor
 void cancelTurnoutTimer(String sname)
          Stop a turnout timer if one is actively delaying setting of the specified turnout
 void deleteAllStateVariables()
          Delete all State Variables from this Conditional
 void getAction(int[] opt, int[] delay, int[] type, String[] name, int[] data, String[] s)
          Get action parameters for action 1 and action 2
 int getNumStateVariables()
          Get number of State Variables for this Conditional
 int getState()
          State of the Conditional is returned.
 String getStateVariableDataString(int index)
          Provide access to data string of state variable by index Note: index ranges from 0 to numStateVariables-1
 String getStateVariableName(int index)
          Provide access to Name (user or system, whichever was specified) of state variable by index Note: index ranges from 0 to numStateVariables-1
 int getStateVariableNum1(int index)
          Provide access to number 1 data of state variable by index Note: index ranges from 0 to numStateVariables-1
 int getStateVariableNum2(int index)
          Provide access to number 2 data of state variable by index Note: index ranges from 0 to numStateVariables-1
 int getStateVariableOperator(int index)
          Provide access to operator of state variable by index Note: index ranges from 0 to numStateVariables-1
 void getStateVariables(int[] opern, int[] type, String[] name, String[] data, int[] num1, int[] num2, boolean[] triggersCalc)
          Get State Variables for this Conditional.
 boolean getStateVariableTriggersCalculation(int index)
          Provide access to triggers option of state variable by index Note: returns true if Logix should listen for changes in this state variable to trigger calculation (default) and returns false if the listener should be suppressed.
 int getStateVariableType(int index)
          Provide access to type of state variable by index Note: index ranges from 0 to numStateVariables-1
 void setAction(int[] opt, int[] delay, int[] type, String[] name, int[] data, String[] s)
          Set action parameters for action 1 and action 2
 void setState(int state)
          State of Conditional is set.
 boolean setStateVariables(int[] opern, int[] type, String[] name, String[] data, int[] num1, int[] num2, boolean[] triggersCalc, int numVariables)
          Set State Variables for this Conditional.
 
Methods inherited from class jmri.AbstractNamedBean
addPropertyChangeListener, dispose, firePropertyChange, getComment, getNumPropertyChangeListeners, getSystemName, getUserName, removePropertyChangeListener, setComment, setUserName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.Conditional
addPropertyChangeListener, dispose, removePropertyChangeListener
 
Methods inherited from interface jmri.NamedBean
getComment, getNumPropertyChangeListeners, getSystemName, getUserName, setComment, setUserName
 

Field Detail

varOperator

protected int[] varOperator
Persistant instance variables (saved between runs)


varType

protected int[] varType

varName

protected String[] varName

varDataString

protected String[] varDataString

varNum1

protected int[] varNum1

varNum2

protected int[] varNum2

varTriggersCalculation

protected boolean[] varTriggersCalculation

actionOption

protected int[] actionOption

actionDelay

protected int[] actionDelay

actionType

protected int[] actionType

actionName

protected String[] actionName

actionData

protected int[] actionData

actionString

protected String[] actionString

numStateVariables

protected int numStateVariables
Operational instance variables (not saved between runs)


currentState

protected int currentState

mDelayTimer

protected Timer[] mDelayTimer

mDelayListener

protected ActionListener[] mDelayListener

mDelayTimerActive

protected boolean[] mDelayTimerActive

snd

protected Sound[] snd
Constructor Detail

DefaultConditional

public DefaultConditional(String systemName,
                          String userName)

DefaultConditional

public DefaultConditional(String systemName)
Method Detail

getNumStateVariables

public int getNumStateVariables()
Get number of State Variables for this Conditional

Specified by:
getNumStateVariables in interface Conditional

setStateVariables

public boolean setStateVariables(int[] opern,
                                 int[] type,
                                 String[] name,
                                 String[] data,
                                 int[] num1,
                                 int[] num2,
                                 boolean[] triggersCalc,
                                 int numVariables)
Set State Variables for this Conditional. Each state variable will evaluate either True or False when this Conditional is calculated.

Returns true if state variables were successfully set, otherwise false.

This method should only be called by LogixTableAction. It assumes that all information has been validated.

Specified by:
setStateVariables in interface Conditional
Parameters:
opern - array of operator values, e.g. OPERATOR_NOT, OPERATOR_AND, etc
type - array of type variables, e.g. TYPE_SENSOR_ACTIVE, etc
name - array of system or user names for NamedBeans being referenced
numVariables - the number of variables being set, also the length of the parameter arrays

getStateVariables

public void getStateVariables(int[] opern,
                              int[] type,
                              String[] name,
                              String[] data,
                              int[] num1,
                              int[] num2,
                              boolean[] triggersCalc)
Get State Variables for this Conditional.

Returns state variables for this Conditional in supplied arrays.

This method should only be called by LogixTableAction and methods to save this conditional to disk in a panel file.

Specified by:
getStateVariables in interface Conditional

getStateVariableOperator

public int getStateVariableOperator(int index)
Provide access to operator of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableOperator in interface Conditional

getStateVariableType

public int getStateVariableType(int index)
Provide access to type of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableType in interface Conditional

getStateVariableName

public String getStateVariableName(int index)
Provide access to Name (user or system, whichever was specified) of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableName in interface Conditional

getStateVariableDataString

public String getStateVariableDataString(int index)
Provide access to data string of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableDataString in interface Conditional

getStateVariableNum1

public int getStateVariableNum1(int index)
Provide access to number 1 data of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableNum1 in interface Conditional

getStateVariableNum2

public int getStateVariableNum2(int index)
Provide access to number 2 data of state variable by index Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableNum2 in interface Conditional

getStateVariableTriggersCalculation

public boolean getStateVariableTriggersCalculation(int index)
Provide access to triggers option of state variable by index Note: returns true if Logix should listen for changes in this state variable to trigger calculation (default) and returns false if the listener should be suppressed. Note: index ranges from 0 to numStateVariables-1

Specified by:
getStateVariableTriggersCalculation in interface Conditional

deleteAllStateVariables

public void deleteAllStateVariables()
Delete all State Variables from this Conditional

Specified by:
deleteAllStateVariables in interface Conditional

setAction

public void setAction(int[] opt,
                      int[] delay,
                      int[] type,
                      String[] name,
                      int[] data,
                      String[] s)
Set action parameters for action 1 and action 2

Specified by:
setAction in interface Conditional

getAction

public void getAction(int[] opt,
                      int[] delay,
                      int[] type,
                      String[] name,
                      int[] data,
                      String[] s)
Get action parameters for action 1 and action 2

Specified by:
getAction in interface Conditional

calculate

public int calculate(boolean logixEnabled)
Calculate this Conditional, triggering either or both actions if the user specified conditions are met, and the Logix is enabled. Note: if any state variable evaluates false, the Conditional calculates to false. If all state variables evaluate true, the Conditional calculates to true. So, the first false state variable results in a false state for the conditional. Sets the state of the conditional. Returns the calculated state of this Conditional.

Specified by:
calculate in interface Conditional

cancelSensorTimer

public void cancelSensorTimer(String sname)
Stop a sensor timer if one is actively delaying setting of the specified sensor

Specified by:
cancelSensorTimer in interface Conditional

cancelTurnoutTimer

public void cancelTurnoutTimer(String sname)
Stop a turnout timer if one is actively delaying setting of the specified turnout

Specified by:
cancelTurnoutTimer in interface Conditional

getState

public int getState()
State of the Conditional is returned.

Specified by:
getState in interface Conditional
Specified by:
getState in interface NamedBean
Returns:
state value

setState

public void setState(int state)
State of Conditional is set. Not really public for Conditionals. The state of a Conditional is only changed by its calculate method, so the state is really a read-only bound property.

Specified by:
setState in interface Conditional
Specified by:
setState in interface NamedBean


Copyright © 1997 - 2008 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: SourceForge_Logo