jmri.jmrit.symbolicprog
Class SpeedTableVarValue

Show UML class diagram
java.lang.Object
  extended by jmri.jmrit.symbolicprog.AbstractValue
      extended by jmri.jmrit.symbolicprog.VariableValue
          extended by jmri.jmrit.symbolicprog.SpeedTableVarValue
All Implemented Interfaces:
PropertyChangeListener, EventListener, ChangeListener

public class SpeedTableVarValue
extends VariableValue
implements PropertyChangeListener, ChangeListener

Represent an entire speed table as a single Variable.

This presents as a set of vertically oriented sliders, with numeric values above them. That it turn is done using VarSlider and DecVariableValue objects respectively. VarSlider is an interior class to color a JSlider by state. The respective VarSlider and DecVariableValue communicate through their underlying CV objects. Changes to CV Values are listened to by this class, which updates the model objects for the VarSliders; the DecVariableValues listen directly.

Color (hence state) of individual sliders (hence CVs) are directly coupled to the state of those CVs.

The state of the entire variable has to be a composite of all the sliders, hence CVs. The mapping is (in order):

A similar pattern is used for a read or write request. Write writes them all; Read reads any that aren't READ or WRITTEN.

Speed tables can have different numbers of entries; 28 is the default, and also the maximum.

The NMRA specification says that speed table entries cannot be non-monotonic (e.g. cannot decrease when moving from lower to higher CV numbers). In earlier versions of the code, this was enforced any time a value was changed (for any reason). This caused a problem when CVs were read that were non-monotonic: That value was read, causing lower CVs to be made consistent, a change in their value which changed their state, so they were read again. To avoid this, the class now only enforces non-monotonicity when the slider is adjusted.

_value is a holdover from the LongAddrVariableValue, which this was copied from; it should be removed.


Nested Class Summary
 class SpeedTableVarValue.VarSlider
           
 
Field Summary
(package private)  Color _defaultColor
           
(package private)  int _max
           
(package private)  int _min
           
(package private)  int _range
           
(package private)  String[] cvList
           
(package private)  boolean isReading
           
(package private)  boolean isWriting
           
(package private) static org.slf4j.Logger log
           
(package private)  boolean mfx
           
(package private)  BoundedRangeModel[] models
           
(package private)  int numCvs
           
(package private)  int nValues
           
(package private)  boolean onlyChanges
           
(package private)  List<JCheckBox> stepCheckBoxes
           
(package private) static String VHIGH_CV
           
(package private) static String VSTART_CV
           
 
Fields inherited from class jmri.jmrit.symbolicprog.VariableValue
_cvMap, _status, _tooltipText
 
Fields inherited from class jmri.jmrit.symbolicprog.AbstractValue
COLOR_DIFF, COLOR_EDITED, COLOR_FROMFILE, COLOR_READ, COLOR_SAME, COLOR_STORED, COLOR_UNKNOWN, DIFF, EDITED, FROMFILE, prop, READ, SAME, STORED, UNKNOWN
 
Constructor Summary
SpeedTableVarValue()
          Create a null object.
SpeedTableVarValue(String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cvNum, String mask, int minVal, int maxVal, HashMap<String,CvValue> v, JLabel status, String stdname, int entries, boolean mfxFlag)
          Create the object with a "standard format ctor".
 
Method Summary
 void dispose()
           
(package private)  void doForceStraight(ActionEvent e)
          Set the values to a straight line from _min to _max
(package private)  void doLogCurve(ActionEvent e)
          Set a log curve
(package private)  void doMatchEnds(ActionEvent e)
          Set the values to a straight line from existing ends
(package private)  void doRatioCurve(ActionEvent e)
          Set a constant ratio curve
(package private)  void doShiftLeft(ActionEvent e)
          Shift the curve one CV to left.
(package private)  void doShiftRight(ActionEvent e)
          Shift the curve one CV to right.
(package private)  void forceMonotonic(int modifiedStepIndex, int value)
          Check entries on either side to see if they are set monotonically.
 Component getCommonRep()
           
 int getIntValue()
          Get the value as a single number.
 Component getNewRep(String format)
           
 int getState()
           
 Object getValueObject()
           
 String getValueString()
           
(package private)  void initStepCheckBoxes()
           
 boolean isChanged()
          Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.
(package private)  void matchPoints(int modifiedStepIndex)
          If there are fixed points specified, set linear step settings to them.
(package private)  void matchPointsLeft(int modifiedStepIndex)
           
(package private)  void matchPointsRight(int modifiedStepIndex)
           
 void propertyChange(PropertyChangeEvent e)
           
 Object rangeVal()
           
 void readAll()
          Always read the contents of this Variable
 void readChanges()
          Read the contents of this Variable if it's in a state that indicates it was "changed"
(package private)  void readNext()
           
(package private)  void setColor(Color c)
           
 void setCvState(int state)
          Notify the connected CVs of a state change from above
 void setIntValue(int i)
          Set the value from a single number.
(package private)  void setModel(int i, int value)
           
 void setValue(int value)
           
 void stateChanged(ChangeEvent e)
          Called for new values of a slider.
 CvValue[] usesCVs()
          Provide access to CVs referenced by this operation
 void writeAll()
          Always write the contents of this Variable
 void writeChanges()
          Write the contents of this Variable if it's in a state that indicates it was "changed"
(package private)  void writeNext()
           
 
Methods inherited from class jmri.jmrit.symbolicprog.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvDescription, getCvName, getCvNum, getInfoOnly, getMask, getOpsOnly, getReadOnly, getTextValue, getWriteOnly, isBusy, isToRead, isToWrite, item, label, maskVal, newValue, offsetVal, setBusy, setState, setToolTipText, setToRead, setToWrite, updatedTextField, updateRepresentation
 
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable, stateNameFromValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VSTART_CV

