| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
edu.ucla.stat.SOCR.util.tablemodels.SortedTableModel
public class SortedTableModel
An AbstractTableModel implementation with sorting and multisorting support.
 It uses supplied RowComparator to sort table rows.
 The original TableModel is used only as the data
 source and is not modified.
 
Sample usage:
    // Old code:
    //    JTable jTable = new JTable(tableModel);
    // New code:
    SortedTableModel sortedTableModel = new SortedTableModel(tableModel);
    JTable jTable = new JTable(sortedTableModel);
    // Adding mouse listener that invokes sorting when table column's header is clicked
    jTable.getTableHeader().addMouseListener(new SortedTableHeaderMouseListener(jTable, sortedTableModel));
    // Adding renderer to display sorting icon
    jTable.getTableHeader().setDefaultRenderer(new SortedTableHeaderRenderer(jTable, sortedTableModel));
 After that your table has ability to sort its columns. If the user clicks on column's header it will be sorted.
 The first left click will set ascending sort order, the second descending, and the third reset sort order back to unsorted.
 The right click will show popup menu that allows set sort order exactly you want. To enable multisorting support just
 hold CTRL key and click on several table headers. The column header will show an icon than represents column
 sort order (ascending/descending) and column sort rank.
RowComparator, 
Serialized Form| Field Summary | |
|---|---|
protected  javax.swing.table.TableModel | 
model
Original TableModel used as data source. | 
| Fields inherited from class javax.swing.table.AbstractTableModel | 
|---|
listenerList | 
| Fields inherited from interface edu.ucla.stat.SOCR.util.tablemodels.SortOrderConstants | 
|---|
ASCENDING, DESCENDING, NOT_SORTED | 
| Constructor Summary | |
|---|---|
SortedTableModel(javax.swing.table.TableModel model)
Creates SortedTableModel object with specified TableModel
 as the data source. | 
|
| Method Summary | |
|---|---|
protected  boolean | 
checkModel()
 | 
 java.lang.Class | 
getColumnClass(int columnIndex)
 | 
 int | 
getColumnCount()
 | 
 java.lang.String | 
getColumnName(int columnIndex)
 | 
 int | 
getColumnSortOrder(int columnIndex)
Returns column's sort order.  | 
 int | 
getColumnSortRank(int columnIndex)
Returns column's sort rank within all sorted columns.  | 
 javax.swing.table.TableModel | 
getModel()
Returns original TableModel used as data source. | 
 int | 
getRealRowIndex(int rowIndex)
Returns row index in original model by index in current model (view index). | 
 RowComparator | 
getRowComparator()
Returns RowComparator used to sort table rows. | 
 int | 
getRowCount()
 | 
 int[] | 
getSortingColumnIndexes()
Returns array that contains sorted columns indexes.  | 
 java.util.List | 
getSortingColumns()
Returns list with sorted columns info.  | 
 int | 
getSortingColumnsCount()
Returns the number of sorting columns.  | 
 java.lang.Object | 
getValueAt(int rowIndex,
           int columnIndex)
 | 
 boolean | 
isCellEditable(int rowIndex,
               int columnIndex)
 | 
 boolean | 
isColumnAscending(int columnIndex)
Returns true if columnIndex is sorted
 and sort mode is SortOrderConstants.ASCENDING, false otherwise. | 
 boolean | 
isColumnDescending(int columnIndex)
Returns true if columnIndex is sorted
 and sort mode is SortOrderConstants.DESCENDING, false otherwise. | 
 boolean | 
isColumnSorted(int columnIndex)
Returns true if column is sorted, false otherwise. | 
 void | 
setModel(javax.swing.table.TableModel model)
Sets original TableModel used as data source. | 
 void | 
setRowComparator(RowComparator rowComparator)
Sets RowComparator used to sort table rows. | 
 void | 
setSortingColumns(java.util.List sortingColumns)
Specifies sorting columns infos and calls sort() method. | 
 void | 
setValueAt(java.lang.Object aValue,
           int rowIndex,
           int columnIndex)
 | 
 void | 
sort()
Forces sorting of data contained in model. | 
 void | 
sortColumn(int columnIndex,
           boolean resetSort)
Sorts specified column ascending allowing to reset or keep all others columns' sort order.  | 
 void | 
sortColumn(int columnIndex,
           int sortOrder,
           boolean resetSort)
Sorts specified column using sortOrder and allowing to reset or keep all others columns' sort order. | 
 void | 
tableChanged(javax.swing.event.TableModelEvent e)
 | 
| 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 | 
|---|
protected javax.swing.table.TableModel model
TableModel used as data source.
| Constructor Detail | 
|---|
public SortedTableModel(javax.swing.table.TableModel model)
SortedTableModel object with specified TableModel
 as the data source.
model - TableModel used as the data source| Method Detail | 
|---|
public RowComparator getRowComparator()
RowComparator used to sort table rows.
 The default is DefaultRowComparator instance.
RowComparator used to sort table rows.public void setRowComparator(RowComparator rowComparator)
RowComparator used to sort table rows. Invokes sort()
 before return. The default is DefaultRowComparator instance.
rowComparator - RowComparator used to sort table rowspublic void sort()
model. The original model is not modified.
public void sortColumn(int columnIndex,
                       boolean resetSort)
setSortingColumns(java.util.List)
columnIndex - model column indexresetSort - if true reset all previously sorted columns, if false
                    specified column is added to the sorted column set with incremental sort ranksortColumn(int, int, boolean)
public void sortColumn(int columnIndex,
                       int sortOrder,
                       boolean resetSort)
sortOrder and allowing to reset or keep all others columns' sort order.
 setSortingColumns(java.util.List)
columnIndex - model column indexsortOrder - column sort order, must be one of the following values:
                    SortOrderConstants.ASCENDING, SortOrderConstants.DESCENDING or SortOrderConstants.NOT_SORTEDresetSort - if true reset all previously sorted columns, if false
                    specified column is added to the sorted column set with incremental sort ranksortColumn(int, boolean)public int getRealRowIndex(int rowIndex)
model by index in current model (view index).
rowIndex - index in current model (view index)
model.public boolean isColumnSorted(int columnIndex)
true if column is sorted, false otherwise.
columnIndex - model column index
true if column is sorted, false otherwise.public boolean isColumnAscending(int columnIndex)
true if columnIndex is sorted
 and sort mode is SortOrderConstants.ASCENDING, false otherwise.
columnIndex - model column index
true if columnIndex is sorted ascending.isColumnDescending(int), 
isColumnSorted(int)public boolean isColumnDescending(int columnIndex)
true if columnIndex is sorted
 and sort mode is SortOrderConstants.DESCENDING, false otherwise.
 
columnIndex - model column index
true if columnIndex is sorted desending.isColumnAscending(int), 
isColumnSorted(int)public int getColumnSortOrder(int columnIndex)
SortOrderConstants.ASCENDING, SortOrderConstants.DESCENDING or SortOrderConstants.NOT_SORTED
columnIndex - model column index
SortOrderConstantspublic int getColumnSortRank(int columnIndex)
columnIndex - model column index
public int[] getSortingColumnIndexes()
getSortingColumns()public java.util.List getSortingColumns()
getSortingColumnIndexes(), 
SortedColumnInfopublic void setSortingColumns(java.util.List sortingColumns)
sort() method.
sortingColumns - list of SortedColumnInfopublic int getSortingColumnsCount()
public void setModel(javax.swing.table.TableModel model)
TableModel used as data source.
model - original TableModel used as data source
public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
getValueAt in interface javax.swing.table.TableModel
public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
setValueAt in interface javax.swing.table.TableModelpublic void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged in interface javax.swing.event.TableModelListenerprotected boolean checkModel()
public javax.swing.table.TableModel getModel()
TableModel used as data source.
TableModel used as data source.public int getRowCount()
getRowCount in interface javax.swing.table.TableModelpublic int getColumnCount()
getColumnCount in interface javax.swing.table.TableModelpublic java.lang.String getColumnName(int columnIndex)
getColumnName in interface javax.swing.table.TableModelgetColumnName in class javax.swing.table.AbstractTableModelpublic java.lang.Class getColumnClass(int columnIndex)
getColumnClass in interface javax.swing.table.TableModelgetColumnClass in class javax.swing.table.AbstractTableModel
public boolean isCellEditable(int rowIndex,
                              int columnIndex)
isCellEditable in interface javax.swing.table.TableModelisCellEditable in class javax.swing.table.AbstractTableModel
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||