public class TableSorter extends TableMap
Original version 1.5 12/17/97
Modifier and Type | Field and Description |
---|---|
private boolean |
ascending
Whether sort is ascending
|
private int |
compares
Track the comparison result of two rows
|
private int[] |
indexes
Sorted indexes
|
private static org.apache.log4j.Logger |
LOGGER
Logger
|
private java.util.List<java.awt.event.MouseAdapter> |
myMouseListeners
The listeners registered for mouse events on the table
DSR - So I can remove them
|
private static long |
serialVersionUID
Serial UID
|
private java.util.Vector<java.lang.Integer> |
sortingColumns
Columns used to sort the model
|
Constructor and Description |
---|
TableSorter()
Constructs a Table Sorter
Creates an integer array for consistency
|
TableSorter(javax.swing.table.TableModel model)
Constructs a Table Sorter
|
Modifier and Type | Method and Description |
---|---|
void |
addMouseListenerToHeaderInTable(javax.swing.JTable table)
Adds a mouse listener to the Table to trigger a table sort
when a column heading is clicked in the JTable.
|
private void |
checkModel()
Checks if there has been any uninformed change in the model
|
private int |
compare(int row1,
int row2)
Compares values in row1 and row2
|
private int |
compareRowsByColumn(int row1,
int row2,
int column)
Compares the values of two rows in a column
|
java.lang.Object |
getValueAt(int aRow,
int aColumn)
Gets the value of the model at indexes[aRow] and aColumn
|
private void |
reallocateIndexes()
Set up a new mapping array of indexes with the right number of
elements for the new data model
|
void |
removeModel(javax.swing.table.TableModel model)
Remove the Model model
|
void |
removeMouseListenerFromHeaderInTable(javax.swing.JTable table)
Need ability to remove mouselistener
Otherwise creation of new sorter leaks memory
|
void |
setModel(javax.swing.table.TableModel model)
Sets the data model for this table to model and
registers with it for listener notifications from
the new data model.
|
void |
setValueAt(java.lang.Object aValue,
int aRow,
int aColumn)
Sets the value of the model at aRow and aColumn to aValue
|
private 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.
|
private void |
sort(java.lang.Object sender)
Performs sort operation on the sender
|
private void |
sortByColumn(int column,
boolean pAscending)
Sorts the column in an ascending order
|
void |
sortByColumns(int[] columns)
Calls the method sortByColumns(int,boolean) after setting the sorting
option as ascending
|
void |
sortByColumns(int[] columns,
boolean pAscending)
Sort the data by the selected columns
|
void |
tableChanged(javax.swing.event.TableModelEvent e)
The tableChanged Method is called when any change is made to the table
|
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, isCellEditable
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
private static final long serialVersionUID
private static final org.apache.log4j.Logger LOGGER
private int[] indexes
private java.util.Vector<java.lang.Integer> sortingColumns
private boolean ascending
private int compares
private java.util.List<java.awt.event.MouseAdapter> myMouseListeners
public TableSorter()
public TableSorter(javax.swing.table.TableModel model)
model
- The Table Model Objectpublic void setModel(javax.swing.table.TableModel model)
public void removeModel(javax.swing.table.TableModel model)
removeModel
in class TableMap
model
- The Table Model object to be removedprivate int compareRowsByColumn(int row1, int row2, int column)
row1
- row indexrow2
- row indexcolumn
- column indexprivate int compare(int row1, int row2)
row1
- row indexrow2
- row indexprivate void reallocateIndexes()
public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
tableChanged
in class TableMap
e
- The Table ModelEventprivate void checkModel()
private void sort(java.lang.Object sender)
sender
- Object that is to sortedprivate void shuttlesort(int[] from, int[] to, int low, int high)
from
- [] array that has to be sortedto
- [] array that has the sorted resultlow
- Starting row index 1high
- Maximum number of rowspublic java.lang.Object getValueAt(int aRow, int aColumn)
getValueAt
in interface javax.swing.table.TableModel
getValueAt
in class TableMap
aRow
- row indexaColumn
- column indexpublic void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class TableMap
aValue
- The value to assignaRow
- row indexaColumn
- column indexprivate void sortByColumn(int column, boolean pAscending)
column
- column indexpAscending
- the column is sorted in an ascending orderpublic void sortByColumns(int[] columns)
columns
- The column valuespublic void sortByColumns(int[] columns, boolean pAscending)
columns
- The columns to sort the data bypAscending
- A boolean value that determines whether the column
is sorted in an ascending or descending orderpublic void addMouseListenerToHeaderInTable(javax.swing.JTable table)
table
- The JTabel objectpublic void removeMouseListenerFromHeaderInTable(javax.swing.JTable table)
table
- The JTable object