diva.graph
Class AbstractGraphController

java.lang.Object
  extended by diva.graph.AbstractGraphController
All Implemented Interfaces:
GraphController
Direct Known Subclasses:
BasicGraphController, SimpleGraphController

public abstract class AbstractGraphController
extends java.lang.Object
implements GraphController

An abstract implementation of the GraphController interface. Concrete subclasses must implement the getNodeController() and getEdgeController() methods, to return the correct controller for a given node or edge.

Version:
$Id: AbstractGraphController.java 41477 2006-03-29 00:03:58Z cxh $
Author:
John Reekie, Michael Shilman, Steve Neuendorffer
Accepted Rating:
Red

Nested Class Summary
private  class AbstractGraphController.ChangeListener
          This inner class responds to changes in the graph we are controlling.
 
Field Summary
private  java.util.List _graphViewListenerList
          The list of view listeners.
private  AbstractGraphController.ChangeListener _localListener
          The listener of graph events.
private  java.util.HashMap _map
          Map semantic objects to their figure representations
private  GraphModel _model
          The graph that is being displayed.
private  GraphPane _pane
          The graph pane that this is controlling.
private  SelectionModel _selectionModel
          The default selection model
 
Constructor Summary
AbstractGraphController()
          Construct a graph controller without a parent pane.
 
Method Summary
 void addEdge(java.lang.Object edge, java.lang.Object node, int end, double x, double y)
          Add an edge to this graph editor and render it from the given tail node to an autonomous site at the given location.
 void addEdge(java.lang.Object edge, java.lang.Object tail, java.lang.Object head)
          Add an edge to this graph between the given tail and head nodes.
 void addGraphViewListener(GraphViewListener l)
           
 void addNode(java.lang.Object node)
          Add the node to this graph editor and place it wherever convenient.
 void addNode(java.lang.Object node, double x, double y)
          Add the node to this graph editor and render it at the given location.
 void addNode(java.lang.Object node, java.lang.Object parent)
          Add the node to this graph editor, inside the given parent node at whatever position is convenient
 void addNode(java.lang.Object node, java.lang.Object parent, double x, double y)
          Add the node to this graph editor, inside the given parent node and render it at the given location relative to its parent.
 void clear()
          Remove all figures from the display
 void clearEdge(java.lang.Object edge)
          Remove the figure for the given edge.
 void clearNode(java.lang.Object node)
          Remove the figure for the given node.
 void dispatch(GraphViewEvent e)
          Dispatch the given graph view event to all registered graph view listeners.
 Figure drawEdge(java.lang.Object edge)
          Draw the given edge: create a figure, place it in the canvas, and associate the figure with the edge.
 Figure drawNode(java.lang.Object node)
          Draw the given node: create a figure, place it in the canvas, and associate the figure with the node.
 Figure drawNode(java.lang.Object node, java.lang.Object parent)
          Draw the given node: create a figure, place it in the figure of the given parent node, and associate the figure with the node.
abstract  EdgeController getEdgeController(java.lang.Object edge)
          Given an edge, return the controller associated with that edge.
 Figure getFigure(java.lang.Object semanticObj)
          Return the figure associated with the given semantic object (node or edge), or null if there is no association.
 GraphModel getGraphModel()
          Return the graph being viewed.
 GraphPane getGraphPane()
          Return the graphics pane of this controller cast as a GraphPane.
abstract  NodeController getNodeController(java.lang.Object node)
          Given an node, return the controller associated with that node.
 SelectionModel getSelectionModel()
          Get the default selection model
protected abstract  void initializeInteraction()
          Initialize all interaction on the graph pane.
 void removeEdge(java.lang.Object edge)
          Remove the given edge.
 void removeGraphViewListener(GraphViewListener l)
          Remove the given view listener.
 void removeNode(java.lang.Object node)
          Remove the given node.
 void rerender()
          Render the current graph again by recreating the figures for all nodes and edges, but do not alter the connectivity in the graph.
 void rerenderEdge(java.lang.Object edge)
          Rerender the given edge by replacing its figure with a new figure.
 void rerenderNode(java.lang.Object node)
          Rerender the given node by replacing its figure with a new figure.
 void setFigure(java.lang.Object semanticObj, Figure f)
          Set the figure associated with the given semantic object (node or edge).
 void setGraphModel(GraphModel model)
          Set the graph being viewed.
 void setGraphPane(GraphPane pane)
          Set the graph pane.
 void setSelectionModel(SelectionModel m)
          Set the default selection model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_map

private java.util.HashMap _map
Map semantic objects to their figure representations


_pane

private GraphPane _pane
The graph pane that this is controlling.


_model

private GraphModel _model
The graph that is being displayed.


_selectionModel

private SelectionModel _selectionModel
The default selection model


_localListener

private AbstractGraphController.ChangeListener _localListener
The listener of graph events.


_graphViewListenerList

private java.util.List _graphViewListenerList
The list of view listeners.

Constructor Detail

AbstractGraphController

public AbstractGraphController()
Construct a graph controller without a parent pane.

Method Detail

addEdge

public void addEdge(java.lang.Object edge,
                    java.lang.Object node,
                    int end,
                    double x,
                    double y)
Add an edge to this graph editor and render it from the given tail node to an autonomous site at the given location. Give the new edge the given semanticObject. The "end" flag is either HEAD_END or TAIL_END, from diva.canvas.connector.ConnectorEvent.

Specified by:
addEdge in interface GraphController
Throws:
GraphException - If the connector target cannot return a valid site on the node's figure.

addEdge

public void addEdge(java.lang.Object edge,
                    java.lang.Object tail,
                    java.lang.Object head)
Add an edge to this graph between the given tail and head nodes. Give the new edge the given semanticObject.

