org.crosswire.common.swing
Class MapTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.crosswire.common.swing.MapTableModel
All Implemented Interfaces:
Serializable, TableModel
Direct Known Subclasses:
MapField.NamedMapTableModel

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 whilst we are displaying it then don't expect the changes to be automatically reflected in the JTable.

Author:
Joe Walker [joe at eireneh dot com]
See Also:
for license details. The copyright to this program is held by it's authors., Serialized Form

Nested Class Summary
private static class MapTableModel.StringPair
          A simple holder of a key/value pair of Strings.
 
Field Summary
private  String[] colNames
          The default column names
private  List list
          The List that is a copy of the list.
private  Map map
          The backing map
private static long serialVersionUID
          Serialization ID
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
MapTableModel()
          Create an internal store from a 2D array
MapTableModel(Map map)
          Create an internal store from a 2D array
 
Method Summary
 void add(String key, String aValue)
           
 Class 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 colth 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
 void remove(String key)
           
 void setColumnName(int col, String name)
          The name of the of the colth column
 void setMap(Map 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 List list
The List that is a copy of the list. A list is used for direct access performance.


map

private Map 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 void setMap(Map 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 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 colth 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 colth column

Parameters:
col - The column index
name - The column name

Copyright ยจ 2003-2006