Package noaa.coastwatch.gui
Class SortedTableModel
java.lang.Object
noaa.coastwatch.gui.SortedTableModel
- All Implemented Interfaces:
TableModel
A
SortedTableModel
can be used to provide row
sorting services for any
javax.swing.table.TableModel
. The new model
simply wraps the old one and translates row indicies through
the wrapper so as to make it appear that the table is sorted
according to the values held in a specific column of the
table.- Since:
- 3.2.1
- Author:
- Peter Hollemans
-
Constructor Summary
ConstructorDescriptionSortedTableModel
(TableModel model) Creates a sorted model using the specified unsorted model for its data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
convertRowIndexToModel
(int row) Converts a row index in the sorted model to a row index in the underlying model.int
convertRowIndexToView
(int row) Converts a row index in the underlying model to a row index in the sorted model.getColumnClass
(int columnIndex) int
getColumnName
(int columnIndex) boolean
Gets the current sorting order.int
int
Gets the current sorting column, or -1 for no sorting.getValueAt
(int rowIndex, int columnIndex) boolean
isCellEditable
(int rowIndex, int columnIndex) void
void
setSort
(int sortColumn, boolean isAscending) Set the sorting column and order.void
setValueAt
(Object aValue, int rowIndex, int columnIndex)
-
Constructor Details
-
SortedTableModel
Creates a sorted model using the specified unsorted model for its data. The table is initially unsorted so that rows in the sorted table model are in exactly the same order as rows in the unsorted model.- Parameters:
model
- the model to use for row and column data.
-
-
Method Details
-
setSort
public void setSort(int sortColumn, boolean isAscending) Set the sorting column and order.- Parameters:
sortColumn
- the new sorting column, or -1 for no sorting.isAscending
- the new sorting order, true for ascending.
-
getSortColumn
public int getSortColumn()Gets the current sorting column, or -1 for no sorting. -
getIsAscending
public boolean getIsAscending()Gets the current sorting order. -
convertRowIndexToModel
public int convertRowIndexToModel(int row) Converts a row index in the sorted model to a row index in the underlying model.- Parameters:
row
- the row index to convert.- Returns:
- the row index in the underlying table model.
-
convertRowIndexToView
public int convertRowIndexToView(int row) Converts a row index in the underlying model to a row index in the sorted model.- Parameters:
row
- the row index to convert.- Returns:
- the row index in the sorted table model.
-
getRowCount
public int getRowCount()- Specified by:
getRowCount
in interfaceTableModel
-
getColumnCount
public int getColumnCount()- Specified by:
getColumnCount
in interfaceTableModel
-
getColumnName
- Specified by:
getColumnName
in interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClass
in interfaceTableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex) - Specified by:
isCellEditable
in interfaceTableModel
-
getValueAt
- Specified by:
getValueAt
in interfaceTableModel
-
setValueAt
- Specified by:
setValueAt
in interfaceTableModel
-
addTableModelListener
- Specified by:
addTableModelListener
in interfaceTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListener
in interfaceTableModel
-