org.afcs.warts.gui
Class TableMap

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byorg.afcs.warts.gui.TableMap
All Implemented Interfaces:
java.util.EventListener, java.io.Serializable, javax.swing.table.TableModel, javax.swing.event.TableModelListener
Direct Known Subclasses:
TableModelRowColumnMap, TableSorter

public class TableMap
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.TableModelListener

The TableMap class is an identity transformation for TableModels, and can be used as the basis for classes that wish to perform more complex transformations or mappings on TableModels.

TableMap implements TableModel by routing all requests to its model, and TableModelListener by routing all events to its listeners. Inserting a TableMap which has not been subclassed into a chain of table filters should have no effect.

This implementation is based on version 1.5 of Philip Milne's code (I can't find the original implementation, but google finds lots of other people using it), but has some minor major API changes.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 16 September 2003
Author:
Philip Milne & Warren Hedley ( whedley at sdsc dot edu )
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableMap(javax.swing.table.TableModel model)
          Constructs a new map with the specified base model, which will provide all information in methods that are not overridden by subclasses.
 
Method Summary
 java.lang.Class getColumnClass(int columnIndex)
          Returns the class of the specified column from the base model.
 int getColumnCount()
          Returns the number of columns in the base model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the specified column from the base model.
 javax.swing.table.TableModel getModel()
          Returns the base model specified at initialisation.
 int getRowCount()
          Returns the number of rows in the base model.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value in the base model at the specified row and column.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell in the specified row and column in the base model is editable.
 void setValueAt(java.lang.Object newValue, int rowIndex, int columnIndex)
          Sets the value at the specified row and column in the base model to the specified new value.
 void tableChanged(javax.swing.event.TableModelEvent event)
          When the table is changed, this method makes sure that all listeners get the event.
 
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

TableMap

public TableMap(javax.swing.table.TableModel model)
Constructs a new map with the specified base model, which will provide all information in methods that are not overridden by subclasses.

Parameters:
model - The base model to use.
Method Detail

getModel

public javax.swing.table.TableModel getModel()
Returns the base model specified at initialisation.

Returns:
The base model specified at initialisation.

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value in the base model at the specified row and column.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - The row to fetch data from.
columnIndex - The column to fetch data from.
Returns:
The value in the base model at the specified row and column.

setValueAt

public void setValueAt(java.lang.Object newValue,
                       int rowIndex,
                       int columnIndex)
Sets the value at the specified row and column in the base model to the specified new value.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Parameters:
newValue - The new value to set.
rowIndex - The row to set the new value in.
columnIndex - The column to set the new value in.

getRowCount

public int getRowCount()
Returns the number of rows in the base model.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
The number of rows in the base model.

getColumnCount

public int getColumnCount()
Returns the number of columns in the base model.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
The number of columns in the base model.

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the specified column from the base model.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
columnIndex - The column to return data for.
Returns:
The name of the specified column from the base model.

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Returns the class of the specified column from the base model.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
columnIndex - The column to return data for.
Returns:
The class of the specified column from the base model.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell in the specified row and column in the base model is editable.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Parameters:
rowIndex - The row the cell is in.
columnIndex - The column the cell is in.
Returns:
True if the cell in the specified row and column in the base model is editable.

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent event)
When the table is changed, this method makes sure that all listeners get the event.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Parameters:
event - The event to send out.