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 class
SpeedTableVarValue.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) boolean
isReading
(package private) boolean
isWriting
(package private) boolean
mfx
(package private) javax.swing.BoundedRangeModel[]
models
(package private) int
numCvs
(package private) int
nValues
(package private) boolean
onlyChanges
(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 void
dispose()
Dispose of the object.(package private) void
doForceStraight(java.awt.event.ActionEvent e)
Set the values to a straight line from _min to _max(package private) void
doLogCurve(java.awt.event.ActionEvent e)
Set a log curve(package private) void
doMatchEnds(java.awt.event.ActionEvent e)
Set the values to a straight line from existing ends(package private) void
doRatioCurve(java.awt.event.ActionEvent e)
Set a constant ratio curve(package private) void
doShiftLeft(java.awt.event.ActionEvent e)
Shift the curve one CV to left.(package private) void
doShiftRight(java.awt.event.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.java.awt.Component
getCommonRep()
Get a display representationObject
of this variable.int
getIntValue()
Get the value as a single integer.java.awt.Component
getNewRep(java.lang.String format)
Creates a newObject
representation for display purposes, using the specified format.AbstractValue.ValueState
getState()
java.lang.Object
getValueObject()
java.lang.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(java.beans.PropertyChangeEvent e)
java.lang.Object
rangeVal()
Gets a (usually text) description of the variable type and range.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(java.awt.Color c)
Method to handle color changes for states.void
setCvState(AbstractValue.ValueState state)
Notify the connected CVs of a state change from abovevoid
setIntValue(int i)
Set the value from a single number.(package private) void
setModel(int i, int value)
void
setValue(int value)
void
setValue(java.lang.String value)
Set value from a String value.void
stateChanged(javax.swing.event.ChangeEvent e)
Called for new values of a slider.CvValue[]
usesCVs()
Provide access to CVs used by this Variable.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, 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:VariableValue
Gets a (usually text) description of the variable type and range.- Specified by:
rangeVal
in classVariableValue
- Returns:
- description of the variable type and range
-
usesCVs
public CvValue[] usesCVs()
Description copied from class:VariableValue
Provide access to CVs used by this Variable.- Specified by:
usesCVs
in 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:
stateChanged
in 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:
getState
in classVariableValue
- Returns:
- the current state of the Variable
-
getValueString
public java.lang.String getValueString()
- Specified by:
getValueString
in 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:
setValue
in classVariableValue
- Parameters:
value
- the String value to set
-
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 classVariableValue
- Parameters:
i
- the integer value to set
-
getIntValue
public int getIntValue()
Description copied from class:VariableValue
Get 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:
getIntValue
in classVariableValue
- Returns:
- the value as an integer
-
getValueObject
public java.lang.Object getValueObject()
- Specified by:
getValueObject
in classVariableValue
- Returns:
- Value as a native-form Object
-
getCommonRep
public java.awt.Component getCommonRep()
Description copied from class:VariableValue
Get a display representationObject
of this variable.
The actual stored value of a variable is not the most interesting thing. Instead, you usually get anObject
representation 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:
getCommonRep
in classVariableValue
- Returns:
- the
Object
representation for display purposes
-
setValue
public void setValue(int value)
-
setColor
void setColor(java.awt.Color c)
Description copied from class:AbstractValue
Method to handle color changes for states.- Specified by:
setColor
in classAbstractValue
- Parameters:
c
- the desired colour
-
getNewRep
public java.awt.Component getNewRep(java.lang.String format)
Description copied from class:VariableValue
Creates a newObject
representation for display purposes, using the specified format.- Specified by:
getNewRep
in classVariableValue
- Parameters:
format
- a name representing- Returns:
- an
Object
representation 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:
setCvState
in classVariableValue
- Parameters:
state
- the new state to set
-
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 classVariableValue
- Returns:
- true if Variable is "changed"
- 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 classVariableValue
- 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 classVariableValue
- See Also:
VariableValue.isChanged()
-
readAll
public void readAll()
Description copied from class:VariableValue
Always read the contents of this Variable.- Specified by:
readAll
in classVariableValue
-
writeAll
public void writeAll()
Description copied from class:VariableValue
Always write the contents of this Variable.- Specified by:
writeAll
in classVariableValue
-
readNext
void readNext()
-
writeNext
void writeNext()
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Specified by:
propertyChange
in classVariableValue
-
dispose
public void dispose()
Description copied from class:VariableValue
Dispose of the object.- Specified by:
dispose
in classVariableValue
-
-