QJCC homepage

biz.chitec.quarterback.swing
Class MapListTableSorter

java.lang.Object
  extended byjava.awt.event.MouseAdapter
      extended bybiz.chitec.quarterback.swing.MapListTableSorter
All Implemented Interfaces:
java.util.EventListener, java.awt.event.MouseListener, java.beans.PropertyChangeListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener

public class MapListTableSorter
extends java.awt.event.MouseAdapter
implements java.beans.PropertyChangeListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener

Knows how to sort tables with MapListTableModel behind using a sorting constraint.

Version:
$Id: 2c45ed14134bcf174c1400e02b9779c2709fb859 $
Author:
cantamen/Dirk Hillbrecht 2004 Distributed under the terms of the GNU LGPL.

Nested Class Summary
protected  class MapListTableSorter.ComponentBasedReconnector
          Helper class for cases where multiple tables link to the same model.
private  class MapListTableSorter.SortShowingTableHeaderRenderer
           
 
Field Summary
private static javax.swing.Icon ASCENDING_ICON
           
private static javax.swing.Icon DESCENDING_ICON
           
protected  javax.swing.JTable jt
           
protected  MapComparator mycomparator
           
protected  boolean primaryascending
           
protected  int primarycolumn
           
protected  java.util.List sortingconstraints
           
protected  javax.swing.table.TableCellRenderer tableheaderrenderer
           
protected  javax.swing.table.TableColumnModel tcm
           
protected  MapListTableModel tm
           
 
Constructor Summary
protected MapListTableSorter()
           
protected MapListTableSorter(javax.swing.JTable jtx)
           
protected MapListTableSorter(javax.swing.JTable jtx, java.lang.Object cx)
           
protected MapListTableSorter(MapComparator mcx)
           
protected MapListTableSorter(MapComparator mcx, javax.swing.JTable jtx)
           
protected MapListTableSorter(MapComparator mcx, javax.swing.JTable jtx, java.lang.Object cx)
           
 
Method Summary
protected  void activateSortingConstraints()
           
static void addTo(javax.swing.JTable jt)
           
static void addTo(javax.swing.JTable jt, java.lang.Object cx)
           
static void addTo(MapComparator mcx, javax.swing.JTable jt)
           
static void addTo(MapComparator mcx, javax.swing.JTable jt, java.lang.Object cx)
           
 void columnAdded(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener.
 void columnMarginChanged(javax.swing.event.ChangeEvent e)
          From TableColumnModelListener.
 void columnMoved(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener.
 void columnRemoved(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener.
 void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
          From TableColumnModelListener.
protected  void doSort()
           
protected  int getColumnIndex(java.lang.String key)
           
protected  int getColumnIndexBySortReplace(java.lang.String sortkey)
           
protected  java.lang.String getColumnKey(int column)
           
protected  java.lang.String getSortReplaceKey(int column)
           
protected  void initPrimarySortingConstraint()
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void propertyChange(java.beans.PropertyChangeEvent evt)
          From PropertyChangeListener to the JTable.
private  void rebindToColumnModel()
          Rebinds the adjustor to the table's column model.
protected  void rebindToModel()
          Rebinds the adjustor to the table's model.
private  void setAllTableHeaderRenderers()
           
 void setMapComparator(MapComparator mcx)
           
 void setSortingConstraints(java.lang.Object constraints)
           
 void setTable(javax.swing.JTable jtx)
           
private  java.util.Map sortingConstraintStringToMap(java.lang.String s)
           
 void tableChanged(javax.swing.event.TableModelEvent e)
          From TableModelListener.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseEntered, mouseExited, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASCENDING_ICON

private static final javax.swing.Icon ASCENDING_ICON

DESCENDING_ICON

private static final javax.swing.Icon DESCENDING_ICON

jt

protected javax.swing.JTable jt

tm

protected MapListTableModel tm

tcm

protected javax.swing.table.TableColumnModel tcm

mycomparator

protected MapComparator mycomparator

sortingconstraints

protected java.util.List sortingconstraints

primarycolumn

protected int primarycolumn

primaryascending

protected boolean primaryascending

tableheaderrenderer

protected javax.swing.table.TableCellRenderer tableheaderrenderer
Constructor Detail

MapListTableSorter

protected MapListTableSorter(MapComparator mcx)

MapListTableSorter

protected MapListTableSorter()

MapListTableSorter

protected MapListTableSorter(javax.swing.JTable jtx)

MapListTableSorter

protected MapListTableSorter(MapComparator mcx,
                             javax.swing.JTable jtx)

MapListTableSorter

protected MapListTableSorter(javax.swing.JTable jtx,
                             java.lang.Object cx)

MapListTableSorter

protected MapListTableSorter(MapComparator mcx,
                             javax.swing.JTable jtx,
                             java.lang.Object cx)
Method Detail

setMapComparator

public void setMapComparator(MapComparator mcx)

setTable

public void setTable(javax.swing.JTable jtx)

setSortingConstraints

public void setSortingConstraints(java.lang.Object constraints)

sortingConstraintStringToMap

private java.util.Map sortingConstraintStringToMap(java.lang.String s)

getColumnKey

protected java.lang.String getColumnKey(int column)

getSortReplaceKey

protected java.lang.String getSortReplaceKey(int column)

getColumnIndex

protected int getColumnIndex(java.lang.String key)

getColumnIndexBySortReplace

protected int getColumnIndexBySortReplace(java.lang.String sortkey)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

initPrimarySortingConstraint

protected void initPrimarySortingConstraint()

activateSortingConstraints

protected void activateSortingConstraints()

doSort

protected void doSort()

rebindToModel

protected void rebindToModel()
Rebinds the adjustor to the table's model. That one is needed for obtaining knowledge of data changes.


setAllTableHeaderRenderers

private void setAllTableHeaderRenderers()

rebindToColumnModel

private void rebindToColumnModel()
Rebinds the adjustor to the table's column model. Needed to learn about addition/removal of columns


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
From PropertyChangeListener to the JTable. Notices the adjustor of property changes in the table (new model)

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
From TableModelListener. Tells listener that something changed in the model. In case of a structure change, we rerender the headers.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener

columnAdded

public void columnAdded(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. Tells listeners that a column was added to the model. We set the renderer in this case.

Specified by:
columnAdded in interface javax.swing.event.TableColumnModelListener

columnRemoved

public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. Tells listeners that a column was removed from the model. We do nothing in this case.

Specified by:
columnRemoved in interface javax.swing.event.TableColumnModelListener

columnMoved

public void columnMoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener. Tells listeners that a column was repositioned. We do nothing in this case.

Specified by:
columnMoved in interface javax.swing.event.TableColumnModelListener

columnMarginChanged

public void columnMarginChanged(javax.swing.event.ChangeEvent e)
From TableColumnModelListener. Tells listeners that a column was moved due to a margin change. We do nothing in this case.

Specified by:
columnMarginChanged in interface javax.swing.event.TableColumnModelListener

columnSelectionChanged

public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
From TableColumnModelListener. Tells listeners that the selection model of the TableColumnModel changed. We do nothing in this case.

Specified by:
columnSelectionChanged in interface javax.swing.event.TableColumnModelListener

addTo

public static void addTo(MapComparator mcx,
                         javax.swing.JTable jt)

addTo

public static void addTo(MapComparator mcx,
                         javax.swing.JTable jt,
                         java.lang.Object cx)

addTo

public static void addTo(javax.swing.JTable jt,
                         java.lang.Object cx)

addTo

public static void addTo(javax.swing.JTable jt)

QJCC homepage