Specified by:
addEdge in interface GraphController

addGraphViewListener

public void addGraphViewListener(GraphViewListener l)
Specified by:
addGraphViewListener in interface GraphController

addNode

public void addNode(java.lang.Object node)
Add the node to this graph editor and place it wherever convenient.

Specified by:
addNode in interface GraphController

addNode

public void addNode(java.lang.Object node,
                    double x,
                    double y)
Add the node to this graph editor and render it at the given location.

Specified by:
addNode in interface GraphController

addNode

public void addNode(java.lang.Object node,
                    java.lang.Object parent)
Add the node to this graph editor, inside the given parent node at whatever position is convenient

Specified by:
addNode in interface GraphController

addNode

public void addNode(java.lang.Object node,
                    java.lang.Object parent,
                    double x,
                    double y)
Add the node to this graph editor, inside the given parent node and render it at the given location relative to its parent.

Specified by:
addNode in interface GraphController

clear

public void clear()
Remove all figures from the display

Specified by:
clear in interface GraphController

clearEdge

public void clearEdge(java.lang.Object edge)
Remove the figure for the given edge.

Specified by:
clearEdge in interface GraphController

clearNode

public void clearNode(java.lang.Object node)
Remove the figure for the given node.

Specified by:
clearNode in interface GraphController

drawEdge

public Figure drawEdge(java.lang.Object edge)
Draw the given edge: create a figure, place it in the canvas, and associate the figure with the edge. This should only be called when the object is in the model but does not yet have a figure associated with it.

Specified by:
drawEdge in interface GraphController

drawNode

public Figure drawNode(java.lang.Object node)
Draw the given node: create a figure, place it in the canvas, and associate the figure with the node. This should only be called when the object is in the model but does not yet have a figure associated with it. The location of the figure should be set if some location is appropriate for it.

Specified by:
drawNode in interface GraphController

drawNode

public Figure drawNode(java.lang.Object node,
                       java.lang.Object parent)
Draw the given node: create a figure, place it in the figure of the given parent node, and associate the figure with the node. This should only be called when the object is in the model but does not yet have a figure associated with it. The location of the figure should be set if some location is appropriate for it.

Specified by:
drawNode in interface GraphController

getEdgeController

public abstract EdgeController getEdgeController(java.lang.Object edge)
Given an edge, return the controller associated with that edge.

Specified by:
getEdgeController in interface GraphController

getNodeController

public abstract NodeController getNodeController(java.lang.Object node)
Given an node, return the controller associated with that node.

Specified by:
getNodeController in interface GraphController

getGraphModel

public GraphModel getGraphModel()
Return the graph being viewed.

Specified by:
getGraphModel in interface GraphController

getGraphPane

public GraphPane getGraphPane()
Return the graphics pane of this controller cast as a GraphPane.

Specified by:
getGraphPane in interface GraphController

getFigure

public Figure getFigure(java.lang.Object semanticObj)
Return the figure associated with the given semantic object (node or edge), or null if there is no association.

Specified by:
getFigure in interface GraphController

getSelectionModel

public SelectionModel getSelectionModel()
Get the default selection model

Specified by:
getSelectionModel in interface GraphController

removeEdge

public void removeEdge(java.lang.Object edge)
Remove the given edge. Find the edge controller associated with that edge and delegate to that edge controller.

Specified by:
removeEdge in interface GraphController

removeGraphViewListener

public void removeGraphViewListener(GraphViewListener l)
Remove the given view listener.

Specified by:
removeGraphViewListener in interface GraphController

removeNode

public void removeNode(java.lang.Object node)
Remove the given node. Find the node controller associated with that node and delegate to that node controller.

Specified by:
removeNode in interface GraphController

rerender

public void rerender()
Render the current graph again by recreating the figures for all nodes and edges, but do not alter the connectivity in the graph. This should be called when changes to renderers are made.

Specified by:
rerender in interface GraphController

rerenderEdge

public void rerenderEdge(java.lang.Object edge)
Rerender the given edge by replacing its figure with a new figure. This should be called if the state of the edge has changed in such a way that the rendering should change.

Specified by:
rerenderEdge in interface GraphController

rerenderNode

public void rerenderNode(java.lang.Object node)
Rerender the given node by replacing its figure with a new figure. This should be called if the state of the node has changed in such a way that the rendering should change.

Specified by:
rerenderNode in interface GraphController

setGraphModel

public void setGraphModel(GraphModel model)
Set the graph being viewed. If there is a graph already and it contains data, delete the figures of that graph's nodes and edges (but don't modify the graph itself).

Specified by:
setGraphModel in interface GraphController

setFigure

public void setFigure(java.lang.Object semanticObj,
                      Figure f)
Set the figure associated with the given semantic object (node or edge). A null figure clears the association.

Specified by:
setFigure in interface GraphController

setGraphPane

public void setGraphPane(GraphPane pane)
Set the graph pane. This is called by the GraphPane. FIXME: should this be package private?

Specified by:
setGraphPane in interface GraphController

setSelectionModel

public void setSelectionModel(SelectionModel m)
Set the default selection model. The caller is expected to ensure that the old model is empty before calling this.

Specified by:
setSelectionModel in interface GraphController

dispatch

public void dispatch(GraphViewEvent e)
Dispatch the given graph view event to all registered graph view listeners. This method is generally only called by subclasses and representatives of those subclasses, such as a node controller or an edge controller.

Specified by:
dispatch in interface GraphController

initializeInteraction

protected abstract void initializeInteraction()
Initialize all interaction on the graph pane. This method is called by the setGraphPane() method, and must be overridden by subclasses. This initialization cannot be done in the constructor because the controller does not yet have a reference to its pane at that time.