org.xnap.commons.gui.table
Class TableSorter

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.xnap.commons.gui.table.TableSorter
All Implemented Interfaces:
Serializable, TableModel, SortableModel

public class TableSorter
extends AbstractTableModel
implements SortableModel

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.xnap.commons.gui.table.SortableModel
SortableModel.Order
 
Field Summary
protected  int compares
          Counts number of compares.
protected  int[] indexes
           
protected  int lastSortedColumn
           
protected  boolean maintainSortOrder
           
protected  int[] revIndexes
           
protected  ArrayList<Integer> sortingColumns
           
protected  SortableModel.Order sortOrder
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableSorter()
           
TableSorter(TableModel tableModel)
           
 
Method Summary
protected  int compare(int row1, int row2)
          Compares two rows.
protected  int compareRowsByColumn(int row1, int row2, int column)
          Compares two rows by a column.
 Class<?> getColumnClass(int column)
          Returns the class of the data objects in column at index.
 int getColumnCount()
           
 String getColumnName(int column)
           
 boolean getMaintainSortOrder()
           
 int getRowCount()
           
 int getSortedColumn()
          Returns the index of the column that was sorted last.
 SortableModel.Order getSortOrder()
           
 TableModel getTableModel()
           
 Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 int mapToIndex(int i)
          Returns the mapped row index.
protected  void reallocateIndexes()
           
protected  void reallocateIndexes(TableModelEvent e)
           
 void resort()
           
 void setMaintainSortOrder(boolean newValue)
          Sets the maintain sort order flag.
 void setSortOrder(SortableModel.Order newValue)
           
 void setTableModel(TableModel tableModel)
           
 void setValueAt(Object aValue, int row, int column)
           
 boolean shuttlesort(int[] from, int[] to, int low, int high)
          Returns false if nothing has changed.
protected  boolean sort()
          Returns false if nothing has changed.
 SortableModel.Order sortByColumn(int column, SortableModel.Order sortOrder, boolean revert)
          Sorts the table.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indexes

protected int[] indexes

revIndexes

protected int[] revIndexes

sortingColumns

protected ArrayList<Integer> sortingColumns

sortOrder

protected SortableModel.Order sortOrder

compares

protected int compares
Counts number of compares.


lastSortedColumn

protected int lastSortedColumn

maintainSortOrder

protected boolean maintainSortOrder
Constructor Detail

TableSorter

public TableSorter()

TableSorter

public TableSorter(TableModel tableModel)
Method Detail

getTableModel

public TableModel getTableModel()

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class<?> getColumnClass(int column)
Description copied from interface: SortableModel
Returns the class of the data objects in column at index.

Specified by:
getColumnClass in interface TableModel
Specified by:
getColumnClass in interface SortableModel
Overrides:
getColumnClass in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

getValueAt

public Object getValueAt(int row,
                         int column)
Specified by:
getValueAt in interface TableModel

setValueAt

public void setValueAt(Object aValue,
                       int row,
                       int column)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

getSortedColumn

public int getSortedColumn()
Description copied from interface: SortableModel
Returns the index of the column that was sorted last.

Specified by:
getSortedColumn in interface SortableModel

getSortOrder

public SortableModel.Order getSortOrder()
Specified by:
getSortOrder in interface SortableModel

mapToIndex

public int mapToIndex(int i)
Returns the mapped row index.


setMaintainSortOrder

public void setMaintainSortOrder(boolean newValue)
Description copied from interface: SortableModel
Sets the maintain sort order flag.

Specified by:
setMaintainSortOrder in interface SortableModel

setSortOrder

public void setSortOrder(SortableModel.Order newValue)
Specified by:
setSortOrder in interface SortableModel

setTableModel

public void setTableModel(TableModel tableModel)

sortByColumn

public SortableModel.Order sortByColumn(int column,
                                        SortableModel.Order sortOrder,
                                        boolean revert)
Sorts the table.

Specified by:
sortByColumn in interface SortableModel
Parameters:
column - the column to sort
sortOrder - the sort order to sory by
revert - automatically revert sort order
Returns:
true, if table is sorted ascending; false, if descending

resort

public void resort()

compare

protected int compare(int row1,
                      int row2)
Compares two rows.


compareRowsByColumn

protected int compareRowsByColumn(int row1,
                                  int row2,
                                  int column)
Compares two rows by a column.


reallocateIndexes

protected void reallocateIndexes(TableModelEvent e)

reallocateIndexes

protected void reallocateIndexes()

sort

protected boolean sort()
Returns false if nothing has changed.


shuttlesort

public boolean shuttlesort(int[] from,
                           int[] to,
                           int low,
                           int high)
Returns false if nothing has changed.


getMaintainSortOrder

public boolean getMaintainSortOrder()


Copyright © 2004-2007 XNap Commons Team. All Rights Reserved.