com.jaxfront.swing.ui.tools
Class TableSorter

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jaxfront.swing.ui.tools.TableMap
          extended by com.jaxfront.swing.ui.tools.TableSorter
All Implemented Interfaces:
DOMChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel

public class TableSorter
extends TableMap
implements DOMChangeListener

A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableSorter appears to hold another copy of the table with the rows in a different order. The sorting algorthm used is stable which means that it does not move around rows when its comparison function returns 0 to denote that they are equivalent.

Version:
1.60
See Also:
Serialized Form

Constructor Summary
TableSorter(FlipOrientationTableModel model, javax.swing.JTable table)
          Default constructor.
 
Method Summary
 void addMouseListenerToHeaderInTable(javax.swing.JTable table)
          Adds a mouse listener to the given JTable.
 void checkModel()
          Checks if the sorter has been informed of model changes.
 void domChanged(DOMChangeEvent event)
          Respond method for a DOM state changed (DOMChangeEvent).
 ListType getListType()
          Returns the list type that holds the data for the table.
 int getOriginalRowIndex(int index)
          Returns the original row index for a sort index.
 int getOriginalRowIndexPos(int index)
          Returns the original row index position for a sort index.
 int[] getSortIndexes()
          Returns the sort indexes.
 java.lang.Object getValueAt(int aRow, int aColumn)
           
 void initializeIndexes()
          Initializes the table indexes.
 boolean isFlipped()
          Returns true if the table is flipped or not.
 void release()
          Release cache and initialize variables.
 void setModel(FlipOrientationTableModel model)
          Sets a table model.
 void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
           
 
Methods inherited from class com.jaxfront.swing.ui.tools.TableMap
getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, isCellEditable, tableChanged
 
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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSorter

public TableSorter(FlipOrientationTableModel model,
                   javax.swing.JTable table)
Default constructor.

Parameters:
model - a table model (FlipOrientationTableModel)
Method Detail

setModel

public void setModel(FlipOrientationTableModel model)
Description copied from class: TableMap
Sets a table model.

Overrides:
setModel in class TableMap
Parameters:
model - a table model (FlipOrientationTableModel)
See Also:
TableMap.setModel(com.jaxfront.core.ui.FlipOrientationTableModel)

initializeIndexes

public void initializeIndexes()
Initializes the table indexes.


checkModel

public void checkModel()
Checks if the sorter has been informed of model changes.


getValueAt

public java.lang.Object getValueAt(int aRow,
                                   int aColumn)
Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class TableMap
See Also:
TableModel.getValueAt(int, int)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int aRow,
                       int aColumn)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class TableMap
See Also:
TableModel.setValueAt(java.lang.Object, int, int)

addMouseListenerToHeaderInTable

public void addMouseListenerToHeaderInTable(javax.swing.JTable table)
Adds a mouse listener to the given JTable.

Parameters:
table - a JTable

getOriginalRowIndex

public int getOriginalRowIndex(int index)
Returns the original row index for a sort index.

Parameters:
index - a sort index
Returns:
the original row index

getOriginalRowIndexPos

public int getOriginalRowIndexPos(int index)
Returns the original row index position for a sort index.

Parameters:
index - a sort index
Returns:
the original row index position

domChanged

public void domChanged(DOMChangeEvent event)
Description copied from interface: DOMChangeListener
Respond method for a DOM state changed (DOMChangeEvent).

Specified by:
domChanged in interface DOMChangeListener
Parameters:
event - occured DOMChangeEvent
See Also:
DOMChangeListener.domChanged(com.jaxfront.core.dom.DOMChangeEvent)

getSortIndexes

public int[] getSortIndexes()
Returns the sort indexes.

Returns:
the sort indexes

release

public void release()
Description copied from class: TableMap
Release cache and initialize variables.

Overrides:
release in class TableMap
See Also:
TableMap.release()

getListType

public ListType getListType()
Returns the list type that holds the data for the table.

Returns:
a list type

isFlipped

public boolean isFlipped()
Returns true if the table is flipped or not.

Returns:
true if the table is flipped