ca.odell.glazedlists.swing
Class TableComparatorChooser

java.lang.Object
  extended by ca.odell.glazedlists.gui.AbstractTableComparatorChooser
      extended by ca.odell.glazedlists.swing.TableComparatorChooser

public class TableComparatorChooser
extends AbstractTableComparatorChooser

A TableComparatorChooser is a tool that allows the user to sort a ListTable by clicking on the table's headers. It requires that the ListTable has a SortedList as a source as the sorting on that list is used.

The TableComparatorChooser 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.

The TableComparatorChooser 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".

The TableComparatorChooser 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.

Author:
Jesse Wilson
See Also:
Bug 4, Bug 31

Field Summary
 
Fields inherited from class ca.odell.glazedlists.gui.AbstractTableComparatorChooser
COLUMN_PRIMARY_SORTED, COLUMN_PRIMARY_SORTED_ALTERNATE, COLUMN_PRIMARY_SORTED_ALTERNATE_REVERSE, COLUMN_PRIMARY_SORTED_REVERSE, COLUMN_SECONDARY_SORTED, COLUMN_SECONDARY_SORTED_ALTERNATE, COLUMN_SECONDARY_SORTED_ALTERNATE_REVERSE, COLUMN_SECONDARY_SORTED_REVERSE, COLUMN_UNSORTED, columnClickTrackers, multipleColumnSort, primaryColumn, recentlyClickedColumns, sortedList, sortedListComparator, tableFormat
 
Constructor Summary
TableComparatorChooser(JTable table, SortedList sortedList, boolean multipleColumnSort)
          Creates a new TableComparatorChooser that responds to clicks on the specified table and uses them to sort the specified list.
 
Method Summary
 void addSortActionListener(ActionListener sortActionListener)
          Registers the specified ActionListener to receive notification whenever the JTable is sorted by this TableComparatorChooser.
 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.
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 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 TableComparatorChoosers to use the icons from the directory specified.
 
Methods inherited from class ca.odell.glazedlists.gui.AbstractTableComparatorChooser
appendComparator, clearComparator, columnClicked, createComparatorForElement, fromString, getColumnComparatorIndex, getComparatorsForColumn, getSortingColumns, isColumnReverse, rebuildColumns, setTableFormat, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableComparatorChooser

public TableComparatorChooser(JTable table,
                              SortedList sortedList,
                              boolean multipleColumnSort)
Creates a new TableComparatorChooser that responds to clicks on the specified table and uses them to sort the specified list.

Parameters:
table - the table with headers that can be clicked on.
sortedList - the sorted list to update.
multipleColumnSort - true to sort by multiple columns at a time, or false to sort by a single column. Although sorting by multiple columns is more powerful, the user interface is not as simple and this strategy should only be used where necessary.
Method Detail

addSortActionListener

public void addSortActionListener(ActionListener sortActionListener)
Registers the specified ActionListener to receive notification whenever the JTable is sorted by this TableComparatorChooser.


removeSortActionListener

public void removeSortActionListener(ActionListener sortActionListener)
Deregisters the specified ActionListener to no longer receive action events.


redetectComparator

protected void redetectComparator(Comparator currentComparator)
Examines the current 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 ColumnClickTrackers.

Overrides:
redetectComparator in class AbstractTableComparatorChooser

rebuildComparator

protected final void rebuildComparator()
Updates the comparator in use and applies it to the table.

Overrides:
rebuildComparator in class AbstractTableComparatorChooser

getSortingStyle

protected final int getSortingStyle(int column)
Gets the sorting style currently applied to the specified column.

Overrides:
getSortingStyle in class AbstractTableComparatorChooser

isSortingMouseEvent

protected boolean isSortingMouseEvent(MouseEvent e)
Determines if the specified mouse event shall be handled by this 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.


dispose

public void dispose()
Releases the resources consumed by this 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.

Overrides:
dispose in class AbstractTableComparatorChooser

setIconPath

public static void setIconPath(String path)
Set all TableComparatorChoosers to use the icons from the directory specified. The folder should contain the following eight icon files:
  • primary_sorted.png
  • secondary_sorted.png
  • primary_sorted_alternate.png
  • secondary_sorted_alternate.png
  • primary_sorted_alternate_reverse.png
  • secondary_sorted_alternate_reverse.png
  • primary_sorted_reverse.png
  • secondary_sorted_reverse.png

    Note that this path must be on the system classpath. It may be within a jar file.



  • Glazed Lists, Copyright © 2003-2005 publicobject.com, O'Dell Engineering.
    Generated 2005-09-24 12:46