Make your own free website on Tripod.com

suncertify.swingClient.swingTable
Class TableSorter

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--suncertify.swingClient.swingTable.TableMap
              |
              +--suncertify.swingClient.swingTable.TableSorter

public class TableSorter
extends TableMap

A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter 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 TableSorter 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.

Version:
1.5 12/17/97
See Also:
Serialized Form

Fields inherited from class suncertify.swingClient.swingTable.TableMap
model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableSorter()
          The class constructor with no argument.
TableSorter(javax.swing.table.TableModel model)
          The class constructor with a single argument.
 
Method Summary
 void addMouseListenerToHeaderInTable(javax.swing.JTable table)
          Add a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable.
 void checkModel()
          Validate the table model.
 int compare(int row1, int row2)
          The compare method.
 int compareRowsByColumn(int row1, int row2, int column)
          Sort the values in the table on a row by row basis on the columns.
 java.lang.Object getValueAt(int aRow, int aColumn)
          get cell value
 void n2sort()
          The sorting method.
 void reallocateIndexes()
          The method to reallocate the indexes.
 void setModel(javax.swing.table.TableModel model)
          The method to set the model of a table.
 void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
          set cell value
 void shuttlesort(int[] from, int[] to, int low, int high)
          use the shuttle sort algorithm to sort.
 void sort(java.lang.Object sender)
          Method to sort the table.
 void sortByColumn(int column)
          sort by the chosen column
 void sortByColumn(int column, boolean ascending)
          sort by the chosen column
 void swap(int i, int j)
          swap indexes.
 void tableChanged(javax.swing.event.TableModelEvent e)
          called when the underlying table changes.
 
Methods inherited from class suncertify.swingClient.swingTable.TableMap
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, isCellEditable
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSorter

public TableSorter()
The class constructor with no argument.

TableSorter

public TableSorter(javax.swing.table.TableModel model)
The class constructor with a single argument.
Method Detail

setModel

public void setModel(javax.swing.table.TableModel model)
The method to set the model of a table.
Overrides:
setModel in class TableMap

compareRowsByColumn

public int compareRowsByColumn(int row1,
                               int row2,
                               int column)
Sort the values in the table on a row by row basis on the columns.

compare

public int compare(int row1,
                   int row2)
The compare method.

reallocateIndexes

public void reallocateIndexes()
The method to reallocate the indexes.

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
called when the underlying table changes.
Overrides:
tableChanged in class TableMap

checkModel

public void checkModel()
Validate the table model.

sort

public void sort(java.lang.Object sender)
Method to sort the table.

n2sort

public void n2sort()
The sorting method.

shuttlesort

public void shuttlesort(int[] from,
                        int[] to,
                        int low,
                        int high)
use the shuttle sort algorithm to sort.

swap

public void swap(int i,
                 int j)
swap indexes.

getValueAt

public java.lang.Object getValueAt(int aRow,
                                   int aColumn)
get cell value
Overrides:
getValueAt in class TableMap

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int aRow,
                       int aColumn)
set cell value
Overrides:
setValueAt in class TableMap

sortByColumn

public void sortByColumn(int column)
sort by the chosen column

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
sort by the chosen column

addMouseListenerToHeaderInTable

public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
Add a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable.