org.crosswire.common.swing

## Class MapTableModel

- java.lang.Object
- - javax.swing.table.AbstractTableModel
  - - org.crosswire.common.swing.MapTableModel

- All Implemented Interfaces:
    Serializable, TableModel

      public class MapTableModel
      extends AbstractTableModel

  TableModel using a Map internally. Note that an AbstractTableModel (this is-a AbstractTableModel) reports changes to the data to the table itself. However since a Map does not have a addChangeListener interface we can't do the same - SO if you change the Map while we are displaying it then don't expect the changes to be automatically reflected in the JTable.
  Author:
    Joe Walker
  See Also:
    `The GNU General Public License for details.`, Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `private static class` | `MapTableModel.StringPair` A simple holder of a key/value pair of Strings.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private String[]` | `colNames` The default column names
    `private List<MapTableModel.StringPair>` | `list` The List that is a copy of the list.
    `private Map<Object,Object>` | `map` The backing map
    `private static long` | `serialVersionUID` Serialization ID

    - ### Fields inherited from class javax.swing.table.AbstractTableModel

      `listenerList`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MapTableModel()` Create an internal store from a 2D array
    `MapTableModel(Map map)` Create an internal store from a 2D array

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(String key, String aValue)`
    `Class<String>` | `getColumnClass(int col)` Get the default class
    `int` | `getColumnCount()` How many Cols are there in this store
    `String` | `getColumnName(int col)` The name of the of the `col`th column
    `int` | `getRowCount()` How many Rows are there in this store
    `String` | `getValue()` Return a string version of the current value
    `Object` | `getValueAt(int row, int col)` Return the Object at row, col
    `private void` | `readObject(ObjectInputStream is)` Serialization support.
    `void` | `remove(String key)`
    `void` | `setColumnName(int col, String name)` The name of the of the `col`th column
    `void` | `setMap(Map<Object,Object> map)` Change the map that we report on
    `void` | `update(String oldkey, String newkey, String newvalue)`

    - ### Methods inherited from class javax.swing.table.AbstractTableModel

      `addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### list

          private transient List<MapTableModel.StringPair> list

      The List that is a copy of the list. A list is used for direct access performance.

    - #### map

          private Map<Object,Object> map

      The backing map

    - #### colNames

          private String[] colNames

      The default column names

    - #### serialVersionUID

          private static final long serialVersionUID

      Serialization ID
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### MapTableModel

          public MapTableModel()

      Create an internal store from a 2D array

    - #### MapTableModel

          public MapTableModel(Map map)

      Create an internal store from a 2D array
      Parameters:
        `map` - The table to model

  - ### Method Detail

    - #### setMap

          public final void setMap(Map<Object,Object> map)

      Change the map that we report on
      Parameters:
        `map` - The map we are getting our data from

    - #### add

          public void add(String key,
                 String aValue)

      Parameters:
        `key` -
        `aValue` -

    - #### remove

          public void remove(String key)

      Parameters:
        `key` -

    - #### update

          public void update(String oldkey,
                    String newkey,
                    String newvalue)

      Parameters:
        `oldkey` -
        `newkey` -
        `newvalue` -

    - #### getValue

          public String getValue()

      Return a string version of the current value
      Returns:
        The current value

    - #### getColumnCount

          public int getColumnCount()

      How many Cols are there in this store
      Returns:
        The number of columns

    - #### getRowCount

          public int getRowCount()

      How many Rows are there in this store
      Returns:
        the number of row in the TableModel = elements in the map

    - #### getValueAt

          public Object getValueAt(int row,
                          int col)

      Return the Object at row, col
      Parameters:
        `row` - The element in the list
        `col` - 1=keys, 2=values
      Returns:
        The key/value of the given element

    - #### getColumnClass

          public Class<String> getColumnClass(int col)

      Get the default class
      Specified by:
        `getColumnClass` in interface `TableModel`
      Overrides:
        `getColumnClass` in class `AbstractTableModel`
      Parameters:
        `col` - 1=keys, 2=values
      Returns:
        String.class

    - #### getColumnName

          public String getColumnName(int col)

      The name of the of the `col`th column
      Specified by:
        `getColumnName` in interface `TableModel`
      Overrides:
        `getColumnName` in class `AbstractTableModel`
      Parameters:
        `col` - The column index
      Returns:
        The column name

    - #### setColumnName

          public void setColumnName(int col,
                           String name)

      The name of the of the `col`th column
      Parameters:
        `col` - The column index
        `name` - The column name

    - #### readObject

          private void readObject(ObjectInputStream is)
                           throws IOException,
                                  ClassNotFoundException

      Serialization support.
      Parameters:
        `is` -
      Throws:
        `IOException`
        `ClassNotFoundException`