org.ejtools.swing.table
Class TableModelSorter

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--org.ejtools.swing.table.TableModelDecorator
              |
              +--org.ejtools.swing.table.TableModelIndexed
                    |
                    +--org.ejtools.swing.table.TableModelSorter
All Implemented Interfaces:
java.util.EventListener, java.io.Serializable, javax.swing.table.TableModel, javax.swing.event.TableModelListener

public class TableModelSorter
extends TableModelIndexed

Version:
$Revision: 1.8 $
Author:
Laurent Etiemble
See Also:
Serialized Form

Field Summary
protected  boolean ascending
          Description of the Field
protected  int column
          Description of the Field
protected  int compares
          Description of the Field
protected  java.util.Vector sortingColumns
          Description of the Field
 
Fields inherited from class org.ejtools.swing.table.TableModelIndexed
indexes
 
Fields inherited from class org.ejtools.swing.table.TableModelDecorator
model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableModelSorter(javax.swing.table.TableModel model)
          Constructor for TableModelSorter.
 
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()
          Description of the Method
 int compare(int row1, int row2)
          Description of the Method
 int compareRowsByColumn(int row1, int row2, int column)
          Description of the Method
 int getColumn()
          Gets the column attribute of the TableModelSorter object
 java.lang.Object getValueAt(int aRow, int aColumn)
          Gets the valueAt attribute of the TableModelSorter object
 boolean isAscending()
          Gets the ascending attribute of the TableModelSorter object
 void n2sort()
          Description of the Method
 void reallocateIndexes()
          Description of the Method
 void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
          Sets the valueAt attribute of the TableModelSorter object
 void shuttlesort(int[] from, int[] to, int low, int high)
          This is a home-grown implementation which we have not had time to research - it may perform poorly in some circumstances.
 void sort(java.lang.Object sender)
          Description of the Method
 void sortByColumn(int column)
          Description of the Method
 void sortByColumn(int column, boolean ascending)
          Description of the Method
 void tableChanged(javax.swing.event.TableModelEvent event)
          Description of the Method
 
Methods inherited from class org.ejtools.swing.table.TableModelIndexed
getRowCount, setModel, swap
 
Methods inherited from class org.ejtools.swing.table.TableModelDecorator
getColumnClass, getColumnCount, getColumnName, getModel, isCellEditable
 
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

ascending

protected boolean ascending
Description of the Field


column

protected int column
Description of the Field


compares

protected int compares
Description of the Field


sortingColumns

protected java.util.Vector sortingColumns
Description of the Field

Constructor Detail

TableModelSorter

public TableModelSorter(javax.swing.table.TableModel model)
Constructor for TableModelSorter.

Parameters:
model -
Method Detail

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.

Parameters:
table - The feature to be added to the MouseListenerToHeaderInTable attribute

checkModel

public void checkModel()
Description of the Method


compare

public int compare(int row1,
                   int row2)
Description of the Method

Parameters:
row1 - Description of the Parameter
row2 - Description of the Parameter
Returns:
Description of the Return Value

compareRowsByColumn

public int compareRowsByColumn(int row1,
                               int row2,
                               int column)
Description of the Method

Parameters:
row1 - Description of the Parameter
row2 - Description of the Parameter
column - Description of the Parameter
Returns:
Description of the Return Value

getColumn

public int getColumn()
Gets the column attribute of the TableModelSorter object

Returns:
The column value

getValueAt

public java.lang.Object getValueAt(int aRow,
                                   int aColumn)
Gets the valueAt attribute of the TableModelSorter object

Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class TableModelIndexed
Parameters:
aRow - Description of the Parameter
aColumn - Description of the Parameter
Returns:
The valueAt value

isAscending

public boolean isAscending()
Gets the ascending attribute of the TableModelSorter object

Returns:
The ascending value

n2sort

public void n2sort()
Description of the Method


reallocateIndexes

public void reallocateIndexes()
Description of the Method


setValueAt

public void setValueAt(java.lang.Object aValue,
                       int aRow,
                       int aColumn)
Sets the valueAt attribute of the TableModelSorter object

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class TableModelIndexed
Parameters:
aValue - The new valueAt value
aRow - The new valueAt value
aColumn - The new valueAt value

shuttlesort

public void shuttlesort(int[] from,
                        int[] to,
                        int low,
                        int high)
This is a home-grown implementation which we have not had time to research - it may perform poorly in some circumstances. It requires twice the space of an in-place algorithm and makes NlogN assigments shuttling the values between the two arrays. The number of compares appears to vary between N-1 and NlogN depending on the initial order but the main reason for using it here is that, unlike qsort, it is stable.

Parameters:
from - Description of the Parameter
to - Description of the Parameter
low - Description of the Parameter
high - Description of the Parameter

sort

public void sort(java.lang.Object sender)
Description of the Method

Parameters:
sender - Description of the Parameter

sortByColumn

public void sortByColumn(int column)
Description of the Method

Parameters:
column - Description of the Parameter

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Description of the Method

Parameters:
column - Description of the Parameter
ascending - Description of the Parameter

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent event)
Description of the Method

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Overrides:
tableChanged in class TableModelDecorator
Parameters:
event - Description of the Parameter


Copyright © 2002-2003 EJTools Org.. All Rights Reserved.