edu.ucla.stat.SOCR.util.tablemodels
Class FilteredTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by edu.ucla.stat.SOCR.util.tablemodels.FilteredTableModel
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel

public class FilteredTableModel
extends javax.swing.table.AbstractTableModel

An AbstractTableModel implementation with filtering support. It uses supplied RowFilter to filter table rows. The original TableModel is used only as the data source and is not modified.

Sample usage:

    // Old code:
    //    JTable jTable = new JTable(tableModel);
    // New code:
    JTable jTable = new JTable(new FilteredTableModel(tableModel));

See Also:
RowFilter, Serialized Form

Field Summary
protected  javax.swing.table.TableModel model
          Original TableModel used as data source.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FilteredTableModel(javax.swing.table.TableModel model)
          Creates FilteredTableModel object with specified TableModel as the data source.
 
Method Summary
 void filter()
          Forces filtering of data contained in model.
 java.lang.Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 javax.swing.table.TableModel getModel()
          Returns original TableModel used as data source.
 int getRealRowIndex(int rowIndex)
          Returns row index in original model by index in current model (view index).
 int getRowCount()
           
 RowFilter getRowFilter()
          Returns RowFilter used to filter table rows.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 void setModel(javax.swing.table.TableModel model)
          Sets original TableModel used as data source.
 void setRowFilter(RowFilter rowFilter)
          Sets RowFilter used to filter table rows.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void tableChanged(javax.swing.event.TableModelEvent e)
           
 
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
 

Field Detail

model

protected javax.swing.table.TableModel model
Original TableModel used as data source.

Constructor Detail

FilteredTableModel

public FilteredTableModel(javax.swing.table.TableModel model)
Creates FilteredTableModel object with specified TableModel as the data source.

Parameters:
model - TableModel used as the data source
Method Detail

getRowFilter

public RowFilter getRowFilter()
Returns RowFilter used to filter table rows.

Returns:
RowFilter used to filter table rows.

setRowFilter

public void setRowFilter(RowFilter rowFilter)
Sets RowFilter used to filter table rows. Invokes filter() before return.

Parameters:
rowFilter - RowFilter used to filter table rows

filter

public void filter()
Forces filtering of data contained in model. The original model is not modified.


getRealRowIndex

public int getRealRowIndex(int rowIndex)
Returns row index in original model by index in current model (view index).

Parameters:
rowIndex - index in current model (view index)
Returns:
row index in original model.

setModel

public void setModel(javax.swing.table.TableModel model)
Sets original TableModel used as data source.

Parameters:
model - original TableModel used as data source

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface javax.swing.table.TableModel

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface javax.swing.table.TableModel

getRowCount

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

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
Specified by:
tableChanged in interface javax.swing.event.TableModelListener

getModel

public javax.swing.table.TableModel getModel()
Returns original TableModel used as data source.

Returns:
original TableModel used as data source.

getColumnCount

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

getColumnName

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

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel