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 classCompositeVariableValue.SettingDefine objects to save and manipulate a particular setting.(package private) static classCompositeVariableValue.SettingListDefines 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) booleanamReading(package private) booleanamWriting(package private) java.util.Hashtable<java.lang.String,CompositeVariableValue.SettingList>choiceHash(package private) booleanreadingChanges(package private) java.util.HashSet<VariableValue>variables(package private) booleanwritingChanges-
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 voidactionPerformed(java.awt.event.ActionEvent e)voidaddChoice(java.lang.String name)Create a new possible selection.voidaddSetting(java.lang.String choice, java.lang.String varName, VariableValue variable, java.lang.String value)Add a setting to an existing choice.protected voidcontinueRead()See if there's anything to read, and if so do it.protected voidcontinueWrite()See if there's anything to write, and if so do it.voiddispose()Dispose of the object.(package private) voidfindValue()Suspect underlying variables have changed value; check.java.awt.ComponentgetCommonRep()Get a display representationObjectof this variable.intgetIntValue()Get the value as a single integer.booleanisChanged()Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.booleanisToRead()This variable needs to be read if any of its subsidiary variables needs to be read.booleanisToWrite()This variable needs to be written if any of its subsidiary variables needs to be written.voidlastItem()Do end of initialization processing.voidpropertyChange(java.beans.PropertyChangeEvent e)java.lang.ObjectrangeVal()Gets a (usually text) description of the variable type and range.voidreadAll()Always read the contents of this Variable.voidreadChanges()Read the contents of this Variable if it's in a state that indicates it was "changed".protected voidselectValue(int value)Set to a specific value.voidsetCvState(AbstractValue.ValueState state)Notify the connected CVs of a state change from above by way of the variables (e.g. not direct to CVs).voidsetState(AbstractValue.ValueState state)This variable doesn't change state, hence doesn't change color.voidsetToolTipText(java.lang.String t)Set tooltip text to be used by both the "value" and representations of this Variable.voidsetToRead(boolean state)Mark whether this object needs to be read.voidsetToWrite(boolean state)Mark whether this object needs to be written.voidsetValue(int value)CvValue[]usesCVs()Provide access to CVs used by this Variable.voidwriteAll()Always write the contents of this Variable.voidwriteChanges()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:VariableValueProvide access to CVs used by this Variable.- Overrides:
usesCVsin 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:
lastItemin classEnumVariableValue
-
setToolTipText
public void setToolTipText(java.lang.String t)
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 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:VariableValueGets a (usually text) description of the variable type and range.- Overrides:
rangeValin classEnumVariableValue- Returns:
- description of the variable type and range
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener- Overrides:
actionPerformedin classEnumVariableValue
-
setState
public void setState(AbstractValue.ValueState state)
This variable doesn't change state, hence doesn't change color.- Overrides:
setStatein 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:
selectValuein classEnumVariableValue- Parameters:
value- What to set to.
-
getIntValue
public int 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.
- Overrides:
getIntValuein classEnumVariableValue- Returns:
- the value as an integer
-
getCommonRep
public java.awt.Component 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.- Overrides:
getCommonRepin classEnumVariableValue- Returns:
- the
Objectrepresentation for display purposes
-
setValue
public void setValue(int value)
- Overrides:
setValuein 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:
setCvStatein classEnumVariableValue- Parameters:
state- the new state to set
-
isChanged
public boolean isChanged()
Description copied from class:VariableValueDetermine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.- Overrides:
isChangedin 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:VariableValueMark whether this object needs to be read.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
setToReadin 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:
isToReadin 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:VariableValueMark whether this object needs to be written.Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.
- Overrides:
setToWritein 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:
isToWritein classVariableValue- Returns:
- true if the object needs to be written, false otherwise
- See Also:
AbstractValue
-
readChanges
public void readChanges()
Description copied from class:VariableValueRead the contents of this Variable if it's in a state that indicates it was "changed".- Overrides:
readChangesin classEnumVariableValue- See Also:
VariableValue.isChanged()
-
writeChanges
public void writeChanges()
Description copied from class:VariableValueWrite the contents of this Variable if it's in a state that indicates it was "changed".- Overrides:
writeChangesin classEnumVariableValue- See Also:
VariableValue.isChanged()
-
readAll
public void readAll()
Description copied from class:VariableValueAlways read the contents of this Variable.- Overrides:
readAllin 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:VariableValueAlways write the contents of this Variable.- Overrides:
writeAllin 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:
propertyChangein interfacejava.beans.PropertyChangeListener- Overrides:
propertyChangein 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:VariableValueDispose of the object.- Overrides:
disposein classEnumVariableValue
-
-