Class SpeedTableVarValue

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener, javax.swing.event.ChangeListener

    public class SpeedTableVarValue
    extends VariableValue
    implements javax.swing.event.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.

    • Constructor Detail

      • SpeedTableVarValue

        public SpeedTableVarValue​(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 entries,
                                  boolean mfxFlag)
        Create the object with a "standard format ctor".
        Parameters:
        name - name.
        comment - comment.
        cvName - cv name.
        readOnly - true if read only, else false.
        infoOnly - true if info only, else false.
        writeOnly - true if write only, else false.
        opsOnly - true if ops only, else false.
        cvNum - cv number.
        mask - cv mask.
        minVal - minimum value.
        maxVal - maximum value.
        v - hashmap of string and cv value.
        status - status label.
        stdname - std name.
        entries - number entries.
        mfxFlag - set mx flag true or false.
      • SpeedTableVarValue

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

      • rangeVal

        public java.lang.Object rangeVal()
        Description copied from class: VariableValue
        Gets a (usually text) description of the variable type and range.
        Specified by:
        rangeVal in class VariableValue
        Returns:
        description of the variable type and range
      • stateChanged

        public void stateChanged​(javax.swing.event.ChangeEvent e)
        Called for new values of a slider.

        Sets the CV(s) as needed.

        Specified by:
        stateChanged in interface javax.swing.event.ChangeListener
      • setModel

        void setModel​(int i,
                      int value)
      • forceMonotonic

        void forceMonotonic​(int modifiedStepIndex,
                            int value)
        Check entries on either side to see if they are set monotonically. If not, adjust.
        Parameters:
        modifiedStepIndex - number (index) of the entry
        value - new value
      • matchPoints

        void matchPoints​(int modifiedStepIndex)
        If there are fixed points specified, set linear step settings to them.
        Parameters:
        modifiedStepIndex - Index of requested break point
      • setValue

        public void setValue​(java.lang.String value)
        Set value from a String value.

        Requires the format written by getValueString, not implemented yet

        Overrides:
        setValue in class VariableValue
        Parameters:
        value - the String value to set
      • 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
        Parameters:
        i - the integer value to set
      • getIntValue

        public int getIntValue()
        Description copied from class: VariableValue
        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.

        Specified by:
        getIntValue in class VariableValue
        Returns:
        the value as an integer
      • getCommonRep

        public java.awt.Component getCommonRep()
        Description copied from class: VariableValue
        Get a display representation Object of this variable.

        The actual stored value of a variable is not the most interesting thing. Instead, you usually get an Object representation 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:
        getCommonRep in class VariableValue
        Returns:
        the Object representation for display purposes
      • setValue

        public void setValue​(int value)
      • setColor

        void setColor​(java.awt.Color c)
        Description copied from class: AbstractValue
        Method to handle color changes for states.
        Specified by:
        setColor in class AbstractValue
        Parameters:
        c - the desired colour
      • getNewRep

        public java.awt.Component getNewRep​(java.lang.String format)
        Description copied from class: VariableValue
        Creates a new Object representation for display purposes, using the specified format.
        Specified by:
        getNewRep in class VariableValue
        Parameters:
        format - a name representing
        Returns:
        an Object representation for display purposes
      • doForceStraight

        void doForceStraight​(java.awt.event.ActionEvent e)
        Set the values to a straight line from _min to _max
        Parameters:
        e - Event triggering this operation
      • doMatchEnds

        void doMatchEnds​(java.awt.event.ActionEvent e)
        Set the values to a straight line from existing ends
        Parameters:
        e - Event triggering this operation
      • doRatioCurve

        void doRatioCurve​(java.awt.event.ActionEvent e)
        Set a constant ratio curve
        Parameters:
        e - Event triggering this operation
      • doLogCurve

        void doLogCurve​(java.awt.event.ActionEvent e)
        Set a log curve
        Parameters:
        e - Event triggering this operation
      • doShiftLeft

        void doShiftLeft​(java.awt.event.ActionEvent e)
        Shift the curve one CV to left. The last entry is left unchanged.
        Parameters:
        e - Event triggering this operation
      • doShiftRight

        void doShiftRight​(java.awt.event.ActionEvent e)
        Shift the curve one CV to right. The first entry is left unchanged.
        Parameters:
        e - Event triggering this operation
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent e)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Specified by:
        propertyChange in class VariableValue