diva.graphx
Class GraphController

java.lang.Object
  extended by diva.graphx.GraphController
Direct Known Subclasses:
SimpleGraphController

public abstract class GraphController
extends Object

A graph controller manages graph elements, such as nodes and edges, and their visual representations on a canvas. An instance of this class is, for all intents and purposes, a graph editor.

Each instance of GraphController contains one or more instances of NodeController, and one or more instances of EdgeController. Simple graph editors only need one of each; more complex graph editors will need more than one of each. For example, a graph editor for hierarchical graphs might have two node controllers: one for top-level nodes, and one for child nodes.

Concrete subclasses must implement the following methods (which are abstract in this class):

In addition, subclasses will use the constructor to set up interaction on the canvas that the graph is being drawn on. The recommended structure of a subclass constructor is like this:

   public MyGraphController (GraphicsPane pane, GraphModel model) {
        setGraphicsPane(pane);
        setGraphModel(model);
      ... initialize all interaction ...
   }
 

GraphController is intended to be the primary access point for programmatic control of a graph editor. Many of its methods simply delegate to a NodeController or EdgeController. In these cases the documentation in this class is minimal and there is a reference to the fully documented method in the relevant class.

Version:
$Revision: 1.5 $
Author:
John Reekie, Michael Shilman (michaels@eecs.berkeley.edu), Steve Neuendorffer (neuendor@eecs.berkeley.edu)

Constructor Summary
GraphController()
           
 
Method Summary
 void addEdge(Object edge, Object parent)
          Add an edge to the model and render it on the canvas.
 void addEdge(Object edge, Object parent, Object tail, Object head)
          Add an edge to the model and render it on the canvas.
 void addGraphViewListener(GraphViewListener l)
           
 void addNode(Object node, double x, double y)
          Add the node to this graph editor and render it at the given location.
 void addNode(Object node, 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 dispatch(GraphViewEvent e)
          Dispatch the given graph view event to all registered grpah view listeners.
abstract  EdgeController getEdgeController(Object edge)
          Given an edge, return the controller associated with that edge.
 GraphicsPane getGraphicsPane()
          Return the graphics pane of this controller
 GraphModel getGraphModel()
          Return the graph being viewed.
abstract  NodeController getNodeController(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(Object edge)
          Register a graph controller with its canvas pane.
 void removeGraphViewListener(GraphViewListener l)
          Remove the given view listener.
 void removeNode(Object node)
          Remove the given node.
 void render()
          Render the complete graph.
 void rerender()
          Re-render the complete graph.
 void rerenderSubGraph(Iterator elements)
          Rerender a subgraph.
protected  void setGraphicsPane(GraphicsPane pane)
          Set the graphics pane that the controller operates on.
protected  void setGraphModel(GraphModel model)
          Set the graph model being viewed.
 void setHead(Object edge, Object head)
          Set the head of the edge to the given node.
 void setSelectionModel(SelectionModel m)
          Set the default selection model.
 void setTail(Object edge, Object tail)
          Set the tail of the edge to the given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphController

public GraphController()
Method Detail

addEdge

public void addEdge(Object edge,
                    Object parent)
Add an edge to the model and render it on the canvas.

See Also:
EdgeController.addEdge(Object, Object)

addEdge

public void addEdge(Object edge,
                    Object parent,
                    Object tail,
                    Object head)
Add an edge to the model and render it on the canvas.

See Also:
EdgeController.addEdge(Object, Object, Object, Object)

addGraphViewListener

public void addGraphViewListener(GraphViewListener l)

addNode

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

See Also:
NodeController.addNode(Object, Object, double, double)

addNode

public void addNode(Object node,
                    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.

See Also:
NodeController.addNode(Object, Object, double, double)

getEdgeController

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


getNodeController

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


getGraphModel

public GraphModel getGraphModel()
Return the graph being viewed.


getGraphicsPane

public GraphicsPane getGraphicsPane()
Return the graphics pane of this controller


getSelectionModel

public SelectionModel getSelectionModel()
Get the default selection model


removeEdge

public void removeEdge(Object edge)
Register a graph controller with its canvas pane. This is a hack that we use because we no longer have a way to get from a graph editing canvas to a /** Remove the given edge. Find the edge controller associated with that edge and delegate to that edge controller.


removeGraphViewListener

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


removeNode

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

See Also:
NodeController.removeNode(Object)

render

public void render()
Render the complete graph. This utility method should be called only when a non-empty GraphModel is set for the first time. Once anything has been drawn, this method will not work.


rerender

public void rerender()
Re-render the complete graph. This utility method is provided for those times when it's simply not possible to intelligently redraw relevant portions of the graph. Responding to a STRUCTURE_CHANGED would be one such situation. The selection is cleared before performing this, so it's not a good idea to use this method unless it's really necessary.


rerenderSubGraph

public void rerenderSubGraph(Iterator elements)
Rerender a subgraph. This method finds the set of all nodes returned by the given iterator, and the set of edges that includes all edges returned by the iterator and all edges connected to the set of nodes. Then it removes the connectors for all edges, then the figures for all nodes, then it redraws them all. Any nodes or edges that were originally in the selection get put back into the selection. Note however that this method might not always get it right in the presence of multiple selections or hierarchy, so be warned.


setGraphModel

protected final void setGraphModel(GraphModel model)
Set the graph model being viewed. This protected method is for use only by subclass constructors.


setGraphicsPane

protected final void setGraphicsPane(GraphicsPane pane)
Set the graphics pane that the controller operates on. This protected method is for use only by subclass constructors.


setHead

public void setHead(Object edge,
                    Object head)
Set the head of the edge to the given node.

See Also:
EdgeController.setHead(Object, Object)

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.


setTail

public void setTail(Object edge,
                    Object tail)
Set the tail of the edge to the given node.

See Also:
EdgeController.setTail(Object, Object)

dispatch

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


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.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.