Class SpeedTableVarValue
- java.lang.Object
-
- jmri.jmrit.symbolicprog.AbstractValue
-
- jmri.jmrit.symbolicprog.VariableValue
-
- jmri.jmrit.symbolicprog.SpeedTableVarValue
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,javax.swing.event.ChangeListener
public class SpeedTableVarValue extends VariableValue implements javax.swing.event.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):
- If any CVs are UNKNOWN, its UNKNOWN..
- If not, and any are EDITED, its EDITED.
- If not, and any are FROMFILE, its FROMFILE.
- If not, and any are READ, its READ.
- If not, and any are STORED, its STORED.
- And if we get to here, something awful has happened.
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
Nested Classes Modifier and Type Class Description classSpeedTableVarValue.VarSlider-
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.awt.Color_defaultColor(package private) int_max(package private) int_min(package private) int_range(package private) java.lang.String[]cvList(package private) booleanisReading(package private) booleanisWriting(package private) booleanmfx(package private) javax.swing.BoundedRangeModel[]models(package private) intnumCvs(package private) intnValues(package private) booleanonlyChanges(package private) java.util.List<javax.swing.JCheckBox>stepCheckBoxes-
Fields inherited from class jmri.jmrit.symbolicprog.VariableValue
_cvMap, _status, _tooltipText
-
Fields inherited from class jmri.jmrit.symbolicprog.AbstractValue
prop
-
-
Constructor Summary
Constructors Constructor Description SpeedTableVarValue()Create a null object.SpeedTableVarValue(java.lang.String name, java.lang.String comment, java.lang.String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String cvNum, java.lang.String mask, int minVal, int maxVal, java.util.HashMap<java.lang.String,CvValue> v, javax.swing.JLabel status, java.lang.String stdname, int entries, boolean mfxFlag)Create the object with a "standard format ctor".
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Dispose of the object.(package private) voiddoForceStraight(java.awt.event.ActionEvent e)Set the values to a straight line from _min to _max(package private) voiddoLogCurve(java.awt.event.ActionEvent e)Set a log curve(package private) voiddoMatchEnds(java.awt.event.ActionEvent e)Set the values to a straight line from existing ends(package private) voiddoRatioCurve(java.awt.event.ActionEvent e)Set a constant ratio curve(package private) voiddoShiftLeft(java.awt.event.ActionEvent e)Shift the curve one CV to left.(package private) voiddoShiftRight(java.awt.event.ActionEvent e)Shift the curve one CV to right.(package private) voidforceMonotonic(int modifiedStepIndex, int value)Check entries on either side to see if they are set monotonically.java.awt.ComponentgetCommonRep()Get a display representationObjectof this variable.intgetIntValue()Get the value as a single integer.java.awt.ComponentgetNewRep(java.lang.String format)Creates a newObjectrepresentation for display purposes, using the specified format.AbstractValue.ValueStategetState()java.lang.ObjectgetValueObject()java.lang.StringgetValueString()(package private) voidinitStepCheckBoxes()booleanisChanged()Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.(package private) voidmatchPoints(int modifiedStepIndex)If there are fixed points specified, set linear step settings to them.(package private) voidmatchPointsLeft(int modifiedStepIndex)(package private) voidmatchPointsRight(int modifiedStepIndex)voidpropertyChange(java.beans.PropertyChangeEvent e)java.lang.ObjectrangeVal()Gets a (usually text) description of the variable type and range.voidreadAll()Always read the contents of this Variable.voidreadChanges()Read the contents of this Variable if it's in a state that indicates it was "changed".(package private) voidreadNext()(package private) voidsetColor(java.awt.Color c)Method to handle color changes for states.voidsetCvState(AbstractValue.ValueState state)Notify the connected CVs of a state change from abovevoidsetIntValue(int i)Set the value from a single number.(package private) voidsetModel(int i, int value)voidsetValue(int value)voidsetValue(java.lang.String value)Set value from a String value.voidstateChanged(javax.swing.event.ChangeEvent e)Called for new values of a slider.CvValue[]usesCVs()Provide access to CVs used by this Variable.voidwriteAll()Always write the contents of this Variable.voidwriteChanges()Write the contents of this Variable if it's in a state that indicates it was "changed".(package private) voidwriteNext()-
Methods inherited from class jmri.jmrit.symbolicprog.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvDescription, getCvName, getCvNum, getInfoOnly, getLongValue, getMask, getMaxMask, getOpsOnly, getReadOnly, getTextValue, getValueInCV, getWriteOnly, isBitMask, isBusy, isToRead, isToWrite, item, label, maskValAsInt, offsetVal, setBusy, setState, setToolTipText, setToRead, setToWrite, setValueInCV, simplifyMask, updatedTextField, updateRepresentation
-
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable
-
-
-
-
Field Detail
-
nValues
int nValues
-
numCvs
int numCvs
-
cvList
java.lang.String[] cvList
-
models
javax.swing.BoundedRangeModel[] models
-
_min
int _min
-
_max
int _max
-
_range
int _range
-
mfx
boolean mfx
-
stepCheckBoxes
java.util.List<javax.swing.JCheckBox> stepCheckBoxes
-
_defaultColor
java.awt.Color _defaultColor
-
isReading
boolean isReading
-
isWriting
boolean isWriting
-
onlyChanges
boolean onlyChanges
-
-
Constructor Detail
-
SpeedTableVarValue
public SpeedTableVarValue(java.lang.String name, java.lang.String comment, java.lang.String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String cvNum, java.lang.String mask, int minVal, int maxVal, java.util.HashMap<java.lang.String,CvValue> v, javax.swing.JLabel status, java.lang.String stdname, int entries, boolean mfxFlag)
Create the object with a "standard format ctor".- Parameters:
name- name.comment- comment.cvName- cv name.readOnly- true if read only, else false.infoOnly- true if info only, else false.writeOnly- true if write only, else false.opsOnly- true if ops only, else false.cvNum- cv number.mask- cv mask.minVal- minimum value.maxVal- maximum value.v- hashmap of string and cv value.status- status label.stdname- std name.entries- number entries.mfxFlag- set mx flag true or false.
-
SpeedTableVarValue
public SpeedTableVarValue()
Create a null object. Normally only used for tests and to pre-load classes.
-
-
Method Detail
-
rangeVal
public java.lang.Object rangeVal()
Description copied from class:VariableValueGets a (usually text) description of the variable type and range.- Specified by:
rangeValin classVariableValue- Returns:
- description of the variable type and range
-
usesCVs
public CvValue[] usesCVs()
Description copied from class:VariableValueProvide access to CVs used by this Variable.- Specified by:
usesCVsin classVariableValue- Returns:
- an array of CVs used by this Variable
-
stateChanged
public void stateChanged(javax.swing.event.ChangeEvent e)
Called for new values of a slider.Sets the CV(s) as needed.
- Specified by:
stateChangedin interfacejavax.swing.event.ChangeListener
-
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 entryvalue- new value
-
matchPoints
void matchPoints(int modifiedStepIndex)
If there are fixed points specified, set linear step settings to them.- Parameters:
modifiedStepIndex- Index of requested break point
-
matchPointsLeft
void matchPointsLeft(int modifiedStepIndex)
-
matchPointsRight
void matchPointsRight(int modifiedStepIndex)
-
getState
public AbstractValue.ValueState getState()
- Overrides:
getStatein classVariableValue- Returns:
- the current state of the Variable
-
getValueString
public java.lang.String getValueString()
- Specified by:
getValueStringin classVariableValue- Returns:
- String that can (usually) be interpreted as an integer
-
setValue
public void setValue(java.lang.String value)
Set value from a String value.Requires the format written by getValueString, not implemented yet
- Overrides:
setValuein classVariableValue- Parameters:
value- the String value to set
-
setIntValue
public void setIntValue(int i)
Description copied from class:VariableValueSet 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:
setIntValuein classVariableValue- Parameters:
i- the integer value to set
-
getIntValue
public int getIntValue()
Description copied from class:VariableValueGet the value as a single integer.In some cases, e.g. speed tables, this will result in complex behavior, where setIntValue(getIntValue()) results in something unexpected.
- Specified by:
getIntValuein classVariableValue- Returns:
- the value as an integer
-
getValueObject
public java.lang.Object getValueObject()
- Specified by:
getValueObjectin classVariableValue- Returns:
- Value as a native-form Object
-
getCommonRep
public java.awt.Component getCommonRep()
Description copied from class:VariableValueGet a display representationObjectof this variable.
The actual stored value of a variable is not the most interesting thing. Instead, you usually get anObjectrepresentation for display in a table, etc. Modification of the state of that object then gets reflected back, causing the underlying CV objects to change.- Specified by:
getCommonRepin classVariableValue- Returns:
- the
Objectrepresentation for display purposes
-
setValue
public void setValue(int value)
-
setColor
void setColor(java.awt.Color c)
Description copied from class:AbstractValueMethod to handle color changes for states.- Specified by:
setColorin classAbstractValue- Parameters:
c- the desired colour
-
getNewRep
public java.awt.Component getNewRep(java.lang.String format)
Description copied from class:VariableValueCreates a newObjectrepresentation for display purposes, using the specified format.- Specified by:
getNewRepin classVariableValue- Parameters:
format- a name representing- Returns:
- an
Objectrepresentation for display purposes
-
initStepCheckBoxes
void initStepCheckBoxes()
-
doForceStraight
void doForceStraight(java.awt.event.ActionEvent e)
Set the values to a straight line from _min to _max- Parameters:
e- Event triggering this operation
-
doMatchEnds
void doMatchEnds(java.awt.event.ActionEvent e)
Set the values to a straight line from existing ends- Parameters:
e- Event triggering this operation
-
doRatioCurve
void doRatioCurve(java.awt.event.ActionEvent e)
Set a constant ratio curve- Parameters:
e- Event triggering this operation
-
doLogCurve
void doLogCurve(java.awt.event.ActionEvent e)
Set a log curve- Parameters:
e- Event triggering this operation
-
doShiftLeft
void doShiftLeft(java.awt.event.ActionEvent e)
Shift the curve one CV to left. The last entry is left unchanged.- Parameters:
e- Event triggering this operation
-
doShiftRight
void doShiftRight(java.awt.event.ActionEvent e)
Shift the curve one CV to right. The first entry is left unchanged.- Parameters:
e- Event triggering this operation
-
setCvState
public void setCvState(AbstractValue.ValueState state)
Notify the connected CVs of a state change from above- Specified by:
setCvStatein classVariableValue- Parameters:
state- the new state to set
-
isChanged
public boolean isChanged()
Description copied from class:VariableValueDetermine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.- Specified by:
isChangedin classVariableValue- Returns:
- true if Variable is "changed"
- See Also:
VariableValue.considerChanged(jmri.jmrit.symbolicprog.CvValue)
-
readChanges
public void readChanges()
Description copied from class:VariableValueRead the contents of this Variable if it's in a state that indicates it was "changed".- Specified by:
readChangesin classVariableValue- See Also:
VariableValue.isChanged()
-
writeChanges
public void writeChanges()
Description copied from class:VariableValueWrite the contents of this Variable if it's in a state that indicates it was "changed".- Specified by:
writeChangesin classVariableValue- See Also:
VariableValue.isChanged()
-
readAll
public void readAll()
Description copied from class:VariableValueAlways read the contents of this Variable.- Specified by:
readAllin classVariableValue
-
writeAll
public void writeAll()
Description copied from class:VariableValueAlways write the contents of this Variable.- Specified by:
writeAllin classVariableValue
-
readNext
void readNext()
-
writeNext
void writeNext()
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Specified by:
propertyChangein classVariableValue
-
dispose
public void dispose()
Description copied from class:VariableValueDispose of the object.- Specified by:
disposein classVariableValue
-
-