org.afcs.warts.gui
Class TableModelRowColumnMap

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

public final class TableModelRowColumnMap
extends TableMap
implements javax.swing.table.TableModel

The TableModelRowColumnMap class can be used to filter any class implementing Swing's TableModel interface using row and column checkers (defined using a public interface) to filter the rows and columns. A row and column map that maps the filtered model to the base model is created at initialisation using the filters supplied, and these are used to map all indices specified in API calls to the approriate indices in the base model.

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

Version:
Last Modified 21 August 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )
See Also:
Serialized Form

Nested Class Summary
static interface TableModelRowColumnMap.RowColumnChecker
          This interface must be implemented by any class that will be used to determine whether a row or column should be included in the model that a TableModelRowColumnMap is used to wrap.
 
Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableModelRowColumnMap(javax.swing.table.TableModel baseModel, TableModelRowColumnMap.RowColumnChecker rowChecker, TableModelRowColumnMap.RowColumnChecker columnChecker)
          Constructs a new map with the specified base model and the specified filters for both rows and columns.
 
Method Summary
 int getBaseModelColumnIndex(int columnIndex)
          Returns the column index in the base table model that corresponds to the specified column index in the filtered table model.
 int getBaseModelRowIndex(int rowIndex)
          Returns the row index in the base table model that corresponds to the specified row index in the filtered table model.
 java.lang.Class getColumnClass(int columnIndex)
          Returns the class of object in the specified column, which is mapped to the appropriate column in the unfiltered base model.
 int getColumnCount()
          Returns the number of columns in the filtered table model.
 java.lang.String getColumnName(int columnIndex)
          Returns the name of the specified column, which is mapped to the appropriate column in the unfiltered base model.
 int getRowCount()
          Returns the number of rows in the filtered table model.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value at the specified row and column, which are mapped to the appropriate unfiltered row and column indices in the base model.
 java.lang.String toString()
          Returns a text description of the current instance that can be used for debugging purposes.
 
Methods inherited from class org.afcs.warts.gui.TableMap
getModel, isCellEditable, setValueAt, tableChanged
 
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, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener, setValueAt
 

Constructor Detail

TableModelRowColumnMap

public TableModelRowColumnMap(javax.swing.table.TableModel baseModel,
                              TableModelRowColumnMap.RowColumnChecker rowChecker,
                              TableModelRowColumnMap.RowColumnChecker columnChecker)
Constructs a new map with the specified base model and the specified filters for both rows and columns. If either filter is null, then all of the rows or columns will be included in the model presented.

Parameters:
baseModel - The base model to wrap.
rowChecker - The class that will be responsible for deciding whether a row in the base model should be included or not.
columnChecker - The class that will be responsible for deciding whether a column in the base model should be included or not.
Method Detail

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value at the specified row and column, which are mapped to the appropriate unfiltered row and column indices in the base model.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class TableMap
Parameters:
rowIndex - The row to return data from.
columnIndex - The column to return data from.
Returns:
The value at the specified row and column.
Throws:
java.lang.IllegalArgumentException - If either index is out of bounds.

getBaseModelRowIndex

public int getBaseModelRowIndex(int rowIndex)
Returns the row index in the base table model that corresponds to the specified row index in the filtered table model.

Parameters:
rowIndex - A row index in the filtered table model.
Returns:
The matching row index in the base table model.
Throws:
java.lang.IllegalArgumentException - If rowIndex is out of bounds.

getBaseModelColumnIndex

public int getBaseModelColumnIndex(int columnIndex)
Returns the column index in the base table model that corresponds to the specified column index in the filtered table model.

Parameters:
columnIndex - A column index in the filtered table model.
Returns:
The matching column index in the base table model.
Throws:
java.lang.IllegalArgumentException - If columnIndex is out of bounds.

getRowCount

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

Specified by:
getRowCount in interface javax.swing.table.TableModel
Overrides:
getRowCount in class TableMap
Returns:
The number of rows in the filtered table model.

getColumnCount

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

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Overrides:
getColumnCount in class TableMap
Returns:
The number of columns in the filtered table model.

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Returns the class of object in the specified column, which is mapped to the appropriate column in the unfiltered base model.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class TableMap
Parameters:
columnIndex - The column to obtain the class for.
Returns:
The class of object in the specified column.
Throws:
java.lang.IllegalArgumentException - If columnIndex is out of bounds.

getColumnName

public java.lang.String getColumnName(int columnIndex)
Returns the name of the specified column, which is mapped to the appropriate column in the unfiltered base model.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class TableMap
Parameters:
columnIndex - The column to return the name of.
Returns:
The name of the specified column.
Throws:
java.lang.IllegalArgumentException - If columnIndex is out of bounds.

toString

public java.lang.String toString()
Returns a text description of the current instance that can be used for debugging purposes.

Returns:
A text description of the current instance that can be used for debugging purposes.