|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.table.AbstractTableModel com.anthonyeden.lib.util.TableMap com.anthonyeden.lib.util.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 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 com.anthonyeden.lib.util.TableMap |
model |
Fields inherited from class javax.swing.table.AbstractTableModel |
listenerList |
Constructor Summary | |
TableSorter()
Construct a TableSorter with no TableModel. |
|
TableSorter(javax.swing.table.TableModel model)
Construct a TableSorter with the given TableModel. |
Method Summary | |
void |
addMouseListenerToHeaderInTable(javax.swing.JTable table)
Add a MouseListener to the given table which will cause the table to be sorted when the header is clicked. |
void |
checkModel()
Check to see if the index length matches the model row count. |
int |
compare(int row1,
int row2)
Compare two rows. |
int |
compareRowsByColumn(int row1,
int row2,
int column)
Compare values row by row. |
int |
getColumn()
Get the column which is being sorted. |
int |
getRealIndex(int row)
Get the real index of the given row. |
java.lang.Object |
getValueAt(int aRow,
int aColumn)
Get the value at the given row and column. |
boolean |
isAscending()
Return true if the data is sorted in ascending order. |
void |
n2sort()
|
void |
reallocateIndexes()
Reallocate the array which holds sorted indexes. |
void |
setModel(javax.swing.table.TableModel model)
Set the TableModel. |
void |
setValueAt(java.lang.Object aValue,
int aRow,
int aColumn)
Set the value at the given row and column. |
void |
shuttlesort(int[] from,
int[] to,
int low,
int high)
|
void |
sort(java.lang.Object sender)
Sort the table data. |
void |
sortByColumn(int column)
Sort by the given column in ascending order. |
void |
sortByColumn(int column,
boolean ascending)
Sort by the given column and order. |
void |
swap(int i,
int j)
|
void |
tableChanged(javax.swing.event.TableModelEvent e)
Fire a TableModelEvent signaling that the table has changed. |
Methods inherited from class com.anthonyeden.lib.util.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()
public TableSorter(javax.swing.table.TableModel model)
model
- The TableModelMethod Detail |
public void setModel(javax.swing.table.TableModel model)
setModel
in class TableMap
model
- The TableModelpublic int compareRowsByColumn(int row1, int row2, int column)
java.lang.Comparable
interface.
row1
- Row 1row2
- Row 2column
- The column to sort
public int compare(int row1, int row2)
row1
- Row 1row2
- Row 2
public void reallocateIndexes()
public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
tableChanged
in class TableMap
e
- The TableModelEventpublic void checkModel()
public void sort(java.lang.Object sender)
sender
- The object which invoked the sortpublic void n2sort()
public void shuttlesort(int[] from, int[] to, int low, int high)
public void swap(int i, int j)
public java.lang.Object getValueAt(int aRow, int aColumn)
TableMap
getValueAt
in interface javax.swing.table.TableModel
getValueAt
in class TableMap
aRow
- The rowaColumn
- The column
public void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
TableMap
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class TableMap
aValue
- The valueaRow
- The rowaColumn
- The columnpublic void sortByColumn(int column)
column
- The columnpublic void sortByColumn(int column, boolean ascending)
column
- The columnascending
- True to sort in ascending orderpublic int getColumn()
public int getRealIndex(int row)
row
- The row index
public boolean isAscending()
public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
table
- The JTable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |