gumbo.visualize.data.impl.swing
Class SwingTreeViewFactory

java.lang.Object
  |
  +--gumbo.visualize.data.AbstractDataViewFactory
        |
        +--gumbo.visualize.data.impl.swing.SwingTreeViewFactory
All Implemented Interfaces:
DataViewFactory

public class SwingTreeViewFactory
extends AbstractDataViewFactory

A data view factory for a tree data presentation implemented using Swing native graphics. In a tree view, tree nodes (root, branch, leaf) correspond to vertex models, with the order specified by the edge models, in a GraphModel. The initial tree if formed by starting with the first source vertex in the whole view's graph model, followed by the head vertex of the edges of each subsequent vertex, ending when a loop or a sink node is found. All other part models in the whole model are ignored. The whole graphic views will be registered automatically as spatial targets of the factory Swing sensors. The part graphic views are proxies and, as such, require a special (non-spatial) picker.

The tree view created by this factory is based on SwingTreeView, which uses a JTree as its native graphic, and a TreeModel as its native data model. Instead of being a composite of Swing components, with one for each tree node, a JTree is a monolithic component that renders nodes as virtual components using a cell renderer. As such, spatial hit testing cannot be used for picking tree nodes. Instead, a special pick engine (SwingTreeView.SwingPickEngine) must be used to detect tree node hits. Since the native graphics associated with tree node graphic views (SwingTreeNode) are not picked directly, they are maintained as a Swing tree node "user object" and returned as pick hits.

Note that TreeModel is rather dumb regarding updates and must be carefully notified of the changes, otherwise it will try to update missing nodes or mess up the expansion state of old nodes.

Version:
$Revision: 1.1 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Constructor Summary
SwingTreeViewFactory(MouseSensor mouse, KeyboardSensor keyboard)
          Creates and instance.
 
Method Summary
protected  java.util.Collection addPartViews(java.util.Collection partModels, java.util.Collection retVal)
          Default implementation: For each part model, in iterator order: If an edge model, adds its head end vertex and forward subtree as a child of its tail end vertex; if a vertex model, and the native model root is null, sets it as the root node, otherwise ignores it (and waits for an edge).
protected  void createdPartView(PartView partView)
          Default implementation: Uses _partMap to find the tree node corresponding to the part view's vertex model, inits the graphic view with the graphic model and node, and sets the node's user object to the part view's graphic view.
protected  void createdWholeView()
          Default implementation: Saves the new whole view and its associates; connects graph model change events to this factory; builds a Swing tree model and part map using SwingDataModels.toTreeModel(), with the first source vertex in the whole view's model as the seed; adds the whole view's graphic view as a sensor target;
 void disposeWholeView(WholeView wholeView)
          Default implementation: Sets the graphic model root null, then calls the super method.
protected  GraphicView newPartViewGraphic(PartView partView)
          Default implementation: If view is of a VertexModel, returns a SwingTreeNode shape; otherwise, throws an exception.
 WholeView newWholeView(WholeModel wholeModel)
          Default implementation: Throws an exception if the whole model is not a GraphModel, then calls the super method.
 GraphicView newWholeViewGraphic()
          Default implementation: If view is of a GraphModel returns a SwingTreeView; otherwise, throws an exception.
protected  void removePartViews(java.util.Collection partModels)
          Default implementation: For each part model, in iterator order: If an edge model, removes its head end vertex and forward subtree; if a vertex model, removes it and its forward subtree.
 
Methods inherited from class gumbo.visualize.data.AbstractDataViewFactory
getAddedPartModelIn, getRemovingPartModelIn, getWholeView, newPartView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingTreeViewFactory

public SwingTreeViewFactory(MouseSensor mouse,
                            KeyboardSensor keyboard)
Creates and instance. Sensors should be able to handle targets with Swing/AWT native graphics.

Parameters:
mouse - Reference to the mouse sensor. Null if none.
keyboard - Reference to the keyboard sensor. Null if none.
Method Detail

newWholeViewGraphic

public GraphicView newWholeViewGraphic()
Default implementation: If view is of a GraphModel returns a SwingTreeView; otherwise, throws an exception.

Overrides:
newWholeViewGraphic in class AbstractDataViewFactory
Returns:
Reference to the whole view graphic. Never null.

createdWholeView

protected void createdWholeView()
Default implementation: Saves the new whole view and its associates; connects graph model change events to this factory; builds a Swing tree model and part map using SwingDataModels.toTreeModel(), with the first source vertex in the whole view's model as the seed; adds the whole view's graphic view as a sensor target;

Overrides:
createdWholeView in class AbstractDataViewFactory

newPartViewGraphic

protected GraphicView newPartViewGraphic(PartView partView)
Default implementation: If view is of a VertexModel, returns a SwingTreeNode shape; otherwise, throws an exception.

Overrides:
newPartViewGraphic in class AbstractDataViewFactory
Parameters:
partView - The part view. Never null.
Returns:
The part view graphic. Never null.

createdPartView

protected void createdPartView(PartView partView)
Default implementation: Uses _partMap to find the tree node corresponding to the part view's vertex model, inits the graphic view with the graphic model and node, and sets the node's user object to the part view's graphic view.

Overrides:
createdPartView in class AbstractDataViewFactory
Parameters:
partView - The part view. Never null.

addPartViews

protected java.util.Collection addPartViews(java.util.Collection partModels,
                                            java.util.Collection retVal)
Default implementation: For each part model, in iterator order: If an edge model, adds its head end vertex and forward subtree as a child of its tail end vertex; if a vertex model, and the native model root is null, sets it as the root node, otherwise ignores it (and waits for an edge). Updates the the vertex to node map _partMap and the graphic view accordingly. Throws an exception if a part model is not a VertexModel or an EdgeModel in the whole view's whole model. Ignores missing parent and duplicate part models

Overrides:
addPartViews in class AbstractDataViewFactory
Parameters:
partModels - The part model group (PartModel). Never null.
retVal - Return value object. The added part views (PartView) in iterator order. Null if none.
Returns:
Reference to retVal. Null if none.

removePartViews

protected void removePartViews(java.util.Collection partModels)
Default implementation: For each part model, in iterator order: If an edge model, removes its head end vertex and forward subtree; if a vertex model, removes it and its forward subtree. If a vertex corresponds to the model root, its node is removed as the root, otherwise its node is removed as a child of its parent node. Updates the the vertex to node map _partMap and the graphic view accordingly. Throws an exception if a part model is not a VertexModel or an EdgeModel in the whole view's whole model. Ignores missing part models.

Overrides:
removePartViews in class AbstractDataViewFactory
Parameters:
partModels - The part model group (PartModel). Never null.

newWholeView

public WholeView newWholeView(WholeModel wholeModel)
Default implementation: Throws an exception if the whole model is not a GraphModel, then calls the super method.

Specified by:
newWholeView in interface DataViewFactory
Overrides:
newWholeView in class AbstractDataViewFactory
Parameters:
wholeModel - The whole model. Never null.
Returns:
A new whole view. Never null.

disposeWholeView

public void disposeWholeView(WholeView wholeView)
Default implementation: Sets the graphic model root null, then calls the super method. Throws an exception if whole view is not the current one being managed by this factory.

Specified by:
disposeWholeView in interface DataViewFactory
Overrides:
disposeWholeView in class AbstractDataViewFactory
Parameters:
wholeView - The whole view. Never null.