uic.model
Class TableRowSorter

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended byuic.widgets.TableSorter
          extended byuic.model.TableRowSorter
All Implemented Interfaces:
EventListener, Serializable, TableModel, TableModelListener, TableViewInterface, TableViewInterface

public class TableRowSorter
extends TableSorter
implements TableViewInterface

A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableRowSorter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableRowSorter appears to hold another copy of the table with the rows in a different order. The sorting algorthm used is stable which means that it does not move around rows when its comparison function returns 0 to denote that they are equivalent. Various bugfixes and make-faster patches by Roy van der Kuil and Thomas Zander

Version:
1.5 12/17/97
Author:
Philip Milne, Roy van der Kuil, Thomas Zander
See Also:
Serialized Form

Field Summary
 
Fields inherited from class uic.widgets.TableSorter
model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableRowSorter()
          Empty constructor, be sure to do a 'setModel' afterwards.
TableRowSorter(TableModel model)
          Main constructor; creates a new table sorter wrapping your data model to pass to that table.
 
Method Summary
 void addKeyListenerToTable(JTable table)
          Add a key listener to the table for making it possible to browse with key events
 void addMouseListenerToHeaderInTable(JTable table)
          Adds functionality so that clicking on the table header of the given JTable Changes the sorting of the corresponding column
 void addSortedColumn(int column, boolean ascending)
          Add a sorting column in a given direction
 Class getColumnClass(int column)
          Return the column class of the specified column index
 int getColumnCount()
          Return number of columns that this model has
 String getColumnName(int column)
          Return the column name of the specified column index
 TableModel getModel()
          Returns the (data) model
 int getOriginalIndex(int localIndex)
          Return the original index of the view index
 int getRowCount()
          Return number of rows that this model has
 int[] getSortedColumns()
          Returns all sorted columns or an empty array if no columns are being sorted
 Object getValueAt(int row, int column)
          Deprectated class since the original has been moved to uic.model.
 boolean isAscending()
          Is current sort ascending?
 boolean isCellEditable(int row, int column)
          Returns true if cell is editable Per default ONLY booleans are editable
 void setModel(TableModel model)
          set the (data)model this sorter wraps.
 void setValueAt(Object value, int row, int column)
          Update cell value
 void sort()
          This is the general, please sort me, method.
 void sortByColumn(int column)
          Sort column
 void sortByColumn(int column, boolean ascending)
          Sort column in a given direction
 void tableChanged(TableModelEvent e)
          React on table change events.
 
Methods inherited from class uic.widgets.TableSorter
getOrgIndex, n2sort
 
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

TableRowSorter

public TableRowSorter()
Empty constructor, be sure to do a 'setModel' afterwards.


TableRowSorter

public TableRowSorter(TableModel model)
Main constructor; creates a new table sorter wrapping your data model to pass to that table. Example usage:
UICDefaultTableModel tableTableModel = new UICDefaultTableModel();
       tableTableModel.addColumn(translate().i18n("Name"));
       tableTableModel.addColumn(translate().i18n("Address"));
       tableTableModel.addColumn(translate().i18n("City"));
       TableRowSorter sorter = new TableRowSorter(tableTableModel);
       table = new UICTable(sorter);

Method Detail

tableChanged

public void tableChanged(TableModelEvent e)
React on table change events. If table row count has changed.. update the sort

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class TableSorter
See Also:
TableRowSorter

sort

public void sort()
This is the general, please sort me, method. During implementation we can swift between a simple sorter and the shuttlesorter. If this performs poorly; we will have to check if the implementation of this method should not forward the sorting request to someone else.

Overrides:
sort in class TableSorter
See Also:
TableRowSorter

getValueAt

public Object getValueAt(int row,
                         int column)
Description copied from class: TableSorter
Deprectated class since the original has been moved to uic.model.

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class TableSorter
See Also:
TableRowSorter

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Update cell value

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class TableSorter
See Also:
TableRowSorter

sortByColumn

public void sortByColumn(int column)
Sort column

Overrides:
sortByColumn in class TableSorter
See Also:
TableRowSorter

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Sort column in a given direction

Overrides:
sortByColumn in class TableSorter
See Also:
TableRowSorter

addSortedColumn

public void addSortedColumn(int column,
                            boolean ascending)
Add a sorting column in a given direction

Overrides:
addSortedColumn in class TableSorter
See Also:
TableRowSorter

getSortedColumns

public int[] getSortedColumns()
Returns all sorted columns or an empty array if no columns are being sorted

Overrides:
getSortedColumns in class TableSorter
See Also:
TableRowSorter

isAscending

public boolean isAscending()
Is current sort ascending?

Overrides:
isAscending in class TableSorter
See Also:
TableRowSorter

addMouseListenerToHeaderInTable

public void addMouseListenerToHeaderInTable(JTable table)
Adds functionality so that clicking on the table header of the given JTable Changes the sorting of the corresponding column

Overrides:
addMouseListenerToHeaderInTable in class TableSorter
Parameters:
table - the table which header should react on mouse events
See Also:
TableRowSorter

addKeyListenerToTable

public void addKeyListenerToTable(JTable table)
Add a key listener to the table for making it possible to browse with key events

Overrides:
addKeyListenerToTable in class TableSorter
Parameters:
table - the table to add the keylistener to
See Also:
TableRowSorter

getRowCount

public int getRowCount()
Return number of rows that this model has

Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class TableSorter
Returns:
number of rows in the model
See Also:
TableRowSorter

getColumnCount

public int getColumnCount()
Return number of columns that this model has

Specified by:
getColumnCount in interface TableModel
Overrides:
getColumnCount in class TableSorter
Returns:
number of columns in the model
See Also:
TableRowSorter

getColumnName

public String getColumnName(int column)
Return the column name of the specified column index

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class TableSorter
Returns:
column name at specified index
See Also:
TableRowSorter

getColumnClass

public Class getColumnClass(int column)
Return the column class of the specified column index

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class TableSorter
Returns:
column class at specified index
See Also:
TableRowSorter

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if cell is editable Per default ONLY booleans are editable

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class TableSorter
Returns:
true if a cell is editable
See Also:
TableRowSorter

getModel

public TableModel getModel()
Returns the (data) model

Specified by:
getModel in interface TableViewInterface
Overrides:
getModel in class TableSorter
See Also:
TableRowSorter

getOriginalIndex

public int getOriginalIndex(int localIndex)
Return the original index of the view index

Specified by:
getOriginalIndex in interface TableViewInterface
Overrides:
getOriginalIndex in class TableSorter
Parameters:
localIndex - the visible index
Returns:
original index of the visible index localIndex
See Also:
TableRowSorter

setModel

public void setModel(TableModel model)
set the (data)model this sorter wraps.

Specified by:
setModel in interface TableViewInterface
Overrides:
setModel in class TableSorter
See Also:
TableRowSorter


Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence