Class VariableTableModel

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.table.TableModel

    public class VariableTableModel
    extends javax.swing.table.AbstractTableModel
    implements java.awt.event.ActionListener, java.beans.PropertyChangeListener
    Table data model for display of variables in symbolic programmer. Also responsible for loading from the XML file.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected DecoderFile _df  
      • Fields inherited from class javax.swing.table.AbstractTableModel

        listenerList
    • Constructor Summary

      Constructors 
      Constructor Description
      VariableTableModel​(javax.swing.JLabel status, java.lang.String[] h, CvTableModel cvModel)
      Define the columns.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent e)  
      void configDone()  
      boolean decoderDirty()
      Check for change to values, etc, hence rewriting the decoder is desirable.
      void dispose()  
      boolean fileDirty()
      Represents any change to values, etc, hence rewriting the file is desirable.
      VariableValue findVar​(java.lang.String name)
      Returns the (first) variable that matches a given name string.
      int findVarIndex​(java.lang.String name)
      Returns the index of the first variable that matches a given name string.
      int findVarIndex​(java.lang.String name, boolean searchFromEnd)
      Returns the index of a variable that matches a given name string.
      java.lang.Class<?> getColumnClass​(int col)  
      int getColumnCount()  
      java.lang.String getColumnName​(int col)  
      java.lang.String getCvName​(int row)  
      java.lang.String getItem​(int row)  
      java.lang.String getLabel​(int row)  
      java.lang.Object getRep​(int row, java.lang.String format)  
      int getRowCount()  
      AbstractValue.ValueState getState​(int row)  
      java.lang.String getValString​(int row)  
      java.lang.Object getValueAt​(int row, int col)  
      VariableValue getVariable​(int row)  
      protected void handleCompositeValChildren​(Element e, CompositeVariableValue var)
      Recursively walk the child compositeChoice elements, working through the compositeChoiceGroup elements as needed.
      protected void handleEnumValChildren​(Element e, EnumVariableValue var)
      Recursively walk the child enumChoice elements, working through the enumChoiceGroup elements as needed.
      protected void handleSplitEnumValChildren​(Element e, SplitEnumVariableValue var)
      Recursively walk the child enumChoice elements, working through the enumChoiceGroup elements as needed.
      boolean isCellEditable​(int row, int col)  
      void newDecVariableValue​(java.lang.String name, java.lang.String CV, java.lang.String comment, java.lang.String mask, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly)
      Programmatically create a new DecVariableValue from parameters.
      protected VariableValue processCompositeVal​(Element child, java.lang.String name, java.lang.String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String CV, java.lang.String mask, java.lang.String item)  
      protected VariableValue processDecVal​(Element child, java.lang.String name, java.lang.String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String CV, java.lang.String mask, java.lang.String item)  
      protected VariableValue processEnumVal​(Element child, java.lang.String name, java.lang.String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String CV, java.lang.String mask, java.lang.String item)  
      protected VariableValue processHexVal​(Element child, java.lang.String name, java.lang.String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String CV, java.lang.String mask, java.lang.String item)  
      protected VariableValue processLongAddressVal​(java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected void processModifierElements​(Element e, VariableValue variable)
      If there are any modifier elements, process them by e.g. setting attributes on the VariableValue.
      protected VariableValue processShortAddressVal​(java.lang.String name, java.lang.String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, java.lang.String CV, java.lang.String mask, java.lang.String item, Element child)  
      protected VariableValue processSpeedTableVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitDateTimeVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitEnumVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitHexVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitHundredsVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitTextVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      protected VariableValue processSplitVal​(Element child, java.lang.String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, java.lang.String name, java.lang.String comment, boolean opsOnly, java.lang.String mask, java.lang.String item)  
      void propertyChange​(java.beans.PropertyChangeEvent e)  
      void read​(int i)
      Command reading of a particular variable.
      (package private) void reportBogus()  
      void setButtonModeFromProgrammer()  
      protected void setButtonsReadWrite​(boolean readOnly, boolean infoOnly, boolean writeOnly, javax.swing.JButton bw, javax.swing.JButton br, int row)  
      void setConstant​(Element e)
      Configure from a constant.
      (package private) boolean setDefaultValue​(Element e, VariableValue variable)
      If there's a "default" attribute, or matching defaultItem element, set that value to start.
      void setFileDirty​(boolean b)  
      void setIntValue​(int row, int val)  
      void setRow​(int row, Element e)
      Load one row in the VariableTableModel, by reading in the Element containing its definition.
      void setRow​(int row, Element e, DecoderFile df)
      Load one row in the VariableTableModel, by reading in the Element containing its definition.
      void setState​(int row, AbstractValue.ValueState val)  
      protected void setToolTip​(Element e, VariableValue v)  
      void setValueAt​(java.lang.Object value, int row, int col)  
      void write​(int i)
      Command writing of a particular variable.
      • Methods inherited from class javax.swing.table.AbstractTableModel

        addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VariableTableModel

        public VariableTableModel​(javax.swing.JLabel status,
                                  java.lang.String[] h,
                                  CvTableModel cvModel)
        Define the columns.

        Values understood are: "Name", "Value", "Range", "Read", "Write", "Comment", "CV", "Mask", "State".

        For each, a property key in SymbolicProgBundle by the same name allows i18n.

        Parameters:
        status - variable status.
        h - values headers array.
        cvModel - cv table model to use.
    • Method Detail

      • getRowCount

        public int getRowCount()
        Specified by:
        getRowCount in interface javax.swing.table.TableModel
      • getColumnCount

        public int getColumnCount()
        Specified by:
        getColumnCount in interface javax.swing.table.TableModel
      • getColumnName

        public java.lang.String getColumnName​(int col)
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.swing.table.AbstractTableModel
      • getColumnClass

        public java.lang.Class<?> getColumnClass​(int col)
        Specified by:
        getColumnClass in interface javax.swing.table.TableModel
        Overrides:
        getColumnClass in class javax.swing.table.AbstractTableModel
      • isCellEditable

        public boolean isCellEditable​(int row,
                                      int col)
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.AbstractTableModel
      • getLabel

        public java.lang.String getLabel​(int row)
      • getItem

        public java.lang.String getItem​(int row)
      • getCvName

        public java.lang.String getCvName​(int row)
      • getValString

        public java.lang.String getValString​(int row)
      • setIntValue

        public void setIntValue​(int row,
                                int val)
      • getRep

        public java.lang.Object getRep​(int row,
                                       java.lang.String format)
      • getValueAt

        public java.lang.Object getValueAt​(int row,
                                           int col)
        Specified by:
        getValueAt in interface javax.swing.table.TableModel
      • setValueAt

        public void setValueAt​(java.lang.Object value,
                               int row,
                               int col)
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.AbstractTableModel
      • setRow

        public void setRow​(int row,
                           Element e)
        Load one row in the VariableTableModel, by reading in the Element containing its definition.

        Note that this method does not pass a reference to a DecoderFile instance, hence include/exclude processing at the sub-variable level is not possible and will be ignored.

        Use of setRow(int row, Element e, DecoderFile df) is preferred.

        Parameters:
        row - number of row to fill
        e - Element of type "variable"
      • setRow

        public void setRow​(int row,
                           Element e,
                           DecoderFile df)
        Load one row in the VariableTableModel, by reading in the Element containing its definition.

        Invoked from DecoderFile

        Parameters:
        row - number of row to fill
        e - Element of type "variable"
        df - the source DecoderFile instance (needed for include/exclude processing at the sub-variable level)
      • processModifierElements

        protected void processModifierElements​(Element e,
                                               VariableValue variable)
        If there are any modifier elements, process them by e.g. setting attributes on the VariableValue.
        Parameters:
        e - Element that's source of info
        variable - Variable to load
      • setDefaultValue

        boolean setDefaultValue​(Element e,
                                VariableValue variable)
        If there's a "default" attribute, or matching defaultItem element, set that value to start.
        Parameters:
        e - Element that's source of info
        variable - Variable to load
        Returns:
        true if the value was set
      • processCompositeVal

        protected VariableValue processCompositeVal​(Element child,
                                                    java.lang.String name,
                                                    java.lang.String comment,
                                                    boolean readOnly,
                                                    boolean infoOnly,
                                                    boolean writeOnly,
                                                    boolean opsOnly,
                                                    java.lang.String CV,
                                                    java.lang.String mask,
                                                    java.lang.String item)
      • handleCompositeValChildren

        protected void handleCompositeValChildren​(Element e,
                                                  CompositeVariableValue var)
        Recursively walk the child compositeChoice elements, working through the compositeChoiceGroup elements as needed.

        Adapted from handleEnumValChildren for use in LocoIO Legacy tool.

        Parameters:
        e - Element that's source of info
        var - Variable to load
      • processDecVal

        protected VariableValue processDecVal​(Element child,
                                              java.lang.String name,
                                              java.lang.String comment,
                                              boolean readOnly,
                                              boolean infoOnly,
                                              boolean writeOnly,
                                              boolean opsOnly,
                                              java.lang.String CV,
                                              java.lang.String mask,
                                              java.lang.String item)
                                       throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processEnumVal

        protected VariableValue processEnumVal​(Element child,
                                               java.lang.String name,
                                               java.lang.String comment,
                                               boolean readOnly,
                                               boolean infoOnly,
                                               boolean writeOnly,
                                               boolean opsOnly,
                                               java.lang.String CV,
                                               java.lang.String mask,
                                               java.lang.String item)
                                        throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitEnumVal

        protected VariableValue processSplitEnumVal​(Element child,
                                                    java.lang.String CV,
                                                    boolean readOnly,
                                                    boolean infoOnly,
                                                    boolean writeOnly,
                                                    java.lang.String name,
                                                    java.lang.String comment,
                                                    boolean opsOnly,
                                                    java.lang.String mask,
                                                    java.lang.String item)
                                             throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • handleSplitEnumValChildren

        protected void handleSplitEnumValChildren​(Element e,
                                                  SplitEnumVariableValue var)
        Recursively walk the child enumChoice elements, working through the enumChoiceGroup elements as needed.
        Parameters:
        e - Element that's source of info
        var - Variable to load
      • handleEnumValChildren

        protected void handleEnumValChildren​(Element e,
                                             EnumVariableValue var)
        Recursively walk the child enumChoice elements, working through the enumChoiceGroup elements as needed.
        Parameters:
        e - Element that's source of info
        var - Variable to load
      • processHexVal

        protected VariableValue processHexVal​(Element child,
                                              java.lang.String name,
                                              java.lang.String comment,
                                              boolean readOnly,
                                              boolean infoOnly,
                                              boolean writeOnly,
                                              boolean opsOnly,
                                              java.lang.String CV,
                                              java.lang.String mask,
                                              java.lang.String item)
                                       throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processLongAddressVal

        protected VariableValue processLongAddressVal​(java.lang.String CV,
                                                      boolean readOnly,
                                                      boolean infoOnly,
                                                      boolean writeOnly,
                                                      java.lang.String name,
                                                      java.lang.String comment,
                                                      boolean opsOnly,
                                                      java.lang.String mask,
                                                      java.lang.String item)
      • processShortAddressVal

        protected VariableValue processShortAddressVal​(java.lang.String name,
                                                       java.lang.String comment,
                                                       boolean readOnly,
                                                       boolean infoOnly,
                                                       boolean writeOnly,
                                                       boolean opsOnly,
                                                       java.lang.String CV,
                                                       java.lang.String mask,
                                                       java.lang.String item,
                                                       Element child)
      • processSpeedTableVal

        protected VariableValue processSpeedTableVal​(Element child,
                                                     java.lang.String CV,
                                                     boolean readOnly,
                                                     boolean infoOnly,
                                                     boolean writeOnly,
                                                     java.lang.String name,
                                                     java.lang.String comment,
                                                     boolean opsOnly,
                                                     java.lang.String mask,
                                                     java.lang.String item)
                                              throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitVal

        protected VariableValue processSplitVal​(Element child,
                                                java.lang.String CV,
                                                boolean readOnly,
                                                boolean infoOnly,
                                                boolean writeOnly,
                                                java.lang.String name,
                                                java.lang.String comment,
                                                boolean opsOnly,
                                                java.lang.String mask,
                                                java.lang.String item)
                                         throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitHexVal

        protected VariableValue processSplitHexVal​(Element child,
                                                   java.lang.String CV,
                                                   boolean readOnly,
                                                   boolean infoOnly,
                                                   boolean writeOnly,
                                                   java.lang.String name,
                                                   java.lang.String comment,
                                                   boolean opsOnly,
                                                   java.lang.String mask,
                                                   java.lang.String item)
                                            throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitHundredsVal

        protected VariableValue processSplitHundredsVal​(Element child,
                                                        java.lang.String CV,
                                                        boolean readOnly,
                                                        boolean infoOnly,
                                                        boolean writeOnly,
                                                        java.lang.String name,
                                                        java.lang.String comment,
                                                        boolean opsOnly,
                                                        java.lang.String mask,
                                                        java.lang.String item)
                                                 throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitTextVal

        protected VariableValue processSplitTextVal​(Element child,
                                                    java.lang.String CV,
                                                    boolean readOnly,
                                                    boolean infoOnly,
                                                    boolean writeOnly,
                                                    java.lang.String name,
                                                    java.lang.String comment,
                                                    boolean opsOnly,
                                                    java.lang.String mask,
                                                    java.lang.String item)
                                             throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • processSplitDateTimeVal

        protected VariableValue processSplitDateTimeVal​(Element child,
                                                        java.lang.String CV,
                                                        boolean readOnly,
                                                        boolean infoOnly,
                                                        boolean writeOnly,
                                                        java.lang.String name,
                                                        java.lang.String comment,
                                                        boolean opsOnly,
                                                        java.lang.String mask,
                                                        java.lang.String item)
                                                 throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • setButtonsReadWrite

        protected void setButtonsReadWrite​(boolean readOnly,
                                           boolean infoOnly,
                                           boolean writeOnly,
                                           javax.swing.JButton bw,
                                           javax.swing.JButton br,
                                           int row)
      • setConstant

        public void setConstant​(Element e)
        Configure from a constant. This is like setRow (which processes a variable Element).
        Parameters:
        e - element to set.
      • newDecVariableValue

        public void newDecVariableValue​(java.lang.String name,
                                        java.lang.String CV,
                                        java.lang.String comment,
                                        java.lang.String mask,
                                        boolean readOnly,
                                        boolean infoOnly,
                                        boolean writeOnly,
                                        boolean opsOnly)
        Programmatically create a new DecVariableValue from parameters.
        Parameters:
        name - variable name.
        CV - CV string.
        comment - variable comment.
        mask - CV mask.
        readOnly - true if read only, else false.
        infoOnly - true if information only, else false.
        writeOnly - true if write only, else false.
        opsOnly - true if ops only, else false.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
      • read

        public void read​(int i)
        Command reading of a particular variable.
        Parameters:
        i - row number
      • write

        public void write​(int i)
        Command writing of a particular variable.
        Parameters:
        i - row number
      • propertyChange

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

        public boolean fileDirty()
        Represents any change to values, etc, hence rewriting the file is desirable.
        Returns:
        true if dirty, else false.
      • decoderDirty

        public boolean decoderDirty()
        Check for change to values, etc, hence rewriting the decoder is desirable.
        Returns:
        true if dirty, else false.
      • findVar

        public VariableValue findVar​(java.lang.String name)
        Returns the (first) variable that matches a given name string.

        Searches first for "item", the true name, but if none found will attempt to find a matching "label". In that case, only the default language is checked.

        Parameters:
        name - search string.
        Returns:
        first matching variable found.
      • findVarIndex

        public int findVarIndex​(java.lang.String name)
        Returns the index of the first variable that matches a given name string.

        Checks the search string against every variable's "item", the true name, then against their "label" (default language only) and finally the CV name before moving on to the next variable if none of those match.

        Parameters:
        name - search string.
        Returns:
        index of the first matching variable found.
      • findVarIndex

        public int findVarIndex​(java.lang.String name,
                                boolean searchFromEnd)
        Returns the index of a variable that matches a given name string.

        Checks the search string against every variable's "item", the true name, then against their "label" (default language only) and finally the CV name before moving on to the next variable if none of those match. Depending on the second parameter, it will return the index of the first or last variable in our internal rowVector that matches the given string.

        Parameters:
        name - search string.
        searchFromEnd - If true, will start searching from the end.
        Returns:
        index of the first matching variable found.