Package jmri.jmrit.symbolicprog
Class SplitEnumVariableValue
java.lang.Object
jmri.jmrit.symbolicprog.AbstractValue
jmri.jmrit.symbolicprog.VariableValue
jmri.jmrit.symbolicprog.SplitEnumVariableValue
- All Implemented Interfaces:
ActionListener,FocusListener,PropertyChangeListener,EventListener
Extends VariableValue to represent a variable split across multiple CVs with
values from a pre-selected range each of which is associated with a text name
(aka, a drop down)
The
It is possible to assign a specific mask for each CV by providing a space separated list of masks, starting with the lowest, and matching the order of CVs
The original use was for addresses of stationary (accessory) decoders.
The original version only allowed two CVs, with the second CV specified by the attributes
The preferred technique is now to specify all CVs in the
Optional attributes
The
mask attribute represents the part of the value that's present in
each CV; higher-order bits are loaded to subsequent CVs.It is possible to assign a specific mask for each CV by providing a space separated list of masks, starting with the lowest, and matching the order of CVs
The original use was for addresses of stationary (accessory) decoders.
The original version only allowed two CVs, with the second CV specified by the attributes
highCV and upperMask.
The preferred technique is now to specify all CVs in the
CV attribute
alone, as documented at expandCvList(String).
Optional attributes
factor and offset are applied when going
from the variable value to the CV values, or vice-versa:
Value to put in CVs = ((value in text field) -offset)/factorValue to put in text field = ((value in CVs) *factor) +offset
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classClass to hold CV parameters for CVs used.(package private) static classstatic classNested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState -
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) String(package private) Color(package private) boolean(package private) String(package private) String[](package private) long(package private) long(package private) String(package private) int(package private) String(package private) int(package private) static final int(package private) int(package private) int(package private) List<SplitEnumVariableValue.CvItem>(package private) static final int(package private) static final long(package private) int(package private) int(package private) String(package private) String(package private) static final intint(package private) Deque<DefaultMutableTreeNode>(package private) static final intFields inherited from class jmri.jmrit.symbolicprog.VariableValue
_cvMap, _status, _tooltipTextFields inherited from class jmri.jmrit.symbolicprog.AbstractValue
prop -
Constructor Summary
ConstructorsConstructorDescriptionSplitEnumVariableValue(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, String pSecondCV, int pFactor, int pOffset, String uppermask, String extra1, String extra2, String extra3, String extra4) -
Method Summary
Modifier and TypeMethodDescriptionvoidActionListener implementation.voidCreate a new item in the enumeration, with an associated value one more than the last item (or zero if this is the first one added)voidvoiddispose()Dispose of the object.(package private) voidvoidendGroup()(package private) voidSaves selected item from _value (enumField) to oldContents.(package private) voidContains numeric-value specific code.voidFocusListener implementations.voidGet a display representationObjectof this variable.Provide a user-readable description of the CVs accessed by this variable.getCvNum()Get the first CV from the set used to define this variable(package private) int[]getCvValsFromSingleInt(long newEntry) intGet the value as a single integer.longGet the value as an unsigned long.getMask()Multiple masks can be defined for the CVs accessed by this variable.protected StringgetMask(int i) Access a specific mask, used in testsCreates a newObjectrepresentation for display purposes, using the specified format.(package private) StringgetTextFromValue(long v) (package private) longbooleanDetermine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.booleanisToRead()Ask whether this object needs to be read.booleanAsk whether this object needs to be written.voidlastItem()voidnItems(int n) (package private) intAssigns a priority value to a given state.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".protected voidselectValue(int value) Select a specific value in the JComboBox display or, if need be, create another onevoidsetAvailable(boolean a) Sets the availability status of the object.(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.voidsetLongValue(long value) voidSet tooltip text to be used by both the "value" and representations of this Variable.voidsetValue(int value) Set value from a String value.voidstartGroup(String name) voidstepOneActions(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, String pSecondCV, int pFactor, int pOffset, String uppermask, String extra1, String extra2, String extra3, String extra4) Subclasses can override this to pick up constructor-specific attributes and perform other actions before cvList has been built.voidSubclasses can override this to invoke further actions after cvList has been built.(package private) void(package private) voidupdateVariableValue(int[] intVals) Contains numeric-value specific code.CvValue[]usesCVs()Simple request getter for the CVs composing this variablevoidwriteAll()Always write the contents of this Variable.voidWrite the contents of this Variable if it's in a state that indicates it was "changed".Methods inherited from class jmri.jmrit.symbolicprog.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvName, getInfoOnly, getMaxMask, getOpsOnly, getReadOnly, getState, getValueInCV, getWriteOnly, isBitMask, isBusy, item, label, maskValAsInt, offsetVal, setBusy, setState, setToRead, setToWrite, setValue, setValueInCV, simplifyMask, updatedTextField, updateRepresentationMethods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener
-
Field Details
-
atest
int atest -
_value
-
treeNodes
-
mSecondCV
-
_uppermask
-
mFactor
int mFactor -
mOffset
int mOffset -
_name
-
_mask
-
_maskArray
-
_cvNum
-
cvList
-
cvCount
int cvCount -
currentOffset
int currentOffset -
_minVal
long _minVal -
_maxVal
long _maxVal -
oldContents
-
_fieldShrink
boolean _fieldShrink -
_defaultColor
-
_columns
int _columns -
reps
-
retry
-
_progState
int _progState -
IDLE
- See Also:
-
READING_FIRST
- See Also:
-
WRITING_FIRST
- See Also:
-
bitCount
-
intMask
-
-
Constructor Details
-
SplitEnumVariableValue
public SplitEnumVariableValue(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, String pSecondCV, int pFactor, int pOffset, String uppermask, String extra1, String extra2, String extra3, String extra4)
-
-
Method Details
-
stepOneActions
public void stepOneActions(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, String pSecondCV, int pFactor, int pOffset, String uppermask, String extra1, String extra2, String extra3, String extra4) Subclasses can override this to pick up constructor-specific attributes and perform other actions before cvList has been built.- Parameters:
name- name.comment- comment.cvName- cv name.readOnly- true for read only, else false.infoOnly- true for info only, else false.writeOnly- true for write only, else false.opsOnly- true for 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.stdname- std name.pSecondCV- second cv (no longer preferred, specify in cv)pFactor- factor.pOffset- offset.uppermask- upper mask (no longer preferred, specify in mask)extra1- extra 1.extra2- extra 2.extra3- extra 3.extra4- extra 4.
-
nItems
-
addItem
Create a new item in the enumeration, with an associated value one more than the last item (or zero if this is the first one added)- Parameters:
s- Name of the enumeration item
-
addItem
-
startGroup
-
endGroup
-
lastItem
-
setToolTipText
Description copied from class:VariableValueSet tooltip text to be used by both the "value" and representations of this Variable.This is expected to be overridden in subclasses to change their internal info.
- Overrides:
setToolTipTextin classVariableValue- Parameters:
t- the tooltip text to be used- See Also:
-
stepTwoActions
Subclasses can override this to invoke further actions after cvList has been built. -
setAvailable
Description copied from class:AbstractValueSets the availability status of the object.- Overrides:
setAvailablein classAbstractValue- Parameters:
a-trueif the object should be made available,falseif should be made unavailable
-
usesCVs
Simple request getter for the CVs composing this variable- Specified by:
usesCVsin classVariableValue- Returns:
- Array of CvValue for all of associated CVs
-
getMask
Multiple masks can be defined for the CVs accessed by this variable.
Actual individual masks are returned ingetCvDescription().- Overrides:
getMaskin classVariableValue- Returns:
- The legacy two-CV mask if
highCVis specified.
ThemaskifhighCVis not specified.
-
getMask
Access a specific mask, used in tests- Parameters:
i- index of CV in variable- Returns:
- a single mask as string in the form XXXXVVVV, or empty string if index out of bounds
-
getCvDescription
Provide a user-readable description of the CVs accessed by this variable.
Actual individual masks are added to CVs if more are present.- Overrides:
getCvDescriptionin classVariableValue- Returns:
- A user-friendly CV(s) and bitmask(s) description
-
getCvNum
Get the first CV from the set used to define this variable- Overrides:
getCvNumin classVariableValue- Returns:
- The legacy two-CV mask if
highCVis specified.
-
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
-
getValueFromText
-
getTextFromValue
-
updateVariableValue
Contains numeric-value specific code.
Calculates new value for _enumField and invokessetLongValue(newVal)to make and notify the change- Parameters:
intVals- array of new CV values
-
enterField
void enterField()Saves selected item from _value (enumField) to oldContents. -
exitField
void exitField()Contains numeric-value specific code.
firePropertyChange for "Value" with new and old contents of _enumField -
updatedDropDown
void updatedDropDown() -
getCvValsFromSingleInt
-
actionPerformed
ActionListener implementation. Called by new selection in the JComboBox representation.Invokes
exitField()- Specified by:
actionPerformedin interfaceActionListener- Parameters:
e- the action event
-
focusGained
FocusListener implementations.- Specified by:
focusGainedin interfaceFocusListener
-
focusLost
- Specified by:
focusLostin interfaceFocusListener
-
getValueString
- Specified by:
getValueStringin classVariableValue- Returns:
- String that can (usually) be interpreted as an integer
-
setValue
Set value from a String value.- Parameters:
value- a string representing the Long value to be 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
-
getLongValue
Get the value as an unsigned long.- Overrides:
getLongValuein classVariableValue- Returns:
- the value as a long
-
getTextValue
- Overrides:
getTextValuein classVariableValue- Returns:
- User-desired value, which may or may not be 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
-
setLongValue
-
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
-
selectValue
Select a specific value in the JComboBox display or, if need be, create another one- Parameters:
value- The new numerical value for the complete enum variable.
-
setCvState
Notify the connected CVs of a state change from above- Specified by:
setCvStatein classVariableValue- Parameters:
state- The new state
-
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:
-
isToRead
Description copied from class:VariableValueAsk whether this object needs to be read.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
isToReadin classVariableValue- Returns:
- true if the object needs to be read, false otherwise
- See Also:
-
isToWrite
Description copied from class:VariableValueAsk whether this object needs to be written.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
isToWritein classVariableValue- Returns:
- true if the object needs to be written, false otherwise
- 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
-
priorityValue
Assigns a priority value to a given state.- Parameters:
state- State to be converted to a priority value- Returns:
- Priority value from state, with UNKNOWN numerically highest
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener- Specified by:
propertyChangein classVariableValue
-
dispose
Description copied from class:VariableValueDispose of the object.- Specified by:
disposein classVariableValue
-
disposeReps
void disposeReps()
-