Package jmri.jmrit.symbolicprog
Class SplitEnumVariableValue
- java.lang.Object
-
- jmri.jmrit.symbolicprog.AbstractValue
-
- jmri.jmrit.symbolicprog.VariableValue
-
- jmri.jmrit.symbolicprog.SplitEnumVariableValue
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.FocusListener
,java.beans.PropertyChangeListener
,java.util.EventListener
public class SplitEnumVariableValue extends VariableValue implements java.awt.event.ActionListener, java.awt.event.FocusListener
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)
Themask
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 attributeshighCV
andupperMask
.
The preferred technique is now to specify all CVs in theCV
attribute alone, as documented atexpandCvList(String)
.
Optional attributesfactor
andoffset
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
)/factor
Value to put in text field = ((value in CVs) *factor
) +offset
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SplitEnumVariableValue.CvItem
Class to hold CV parameters for CVs used.(package private) static class
SplitEnumVariableValue.TreeLeafNode
static class
SplitEnumVariableValue.VarComboBox
-
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
_columns
(package private) java.lang.String
_cvNum
(package private) java.awt.Color
_defaultColor
(package private) boolean
_fieldShrink
(package private) java.lang.String
_mask
(package private) java.lang.String[]
_maskArray
(package private) long
_maxVal
(package private) long
_minVal
(package private) java.lang.String
_name
(package private) int
_progState
(package private) java.lang.String
_uppermask
(package private) javax.swing.JComboBox<java.lang.String>
_value
(package private) int
atest
(package private) static int
bitCount
(package private) int
currentOffset
(package private) int
cvCount
(package private) java.util.List<SplitEnumVariableValue.CvItem>
cvList
(package private) static int
IDLE
(package private) static long
intMask
(package private) int
mFactor
(package private) int
mOffset
(package private) java.lang.String
mSecondCV
(package private) java.lang.String
oldContents
(package private) static int
READING_FIRST
(package private) java.util.List<java.awt.Component>
reps
int
retry
(package private) java.util.Deque<javax.swing.tree.DefaultMutableTreeNode>
treeNodes
(package private) static int
WRITING_FIRST
-
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 SplitEnumVariableValue(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, java.lang.String pSecondCV, int pFactor, int pOffset, java.lang.String uppermask, java.lang.String extra1, java.lang.String extra2, java.lang.String extra3, java.lang.String extra4)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
ActionListener implementation.void
addItem(java.lang.String s)
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)void
addItem(java.lang.String s, int value)
void
dispose()
Dispose of the object.(package private) void
disposeReps()
void
endGroup()
(package private) void
enterField()
Saves selected item from _value (enumField) to oldContents.(package private) void
exitField()
Contains numeric-value specific code.void
focusGained(java.awt.event.FocusEvent e)
FocusListener implementations.void
focusLost(java.awt.event.FocusEvent e)
java.awt.Component
getCommonRep()
Get a display representationObject
of this variable.java.lang.String
getCvDescription()
Provide a user-readable description of the CVs accessed by this variable.java.lang.String
getCvNum()
Get the first CV from the set used to define this variable(package private) int[]
getCvValsFromSingleInt(long newEntry)
int
getIntValue()
Get the value as a single integer.long
getLongValue()
Get the value as an unsigned long.java.lang.String
getMask()
Multiple masks can be defined for the CVs accessed by this variable.protected java.lang.String
getMask(int i)
Access a specific mask, used in testsjava.awt.Component
getNewRep(java.lang.String format)
Creates a newObject
representation for display purposes, using the specified format.java.lang.String
getSecondCvNum()
Deprecated.(package private) java.lang.String
getTextFromValue(long v)
java.lang.String
getTextValue()
(package private) long
getValueFromText(java.lang.String s)
java.lang.Object
getValueObject()
java.lang.String
getValueString()
boolean
isChanged()
Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.boolean
isToRead()
Ask whether this object needs to be read.boolean
isToWrite()
Ask whether this object needs to be written.void
lastItem()
void
nItems(int n)
(package private) int
priorityValue(AbstractValue.ValueState state)
Assigns a priority value to a given state.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".protected void
selectValue(int value)
Select a specific value in the JComboBox display or, if need be, create another onevoid
setAvailable(boolean a)
Sets the availability status of the object.(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.void
setLongValue(long value)
void
setToolTipText(java.lang.String t)
Set tooltip text to be used by both the "value" and representations of this Variable.void
setValue(int value)
Set value from a String value.void
startGroup(java.lang.String name)
void
stepOneActions(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, java.lang.String pSecondCV, int pFactor, int pOffset, java.lang.String uppermask, java.lang.String extra1, java.lang.String extra2, java.lang.String extra3, java.lang.String extra4)
Subclasses can override this to pick up constructor-specific attributes and perform other actions before cvList has been built.void
stepTwoActions()
Subclasses can override this to invoke further actions after cvList has been built.(package private) void
updatedDropDown()
(package private) void
updateVariableValue(int[] intVals)
Contains numeric-value specific code.CvValue[]
usesCVs()
Simple request getter for the CVs composing this variablevoid
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".-
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, updateRepresentation
-
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener
-
-
-
-
Field Detail
-
atest
int atest
-
_value
javax.swing.JComboBox<java.lang.String> _value
-
treeNodes
java.util.Deque<javax.swing.tree.DefaultMutableTreeNode> treeNodes
-
mSecondCV
java.lang.String mSecondCV
-
_uppermask
java.lang.String _uppermask
-
mFactor
int mFactor
-
mOffset
int mOffset
-
_name
java.lang.String _name
-
_mask
java.lang.String _mask
-
_maskArray
java.lang.String[] _maskArray
-
_cvNum
java.lang.String _cvNum
-
cvList
java.util.List<SplitEnumVariableValue.CvItem> cvList
-
cvCount
int cvCount
-
currentOffset
int currentOffset
-
_minVal
long _minVal
-
_maxVal
long _maxVal
-
oldContents
java.lang.String oldContents
-
_fieldShrink
boolean _fieldShrink
-
_defaultColor
java.awt.Color _defaultColor
-
_columns
int _columns
-
reps
java.util.List<java.awt.Component> reps
-
retry
public int retry
-
_progState
int _progState
-
IDLE
static final int IDLE
- See Also:
- Constant Field Values
-
READING_FIRST
static final int READING_FIRST
- See Also:
- Constant Field Values
-
WRITING_FIRST
static final int WRITING_FIRST
- See Also:
- Constant Field Values
-
bitCount
static final int bitCount
-
intMask
static final long intMask
-
-
Constructor Detail
-
SplitEnumVariableValue
public SplitEnumVariableValue(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, java.lang.String pSecondCV, int pFactor, int pOffset, java.lang.String uppermask, java.lang.String extra1, java.lang.String extra2, java.lang.String extra3, java.lang.String extra4)
-
-
Method Detail
-
stepOneActions
public void stepOneActions(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, java.lang.String pSecondCV, int pFactor, int pOffset, java.lang.String uppermask, java.lang.String extra1, java.lang.String extra2, java.lang.String extra3, java.lang.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
public void nItems(int n)
-
addItem
public void addItem(java.lang.String s)
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
public void addItem(java.lang.String s, int value)
-
startGroup
public void startGroup(java.lang.String name)
-
endGroup
public void endGroup()
-
lastItem
public void lastItem()
-
setToolTipText
public void setToolTipText(java.lang.String t)
Description copied from class:VariableValue
Set 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:
setToolTipText
in classVariableValue
- Parameters:
t
- the tooltip text to be used- See Also:
VariableValue.updateRepresentation(javax.swing.JComponent)
-
stepTwoActions
public void stepTwoActions()
Subclasses can override this to invoke further actions after cvList has been built.
-
setAvailable
public void setAvailable(boolean a)
Description copied from class:AbstractValue
Sets the availability status of the object.- Overrides:
setAvailable
in classAbstractValue
- Parameters:
a
-true
if the object should be made available,false
if should be made unavailable
-
usesCVs
public CvValue[] usesCVs()
Simple request getter for the CVs composing this variable- Specified by:
usesCVs
in classVariableValue
- Returns:
- Array of CvValue for all of associated CVs
-
getMask
public java.lang.String getMask()
Multiple masks can be defined for the CVs accessed by this variable.
Actual individual masks are returned ingetCvDescription()
.- Overrides:
getMask
in classVariableValue
- Returns:
- The legacy two-CV mask if
highCV
is specified.
Themask
ifhighCV
is not specified.
-
getMask
protected java.lang.String getMask(int i)
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
public java.lang.String 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:
getCvDescription
in classVariableValue
- Returns:
- A user-friendly CV(s) and bitmask(s) description
-
getCvNum
public java.lang.String getCvNum()
Get the first CV from the set used to define this variable- Overrides:
getCvNum
in classVariableValue
- Returns:
- The legacy two-CV mask if
highCV
is specified.
-
getSecondCvNum
@Deprecated public java.lang.String getSecondCvNum()
Deprecated.
-
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
-
getValueFromText
long getValueFromText(java.lang.String s)
-
getTextFromValue
java.lang.String getTextFromValue(long v)
-
updateVariableValue
void updateVariableValue(int[] intVals)
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
int[] getCvValsFromSingleInt(long newEntry)
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
ActionListener implementation. Called by new selection in the JComboBox representation.Invokes
exitField()
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
e
- the action event
-
focusGained
public void focusGained(java.awt.event.FocusEvent e)
FocusListener implementations.- Specified by:
focusGained
in interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLost
in interfacejava.awt.event.FocusListener
-
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(int value)
Set value from a String value.- Parameters:
value
- a string representing the Long value to be 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
-
getLongValue
public long getLongValue()
Get the value as an unsigned long.- Overrides:
getLongValue
in classVariableValue
- Returns:
- the value as a long
-
getTextValue
public java.lang.String getTextValue()
- Overrides:
getTextValue
in classVariableValue
- Returns:
- User-desired value, which may or may not be 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
-
setLongValue
public void setLongValue(long 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
-
selectValue
protected void selectValue(int value)
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
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
-
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)
-
isToRead
public boolean isToRead()
Description copied from class:VariableValue
Ask whether this object needs to be read.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
isToRead
in classVariableValue
- Returns:
- true if the object needs to be read, false otherwise
- See Also:
AbstractValue
-
isToWrite
public boolean isToWrite()
Description copied from class:VariableValue
Ask whether this object needs to be written.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
isToWrite
in classVariableValue
- Returns:
- true if the object needs to be written, false otherwise
- See Also:
AbstractValue
-
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
-
priorityValue
int priorityValue(AbstractValue.ValueState state)
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
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
-
disposeReps
void disposeReps()
-
-