Package jmri.jmrit.symbolicprog
Class CompositeVariableValue
- java.lang.Object
-
- jmri.jmrit.symbolicprog.AbstractValue
-
- jmri.jmrit.symbolicprog.VariableValue
-
- jmri.jmrit.symbolicprog.EnumVariableValue
-
- jmri.jmrit.symbolicprog.CompositeVariableValue
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.beans.PropertyChangeListener
,java.util.EventListener
public class CompositeVariableValue extends EnumVariableValue
Extends EnumVariableValue to represent a composition of variable values.Internally, each "choice" is stored as a list of "setting" items. Numerical values for this type of variable (itself) are strictly sequential, because they are arbitrary.
This version of the class has certain limitations:
- Variables referenced in the definition of one of these must have already been declared earlier in the decoder file. This prevents circular references, and makes it much easier to find the target variables.
- This version of the variable never changes "State" (color), though it does track its value from changes to other variables.
- There should be a final choice (entry) that doesn't define any settings. This will then form the default value when the target variables change.
- Programming operations on a variable of this type doesn't do anything,
because there doesn't seem to be a consistent model of what "read changes"
and "write changes" should do. This has two implications:
- Variables referenced as targets must appear on some programming pane, or they won't be updated by programming operations.
- If this variable references variables that are not on this pane, the user needs to do a read/write all panes operation to record the changes made to this variable.
- To apply a mask when setting a value, use an intermediary variable set from here, which in turn references the goal variable with a mask.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CompositeVariableValue.Setting
Define objects to save and manipulate a particular setting.(package private) static class
CompositeVariableValue.SettingList
Defines a list of Setting objects.-
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.EnumVariableValue
EnumVariableValue.TreeLeafNode, EnumVariableValue.VarComboBox
-
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
amReading
(package private) boolean
amWriting
(package private) java.util.Hashtable<java.lang.String,CompositeVariableValue.SettingList>
choiceHash
(package private) boolean
readingChanges
(package private) java.util.HashSet<VariableValue>
variables
(package private) boolean
writingChanges
-
Fields inherited from class jmri.jmrit.symbolicprog.EnumVariableValue
_defaultColor, _maxVal, _minVal, _value, treeNodes
-
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 CompositeVariableValue()
Create a null object.CompositeVariableValue(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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
void
addChoice(java.lang.String name)
Create a new possible selection.void
addSetting(java.lang.String choice, java.lang.String varName, VariableValue variable, java.lang.String value)
Add a setting to an existing choice.protected void
continueRead()
See if there's anything to read, and if so do it.protected void
continueWrite()
See if there's anything to write, and if so do it.void
dispose()
Dispose of the object.(package private) void
findValue()
Suspect underlying variables have changed value; check.java.awt.Component
getCommonRep()
Get a display representationObject
of this variable.int
getIntValue()
Get the value as a single integer.boolean
isChanged()
Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.boolean
isToRead()
This variable needs to be read if any of its subsidiary variables needs to be read.boolean
isToWrite()
This variable needs to be written if any of its subsidiary variables needs to be written.void
lastItem()
Do end of initialization processing.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)
Set to a specific value.void
setCvState(AbstractValue.ValueState state)
Notify the connected CVs of a state change from above by way of the variables (e.g. not direct to CVs).void
setState(AbstractValue.ValueState state)
This variable doesn't change state, hence doesn't change color.void
setToolTipText(java.lang.String t)
Set tooltip text to be used by both the "value" and representations of this Variable.void
setToRead(boolean state)
Mark whether this object needs to be read.void
setToWrite(boolean state)
Mark whether this object needs to be written.void
setValue(int value)
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".-
Methods inherited from class jmri.jmrit.symbolicprog.EnumVariableValue
addItem, addItem, disposeReps, endGroup, getNewRep, getTextValue, getValueObject, getValueString, nItems, setAvailable, setColor, setIntValue, startGroup
-
Methods inherited from class jmri.jmrit.symbolicprog.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvDescription, getCvName, getCvNum, getInfoOnly, getLongValue, getMask, getMaxMask, getOpsOnly, getReadOnly, getState, getValueInCV, getWriteOnly, isBitMask, isBusy, item, label, maskValAsInt, offsetVal, setBusy, setValue, setValueInCV, simplifyMask, updatedTextField, updateRepresentation
-
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener
-
-
-
-
Field Detail
-
choiceHash
java.util.Hashtable<java.lang.String,CompositeVariableValue.SettingList> choiceHash
-
variables
java.util.HashSet<VariableValue> variables
-
amReading
boolean amReading
-
readingChanges
boolean readingChanges
-
amWriting
boolean amWriting
-
writingChanges
boolean writingChanges
-
-
Constructor Detail
-
CompositeVariableValue
public CompositeVariableValue(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)
-
CompositeVariableValue
public CompositeVariableValue()
Create a null object. Normally only used for tests and to pre-load classes.
-
-
Method Detail
-
usesCVs
public CvValue[] usesCVs()
Description copied from class:VariableValue
Provide access to CVs used by this Variable.- Overrides:
usesCVs
in classEnumVariableValue
- Returns:
- an array of CVs used by this Variable
-
addChoice
public void addChoice(java.lang.String name)
Create a new possible selection.- Parameters:
name
- Name of the choice being added
-
addSetting
public void addSetting(java.lang.String choice, java.lang.String varName, VariableValue variable, java.lang.String value)
Add a setting to an existing choice.- Parameters:
choice
- existing choice.varName
- variable name.variable
- variable value.value
- setting value.
-
lastItem
public void lastItem()
Do end of initialization processing.- Overrides:
lastItem
in classEnumVariableValue
-
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 classEnumVariableValue
- Parameters:
t
- the tooltip text to be used- See Also:
VariableValue.updateRepresentation(javax.swing.JComponent)
-
rangeVal
public java.lang.Object rangeVal()
Description copied from class:VariableValue
Gets a (usually text) description of the variable type and range.- Overrides:
rangeVal
in classEnumVariableValue
- Returns:
- description of the variable type and range
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Overrides:
actionPerformed
in classEnumVariableValue
-
setState
public void setState(AbstractValue.ValueState state)
This variable doesn't change state, hence doesn't change color.- Overrides:
setState
in classVariableValue
- Parameters:
state
- the desired state as per definitions in AbstractValue- See Also:
AbstractValue
-
selectValue
protected void selectValue(int value)
Set to a specific value.Does this by delegating to the SettingList
- Overrides:
selectValue
in classEnumVariableValue
- Parameters:
value
- What to set to.
-
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.
- Overrides:
getIntValue
in classEnumVariableValue
- Returns:
- the value as an integer
-
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.- Overrides:
getCommonRep
in classEnumVariableValue
- Returns:
- the
Object
representation for display purposes
-
setValue
public void setValue(int value)
- Overrides:
setValue
in classEnumVariableValue
-
setCvState
public void setCvState(AbstractValue.ValueState state)
Notify the connected CVs of a state change from above by way of the variables (e.g. not direct to CVs).- Overrides:
setCvState
in classEnumVariableValue
- 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.- Overrides:
isChanged
in classEnumVariableValue
- Returns:
- true if Variable is "changed"
- See Also:
VariableValue.considerChanged(jmri.jmrit.symbolicprog.CvValue)
-
setToRead
public void setToRead(boolean state)
Description copied from class:VariableValue
Mark whether this object needs to be read.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
setToRead
in classVariableValue
- Parameters:
state
- true if the object needs to be read, false otherwise- See Also:
AbstractValue
-
isToRead
public boolean isToRead()
This variable needs to be read if any of its subsidiary variables needs to be read.- Overrides:
isToRead
in classVariableValue
- Returns:
- true if the object needs to be read, false otherwise
- See Also:
AbstractValue
-
setToWrite
public void setToWrite(boolean state)
Description copied from class:VariableValue
Mark whether this object needs to be written.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
setToWrite
in classVariableValue
- Parameters:
state
- true if the object needs to be written, false otherwise- See Also:
AbstractValue
-
isToWrite
public boolean isToWrite()
This variable needs to be written if any of its subsidiary variables needs to be written.- 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".- Overrides:
readChanges
in classEnumVariableValue
- 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".- Overrides:
writeChanges
in classEnumVariableValue
- See Also:
VariableValue.isChanged()
-
readAll
public void readAll()
Description copied from class:VariableValue
Always read the contents of this Variable.- Overrides:
readAll
in classEnumVariableValue
-
continueRead
protected void continueRead()
See if there's anything to read, and if so do it.
-
writeAll
public void writeAll()
Description copied from class:VariableValue
Always write the contents of this Variable.- Overrides:
writeAll
in classEnumVariableValue
-
continueWrite
protected void continueWrite()
See if there's anything to write, and if so do it.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Overrides:
propertyChange
in classEnumVariableValue
-
findValue
void findValue()
Suspect underlying variables have changed value; check. First match will succeed, so there should not be multiple matches possible. ("First match" is defined in choice-sequence).
-
dispose
public void dispose()
Description copied from class:VariableValue
Dispose of the object.- Overrides:
dispose
in classEnumVariableValue
-
-