static final String VSTART_CV
See Also:
Constant Field Values

VHIGH_CV

static final String VHIGH_CV
See Also:
Constant Field Values

nValues

int nValues

numCvs

int numCvs

cvList

String[] cvList

models

BoundedRangeModel[] models

_min

int _min

_max

int _max

_range

int _range

mfx

boolean mfx

stepCheckBoxes

List<JCheckBox> stepCheckBoxes

_defaultColor

Color _defaultColor

isReading

boolean isReading

isWriting

boolean isWriting

onlyChanges

boolean onlyChanges

log

static org.slf4j.Logger log
Constructor Detail

SpeedTableVarValue

public SpeedTableVarValue(String name,
                          String comment,
                          String cvName,
                          boolean readOnly,
                          boolean infoOnly,
                          boolean writeOnly,
                          boolean opsOnly,
                          String cvNum,
                          String mask,
                          int minVal,
                          int maxVal,
                          HashMap<String,CvValue> v,
                          JLabel status,
                          String stdname,
                          int entries,
                          boolean mfxFlag)
Create the object with a "standard format ctor".


SpeedTableVarValue

public SpeedTableVarValue()
Create a null object. Normally only used for tests and to pre-load classes.

Method Detail

rangeVal

public Object rangeVal()
Specified by:
rangeVal in class VariableValue

usesCVs

public CvValue[] usesCVs()
Description copied from class: VariableValue
Provide access to CVs referenced by this operation

Specified by:
usesCVs in class VariableValue

stateChanged

public void stateChanged(ChangeEvent e)
Called for new values of a slider.

Sets the CV(s) as needed.

Specified by:
stateChanged in interface ChangeListener
Parameters:
e -

setModel

void setModel(int i,
              int value)

forceMonotonic

void forceMonotonic(int modifiedStepIndex,
                    int value)
Check entries on either side to see if they are set monotonically. If not, adjust.

Parameters:
modifiedStepIndex - number (index) of the entry
value - new value

matchPoints

void matchPoints(int modifiedStepIndex)
If there are fixed points specified, set linear step settings to them.


matchPointsLeft

void matchPointsLeft(int modifiedStepIndex)

matchPointsRight

void matchPointsRight(int modifiedStepIndex)

getState

public int getState()
Overrides:
getState in class VariableValue

getValueString

public String getValueString()
Specified by:
getValueString in class VariableValue
Returns:
String that can (usually) be interpreted as an integer

setIntValue

public void setIntValue(int i)
Description copied from class: VariableValue
Set the value from a single number. In some cases, e.g. speed tables, this will result in complex behavior, where setIntValue(getIntValue()) results in something unexpected.

Specified by:
setIntValue in class VariableValue

getIntValue

public int getIntValue()
Description copied from class: VariableValue
Get the value as a single number. In some cases, e.g. speed tables, this will result in complex behavior, where setIntValue(getIntValue()) results in something unexpected.

Specified by:
getIntValue in class VariableValue

getValueObject

public Object getValueObject()
Specified by:
getValueObject in class VariableValue
Returns:
Value as a native-form Object

getCommonRep

public Component getCommonRep()
Specified by:
getCommonRep in class VariableValue

setValue

public void setValue(int value)

setColor

void setColor(Color c)
Specified by:
setColor in class AbstractValue

getNewRep

public Component getNewRep(String format)
Specified by:
getNewRep in class VariableValue

initStepCheckBoxes

void initStepCheckBoxes()

doForceStraight

void doForceStraight(ActionEvent e)
Set the values to a straight line from _min to _max


doMatchEnds

void doMatchEnds(ActionEvent e)
Set the values to a straight line from existing ends


doRatioCurve

void doRatioCurve(ActionEvent e)
Set a constant ratio curve


doLogCurve

void doLogCurve(ActionEvent e)
Set a log curve


doShiftLeft

void doShiftLeft(ActionEvent e)
Shift the curve one CV to left. The last entry is left unchanged.


doShiftRight

void doShiftRight(ActionEvent e)
Shift the curve one CV to right. The first entry is left unchanged.


setCvState

public void setCvState(int state)
Notify the connected CVs of a state change from above

Specified by:
setCvState in class VariableValue
Parameters:
state -

isChanged

public boolean isChanged()
Description copied from class: VariableValue
Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.

Specified by:
isChanged in class VariableValue
See Also:
VariableValue.considerChanged(jmri.jmrit.symbolicprog.CvValue)

readChanges

public void readChanges()
Description copied from class: VariableValue
Read the contents of this Variable if it's in a state that indicates it was "changed"

Specified by:
readChanges in class VariableValue
See Also:
VariableValue.isChanged()

writeChanges

public void writeChanges()
Description copied from class: VariableValue
Write the contents of this Variable if it's in a state that indicates it was "changed"

Specified by:
writeChanges in class VariableValue
See Also:
VariableValue.isChanged()

readAll

public void readAll()
Description copied from class: VariableValue
Always read the contents of this Variable

Specified by:
readAll in class VariableValue

writeAll

public void writeAll()
Description copied from class: VariableValue
Always write the contents of this Variable

Specified by:
writeAll in class VariableValue

readNext

void readNext()

writeNext

void writeNext()

propertyChange

public void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener
Specified by:
propertyChange in class VariableValue

dispose

public void dispose()
Specified by:
dispose in class VariableValue


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