diva.graphx
Class NodeController

java.lang.Object
  extended by diva.graphx.NodeController
Direct Known Subclasses:
SimpleNodeController

public abstract class NodeController
extends Object

A node controller is the object responsible for managing all instances of a particular type of node, and the corresponding Figures that are used to represent them on the canvas. Each graph controller contains one or more node controllers.

Node controllers assume that each node is represented by a single Figure on the canvas. (If the node is composite, then of course it's Figure also has child figures, corresponding to each child node.) The mapping between figures and node objects is set up in two ways:

  1. Each Figure has its "user object" set to the corresponding node
  2. Each node is an index into a hashtable contained in the node controller, and which references the figure.

The binding between a node and its figure is exposed by the methods bind() and unbind(), which add and remove a binding. These methods are fairly low-level and not really intended for general use. The method getFigure() looks up a binding ie gets the figure representing a node, and is what clients should use anytime they need to get the visual representation of a node.

This class has one abstract method which must be implemented by application-specific subclasses, renderNode(). This method creates a Figure given a node. A second method, drawNodeChildren(), should be overridden by any subclass that manages composite nodes.

Finally, concrete subclasses that want to change the default interactor will do so in the subclass' constructor. Subclass constructors must always call super() to ensure that the controller is properly initialized.

Version:
$Revision: 1.4 $
Author:
Steve Neuendorffer, John Reekie

Constructor Summary
NodeController(GraphController controller)
          Create a new node controller with a default node interactor.
 
Method Summary
 void addNode(Object node, Object parent, double x, double y)
          Add the given node to this graph editor, inside the given parent node and render it at the given location relative to its parent.
 void bind(Object node, Figure figure)
          Create or overwrite a binding from a node to a figure.
 void drawNode(Object node, Object parent, double x, double y)
          Draw the given node at the specified location.
 void drawNodeChildren(Object parent, Figure container)
          Draw the children of the given node.
 GraphController getController()
          Return the graph controller containing this controller.
 Figure getFigure(Object node)
          Get the figure corresponding to the given node.
 Interactor getNodeInteractor()
          Return the node interactor associated with this controller.
 void removeNode(Object node)
          Remove the node and its associated figure.
abstract  Figure renderNode(Object node, Object parent, FigureContainer container, double x, double y)
          Render a visual representation of the given node, at the given location, and add it to the given figure container.
 void setNodeInteractor(Interactor interactor)
          Set the node interactor for this controller
 void unbind(Object node, Figure figure)
          Remove a binding from a node to a figure.
 void undrawNode(Object node)
          Remove the figure for the given node.
abstract  void unrenderNode(Object node, Figure figure)
          Remove the visual representation of the given node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeController

public NodeController(GraphController controller)
Create a new node controller with a default node interactor. This interactor is an instance of diva.graphx.interaction.NodeInteractor on the selection model from the GraphController. If the default is not suitable, subclass constructors can call setNodeInteractor after calling super(). Note: super() must be called from subclass constructors.

Method Detail

bind

public void bind(Object node,
                 Figure figure)
Create or overwrite a binding from a node to a figure.


addNode

public void addNode(Object node,
                    Object parent,
                    double x,
                    double y)
Add the given node to this graph editor, inside the given parent node and render it at the given location relative to its parent. The children of the nodes are *not* added -- these must be done by using the addNodeChildren(method).


drawNode

public void drawNode(Object node,
                     Object parent,
                     double x,
                     double y)
Draw the given node at the specified location. If the node is composite, then this method will call the drawNodeChildren() method to draw the node's children.


drawNodeChildren

public void drawNodeChildren(Object parent,
                             Figure container)
Draw the children of the given node. The container argument is the Figure that was previously drawn for this node. Subclasses that control composite nodes must override this method to iterate through child nodes and call drawNode() on the appropriate controller for each of them.


getController

public GraphController getController()
Return the graph controller containing this controller.


getFigure

public Figure getFigure(Object node)
Get the figure corresponding to the given node. Returns null if the node is not known to this controller.


getNodeInteractor

public Interactor getNodeInteractor()
Return the node interactor associated with this controller.


removeNode

public void removeNode(Object node)
Remove the node and its associated figure. This method assumes that any edges connected to the node or any of its children have already been disconnected. Failure to do so on the part of a client will result in errors.


renderNode

public abstract Figure renderNode(Object node,
                                  Object parent,
                                  FigureContainer container,
                                  double x,
                                  double y)
Render a visual representation of the given node, at the given location, and add it to the given figure container. If the node is at the top level of the graph, then the container will be a FigureLayer, otherwise it will be a Figure class that also implements the FigureContainer interface.


setNodeInteractor

public void setNodeInteractor(Interactor interactor)
Set the node interactor for this controller


unbind

public void unbind(Object node,
                   Figure figure)
Remove a binding from a node to a figure. Throw an exception if the binding is not valid. (This is very very bad and should not happen. If it does then there is a serious bug somewhere else.)


undrawNode

public void undrawNode(Object node)
Remove the figure for the given node. If there are any edges connected to the nodes and their figures have not also been undrawn, then things might get weird, so be careful how you call this. In general, if you want to redraw sections of a graph, you should use GraphController.rerenderSubgraph().

See Also:
GraphController#rerenderSubgraph(Iterator);

unrenderNode

public abstract void unrenderNode(Object node,
                                  Figure figure)
Remove the visual representation of the given node. Implementors should remove the node from the selection (if this type of node is selectable), then remove the figure from its parent.



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