Class SpeedTableVarValue
- All Implemented Interfaces:
PropertyChangeListener,EventListener,ChangeListener
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 ClassesNested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState -
Field Summary
FieldsModifier and TypeFieldDescription(package private) Color(package private) int(package private) int(package private) int(package private) String[](package private) boolean(package private) boolean(package private) boolean(package private) BoundedRangeModel[](package private) int(package private) int(package private) booleanFields inherited from class jmri.jmrit.symbolicprog.VariableValue
_cvMap, _status, _tooltipTextFields inherited from class jmri.jmrit.symbolicprog.AbstractValue
prop -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionvoiddispose()Dispose of the object.(package private) voidSet the values to a straight line from _min to _max(package private) voidSet a log curve(package private) voidSet the values to a straight line from existing ends(package private) voidSet a constant ratio curve(package private) voidShift the curve one CV to left.(package private) voidShift 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.Get a display representationObjectof this variable.intGet the value as a single integer.Creates a newObjectrepresentation for display purposes, using the specified format.getState()(package private) voidbooleanDetermine 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) voidrangeVal()Gets a (usually text) description of the variable type and range.voidreadAll()Always read the contents of this Variable.voidRead the contents of this Variable if it's in a state that indicates it was "changed".(package private) voidreadNext()(package private) voidMethod to handle color changes for states.voidNotify 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) voidSet value from a String value.voidCalled for new values of a slider.CvValue[]usesCVs()Provide access to CVs used by this Variable.voidwriteAll()Always write the contents of this Variable.voidWrite the contents of this Variable if it's in a state that indicates it was "changed".(package private) voidMethods 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, updateRepresentationMethods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable
-
Field Details
-
Constructor Details
-
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".- 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 Details
-
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
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
Called for new values of a slider.Sets the CV(s) as needed.
- Specified by:
stateChangedin interfaceChangeListener
-
setModel
-
forceMonotonic
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
If there are fixed points specified, set linear step settings to them.- Parameters:
modifiedStepIndex- Index of requested break point
-
matchPointsLeft
-
matchPointsRight
-
getState
- Overrides:
getStatein classVariableValue- Returns:
- the current state of the Variable
-
getValueString
- Specified by:
getValueStringin classVariableValue- Returns:
- String that can (usually) be interpreted as an integer
-
setValue
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
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
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
- Specified by:
getValueObjectin classVariableValue- Returns:
- Value as a native-form Object
-
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
-
setColor
Description copied from class:AbstractValueMethod to handle color changes for states.- Specified by:
setColorin classAbstractValue- Parameters:
c- the desired colour
-
getNewRep
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
Set the values to a straight line from _min to _max- Parameters:
e- Event triggering this operation
-
doMatchEnds
Set the values to a straight line from existing ends- Parameters:
e- Event triggering this operation
-
doRatioCurve
Set a constant ratio curve- Parameters:
e- Event triggering this operation
-
doLogCurve
Set a log curve- Parameters:
e- Event triggering this operation
-
doShiftLeft
Shift the curve one CV to left. The last entry is left unchanged.- Parameters:
e- Event triggering this operation
-
doShiftRight
Shift the curve one CV to right. The first entry is left unchanged.- Parameters:
e- Event triggering this operation
-
setCvState
Notify the connected CVs of a state change from above- Specified by:
setCvStatein classVariableValue- Parameters:
state- the new state to set
-
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:
-
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:
-
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:
-
readAll
Description copied from class:VariableValueAlways read the contents of this Variable.- Specified by:
readAllin classVariableValue
-
writeAll
Description copied from class:VariableValueAlways write the contents of this Variable.- Specified by:
writeAllin classVariableValue
-
readNext
void readNext() -
writeNext
void writeNext() -
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener- Specified by:
propertyChangein classVariableValue
-
dispose
Description copied from class:VariableValueDispose of the object.- Specified by:
disposein classVariableValue
-