|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.util.base.glazedlists.gui.AbstractTableComparatorChooser<E> com.levigo.util.swing.glazedlists.TableComparatorChooser<E>
public class TableComparatorChooser<E>
A TableComparatorChooser is a tool that allows the user to sort a ListTable by clicking
on the table's headers. It requires that the JTable
s model is an
EventTableModel
with a SortedList
as a source.
This class includes custom arrow icons that indicate the sort order. The icons used are chosen based on the current Swing look and feel. Icons are available for the following look and feels: Mac OS X, Metal, Windows.
This class supports multiple sort strategies for each column, specified by having muliple comparators for each column. This may be useful when you want to sort a single column in either of two ways. For example, when sorting movie names, "The Phantom Menace" may be sorted under "T" for "The", or "P" for "Phantom".
This class supports sorting multiple columns simultaneously. In this mode, the user clicks a first column to sort by, and then the user clicks subsequent columns. The list is sorted by the first column and ties are broken by the second column.
If the EventTableModel
uses an AdvancedTableFormat
, its
AdvancedTableFormat.getColumnComparator(int)
method will be used to
populate the initial column Comparator
s.
Field Summary |
---|
Fields inherited from class com.levigo.util.base.glazedlists.gui.AbstractTableComparatorChooser |
---|
MULTIPLE_COLUMN_KEYBOARD, MULTIPLE_COLUMN_MOUSE, MULTIPLE_COLUMN_MOUSE_WITH_UNDO, SINGLE_COLUMN, sortedList, sortedListComparator, sortingState |
Constructor Summary | |
---|---|
|
TableComparatorChooser(JTable table,
SortedList<E> sortedList,
boolean multipleColumnSort)
Deprecated. replaced with install(javax.swing.JTable, com.levigo.util.base.glazedlists.SortedList , which is functionally
identical but uses a more fitting name to convey the action that is
performed and fixes an API flaw by explicitly requiring the TableFormat. |
|
TableComparatorChooser(JTable table,
SortedList<E> sortedList,
Object strategy)
Deprecated. 9/25/06 replaced with install(javax.swing.JTable, com.levigo.util.base.glazedlists.SortedList , which is functionally
identical but uses a more fitting name to convey the action that is
performed and fixes an API flaw by explicitly requiring the TableFormat. |
protected |
TableComparatorChooser(JTable table,
SortedList<E> sortedList,
Object strategy,
TableFormat<? super E> tableFormat)
Creates and installs a TableComparatorChooser. |
Method Summary | ||
---|---|---|
void |
addSortActionListener(ActionListener sortActionListener)
Registers the specified ActionListener to receive notification whenever
the JTable is sorted by this TableComparatorChooser . |
|
TableCellRenderer |
createSortArrowHeaderRenderer(TableCellRenderer delegateRenderer)
Decorates and returns the given delegateRenderer with
functionality that attempts to install a sorting icon into the Component
returned by the delegateRenderer . |
|
void |
dispose()
Releases the resources consumed by this TableComparatorChooser so that it
may eventually be garbage collected. |
|
protected int |
getSortingStyle(int column)
Gets the sorting style currently applied to the specified column. |
|
static
|
install(JTable table,
SortedList<E> sortedList,
Object strategy)
Installs a new TableComparatorChooser that responds to clicks on the header of the specified table and uses them to sort the specified sortedList by delegating to the given strategy
If at any time the table should no longer sort, the behaviour can be
removed calling dispose() on the object returned by this method. |
|
static
|
install(JTable table,
SortedList<E> sortedList,
Object strategy,
TableFormat<? super E> tableFormat)
Installs a new TableComparatorChooser that responds to clicks on the header of the specified table and uses them to sort the specified sortedList by delegating to the given strategy
If at any time the table should no longer sort, the behaviour can be
removed calling dispose() on the object returned by this method. |
|
protected boolean |
isSortingMouseEvent(MouseEvent e)
Determines if the specified mouse event shall be handled by this TableComparatorChooser . |
|
protected void |
rebuildComparator()
Updates the comparator in use and applies it to the table. |
|
protected void |
redetectComparator(Comparator<? super E> currentComparator)
Examines the current Comparator of the SortedList and
adds icons to the table header renderers in response. |
|
void |
removeSortActionListener(ActionListener sortActionListener)
Deregisters the specified ActionListener to no longer receive
action events. |
|
static void |
setIconPath(String path)
Set all TableComparatorChooser s to use the icons from the directory specified. |
Methods inherited from class com.levigo.util.base.glazedlists.gui.AbstractTableComparatorChooser |
---|
appendComparator, clearComparator, createComparatorForElement, createSortingState, fromString, getColumnComparatorIndex, getComparatorsForColumn, getSortingColumns, isColumnReverse, setTableFormat, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
@Deprecated public TableComparatorChooser(JTable table, SortedList<E> sortedList, boolean multipleColumnSort)
install(javax.swing.JTable, com.levigo.util.base.glazedlists.SortedList, java.lang.Object)
, which is functionally
identical but uses a more fitting name to convey the action that is
performed and fixes an API flaw by explicitly requiring the TableFormat.
@Deprecated public TableComparatorChooser(JTable table, SortedList<E> sortedList, Object strategy)
install(javax.swing.JTable, com.levigo.util.base.glazedlists.SortedList, java.lang.Object)
, which is functionally
identical but uses a more fitting name to convey the action that is
performed and fixes an API flaw by explicitly requiring the TableFormat.
protected TableComparatorChooser(JTable table, SortedList<E> sortedList, Object strategy, TableFormat<? super E> tableFormat)
table
- the table with headers that can be clicked onsortedList
- the sorted list to updatestrategy
- an implementations of SortingStrategy
, typically one of
AbstractTableComparatorChooser.SINGLE_COLUMN
AbstractTableComparatorChooser.MULTIPLE_COLUMN_MOUSE
AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD
AbstractTableComparatorChooser.MULTIPLE_COLUMN_MOUSE_WITH_UNDO
tableFormat
- the TableFormat providing the columns for the tableMethod Detail |
---|
public static <E> TableComparatorChooser<E> install(JTable table, SortedList<E> sortedList, Object strategy)
sortedList
by delegating to the given strategy
If at any time the table should no longer sort, the behaviour can be
removed calling dispose()
on the object returned by this method.
This method assumes that the JTable is backed by an EventTableModel and it is from that EventTableModel that the TableFormat should be extracted. This is, by far, the typical case and so we provide this simpler install method for convenience.
table
- the table with headers that can be clicked onsortedList
- the sorted list to updatestrategy
- an implementations of SortingStrategy
, typically one of
public static <E> TableComparatorChooser<E> install(JTable table, SortedList<E> sortedList, Object strategy, TableFormat<? super E> tableFormat)
sortedList
by delegating to the given strategy
If at any time the table should no longer sort, the behaviour can be
removed calling dispose()
on the object returned by this method.
This method makes no assumptions about the TableModel implementation that backs the JTable. As such, it requires the TableFormat as an explicit parameter and expects the TableFormat to be constant (i.e. never changes) for the life of the TableComparatorChooser.
table
- the table with headers that can be clicked ontableFormat
- the TableFormat providing the columns for the tablesortedList
- the sorted list to updatestrategy
- an implementations of SortingStrategy
, typically one of
public void addSortActionListener(ActionListener sortActionListener)
ActionListener
to receive notification whenever
the JTable
is sorted by this TableComparatorChooser
.
public void removeSortActionListener(ActionListener sortActionListener)
ActionListener
to no longer receive
action events.
public TableCellRenderer createSortArrowHeaderRenderer(TableCellRenderer delegateRenderer)
delegateRenderer
with
functionality that attempts to install a sorting icon into the Component
returned by the delegateRenderer
. In particular, the
delegateRenderer
will be decorated with a sorting icon in
one of two scenarios:
SortableRenderer
- in this
case setSortIcon
is called on
the delegateRenderer and it is expected to place the icon anywhere
it desires on the Component it returns. This allows maximum
flexibility when displaying the sort icon.
setIcon
is called on the JLabel
with the sort icon. This caters to the typical case when a
DefaultTableCellRenderer
is used as the
delegateRenderer.
delegateRenderer
- the TableCellRenderer acting as a table header
renderer and to which a sort icon should be added
delegateRenderer
with a sort iconprotected void redetectComparator(Comparator<? super E> currentComparator)
Comparator
of the SortedList and
adds icons to the table header renderers in response.
To do this, clicks are injected into each of the
corresponding ColumnClickTracker
s.
redetectComparator
in class AbstractTableComparatorChooser<E>
protected final void rebuildComparator()
rebuildComparator
in class AbstractTableComparatorChooser<E>
protected final int getSortingStyle(int column)
getSortingStyle
in class AbstractTableComparatorChooser<E>
protected boolean isSortingMouseEvent(MouseEvent e)
TableComparatorChooser
. The default implementation handles only clicks
with the left mouse button. Extending classes can customize which mouse
events the table comparator chooser responds to by overriding this method.
As of 2005/12/20, this method is no longer called when the corresponding mouse press event was a popup trigger. In effect, if this is a right-click on Windows or a 'control-click' on the Mac.
As of 2008/02/05, this method is no longer called when the Cursor over the JTableHeader indicates a column resize is expected to take place, rather than a change in sort.
public static void setIconPath(String path)
TableComparatorChooser
s to use the icons from the directory specified. The
folder should contain the following eight icon files:
Note that this path must be on the system classpath. It may be within a jar file.
public void dispose()
TableComparatorChooser
so that it
may eventually be garbage collected.
A TableComparatorChooser
will be garbage collected without a call to
dispose()
, but not before its source EventList
is garbage
collected. By calling dispose()
, you allow the TableComparatorChooser
to be garbage collected before its source EventList
. This is
necessary for situations where an TableComparatorChooser
is short-lived but
its source EventList
is long-lived.
Warning: It is an error
to call any method on a TableComparatorChooser
after it has been disposed.
dispose
in class AbstractTableComparatorChooser<E>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |