Package jmri.jmrit.symbolicprog
Class DecVariableValue
- java.lang.Object
-
- jmri.jmrit.symbolicprog.AbstractValue
-
- jmri.jmrit.symbolicprog.VariableValue
-
- jmri.jmrit.symbolicprog.DecVariableValue
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.FocusListener,java.beans.PropertyChangeListener,java.util.EventListener
- Direct Known Subclasses:
HexVariableValue,ShortAddrVariableValue
public class DecVariableValue extends VariableValue implements java.awt.event.ActionListener, java.awt.event.FocusListener
Decimal representation of a value.
Themaskattribute represents the part of the value that's present in the CV.
Optional attributesfactorandoffsetare 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 Classes Modifier and Type Class Description classDecVariableValue.VarTextField-
Nested classes/interfaces inherited from class jmri.jmrit.symbolicprog.AbstractValue
AbstractValue.ValueState
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.awt.Color_defaultColor(package private) int_factor(package private) int_maxVal(package private) int_minVal(package private) int_offset(package private) javax.swing.JTextField_value(package private) java.lang.StringoldContents(package private) java.util.List<java.awt.Component>reps(package private) java.util.ArrayList<DecVarSlider>sliders-
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 DecVariableValue(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)DecVariableValue(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, int offset, int factor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)ActionListener implementationsvoiddispose()Dispose of the object.(package private) voidenterField()(package private) voidexitField()(package private) intfieldLength()voidfocusGained(java.awt.event.FocusEvent e)FocusListener implementationsvoidfocusLost(java.awt.event.FocusEvent e)(package private) java.awt.ColorgetColor()java.awt.ComponentgetCommonRep()Get a display representationObjectof this variable.(package private) java.awt.ColorgetDefaultColor()intgetIntValue()Get the value as a single integer.java.awt.ComponentgetNewRep(java.lang.String format)Creates a newObjectrepresentation for display purposes, using the specified format.java.lang.ObjectgetValueObject()java.lang.StringgetValueString()booleanisChanged()Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.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".voidsetAvailable(boolean a)Sets the availability status of the object.(package private) voidsetColor(java.awt.Color c)Method to handle color changes for states.voidsetCvState(AbstractValue.ValueState state)Notify the connected CVs of a state change from abovevoidsetIntValue(int i)Set the value from a single number.voidsetToolTipText(java.lang.String t)Set tooltip text to be used by both the "value" and representations of this Variable.voidsetValue(int value)Set a new value in the variable (text box), including notification as needed.(package private) inttextToValue(java.lang.String s)(package private) voidupdatedTextField()Invoked when a permanent change to the JTextField has been made.CvValue[]usesCVs()Provide access to CVs used by this Variable.(package private) java.lang.StringvalueToText(int v)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.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvDescription, getCvName, getCvNum, getInfoOnly, getLongValue, getMask, getMaxMask, getOpsOnly, getReadOnly, getState, getTextValue, getValueInCV, getWriteOnly, isBitMask, isBusy, isToRead, isToWrite, item, label, maskValAsInt, offsetVal, setBusy, setState, setToRead, setToWrite, setValue, setValueInCV, simplifyMask, updateRepresentation
-
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener
-
-
-
-
Field Detail
-
_maxVal
int _maxVal
-
_minVal
int _minVal
-
_offset
int _offset
-
_factor
int _factor
-
oldContents
java.lang.String oldContents
-
reps
java.util.List<java.awt.Component> reps
-
sliders
java.util.ArrayList<DecVarSlider> sliders
-
_defaultColor
java.awt.Color _defaultColor
-
_value
javax.swing.JTextField _value
-
-
Constructor Detail
-
DecVariableValue
public DecVariableValue(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)
-
DecVariableValue
public DecVariableValue(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, int offset, int factor)
-
-
Method Detail
-
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 classVariableValue- Parameters:
t- the tooltip text to be used- See Also:
VariableValue.updateRepresentation(javax.swing.JComponent)
-
fieldLength
int fieldLength()
-
usesCVs
public CvValue[] usesCVs()
Description copied from class:VariableValueProvide access to CVs used by this Variable.- Specified by:
usesCVsin classVariableValue- Returns:
- an array of CVs used by this Variable
-
rangeVal
public java.lang.Object 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
-
enterField
void enterField()
-
textToValue
int textToValue(java.lang.String s)
-
valueToText
java.lang.String valueToText(int v)
-
exitField
void exitField()
-
updatedTextField
void updatedTextField()
Invoked when a permanent change to the JTextField has been made. Note that this does _not_ notify property listeners; that should be done by the invoker, who may or may not know what the old value was. Can be overridden in subclasses that want to display the value differently.- Overrides:
updatedTextFieldin classVariableValue
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
ActionListener implementations- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener
-
focusGained
public void focusGained(java.awt.event.FocusEvent e)
FocusListener implementations- Specified by:
focusGainedin interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLostin interfacejava.awt.event.FocusListener
-
getValueString
public java.lang.String getValueString()
- Specified by:
getValueStringin classVariableValue- Returns:
- String that can (usually) be interpreted as an integer
-
setIntValue
public void setIntValue(int i)
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
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.
- Specified by:
getIntValuein classVariableValue- Returns:
- the value as an integer
-
getValueObject
public java.lang.Object getValueObject()
- Specified by:
getValueObjectin classVariableValue- Returns:
- Value as a native-form Object
-
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.- Specified by:
getCommonRepin classVariableValue- Returns:
- the
Objectrepresentation for display purposes
-
setAvailable
public void setAvailable(boolean a)
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
-
getNewRep
public java.awt.Component getNewRep(java.lang.String format)
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
-
setValue
public void setValue(int value)
Set a new value in the variable (text box), including notification as needed.This does the conversion from string to int, so it's the place where formatting needs to be applied.
- Parameters:
value- new value.
-
getDefaultColor
java.awt.Color getDefaultColor()
-
getColor
java.awt.Color getColor()
-
setColor
void setColor(java.awt.Color c)
Description copied from class:AbstractValueMethod to handle color changes for states.- Specified by:
setColorin classAbstractValue- Parameters:
c- the desired colour
-
setCvState
public void setCvState(AbstractValue.ValueState state)
Notify the connected CVs of a state change from above- Specified by:
setCvStatein classVariableValue- 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.- Specified by:
isChangedin classVariableValue- Returns:
- true if Variable is "changed"
- See Also:
VariableValue.considerChanged(jmri.jmrit.symbolicprog.CvValue)
-
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".- Specified by:
readChangesin classVariableValue- 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".- Specified by:
writeChangesin classVariableValue- See Also:
VariableValue.isChanged()
-
readAll
public void readAll()
Description copied from class:VariableValueAlways read the contents of this Variable.- Specified by:
readAllin classVariableValue
-
writeAll
public void writeAll()
Description copied from class:VariableValueAlways write the contents of this Variable.- Specified by:
writeAllin classVariableValue
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener- Specified by:
propertyChangein classVariableValue
-
dispose
public void dispose()
Description copied from class:VariableValueDispose of the object.- Specified by:
disposein classVariableValue
-
-