|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
org.salespointframework.desktop.models.AbstractTableModel
org.salespointframework.desktop.TableMap
org.salespointframework.desktop.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 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 | |
---|---|
private int |
actualColumn
The column to be sorted. |
private boolean |
ascending
Sort ascending or descending. |
private int |
compares
Internal helper variable. |
private int[] |
indexes
Field of indexes. |
private int[] |
reverseIndexes
Field of indexes. |
private java.util.Vector<java.lang.Integer> |
sortingColumns
Sorting vector. |
Fields inherited from class org.salespointframework.desktop.TableMap |
---|
model |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
TableSorter()
Constructor. |
|
TableSorter(AbstractTableModel model)
Constructor. |
Method Summary | |
---|---|
void |
addMouseListenerToHeaderInTable(javax.swing.JTable table,
java.lang.Object[] ao)
Adds a mouse listener to the table header. |
private boolean |
checkModel()
Helper method. |
int |
compare(int row1,
int row2)
Comparison of two rows. |
int |
compareRowsByColumn(int row1,
int row2,
int column)
Compares columns of two specific rows. |
private void |
createReverseIndexes()
Creates a reverse index table. |
java.lang.Object |
getRecord(int row)
Gets the record. |
java.lang.Object |
getValueAt(int aRow,
int aColumn)
Get the value of a table cell. |
private void |
reallocateIndexes()
Helper method. |
void |
setModel(AbstractTableModel model)
Sets the TableModel . |
void |
setValueAt(java.lang.Object aValue,
int aRow,
int aColumn)
Changes the value of a table cell. |
private void |
shuttlesort(int[] from,
int[] to,
int low,
int high)
Sorting method. |
private void |
sort()
Sorts the model. |
void |
sortByColumn(int column)
Sorts the table ascending by a column. |
void |
sortByColumn(int column,
boolean ascending)
Sorts the table by a column. |
void |
tableChanged(javax.swing.event.TableModelEvent e)
Reacts on TableChangeEvents, either converts them as needed or passes them to the model. |
Methods inherited from class org.salespointframework.desktop.TableMap |
---|
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, isCellEditable, setData |
Methods inherited from class org.salespointframework.desktop.models.AbstractTableModel |
---|
getEntryDescriptor, orderByColumn, reOrderBy |
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 |
Field Detail |
---|
private int[] indexes
private int[] reverseIndexes
private java.util.Vector<java.lang.Integer> sortingColumns
private boolean ascending
private int actualColumn
private int compares
Constructor Detail |
---|
public TableSorter()
public TableSorter(AbstractTableModel model)
model
- the wrapped TableModel
Method Detail |
---|
public void setModel(AbstractTableModel model)
TableModel
.
setModel
in class TableMap
model
- the model.public int compareRowsByColumn(int row1, int row2, int column)
Attention:
This code is not 100% Java 1.5 compatible. Had to avoid the warning with SuppressWarnings
because there is no clean solution for this in 1.5 yet.
row1
- first row.row2
- second row.column
- the column index.
public int compare(int row1, int row2)
row1
- first row.row2
- second row.
private void reallocateIndexes()
public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
tableChanged
in class TableMap
e
- the event.private void createReverseIndexes()
private boolean checkModel()
private void sort()
shuttlesort
.
private void shuttlesort(int[] from, int[] to, int low, int high)
from
- the unsorted index array.to
- the sorted index array (i.e. the result).low
- lowest field to be taken into consideration on sorting.high
- highest field to be taken into consideration on sorting.public java.lang.Object getValueAt(int aRow, int aColumn)
getValueAt
in interface javax.swing.table.TableModel
getValueAt
in class TableMap
aRow
- the row of the TableCell to get.aColumn
- the column of the table cell to get.
public java.lang.Object getRecord(int row)
getRecord
in class TableMap
row
- the affected table row.
public 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 set.aRow
- the row of the TableCell to be changed.aColumn
- the column of the table cell to be changed.public void sortByColumn(int column)
column
- the column by which the table should be sorted.public void sortByColumn(int column, boolean ascending)
column
- the column by which the table should be sorted.ascending
- if true
sort sequence is ascending, otherwise descending.public void addMouseListenerToHeaderInTable(javax.swing.JTable table, java.lang.Object[] ao)
table
- the table to which header the listener is to be added
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |