Class SpeedTableVarValue

All Implemented Interfaces:
PropertyChangeListener, EventListener, ChangeListener

public class SpeedTableVarValue extends VariableValue implements 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):

  • If any CVs are UNKNOWN, its UNKNOWN..
  • If not, and any are EDITED, its EDITED.
  • If not, and any are FROMFILE, its FROMFILE.
  • If not, and any are READ, its READ.
  • If not, and any are STORED, its STORED.
  • And if we get to here, something awful has happened.

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.