public class FastTableRowSorter<M extends javax.swing.table.TableModel>
extends javax.swing.RowSorter<M>
To get its speed-ups, this Sorter makes a few assumptions:
FastRowFilter
Constructor and Description |
---|
FastTableRowSorter(M model)
Creates a
TableRowSorter using model
as the underlying TableModel . |
Modifier and Type | Method and Description |
---|---|
void |
allRowsChanged() |
int |
convertRowIndexToModel(int index) |
int |
convertRowIndexToView(int index) |
java.util.Comparator<?> |
getComparator(int column)
Returns the
Comparator for the specified
column. |
int |
getMaxSortKeys()
Returns the maximum number of sort keys.
|
M |
getModel()
Returns the underlying model.
|
int |
getModelRowCount() |
FastRowFilter<? super M> |
getRowFilter()
Returns the filter that determines which rows, if any, should
be hidden from view.
|
java.util.List<? extends javax.swing.RowSorter.SortKey> |
getSortKeys()
Returns the current sort keys.
|
boolean |
getSortsOnUpdates()
Returns true if a sort should happen when the underlying
model is updated; otherwise, returns false.
|
int |
getViewRowCount() |
void |
modelStructureChanged() |
void |
rowsDeleted(int firstRow,
int endRow) |
void |
rowsInserted(int firstRow,
int endRow) |
void |
rowsUpdated(int firstRow,
int endRow) |
void |
rowsUpdated(int firstRow,
int endRow,
int column) |
void |
setComparator(int column,
java.util.Comparator<?> comparator)
Sets the
Comparator to use when sorting the specified
column. |
void |
setMaxSortKeys(int max)
Sets the maximum number of sort keys.
|
void |
setRowFilter(FastRowFilter<? super M> filter)
Sets the filter that determines which rows, if any, should be
hidden from the view.
|
void |
setSortKeys(java.util.List<? extends javax.swing.RowSorter.SortKey> sortKeys)
Sets the sort keys.
|
void |
setSortsOnUpdates(boolean sortsOnUpdates)
If true, specifies that a sort should happen when the underlying
model is updated (
rowsUpdated is invoked). |
void |
sort()
Sorts and filters the rows in the view based on the sort keys
of the columns currently being sorted and the filter, if any,
associated with this sorter.
|
void |
toggleSortOrder(int column)
Reverses the sort order from ascending to descending (or
descending to ascending) if the specified column is already the
primary sorted column; otherwise, makes the specified column
the primary sorted column, with an ascending sort order.
|
protected boolean |
useToString(int column) |
public FastTableRowSorter(M model)
TableRowSorter
using model
as the underlying TableModel
.model
- the underlying TableModel
to use,
null
is treated as an empty modelpublic final M getModel()
getModel
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public java.util.Comparator<?> getComparator(int column)
Comparator
for the specified
column. If a Comparator
has not been specified using
the setComparator
method a Comparator
will be returned based on the column class
(TableModel.getColumnClass
) of the specified column.
If the column class is String
,
Collator.getInstance
is returned. If the
column class implements Comparable
a private
Comparator
is returned that invokes the
compareTo
method. Otherwise
Collator.getInstance
is returned.column
- int zero-based column index into table modeljava.lang.IndexOutOfBoundsException
- if column number is out of range for the associated table modelprotected boolean useToString(int column)
public void setSortKeys(java.util.List<? extends javax.swing.RowSorter.SortKey> sortKeys)
List
; subsequent changes to the supplied
List
do not effect this DefaultRowSorter
.
If the sort keys have changed this triggers a sort.setSortKeys
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
sortKeys
- the new SortKeys
; null
is a shorthand for specifying an empty list,
indicating that the view should be unsortedjava.lang.IllegalArgumentException
- if any of the values in
sortKeys
are null or have a column index outside
the range of the modelpublic java.util.List<? extends javax.swing.RowSorter.SortKey> getSortKeys()
non-null List
. If you need to change the sort keys,
make a copy of the returned List
, mutate the copy
and invoke setSortKeys
with the new list.getSortKeys
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void setMaxSortKeys(int max)
setMaxSortKeys(2)
is invoked on it. The user
clicks the header for column 1, causing the table rows to be
sorted based on the items in column 1. Next, the user clicks
the header for column 2, causing the table to be sorted based
on the items in column 2; if any items in column 2 are equal,
then those particular rows are ordered based on the items in
column 1. In this case, we say that the rows are primarily
sorted on column 2, and secondarily on column 1. If the user
then clicks the header for column 3, then the items are
primarily sorted on column 3 and secondarily sorted on column
2. Because the maximum number of sort keys has been set to 2
with setMaxSortKeys
, column 1 no longer has an
effect on the order.
The maximum number of sort keys is enforced by
toggleSortOrder
. You can specify more sort
keys by invoking setSortKeys
directly and they will
all be honored. However if toggleSortOrder
is subsequently
invoked the maximum number of sort keys will be enforced.
The default value is 3.
max
- the maximum number of sort keysjava.lang.IllegalArgumentException
- if max
< 1public int getMaxSortKeys()
public void setSortsOnUpdates(boolean sortsOnUpdates)
rowsUpdated
is invoked). For
example, if this is true and the user edits an entry the
location of that item in the view may change. The default is
false.sortsOnUpdates
- whether or not to sort on update eventspublic boolean getSortsOnUpdates()
public void setRowFilter(FastRowFilter<? super M> filter)
null
indicates all values from the model should be
included.
FastRowFilter
's include
method is passed the
underlying model. The identifier is the row index into the model.
This method triggers a sort.
filter
- the filter used to determine what entries should be
includedpublic FastRowFilter<? super M> getRowFilter()
public void toggleSortOrder(int column)
toggleSortOrder
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
column
- index of the column to make the primary sorted column,
in terms of the underlying modeljava.lang.IndexOutOfBoundsException
- if list size changes while sorting in progresssetMaxSortKeys(int)
public int convertRowIndexToView(int index)
convertRowIndexToView
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public int convertRowIndexToModel(int index)
convertRowIndexToModel
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void sort()
sortKeys
list
indicates that the view should unsorted, the same as the model.public void setComparator(int column, java.util.Comparator<?> comparator)
Comparator
to use when sorting the specified
column. This does not trigger a sort. If you want to sort after
setting the comparator you need to explicitly invoke sort
.column
- the index of the column the Comparator
is
to be used for, in terms of the underlying modelcomparator
- the Comparator
to usejava.lang.IndexOutOfBoundsException
- if column
is outside
the range of the underlying modelpublic int getViewRowCount()
getViewRowCount
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public int getModelRowCount()
getModelRowCount
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void modelStructureChanged()
modelStructureChanged
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void allRowsChanged()
allRowsChanged
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void rowsInserted(int firstRow, int endRow)
rowsInserted
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void rowsDeleted(int firstRow, int endRow)
rowsDeleted
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void rowsUpdated(int firstRow, int endRow)
rowsUpdated
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>
public void rowsUpdated(int firstRow, int endRow, int column)
rowsUpdated
in class javax.swing.RowSorter<M extends javax.swing.table.TableModel>