|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
gov.nih.nlm.swing.TableMap
gov.nih.nlm.swing.TableSorter
public class TableSorter
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.
| Field Summary |
|---|
| Fields inherited from class gov.nih.nlm.swing.TableMap |
|---|
model |
| Fields inherited from class javax.swing.table.AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
TableSorter()
Instantiates an empty TableSorter. |
|
TableSorter(TableModel model)
Instantiates a TableSorter with the specified model. |
|
| Method Summary | |
|---|---|
void |
addMouseListenerToHeaderInTable(JTable table)
Adds a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable. |
void |
checkModel()
Validates the model. |
int |
compare(int row1,
int row2)
Perform comparison on the sorting column. |
int |
compareRowsByColumn(int row1,
int row2,
int column)
Compares data in sorted column by type. |
void |
dump()
Debug method. |
Object |
getValueAt(int r,
int c)
Returns the value at the specified row and column from the underlying model. |
int |
mapIndex(int i)
Returns the mapped index for the specified table row index. |
void |
reallocateIndexes()
Resets the map so that the first row of the table corresponds to the first index of the underlying model. |
void |
resetSort()
Resets the sorting mechanism to wait until a header is clicked before sorting the table. |
int |
reverseMapIndex(int i)
Returns the table row index for the underlying model index. |
void |
setModel(TableModel model)
Sets the model and resets the map. |
void |
setValueAt(Object value,
int r,
int c)
Sets the value at the specified row and column from the underlying model. |
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(Object sender)
Sorts the table. |
void |
sortByColumn(int column)
Sorts table by a column (ascending by default). |
void |
sortByColumn(int column,
boolean ascending)
Sorts table by a column. |
void |
swap(int i,
int j)
Swap two elements of the map. |
void |
tableChanged(TableModelEvent e)
Handles the table change event. |
| Methods inherited from class gov.nih.nlm.swing.TableMap |
|---|
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, 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 |
| Constructor Detail |
|---|
public TableSorter()
TableSorter.
public TableSorter(TableModel model)
TableSorter with the specified model.
model - the TableModel| Method Detail |
|---|
public void setModel(TableModel model)
setModel in class TableMapmodel - the TableModelpublic void resetSort()
public int compareRowsByColumn(int row1,
int row2,
int column)
row1 - A table rowrow2 - Another table rowcolumn - A table column
row1
and row2 for the specified column
public int compare(int row1,
int row2)
row1 - A table rowrow2 - Another table row
public void reallocateIndexes()
public void tableChanged(TableModelEvent e)
tableChanged in interface TableModelListenertableChanged in class TableMape - the TableModelEventpublic void checkModel()
public void sort(Object sender)
sender - Object
public void shuttlesort(int[] from,
int[] to,
int low,
int high)
from - sourceto - targetlow - low valuehigh - high value
public void swap(int i,
int j)
i - first index to swapj - second index to swap
public Object getValueAt(int r,
int c)
getValueAt in interface TableModelgetValueAt in class TableMapr - a table rowc - a table column
public void setValueAt(Object value,
int r,
int c)
setValueAt in interface TableModelsetValueAt in class TableMapr - a table rowc - a table columnvalue - an Object value.public void sortByColumn(int column)
column - the column number
public void sortByColumn(int column,
boolean ascending)
column - the column numberascending - flag indicating sort orderpublic int mapIndex(int i)
i - a table row
public int reverseMapIndex(int i)
i - the underlying index of the model
public void dump()
public void addMouseListenerToHeaderInTable(JTable table)
table - the sortable JTable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||