Class SplitEnumVariableValue

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.FocusListener, java.beans.PropertyChangeListener, java.util.EventListener

    public class SplitEnumVariableValue
    extends VariableValue
    implements java.awt.event.ActionListener, java.awt.event.FocusListener
    Extends VariableValue to represent a variable split across multiple CVs with values from a pre-selected range each of which is associated with a text name (aka, a drop down)
    The mask attribute represents the part of the value that's present in each CV; higher-order bits are loaded to subsequent CVs.
    It is possible to assign a specific mask for each CV by providing a space separated list of masks, starting with the lowest, and matching the order of CVs

    The original use was for addresses of stationary (accessory) decoders.
    The original version only allowed two CVs, with the second CV specified by the attributes highCV and upperMask.

    The preferred technique is now to specify all CVs in the CV attribute alone, as documented at expandCvList(String).

    Optional attributes factor and offset are applied when going from the variable value to the CV values, or vice-versa:
     Value to put in CVs = ((value in text field) -offset)/factor
     Value to put in text field = ((value in CVs) *factor) +offset
     
    • Constructor Detail

      • SplitEnumVariableValue

        public SplitEnumVariableValue​(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,
                                      java.lang.String pSecondCV,
                                      int pFactor,
                                      int pOffset,
                                      java.lang.String uppermask,
                                      java.lang.String extra1,
                                      java.lang.String extra2,
                                      java.lang.String extra3,
                                      java.lang.String extra4)
    • Method Detail

      • stepOneActions

        public void stepOneActions​(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,
                                   java.lang.String pSecondCV,
                                   int pFactor,
                                   int pOffset,
                                   java.lang.String uppermask,
                                   java.lang.String extra1,
                                   java.lang.String extra2,
                                   java.lang.String extra3,
                                   java.lang.String extra4)
        Subclasses can override this to pick up constructor-specific attributes and perform other actions before cvList has been built.
        Parameters:
        name - name.
        comment - comment.
        cvName - cv name.
        readOnly - true for read only, else false.
        infoOnly - true for info only, else false.
        writeOnly - true for write only, else false.
        opsOnly - true for 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.
        stdname - std name.
        pSecondCV - second cv (no longer preferred, specify in cv)
        pFactor - factor.
        pOffset - offset.
        uppermask - upper mask (no longer preferred, specify in mask)
        extra1 - extra 1.
        extra2 - extra 2.
        extra3 - extra 3.
        extra4 - extra 4.
      • nItems

        public void nItems​(int n)
      • addItem

        public void addItem​(java.lang.String s)
        Create a new item in the enumeration, with an associated value one more than the last item (or zero if this is the first one added)
        Parameters:
        s - Name of the enumeration item
      • addItem

        public void addItem​(java.lang.String s,
                            int value)
      • startGroup

        public void startGroup​(java.lang.String name)
      • stepTwoActions

        public void stepTwoActions()
        Subclasses can override this to invoke further actions after cvList has been built.
      • setAvailable

        public void setAvailable​(boolean a)
        Description copied from class: AbstractValue
        Sets the availability status of the object.
        Overrides:
        setAvailable in class AbstractValue
        Parameters:
        a - true if the object should be made available, false if should be made unavailable
      • usesCVs

        public CvValue[] usesCVs()
        Simple request getter for the CVs composing this variable
        Specified by:
        usesCVs in class VariableValue
        Returns:
        Array of CvValue for all of associated CVs
      • getMask

        public java.lang.String getMask()
        Multiple masks can be defined for the CVs accessed by this variable.
        Actual individual masks are returned in getCvDescription().
        Overrides:
        getMask in class VariableValue
        Returns:
        The legacy two-CV mask if highCV is specified.
        The mask if highCV is not specified.
      • getMask

        protected java.lang.String getMask​(int i)
        Access a specific mask, used in tests
        Parameters:
        i - index of CV in variable
        Returns:
        a single mask as string in the form XXXXVVVV, or empty string if index out of bounds
      • getCvDescription

        public java.lang.String getCvDescription()
        Provide a user-readable description of the CVs accessed by this variable.
        Actual individual masks are added to CVs if more are present.
        Overrides:
        getCvDescription in class VariableValue
        Returns:
        A user-friendly CV(s) and bitmask(s) description
      • getCvNum

        public java.lang.String getCvNum()
        Get the first CV from the set used to define this variable
        Overrides:
        getCvNum in class VariableValue
        Returns:
        The legacy two-CV mask if highCV is specified.
      • getSecondCvNum

        @Deprecated
        public java.lang.String getSecondCvNum()
        Deprecated.
      • 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
      • updateVariableValue

        void updateVariableValue​(int[] intVals)
        Contains numeric-value specific code.

        Calculates new value for _enumField and invokes setLongValue(newVal) to make and notify the change
        Parameters:
        intVals - array of new CV values
      • enterField

        void enterField()
        Saves selected item from _value (enumField) to oldContents.
      • exitField

        void exitField()
        Contains numeric-value specific code.
        firePropertyChange for "Value" with new and old contents of _enumField
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        ActionListener implementation.

        Invokes exitField()

        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Parameters:
        e - the action event
      • focusGained

        public void focusGained​(java.awt.event.FocusEvent e)
        FocusListener implementations.
        Specified by:
        focusGained in interface java.awt.event.FocusListener
      • focusLost

        public void focusLost​(java.awt.event.FocusEvent e)
        Specified by:
        focusLost in interface java.awt.event.FocusListener
      • setValue

        public void setValue​(int value)
        Set value from a String value.
        Parameters:
        value - a string representing the Long value to be 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
      • 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
      • selectValue

        protected void selectValue​(int value)
      • setCvState

        public void setCvState​(int state)
        Notify the connected CVs of a state change from above
        Specified by:
        setCvState in class VariableValue
        Parameters:
        state - The new state
      • isToRead

        public boolean isToRead()
        Description copied from class: VariableValue
        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:
        isToRead in class VariableValue
        Returns:
        true if the object needs to be read, false otherwise
        See Also:
        AbstractValue
      • isToWrite

        public boolean isToWrite()
        Description copied from class: VariableValue
        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:
        isToWrite in class VariableValue
        Returns:
        true if the object needs to be written, false otherwise
        See Also:
        AbstractValue
      • priorityValue

        int priorityValue​(int state)
        Assigns a priority value to a given state.
        Parameters:
        state - State to be converted to a priority value
        Returns:
        Priority value from state, with UNKNOWN numerically highest
      • propertyChange

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