Class VariableValue
- All Implemented Interfaces:
PropertyChangeListener,EventListener
- Direct Known Subclasses:
ConstantValue,DecVariableValue,EnumVariableValue,LongAddrVariableValue,SpeedTableVarValue,SplitEnumVariableValue,SplitVariableValue
The "changed" parameter (non-bound, accessed via isChanged) indicates whether
a "write changes" or "read changes" operation should handle this object.
The mask shown below comes in two forms:
- A character-by-character bit mask of 8 or 16 binary digits, e.g.
"XXVVVVXXX"
In this case, the "V" bits denote a continuous bit field that contains the datum. For use in SplitVariableValue this mask can also be entered a a list of multiple bit masks, separated by spaces. - A small decimal value, i.e. "9"
In this case, aka Radix mask, it forms the multiplier (N) which combines with the maximum value (maxVal, defined in a subclass) to break the CV into three parts:- lowest part, stored as 1 times a value 0-(N-1)
- datum stored as datum*N (datum is limited to maxVal)
- highest part, which stored as N*(maxVal+1) times the value
- mask="1" maxVal="9"
- mask="10" maxVal="9"
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState -
Field Summary
FieldsModifier and TypeFieldDescriptionA vector of CV objects used to look up CVs.protected JLabelField holds the current status.protected StringField holds the current tool tip text.Fields inherited from class jmri.jmrit.symbolicprog.AbstractValue
prop -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConfirm the contents of this Variable.static booleanDefault implementation for subclasses to tell if a CV meets a common definition of "changed".cvName()Get the CV name.abstract voiddispose()Dispose of the object.abstract ComponentGet a display representationObjectof this variable.Provide a user-readable description of the CVs accessed by this variable.getCvNum()booleanabstract intGet the value as a single integer.longGet the value as an Unsigned Long.getMask()Extending classes should override to return a single mask in case a list of masks was provided and the class only uses one.protected static StringgetMaxMask(int maxVal) Create a "VVV" style mask matching the size of max value in bits.abstract ComponentCreates a newObjectrepresentation for display purposes, using the specified format.booleanbooleangetState()protected intgetValueInCV(int Cv, String maskString, int maxVal) Extract the current value from the CV, using the mask as needed.abstract Objectabstract Stringbooleanprotected booleanIs this a bit mask (such as XVVVXXXX form) vs. radix mask (small integer)?booleanisBusy()Check if a variable is busy (during read, write operations).abstract booleanDetermine 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.item()Gets the unique name for this Variable.label()Gets the displayed label for the Variable.protected intmaskValAsInt(String maskString) Convert a String bit mask like XXXVVVXX to an int like 0b00011100.protected intFind number of places to shift a value left to align it with a mask.abstract voidabstract ObjectrangeVal()Gets a (usually text) description of the variable type and range.abstract voidreadAll()Always read the contents of this Variable.abstract voidRead the contents of this Variable if it's in a state that indicates it was "changed".protected voidsetBusy(boolean newBusy) abstract voidPropagate a state change here to the CVs that are related, which will in turn propagate back to here.abstract voidsetIntValue(int i) Set the value from a single number.voidsetState(AbstractValue.ValueState state) Sets the current state of the variable.voidSet 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.voidSet value from a String value.protected intsetValueInCV(int oldCv, int newVal, String maskString, int maxVal) Insert a value into a CV, using the mask as needed.protected voidIn case a set of masks was provided, at end of Ctor pick the first mask for implementing classes that use just one.(package private) voidThis should be overridden by any implementation.protected JComponentAdd the proper tooltip text to a graphical rep before returning it, sets the visibility.abstract CvValue[]usesCVs()Provide access to CVs used by this Variable.abstract voidwriteAll()Always write the contents of this Variable.abstract voidWrite the contents of this Variable if it's in a state that indicates it was "changed".Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable, setColor
-
Field Details
-
_cvMap
A vector of CV objects used to look up CVs. -
_status
Field holds the current status. -
_tooltipText
Field holds the current tool tip text.
-
-
Constructor Details
-
VariableValue
public VariableValue(String label, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cvNum, String mask, HashMap<String, CvValue> v, JLabel status, String item) - Parameters:
label- the displayed label for the Variablecomment- for information only, generally not displayedcvName- the name for the CV. Seems to be generally ignored and set to "".readOnly- true if the variable is to be readable-onlyinfoOnly- true if the variable is to be for information only (a fixed value that is neither readable or writable)writeOnly- true if the variable is to be writable-onlyopsOnly- true if the variable is to be programmable in ops mode onlycvNum- the CV numbermask- a bit mask like XXXVVVXX (converts to a value like 0b00011100) or a series of masks separated by spacesv- a vector of CV objects used to look up CVsstatus- a field that holds the current statusitem- the unique name for this Variable- See Also:
-
VariableValue
protected VariableValue()Create a null object. Normally only used for tests and to pre-load classes.
-
-
Method Details
-
getCommonRep
Get 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.- Returns:
- the
Objectrepresentation for display purposes
-
getNewRep
Creates a newObjectrepresentation for display purposes, using the specified format.- Parameters:
format- a name representing- Returns:
- an
Objectrepresentation for display purposes
-
getValueString
- Returns:
- String that can (usually) be interpreted as an integer
-
getValueObject
- Returns:
- Value as a native-form Object
-
getTextValue
- Returns:
- User-desired value, which may or may not be an integer
-
getCvDescription
Provide a user-readable description of the CVs accessed by this variable.Default is a single CV number
- Returns:
- a user-readable description
-
setIntValue
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.
- Parameters:
i- the integer value to set
-
setValue
Set value from a String value.The current implementation is a stand-in. Note that e.g. Speed Tables don't use a single Int. The solution to that is to override this in complicated variable types.
Since variable values can now be non-integer (text, long, hex etc.) we need a universally-usable method for setting values, such as default values in decoder definitions.
In the long term we don't want to have this method failing silently. Subclasses that need silent failure should override this method.
- Parameters:
value- the String value to set
-
getIntValue
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.
- Returns:
- the value as an integer
-
getLongValue
Get the value as an Unsigned Long.Some subclasses (e.g.
SplitVariableValue) store the value as alongrather than aninteger. This method should be used in cases where such a class may be queried (e.g. byArithmeticQualifier).If not overridden by a subclass, it will return an
UnsignedLongconversion of the value returned bygetIntValue().- Returns:
- the value as a long
-
updatedTextField
void updatedTextField()This should be overridden by any implementation. -
readAll
Always read the contents of this Variable. -
writeAll
Always write the contents of this Variable. -
confirmAll
Confirm the contents of this Variable. -
readChanges
Read the contents of this Variable if it's in a state that indicates it was "changed".- See Also:
-
writeChanges
Write the contents of this Variable if it's in a state that indicates it was "changed".- See Also:
-
isChanged
Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.- Returns:
- true if Variable is "changed"
- See Also:
-
considerChanged
Default implementation for subclasses to tell if a CV meets a common definition of "changed". This implementation will only consider a variable to be changed if the underlying CV(s) state is EDITED, e.g. if the CV(s) has been manually edited, or UNKNOWN.- Parameters:
c- CV to be examined- Returns:
- true if to be considered changed
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
dispose
Dispose of the object. -
rangeVal
Gets a (usually text) description of the variable type and range.- Returns:
- description of the variable type and range
-
label
Gets the displayed label for the Variable.- Returns:
- the displayed label for the Variable
-
item
Gets the unique name for this Variable.- Returns:
- the unique name for this Variable
-
cvName
Get the CV name.- Returns:
- the name for the CV
-
setToolTipText
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.
- Parameters:
t- the tooltip text to be used- See Also:
-
updateRepresentation
Add the proper tooltip text to a graphical rep before returning it, sets the visibility.- Parameters:
c- the current graphical representation- Returns:
- the updated graphical representation
-
getComment
- Returns:
- the comment
-
getReadOnly
- Returns:
- the value of the readOnly attribute
-
getInfoOnly
- Returns:
- the value of the infoOnly attribute
-
getWriteOnly
- Returns:
- the value of the writeOnly attribute
-
getOpsOnly
- Returns:
- the value of the opsOnly attribute
-
getCvNum
- Returns:
- the CV number
-
getCvName
- Returns:
- the CV name
-
getMask
Extending classes should override to return a single mask in case a list of masks was provided and the class only uses one.- Returns:
- the CV bitmask in the form XXXVVVXX
-
getState
- Returns:
- the current state of the Variable
-
setState
Sets the current state of the variable.- Parameters:
state- the desired state as per definitions in AbstractValue- See Also:
-
setToRead
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:
setToReadin classAbstractValue- Parameters:
state- true if the object needs to be read, false otherwise- See Also:
-
isToRead
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:
isToReadin classAbstractValue- Returns:
- true if the object needs to be read, false otherwise
- See Also:
-
setToWrite
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:
setToWritein classAbstractValue- Parameters:
state- true if the object needs to be written, false otherwise- See Also:
-
isToWrite
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:
isToWritein classAbstractValue- Returns:
- true if the object needs to be written, false otherwise
- See Also:
-
setCvState
Propagate a state change here to the CVs that are related, which will in turn propagate back to here.- Parameters:
state- the new state to set
-
isBusy
Check if a variable is busy (during read, write operations).- Returns:
trueif busy
-
setBusy
- Parameters:
newBusy- the desired state
-
simplifyMask
In case a set of masks was provided, at end of Ctor pick the first mask for implementing classes that use just one. Call not required if mask is ignored. -
getMaxMask
Create a "VVV" style mask matching the size of max value in bits.- Parameters:
maxVal- the maximum value to be stored in the cv as decimal- Returns:
- a string of V's
-
maskValAsInt
Convert a String bit mask like XXXVVVXX to an int like 0b00011100.- Parameters:
maskString- the textual (XXXVVVXX style) mask- Returns:
- the binary integer (0b00011100 style) mask
-
isBitMask
Is this a bit mask (such as XVVVXXXX form) vs. radix mask (small integer)?- Parameters:
mask- the bit mask to check- Returns:
trueif XVVVXXXX form
-
offsetVal
Find number of places to shift a value left to align it with a mask.For example, a mask of "XXVVVXXX" means that the value 5 needs to be shifted left 3 places before being masked and stored as XX101XXX
- Parameters:
maskString- the (XXXVVVXX style) mask- Returns:
- the number of places to shift left before masking
-
getValueInCV
Extract the current value from the CV, using the mask as needed.- Parameters:
Cv- the full CV value of interest.maskString- the (XXXVVVXX style or small int) mask for extracting the Variable value from this CVmaxVal- the maximum possible value for this Variable position in the CV. Note it's 10 (0-9) in a single digit using a radix mask.- Returns:
- the current value of the Variable. Optional factor and offset not yet applied.
-
setValueInCV
Insert a value into a CV, using the mask as needed.- Parameters:
oldCv- Value of the CV before this update is appliednewVal- Value for this variable (e.g. not the CV value). Optional factor and offset already applied.maskString- The (XXXVVVXX style or small int) mask for this variable in character formmaxVal- the maximum possible value for this Variable- Returns:
- int new value for the full CV
-
usesCVs
Provide access to CVs used by this Variable.- Returns:
- an array of CVs used by this Variable
-