QJCC homepage

biz.chitec.quarterback.swing
Class TableHeaderConfigurator

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

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

Controlling element for table header configuration. TableHeaderConfigurator is bound to a JTable with a MapListTableModel. It coordinates state changes of its TableHeaderConfigurationModel with the JTable and listens for action if the JTable to pass state changes to the model.

Currently it listens for two interactions:

  1. Moving columns is passed to the configuration model. This overrides the JTable-immanent column swapping. It gives the advantage that the column moving can be stored persistantly in the configuration model. It does not make any difference for the user.
  2. Right-clicking on the header opens an additional menu and eventually a dialog for complex configuration.

Version:
$Id: 4d35c7fd508817c0b9b2101bcf080294590bf98f $
Author:
Dirk Hillbrecht 2005

Field Summary
protected  TableCellSizeAdjustor cellsizeadjustor
           
protected  java.awt.event.ActionListener columnnameitemal
           
protected  javax.swing.JTable jt
           
protected  java.awt.event.ActionListener lockedwidthitemal
           
protected  java.util.List lockedwidthitems
           
protected  java.util.List menuitems
           
protected  MapListTableModel mltm
           
protected  java.util.ResourceBundle myrb
           
protected  javax.swing.JPopupMenu popupmenu
           
protected  java.util.ResourceBundle rb
           
protected  java.lang.String rbprefix
           
protected  int sourcecolumn
           
protected  int targetcolumn
           
protected  TableHeaderConfigurationModel thcm
           
 
Constructor Summary
TableHeaderConfigurator()
          Initializes the configurator with no model.
TableHeaderConfigurator(TableHeaderConfigurationModel thcmx)
          Initialize the configurator with a model.
 
Method Summary
 void addTo(javax.swing.JTable jtx)
          Adds the configurator to a table.
static void addTo(javax.swing.JTable jt, TableHeaderConfigurationModel thcmx)
           
protected  void addToTableModel(javax.swing.JTable jtx)
          Add the configurator to the table's model.
private  void checkPopup(java.awt.event.MouseEvent e)
          Opens the popup menu if needed
protected  void checkPopupMenu()
          Checks whether the entries of the popup menu are correctly activated or deactivated
 void columnAdded(javax.swing.event.TableColumnModelEvent e)
          TableColumnModelListener: unused but needed
 void columnMarginChanged(javax.swing.event.ChangeEvent e)
          TableColumnModelListener: unused but needed
 void columnMoved(javax.swing.event.TableColumnModelEvent e)
          TableColumnModelListener: tracking of column movement
 void columnRemoved(javax.swing.event.TableColumnModelEvent e)
          TableColumnModelListener: unused but needed
 void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
          TableColumnModelListener: unused but needed
protected  void generatePopupMenu()
          Generates the popup menu, i.e. populates it with entries
 void mouseClicked(java.awt.event.MouseEvent e)
          MouseListener on JTable's header: If clicked, show popup menu.
 void mousePressed(java.awt.event.MouseEvent e)
          MouseListener on JTable: If pressed, reset column moving
 void mouseReleased(java.awt.event.MouseEvent e)
          MouseListener on JTable: If released, check if column has been moved and report this to configuration model.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          PropertyEventListener on both configuration model and table.
 void reloadResourceBundle()
          Reload the ResourceBundle from the table's model.
 void setModel(TableHeaderConfigurationModel thcmx)
          Set the configuration model.
protected  void setModelHeader(java.lang.String[] newheader)
          Set the header from the configuration model to the table, in fact to the MapListTableModel of the table.
 void setTableCellSizeAdjustor(TableCellSizeAdjustor tcsax)
          Sets a link to a TableCellSizeAdjustor from the outside and regenerates the popup menu.
protected  void spreadLockedWidthColumns()
          Gets model header from table and locked width columns from own model.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseEntered, mouseExited
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jt

protected javax.swing.JTable jt

mltm

protected MapListTableModel mltm

rb

protected java.util.ResourceBundle rb

myrb

protected java.util.ResourceBundle myrb

rbprefix

protected java.lang.String rbprefix

thcm

protected TableHeaderConfigurationModel thcm

sourcecolumn

protected int sourcecolumn

targetcolumn

protected int targetcolumn

popupmenu

protected javax.swing.JPopupMenu popupmenu

menuitems

protected java.util.List menuitems

lockedwidthitems

protected java.util.List lockedwidthitems

columnnameitemal

protected java.awt.event.ActionListener columnnameitemal

lockedwidthitemal

protected java.awt.event.ActionListener lockedwidthitemal

cellsizeadjustor

protected TableCellSizeAdjustor cellsizeadjustor
Constructor Detail

TableHeaderConfigurator

public TableHeaderConfigurator()
Initializes the configurator with no model. While it is possible to create a configurator this way, it does not make much sense in the long run: Without a model, the configurator cannot do anything.


TableHeaderConfigurator

public TableHeaderConfigurator(TableHeaderConfigurationModel thcmx)
Initialize the configurator with a model. Initialization in this way is possible regardless of the state of the model.

Parameters:
thcmx - The model
Method Detail

setModel

public void setModel(TableHeaderConfigurationModel thcmx)
Set the configuration model. If any old model hat been set before, all listeners will be released appropriately. While it is possible set the model to null, it does not make much sense. The configurator will not be able to perform any actions any more after this.

Parameters:
thcmx - The new configuration model

setModelHeader

protected void setModelHeader(java.lang.String[] newheader)
Set the header from the configuration model to the table, in fact to the MapListTableModel of the table.

Parameters:
newheader - Array of strings containing the new header

spreadLockedWidthColumns

protected void spreadLockedWidthColumns()
Gets model header from table and locked width columns from own model. Stores widths of columns in question and informs TCSA about columns not to touch any more.


addToTableModel

protected void addToTableModel(javax.swing.JTable jtx)
Add the configurator to the table's model. This step is needed as the configurator finally changes the header list in the model (which will be reflected by the table then). The method is called internally only when the

Parameters:
jtx -

addTo

public void addTo(javax.swing.JTable jtx)
Adds the configurator to a table. Each TableHeaderConfigurator can only be bound to one table at a time. Several configurators can share one TableHeaderConfigurationModel, however.

Parameters:
jtx - Table to bind the configurator to

setTableCellSizeAdjustor

public void setTableCellSizeAdjustor(TableCellSizeAdjustor tcsax)
Sets a link to a TableCellSizeAdjustor from the outside and regenerates the popup menu. This method is called by the TCSA itself when it finds the THC in the client properties of the JTable. It registers the TCSA within the THC and performs a menu regerenation.

Parameters:
tcsax - A table cell size adjustor or null if the TCSA is removed.

reloadResourceBundle

public void reloadResourceBundle()
Reload the ResourceBundle from the table's model. This is a quick hack as the model will not fire any events in case of ResourceBundle changes. Therefore the configurator will have to be informed by other means that something has changed.


generatePopupMenu

protected void generatePopupMenu()
Generates the popup menu, i.e. populates it with entries


checkPopupMenu

protected void checkPopupMenu()
Checks whether the entries of the popup menu are correctly activated or deactivated


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
MouseListener on JTable: If pressed, reset column moving

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
MouseListener on JTable: If released, check if column has been moved and report this to configuration model.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
MouseListener on JTable's header: If clicked, show popup menu.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

checkPopup

private void checkPopup(java.awt.event.MouseEvent e)
Opens the popup menu if needed


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
PropertyEventListener on both configuration model and table. TableHeaderConfigurationModel reports all its state changes this way, table reports model change or similar.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

columnMarginChanged

public void columnMarginChanged(javax.swing.event.ChangeEvent e)
TableColumnModelListener: unused but needed

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

columnSelectionChanged

public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
TableColumnModelListener: unused but needed

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

columnAdded

public void columnAdded(javax.swing.event.TableColumnModelEvent e)
TableColumnModelListener: unused but needed

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

columnMoved

public void columnMoved(javax.swing.event.TableColumnModelEvent e)
TableColumnModelListener: tracking of column movement

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

columnRemoved

public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
TableColumnModelListener: unused but needed

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

addTo

public static void addTo(javax.swing.JTable jt,
                         TableHeaderConfigurationModel thcmx)

QJCC homepage