qflib 0.98.0

de.qfs.lib.gui
Class DefaultTableModelSorter

java.lang.Object
  |
  +--de.qfs.lib.gui.DefaultTableModelSorter
All Implemented Interfaces:
Configurable, TableModelSorter

public class DefaultTableModelSorter
extends java.lang.Object
implements TableModelSorter, Configurable

A default implementation of the TableModelSorter interface.

The column class of the sort column determines the comparison for the rows. String columns are compared via a Collator, Comparable's via the Comparable interface and the rest via a Collator on their toString values.

Version:
$Revision: 1.12 $
Author:
Gregor Schmid

Field Summary
protected  boolean ascending
          Whether sort order is ascending or descending.
protected  boolean autoAscending
          Whether setting of the column determines ascending order.
protected  int column
          The column to sort on.
protected  java.lang.String configurableName
          The configuration name.
protected  java.util.List listeners
          The TableModelSorterListeners.
 
Constructor Summary
DefaultTableModelSorter()
          Create a new DefaultTableModelSorter.
DefaultTableModelSorter(java.lang.String name)
          Create a new DefaultTableModelSorter.
 
Method Summary
 void addTableModelSorterListener(TableModelSorterListener listener)
          Add a TableModelSorterListener to the TableModelSorter.
 int compare(javax.swing.table.TableModel model, int idx1, int idx2)
          Compare two rows of the table.
protected  void fireSortOrderChanged(TableModelSorterEvent e)
          Notify the listeners of a change in the sort order.
 java.lang.String getConfigurableName()
          Get the DefaultTableModelSorter's configuration name.
 java.util.Properties getConfigurableState()
          Get the DefaultTableModelSorter's configurable state.
 int getSortColumn()
          Get the column being sorted on.
 boolean isAutoAscending()
          Query whether autoAscending is turned on.
 boolean isSortAscending()
          Query whether the rows are sorted in ascending order.
 void registrationChanged(Configuration config, java.lang.String name, boolean registered, boolean valuesKept)
          This callback is used to notify the Configurable whenever it is registered with or unregistered from the Configuration, so it can decide whether to notify the Configuration when its state changes.
 void removeTableModelSorterListener(TableModelSorterListener listener)
          Remove a TableModelSorterListener from the TableModelSorter.
 void setAutoAscending(boolean auto)
          If autoAscending is set to true (the default), the sort order is determined by setSortColumn.
 void setConfigurableName(java.lang.String name)
          Set the DefaultTableModelSorter's configuration name.
 void setConfigurableState(java.util.Properties state)
          Set the DefaultTableModelSorter's configurable state.
 void setSortAscending(boolean ascending)
          Define whether the rows should be sorted in ascending or descending order.
 void setSortColumn(int column)
          Set the column to sort in model coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected java.util.List listeners
The TableModelSorterListeners.

column

protected int column
The column to sort on.

ascending

protected boolean ascending
Whether sort order is ascending or descending.

autoAscending

protected boolean autoAscending
Whether setting of the column determines ascending order.

configurableName

protected java.lang.String configurableName
The configuration name.
Constructor Detail

DefaultTableModelSorter

public DefaultTableModelSorter()
Create a new DefaultTableModelSorter. The initial column to sort is -1, meaning no order.

DefaultTableModelSorter

public DefaultTableModelSorter(java.lang.String name)
Create a new DefaultTableModelSorter. The initial column to sort is -1, meaning no order.
Parameters:
name - The Configurable name of the DefaultTableModelSorter.
Method Detail

setSortColumn

public final void setSortColumn(int column)
Set the column to sort in model coordinates. If autoAscending is turned on ascending or descending order will be determined as follows:
Specified by:
setSortColumn in interface TableModelSorter
Parameters:
column - The column to sort on. -1 means no order.
See Also:
setAutoAscending(boolean)

getSortColumn

public final int getSortColumn()
Get the column being sorted on.
Specified by:
getSortColumn in interface TableModelSorter
Returns:
The column being sorted on.

setSortAscending

public final void setSortAscending(boolean ascending)
Define whether the rows should be sorted in ascending or descending order.
Specified by:
setSortAscending in interface TableModelSorter
Parameters:
ascending - True for ascending order.

isSortAscending

public final boolean isSortAscending()
Query whether the rows are sorted in ascending order.
Specified by:
isSortAscending in interface TableModelSorter
Returns:
True for ascending sort order.

setAutoAscending

public final void setAutoAscending(boolean auto)
If autoAscending is set to true (the default), the sort order is determined by setSortColumn. Otherwise sort order has to be set explicitly through setSortAscending.
Parameters:
auto - True for autoAscending.

isAutoAscending

public final boolean isAutoAscending()
Query whether autoAscending is turned on.
Returns:
True if autoAscending is turned on.

compare

public int compare(javax.swing.table.TableModel model,
                   int idx1,
                   int idx2)
Compare two rows of the table.
Specified by:
compare in interface TableModelSorter
Parameters:
model - The original TableModel.
idx1 - Index of the first row.
idx2 - Index of the second row.
Returns:
0 if the rows are equal, -1 if the first row is less than the second, 1 if it is greater.

addTableModelSorterListener

public void addTableModelSorterListener(TableModelSorterListener listener)
Add a TableModelSorterListener to the TableModelSorter.
Specified by:
addTableModelSorterListener in interface TableModelSorter
Parameters:
listener - The TableModelSorterListener to add.

removeTableModelSorterListener

public void removeTableModelSorterListener(TableModelSorterListener listener)
Remove a TableModelSorterListener from the TableModelSorter.
Specified by:
removeTableModelSorterListener in interface TableModelSorter
Parameters:
listener - The TableModelSorterListener to remove.

fireSortOrderChanged

protected void fireSortOrderChanged(TableModelSorterEvent e)
Notify the listeners of a change in the sort order.
Parameters:
e - The event containing the details.

getConfigurableName

public final java.lang.String getConfigurableName()
Get the DefaultTableModelSorter's configuration name.
Specified by:
getConfigurableName in interface Configurable
Returns:
The configuration name.

setConfigurableName

public final void setConfigurableName(java.lang.String name)
Set the DefaultTableModelSorter's configuration name.
Specified by:
setConfigurableName in interface Configurable
Parameters:
name - The name to set.

getConfigurableState

public java.util.Properties getConfigurableState()
Get the DefaultTableModelSorter's configurable state.
Specified by:
getConfigurableState in interface Configurable
Returns:
The configurable state.

setConfigurableState

public void setConfigurableState(java.util.Properties state)
Set the DefaultTableModelSorter's configurable state.
Specified by:
setConfigurableState in interface Configurable
Parameters:
state - The state to set.

registrationChanged

public void registrationChanged(Configuration config,
                                java.lang.String name,
                                boolean registered,
                                boolean valuesKept)
This callback is used to notify the Configurable whenever it is registered with or unregistered from the Configuration, so it can decide whether to notify the Configuration when its state changes.
Specified by:
registrationChanged in interface Configurable
Parameters:
config - The affected Configuration.
name - The registration name of the Configurable which may be different from the Configurable's name.
registered - True if the Configurable was just registered, false if it was unregistered.
valuesKept - Whether the Configurable's values were kept, if it was just unregistered.

qflib 0.98.0