QJCC homepage

biz.chitec.quarterback.swing
Class MapListTableCellManager

java.lang.Object
  extended bybiz.chitec.quarterback.swing.MapListTableCellManager
All Implemented Interfaces:
java.util.EventListener, java.beans.PropertyChangeListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener

public class MapListTableCellManager
extends java.lang.Object
implements javax.swing.event.TableModelListener, javax.swing.event.TableColumnModelListener, java.beans.PropertyChangeListener

Managing class for cell renderers and editors in tables which are driven by a MapListTableModel. In tables which are drive by a list-of-maps model, renderers are likely to be assigned by map key names. Unfortunately, the model cannot force the table to use certain renderers for the job. This additional manager class is attached to a table. As soon as the table gets a MapListTableModel, it waits for structural table changes which affect the header (i.e. the header might have changed. In this case, it reassigns renderers to the columns of the table according to the column renderer or editor settings in the model. There are two ways how the cell manager knows which renderer or editor to use for which column: (a) the MapListTableModel contains ResourceBundle-driven entries for renderer and editor class name. If such a name is given, MapListTableCellManager creates an instance of the referenced class and uses it. (b) Renderer and editor instances can be given directly to the manager, either one by one or in a Map. This is the only way to use renderer or editor classes which take parameters in their initializer. Directly given instances do always override ResourceBundle entries. Note that all renderer and editors are cached. Every class is instantiated only once.

Version:
$Id: e2b3673586872f00e14a5c40891cce317a73b3ba $
Author:
cantamen/Dirk Hillbrecht 2005

Field Summary
private  java.util.Map editorcache
           
private  javax.swing.JTable jt
           
private  MapListTableModel mltm
           
private  java.util.Map renderercache
           
private  javax.swing.table.TableColumnModel tcm
           
 
Constructor Summary
MapListTableCellManager()
          Initialize an empty cell manager
MapListTableCellManager(javax.swing.JTable jtx)
          Initialize empty cell manager and bind it to table.
 
Method Summary
 void addEditor(java.util.Map editors)
          Add multiple editors directly to the manager.
 void addEditor(java.lang.String key, javax.swing.table.TableCellEditor tce)
          Add one editor directly to the manager.
 void addRenderer(java.util.Map renderers)
          Add multiple renderers directly to the manager.
 void addRenderer(java.lang.String key, javax.swing.table.TableCellRenderer tcr)
          Add one renderer directly to the manager.
 void addTo(javax.swing.JTable jtx)
          Attaches the cell manager to a JTable instance.
static void addTo(javax.swing.JTable jt, java.lang.Object[] renderers)
          Convenience method to setup a cell manager with one line of code.
static void addTo(javax.swing.JTable jt, java.lang.String name1, javax.swing.table.TableCellRenderer tcr1)
          Convenience method to setup a cell manager with one special column renderer with one line of code.
protected  void assignRendererAndEditors()
          Assigns renderers and editors to column models
protected  void assignRendererAndEditorToColumn(int i)
           
 void columnAdded(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener to the JTable's TableColumnModel.
 void columnMarginChanged(javax.swing.event.ChangeEvent e)
          From TableColumnModelListener to the JTable's TableColumnModel.
 void columnMoved(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener to the JTable's TableColumnModel.
 void columnRemoved(javax.swing.event.TableColumnModelEvent e)
          From TableColumnModelListener to the JTable's TableColumnModel.
 void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
          From TableColumnModelListener to the JTable's TableColumnModel.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          From PropertyChangeListener to the JTable.
protected  void rebindToModel()
          Binds the cell manager to the table's model.
 void setRenderers(java.lang.Object[] renderers)
          Sets the renderers from an array list.
 void tableChanged(javax.swing.event.TableModelEvent e)
          From TableModelListener: If headerstructure changes, re-assign all renderers and editors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jt

private javax.swing.JTable jt

tcm

private javax.swing.table.TableColumnModel tcm

mltm

private MapListTableModel mltm

renderercache

private java.util.Map renderercache

editorcache

private java.util.Map editorcache
Constructor Detail

MapListTableCellManager

public MapListTableCellManager()
Initialize an empty cell manager


MapListTableCellManager

public MapListTableCellManager(javax.swing.JTable jtx)
Initialize empty cell manager and bind it to table.

Method Detail

addTo

public void addTo(javax.swing.JTable jtx)
Attaches the cell manager to a JTable instance. Any earlier assignments are removed in advance.

Parameters:
jtx - JTable to assign to.

addRenderer

public void addRenderer(java.lang.String key,
                        javax.swing.table.TableCellRenderer tcr)
Add one renderer directly to the manager. The renderer will be used for the column with the given key name.

Parameters:
key - Key in the underlying maps of the column in question.
tcr - Renderer to use for this column

addRenderer

public void addRenderer(java.util.Map renderers)
Add multiple renderers directly to the manager. The map must contain tuples with a String key and a TableCellRenderer value.

Parameters:
renderers - Map with renderers of type Map

setRenderers

public void setRenderers(java.lang.Object[] renderers)
Sets the renderers from an array list. Array content must be alternating String and TableCellRenderer objects. For each String, the directly following TableCellRenderer is registered.

Parameters:
renderers - List of column names and renderers.

addEditor

public void addEditor(java.lang.String key,
                      javax.swing.table.TableCellEditor tce)
Add one editor directly to the manager. The editor will be used for the column with the given key name.

Parameters:
key - Key in the underlying maps of the column in question.
tce - Editor to use for this column

addEditor

public void addEditor(java.util.Map editors)
Add multiple editors directly to the manager. The map must contain tuples with a String key and a TableCellEditor value.

Parameters:
editors - Map with editors of type Map

rebindToModel

protected void rebindToModel()
Binds the cell manager to the table's model.


assignRendererAndEditorToColumn

protected void assignRendererAndEditorToColumn(int i)

assignRendererAndEditors

protected void assignRendererAndEditors()
Assigns renderers and editors to column models


tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
From TableModelListener: If headerstructure changes, re-assign all renderers and editors

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

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

columnMarginChanged

public void columnMarginChanged(javax.swing.event.ChangeEvent e)
From TableColumnModelListener to the JTable's TableColumnModel.

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

columnSelectionChanged

public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
From TableColumnModelListener to the JTable's TableColumnModel.

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

columnAdded

public void columnAdded(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener to the JTable's TableColumnModel.

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

columnMoved

public void columnMoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener to the JTable's TableColumnModel.

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

columnRemoved

public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
From TableColumnModelListener to the JTable's TableColumnModel.

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

addTo

public static void addTo(javax.swing.JTable jt,
                         java.lang.Object[] renderers)
Convenience method to setup a cell manager with one line of code. The caller passes the table which cells should be managed and an array of renderers.

Parameters:
jt - Table
renderers - Renderers in form of alternating String and TableCellRenderer objects.

addTo

public static void addTo(javax.swing.JTable jt,
                         java.lang.String name1,
                         javax.swing.table.TableCellRenderer tcr1)
Convenience method to setup a cell manager with one special column renderer with one line of code. Caller passes table, column name and renderer object.

Parameters:
jt - Table
name1 - Name of column which should get special renderer
tcr1 - Renderer for column in question

QJCC homepage