|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.table.AbstractTableModel jwo.utils.gui.TableMap jwo.utils.gui.TableSorter
public class TableSorter
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 e.g. "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 algorithm 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 jwo.utils.gui.TableMap |
---|
model |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
TableSorter()
Creates the sorter with no underlying table model. |
|
TableSorter(TableModel model)
Creates the sorter using the given table model. |
Method Summary | |
---|---|
void |
addMouseListenerToHeaderInTable(JTable table)
|
void |
checkModel()
Checks to see if model is ready for possible changes. |
int |
compare(int row1,
int row2)
Compares two rows and indicates their order. |
int |
compareRowsByColumn(int row1,
int row2,
int column)
Performs a comparison between two rows based on the values in the given column. |
Object |
getValueAt(int aRow,
int aColumn)
Reports the table value at the given coordinates. |
void |
n2sort()
|
void |
reallocateIndexes()
Reallocates row indices in table. |
void |
setModel(TableModel model)
Sets table model that can be sorted. |
void |
setValueAt(Object aValue,
int aRow,
int aColumn)
Sets the table value at the given coordinates. |
void |
shuttlesort(int[] from,
int[] to,
int low,
int high)
|
void |
sort()
|
void |
sortByColumn(int column)
|
void |
sortByColumn(int column,
boolean ascending)
|
void |
swap(int i,
int j)
|
void |
tableChanged(TableModelEvent e)
Used to signal that there has been a change to something in the table. |
Methods inherited from class jwo.utils.gui.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()
setModel
to associate the sorter with a particular table model.
public TableSorter(TableModel model)
model
- Table model to be sortable by this class.Method Detail |
---|
public void setModel(TableModel model)
setModel
in class TableMap
model
- Table model to be sortable by this class.public int compareRowsByColumn(int row1, int row2, int column)
row1
- First row to compare.row2
- Second row to compare.column
- Column value to identify the two cells to compare.
public int compare(int row1, int row2)
row1
- First row to compare.row2
- Second row to compare.
public void reallocateIndexes()
public void tableChanged(TableModelEvent e)
TableMap
tableChanged
in interface TableModelListener
tableChanged
in class TableMap
e
- Event encapsulating the table change.public void checkModel()
public void sort()
public void n2sort()
public void shuttlesort(int[] from, int[] to, int low, int high)
public void swap(int i, int j)
public Object getValueAt(int aRow, int aColumn)
TableMap
getValueAt
in interface TableModel
getValueAt
in class TableMap
aRow
- Row of table cell to report.aColumn
- Column of table cell to report.
public void setValueAt(Object aValue, int aRow, int aColumn)
TableMap
setValueAt
in interface TableModel
setValueAt
in class TableMap
aValue
- Object to place at given table coordinates.aRow
- Row of table cell to set.aColumn
- Column of table cell to set.public void sortByColumn(int column)
public void sortByColumn(int column, boolean ascending)
public void addMouseListenerToHeaderInTable(JTable table)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |