JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.aspects.gui
Class TableSorter

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--org.objectweb.jac.aspects.gui.TableMap
              |
              +--org.objectweb.jac.aspects.gui.TableSorter
All Implemented Interfaces:
CollectionModel, EventListener, ExtendedTableModel, Model, Serializable, TableModel, TableModelListener

public class TableSorter
extends org.objectweb.jac.aspects.gui.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
Author:
Philip Milne
See Also:
Serialized Form

Field Summary
protected  ExtendedTableModel model
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableSorter()
           
TableSorter(ExtendedTableModel model)
           
 
Method Summary
 void checkModel()
           
 void close()
          Unregisters the model from the event it is currently listening to.
 int compare(int row1, int row2)
           
 int compareRowsByColumn(int row1, int row2, int column)
           
 void defaultSortOrder()
          Sets the sort column for the collection from the context or from RTTI configuration.
 int getActualIndex(int row)
           
 Object getCellRenderer(View tableView, int column, ViewFactory factory, DisplayContext context)
          Build a cell render for a given column.
 CollectionItem getCollection()
          Get the collection item represented by the model
 Class getColumnClass(int aColumn)
           
 int getColumnCount()
           
 String getColumnName(int aColumn)
           
 String[] getHeaders()
          Gets the headers' titles.
 MemberItem[] getMembers()
          Returns the members that are displayed in the table.
 ExtendedTableModel getModel()
           
 Object getObject(int row)
          Returns the object at the row represented by the given index.
 Object getObject(int row, int column)
          Gets the value at a given row, column couple.
 int getRowCount()
          Gets the number of rows of this collection.
 SortCriteria getSortCriteria(int column)
          Gets the sort criteria for a column.
 Object getValueAt(int aRow, int aColumn)
           
 int indexOf(Object object)
          Returns the index of an object in the collection
 boolean isCellEditable(int row, int column)
           
 void n2sort()
           
 void reallocateIndexes()
          Reset to default unsorted order of the model.
protected  void saveSortCriteria(SortCriteria criteria)
          Save the sort criteria in the context
 void setModel(ExtendedTableModel model)
           
 void setValueAt(Object aValue, int aRow, int aColumn)
           
 void shuttlesort(int[] from, int[] to, int low, int high)
           
 void sort(Object sender)
           
 void sortByColumn(int column)
          Sorts using values of a column
 void sortByColumn(int column, boolean ascending)
           
 void swap(int i, int j)
           
 void tableChanged(TableModelEvent e)
           
 void toggleSortByColumn(int column)
          Sorts using values of a column.
 
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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

model

protected ExtendedTableModel model
Constructor Detail

TableSorter

public TableSorter()

TableSorter

public TableSorter(ExtendedTableModel model)
Method Detail

getSortCriteria

public SortCriteria getSortCriteria(int column)
Gets the sort criteria for a column.

Returns:
the SortCriteria of the given column, or null.

setModel

public void setModel(ExtendedTableModel model)
Overrides:
setModel in class org.objectweb.jac.aspects.gui.TableMap

defaultSortOrder

public void defaultSortOrder()
Sets the sort column for the collection from the context or from RTTI configuration.


compareRowsByColumn

public int compareRowsByColumn(int row1,
                               int row2,
                               int column)

compare

public int compare(int row1,
                   int row2)

reallocateIndexes

public void reallocateIndexes()
Reset to default unsorted order of the model.


getActualIndex

public int getActualIndex(int row)

tableChanged

public void tableChanged(TableModelEvent e)
Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class org.objectweb.jac.aspects.gui.TableMap

checkModel

public void checkModel()

sort

public void sort(Object sender)

n2sort

public void n2sort()

shuttlesort

public void shuttlesort(int[] from,
                        int[] to,
                        int low,
                        int high)

swap

public void swap(int i,
                 int j)

getValueAt

public Object getValueAt(int aRow,
                         int aColumn)
Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class org.objectweb.jac.aspects.gui.TableMap

getObject

public Object getObject(int row)
Description copied from interface: CollectionModel
Returns the object at the row represented by the given index.

Specified by:
getObject in interface CollectionModel
Overrides:
getObject in class org.objectweb.jac.aspects.gui.TableMap
Parameters:
row - a row index

indexOf

public int indexOf(Object object)
Description copied from interface: CollectionModel
Returns the index of an object in the collection

Specified by:
indexOf in interface CollectionModel
Overrides:
indexOf in class org.objectweb.jac.aspects.gui.TableMap
Parameters:
object - the object whose index to find
Returns:
the index of object, or -1 if the object is not in the collection

getObject

public Object getObject(int row,
                        int column)
Description copied from interface: ExtendedTableModel
Gets the value at a given row, column couple.

Specified by:
getObject in interface ExtendedTableModel
Overrides:
getObject in class org.objectweb.jac.aspects.gui.TableMap

setValueAt

public void setValueAt(Object aValue,
                       int aRow,
                       int aColumn)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class org.objectweb.jac.aspects.gui.TableMap

sortByColumn

public void sortByColumn(int column)
Sorts using values of a column

Parameters:
column - index of column to sort by

toggleSortByColumn

public void toggleSortByColumn(int column)
Sorts using values of a column. Reverse the order if the table was already sorted by this column.

Parameters:
column - index of column to sort by

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)

saveSortCriteria

protected void saveSortCriteria(SortCriteria criteria)
Save the sort criteria in the context

Parameters:
criteria - the sort criteria to save

getModel

public ExtendedTableModel getModel()

getCollection

public CollectionItem getCollection()
Description copied from interface: CollectionModel
Get the collection item represented by the model

Specified by:
getCollection in interface CollectionModel
Returns:
a collection item

getRowCount

public int getRowCount()
Description copied from interface: CollectionModel
Gets the number of rows of this collection.

Specified by:
getRowCount in interface TableModel
Returns:
the number of rows

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int aColumn)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int aColumn)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

getCellRenderer

public Object getCellRenderer(View tableView,
                              int column,
                              ViewFactory factory,
                              DisplayContext context)
Description copied from interface: ExtendedTableModel
Build a cell render for a given column.

Specified by:
getCellRenderer in interface ExtendedTableModel
Parameters:
tableView - the actual table view
column - the column for which to build the viewer
factory - the factory to use
context - the display context

getMembers

public MemberItem[] getMembers()
Description copied from interface: ExtendedTableModel
Returns the members that are displayed in the table.

Specified by:
getMembers in interface ExtendedTableModel
Returns:
one member per column

getHeaders

public String[] getHeaders()
Description copied from interface: ExtendedTableModel
Gets the headers' titles.

Specified by:
getHeaders in interface ExtendedTableModel
Returns:
one title per column

close

public void close()
Description copied from interface: Model
Unregisters the model from the event it is currently listening to.

Specified by:
close in interface Model

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli