org.progeeks.util.swing
Class SortedTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.progeeks.util.swing.SortedTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class SortedTableModel
extends javax.swing.table.AbstractTableModel

Wraps a standard table model and provides a sorted view.

Version:
$Revision: 1.4 $
Author:
Paul Speed
See Also:
Serialized Form

Field Summary
protected  int[] indexMap
          Maps incoming index values to the internal table model index values based on the current sort.
protected  javax.swing.table.TableModel model
          The internal table model to which this model is a sorted view.
protected  int primarySort
          The primary sort column.
protected  boolean reversed
          Set to true if the sort ordering is reversed.
protected  int[] reverseMap
          A reverse of the indexMap;
protected  int secondarySort
          The secondary sort column.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SortedTableModel(javax.swing.table.TableModel model)
           
 
Method Summary
 java.lang.Class getColumnClass(int column)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int column)
           
 int getPrimarySortColumn()
           
 int getRowCount()
           
 int getSecondarySortColumn()
           
 java.lang.Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 boolean isReversed()
           
 boolean isSortable(int column)
           
 void pushSortColumn(int column)
           
protected  void resetIndexMap()
          Creates a new identity mapping.
protected  boolean resortTable()
          Recalculates the sorted view and returns true if the view has changed.
 void setPrimarySortColumn(int column)
           
 void setReversed(boolean flag)
           
 void setSecondarySortColumn(int column)
           
 void setSortColumns(int primary, int secondary)
           
 void setValueAt(java.lang.Object aValue, int row, int column)
           
 int toRealIndex(int sorted)
          Maps an index in the sorted view to an index in the real table.
 int toSortedIndex(int real)
          Maps an index in the real table to an index in the sorted view.
 
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

indexMap

protected int[] indexMap
Maps incoming index values to the internal table model index values based on the current sort.


reverseMap

protected int[] reverseMap
A reverse of the indexMap;


model

protected javax.swing.table.TableModel model
The internal table model to which this model is a sorted view.


primarySort

protected int primarySort
The primary sort column.


secondarySort

protected int secondarySort
The secondary sort column.


reversed

protected boolean reversed
Set to true if the sort ordering is reversed.

Constructor Detail

SortedTableModel

public SortedTableModel(javax.swing.table.TableModel model)
Method Detail

isSortable

public boolean isSortable(int column)

setSortColumns

public void setSortColumns(int primary,
                           int secondary)

pushSortColumn

public void pushSortColumn(int column)

setPrimarySortColumn

public void setPrimarySortColumn(int column)

getPrimarySortColumn

public int getPrimarySortColumn()

setSecondarySortColumn

public void setSecondarySortColumn(int column)

getSecondarySortColumn

public int getSecondarySortColumn()

setReversed

public void setReversed(boolean flag)

isReversed

public boolean isReversed()

getRowCount

public int getRowCount()

getColumnCount

public int getColumnCount()

getColumnName

public java.lang.String getColumnName(int column)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getColumnClass

public java.lang.Class getColumnClass(int column)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

isCellEditable

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

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

toRealIndex

public int toRealIndex(int sorted)
Maps an index in the sorted view to an index in the real table.


toSortedIndex

public int toSortedIndex(int real)
Maps an index in the real table to an index in the sorted view.


resetIndexMap

protected void resetIndexMap()
Creates a new identity mapping.


resortTable

protected boolean resortTable()
Recalculates the sorted view and returns true if the view has changed.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.