jmri.jmrit.symbolicprog
Class SpeedTableVarValue

java.lang.Object
  extended by jmri.jmrit.symbolicprog.AbstractValue
      extended by jmri.jmrit.symbolicprog.VariableValue
          extended by jmri.jmrit.symbolicprog.SpeedTableVarValue
All Implemented Interfaces:
PropertyChangeListener, EventListener, ChangeListener

public class SpeedTableVarValue
extends VariableValue
implements PropertyChangeListener, ChangeListener

Represent an entire speed table as a single Variable.

This presents as a set of vertically oriented sliders, with numeric values above them. That it turn is done using VarSlider and DecVariableValue objects respectively. VarSlider is an interior class to color a JSlider by state. The respective VarSlider and DecVariableValue communicate through their underlying CV objects. Changes to CV Values are listened to by this class, which updates the model objects for the VarSliders; the DecVariableValues listen directly.

Color (hence state) of individual sliders (hence CVs) are directly coupled to the state of those CVs.

The state of the entire variable has to be a composite of all the sliders, hence CVs. The mapping is (in order):

A similar pattern is used for a read or write request. Write writes them all; Read reads any that aren't READ or WRITTEN.

Speed tables can have different numbers of entries; 28 is the default, and also the maximum.

The NMRA specification says that speed table entries cannot be non-monotonic (e.g. cannot decrease when moving from lower to higher CV numbers). In earlier versions of the code, this was enforced any time a value was changed (for any reason). This caused a problem when CVs were read that were non-monotonic: That value was read, causing lower CVs to be made consistent, a change in their value which changed their state, so they were read again. To avoid this, the class now only enforces non-monotonicity when the slider is adjusted.

_value is a holdover from the LongAddrVariableValue, which this was copied from; it should be removed.

Author:
Bob Jacobsen, Alex Shepherd Copyright (C) 2001, 2004

Nested Class Summary
 class SpeedTableVarValue.VarSlider
           
 
Field Summary
 
Fields inherited from class jmri.jmrit.symbolicprog.VariableValue
_cvVector, _status, _tooltipText
 
Fields inherited from class jmri.jmrit.symbolicprog.AbstractValue
DIFF, EDITED, FROMFILE, READ, SAME, STORED, UNKNOWN
 
Constructor Summary
SpeedTableVarValue()
          Create a null object.
SpeedTableVarValue(String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, int cvNum, String mask, int minVal, int maxVal, Vector<CvValue> v, JLabel status, String stdname, int entries)
          Create the object with a "standard format ctor".
 
Method Summary
 void dispose()
           
 Component getCommonRep()
           
 int getIntValue()
          Get the value as a single number.
 Component getNewRep(String format)
           
 int getState()
           
 Object getValueObject()
           
 String getValueString()
           
 boolean isChanged()
          Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.
 void propertyChange(PropertyChangeEvent e)
           
 Object rangeVal()
           
 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"
 void setCvState(int state)
          Notify the connected CVs of a state change from above
 void setIntValue(int i)
          Set the value from a single number.
 void setValue(int value)
           
 void stateChanged(ChangeEvent e)
          Called for new values of a slider.
 CvValue[] usesCVs()
          Provide access to CVs referenced by this operation
 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.VariableValue
confirmAll, considerChanged, cvName, getComment, getCvNum, getInfoOnly, getMask, getOpsOnly, getReadOnly, getTextValue, getWriteOnly, isBusy, isToRead, isToWrite, item, label, maskVal, newValue, offsetVal, setBusy, setState, setToolTipText, setToRead, setToWrite, updateRepresentation
 
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable, stateNameFromValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpeedTableVarValue

public SpeedTableVarValue(String name,
                          String comment,
                          String cvName,
                          boolean readOnly,
                          boolean infoOnly,
                          boolean writeOnly,
                          boolean opsOnly,
                          int cvNum,
                          String mask,
                          int minVal,
                          int maxVal,
                          Vector<CvValue> v,
                          JLabel status,
                          String stdname,
                          int entries)
Create the object with a "standard format ctor".


SpeedTableVarValue

public SpeedTableVarValue()
Create a null object. Normally only used for tests and to pre-load classes.

Method Detail

rangeVal

public Object rangeVal()
Specified by:
rangeVal in class VariableValue

usesCVs

public CvValue[] usesCVs()
Description copied from class: VariableValue
Provide access to CVs referenced by this operation

Specified by:
usesCVs in class VariableValue

stateChanged

public void stateChanged(ChangeEvent e)
Called for new values of a slider.

Sets the CV(s) as needed.

Specified by:
stateChanged in interface ChangeListener
Parameters:
e -

getState

public int getState()
Overrides:
getState in class VariableValue

getValueString

public String getValueString()
Specified by:
getValueString in class VariableValue
Returns:
String that can (usually) be interpreted as an integer

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 class VariableValue

getIntValue

public int getIntValue()
Description copied from class: VariableValue
Get the value as 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:
getIntValue in class VariableValue

getValueObject

public Object getValueObject()
Specified by:
getValueObject in class VariableValue
Returns:
Value as a native-form Object

getCommonRep

public Component getCommonRep()
Specified by:
getCommonRep in class VariableValue

setValue

public void setValue(int value)

getNewRep

public Component getNewRep(String format)
Specified by:
getNewRep in class VariableValue

setCvState

public void setCvState(int state)
Notify the connected CVs of a state change from above

Specified by:
setCvState in class VariableValue
Parameters:
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 class VariableValue
See Also:
VariableValue.considerChanged(jmri.jmrit.symbolicprog.CvValue)

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 class VariableValue
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 class VariableValue
See Also:
VariableValue.isChanged()

readAll

public void readAll()
Description copied from class: VariableValue
Always read the contents of this Variable

Specified by:
readAll in class VariableValue

writeAll

public void writeAll()
Description copied from class: VariableValue
Always write the contents of this Variable

Specified by:
writeAll in class VariableValue

propertyChange

public void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener
Specified by:
propertyChange in class VariableValue

dispose

public void dispose()
Specified by:
dispose in class VariableValue


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads