de.kupzog.ktable
Class KTableSortComparator

java.lang.Object
  extended by de.kupzog.ktable.KTableSortComparator
All Implemented Interfaces:
java.util.Comparator
Direct Known Subclasses:
SortComparatorExample

public abstract class KTableSortComparator
extends java.lang.Object
implements java.util.Comparator

Implementations of this class are used when sorting a tablemodel.

Author:
Lorenz Maierhofer
See Also:
KTableSortedModel

Field Summary
static int SORT_DOWN
           
static int SORT_NONE
           
static int SORT_UP
           
 
Constructor Summary
KTableSortComparator(KTableSortedModel model, int columnIndex, int direction)
          Creates a new comparator on the given KTableSortedModel.
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Compares two cells.
abstract  int doCompare(java.lang.Object o1, java.lang.Object o2, int row1, int row2)
          Implement this method to do the actual compare between the two cell contents.
 int getColumnToSortOn()
           
 KTableSortedModel getModel()
           
 int getSortDirection()
           
 void setColumnToCompare(int column)
          Sets the column index this comparator operates on.
 void setModel(KTableSortedModel model)
          Sets the tablemodel to work on.
 void setSortDirection(int direction)
          Sets the sorting direction.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

SORT_NONE

public static final int SORT_NONE
See Also:
Constant Field Values

SORT_UP

public static final int SORT_UP
See Also:
Constant Field Values

SORT_DOWN

public static final int SORT_DOWN
See Also:
Constant Field Values
Constructor Detail

KTableSortComparator

public KTableSortComparator(KTableSortedModel model,
                            int columnIndex,
                            int direction)
Creates a new comparator on the given KTableSortedModel.

Parameters:
model - The mode to compare on.
Method Detail

compare

public final int compare(java.lang.Object o1,
                         java.lang.Object o2)
Compares two cells.

The given objects are of type Integer and represent the row numbers to use.

Specified by:
compare in interface java.util.Comparator
Throws:
java.lang.ClassCastException - if the arguments' types prevent them from being compared by this Comparator.
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)

doCompare

public abstract int doCompare(java.lang.Object o1,
                              java.lang.Object o2,
                              int row1,
                              int row2)
Implement this method to do the actual compare between the two cell contents.

Parameters:
o1 - The cell content of the first cell
o2 - The cell content of the second cell
row1 - The row index where o1 was found in the model.
row2 - The row index where o2 was found in the model.
Returns:
Returns an int smaller, equal or larger than 0 if o1 is smaller, equal or larger than o2.

setColumnToCompare

public void setColumnToCompare(int column)
Sets the column index this comparator operates on.

Parameters:
column - the column index to use.

getSortDirection

public int getSortDirection()
Returns:
Returns the sorting direction, either SORT_NONE, SORT_UP or SORT_DOWN.

setSortDirection

public void setSortDirection(int direction)
Sets the sorting direction.

Parameters:
direction - The sort direction, either SORT_NONE, SORT_UP or SORT_DOWN.

getColumnToSortOn

public int getColumnToSortOn()
Returns:
Returns the column index that serves as a base for the sorting.

getModel

public KTableSortedModel getModel()
Returns:
Returns the model this comparator compares on.

setModel

public void setModel(KTableSortedModel model)
Sets the tablemodel to work on.

Parameters:
model - The KTableSortedModel to work with.