ptolemy.vergil.basic
Class LocatableNodeController

java.lang.Object
  extended by diva.graph.BasicNodeController
      extended by ptolemy.vergil.basic.LocatableNodeController
All Implemented Interfaces:
NodeController
Direct Known Subclasses:
NamedObjController

public class LocatableNodeController
extends BasicNodeController

This node controller provides interaction techniques for nodes that are locations. This is common when the node has some concept of its graphical location, but does not know about the figure that it is associated with. This class provides the connection between the figure's notion of location and the node's concept of location.

When nodes are drawn, they are automatically placed at the coordinate given by the location. A LocatableNodeDragInteractor is used to update the location of the node as the figure moves.

Since:
Ptolemy II 2.0
Version:
$Id: LocatableNodeController.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Field Summary
protected  boolean _decoratable
          A flag indicating that the figures associated with this controller can be decorated to indicate that they are derived.
private  LocatableNodeDragInteractor _dragInteractor
          The drag interactor, which is remembered so we can change the snap resolution.
static java.awt.Color CLASS_ELEMENT_HIGHLIGHT_COLOR
          A fourth argument would this highlight translucent, which would enable combination with other highlights.
 
Constructor Summary
LocatableNodeController(GraphController controller)
          Create an instance associated with the specified graph controller.
 
Method Summary
protected  void _drawChildren(java.lang.Object node)
          Render the children of the specified node.
protected static CompositeFigure _getCompositeFigure(Figure nf)
          Get the CompositeFigure from the given Figure.
protected  boolean _hide(java.lang.Object node)
          In this base class, return true if the specified node contains a parameter named "_hide" with value true or an attribute that is not a parameter named "_hide".
protected  boolean _isPropertySet(NamedObj object, java.lang.String name)
          Return true if the property of the specified name is set for the specified object.
protected  Figure _renderNode(java.lang.Object node)
          Render the specified node.
 void addNode(java.lang.Object node, double x, double y)
          Add a node to this graph editor and render it at the given location.
 Figure drawNode(java.lang.Object node)
          Draw the node at its location.
 double[] getLocation(java.lang.Object node)
          Return the desired location of this node.
 boolean hasLocation(java.lang.Object node)
          Return true if the node is associated with a desired location.
 void locateFigure(java.lang.Object node)
          Move the node's figure to the location specified in the node's semantic object, if that object is an instance of Locatable.
 void setLocation(java.lang.Object node, double[] location)
          Set the desired location of this node.
 void setSnapResolution(double resolution)
          Specify the snap resolution.
 
Methods inherited from class diva.graph.BasicNodeController
addNode, addNode, addNode, clearNode, drawNode, getController, getNodeInteractor, getNodeRenderer, removeNode, setNodeInteractor, setNodeRenderer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_ELEMENT_HIGHLIGHT_COLOR

public static final java.awt.Color CLASS_ELEMENT_HIGHLIGHT_COLOR
A fourth argument would this highlight translucent, which would enable combination with other highlights. However, this causes printing to PDF to rasterize, which significantly degrades the quality of the graphic output. Used to have value 200.


_decoratable

protected boolean _decoratable
A flag indicating that the figures associated with this controller can be decorated to indicate that they are derived. Some derived classes (like IOPortController) override this to suppress such decoration. This is true by default.


_dragInteractor

private LocatableNodeDragInteractor _dragInteractor
The drag interactor, which is remembered so we can change the snap resolution.

Constructor Detail

LocatableNodeController

public LocatableNodeController(GraphController controller)
Create an instance associated with the specified graph controller.

Parameters:
controller - The graph controller.
Method Detail

addNode

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

Specified by:
addNode in interface NodeController
Overrides:
addNode in class BasicNodeController

drawNode

public Figure drawNode(java.lang.Object node)
Draw the node at its location. This overrides the base class to assign a location to the object.

Specified by:
drawNode in interface NodeController
Overrides:
drawNode in class BasicNodeController

getLocation

public double[] getLocation(java.lang.Object node)
Return the desired location of this node. Throw a runtime exception if the node does not have a desired location.

Parameters:
node - The node.
Returns:
The desired location of the node.
See Also:
setLocation(Object, double[])

hasLocation

public boolean hasLocation(java.lang.Object node)
Return true if the node is associated with a desired location. In this base class, return true if the the node's semantic object is an instance of Locatable.

Parameters:
node - The node.
Returns:
True if the node is associated with a desired location.

locateFigure

public void locateFigure(java.lang.Object node)
Move the node's figure to the location specified in the node's semantic object, if that object is an instance of Locatable. If the semantic object is not a location, then do nothing. If the figure associated with the semantic object is an instance of TerminalFigure, then modify the location to ensure that the connect site snaps to grid.

Parameters:
node - The object to locate.

setLocation

public void setLocation(java.lang.Object node,
                        double[] location)
                 throws IllegalActionException
Set the desired location of this node. Throw an exception if the node can not be given a desired location.

Parameters:
node - The node
location - The location
Throws:
IllegalActionException - Not thrown in this base class.
See Also:
getLocation(Object)

setSnapResolution

public void setSnapResolution(double resolution)
Specify the snap resolution. The default snap resolution is 5.0.

Parameters:
resolution - The snap resolution.

_drawChildren

protected void _drawChildren(java.lang.Object node)
Render the children of the specified node. This overrides the base class to do nothing if the node contains a parameter named "_hide" with value true.

Overrides:
_drawChildren in class BasicNodeController
Parameters:
node - The node with children to render.

_getCompositeFigure

protected static CompositeFigure _getCompositeFigure(Figure nf)
Get the CompositeFigure from the given Figure.

Parameters:
nf - The figure that should be a CompositeFigure itself, or be a TerminalFigure whose getFigure() method returns a CompositeFigure.
Returns:
The CompositeFigure, or null of it cannot be found.

_hide

protected boolean _hide(java.lang.Object node)
In this base class, return true if the specified node contains a parameter named "_hide" with value true or an attribute that is not a parameter named "_hide". Derived classes can override this method to provide more sophisticated methods of choosing which nodes to display.

Parameters:
node - The node
Returns:
true if the specified node should be hidden.

_isPropertySet

protected boolean _isPropertySet(NamedObj object,
                                 java.lang.String name)
Return true if the property of the specified name is set for the specified object. A property is specified if the specified object contains an attribute with the specified name and that attribute is either not a boolean-valued parameter, or it is a boolean-valued parameter with value true.

Parameters:
object - The object.
name - The property name.
Returns:
True if the property is set.

_renderNode

protected Figure _renderNode(java.lang.Object node)
Render the specified node. This overrides the base class to return an invisible figure if the node contains a parameter named "_hide" with value true. This overrides the base class to assign a location and to highlight the node if it is an inherited object, and hence cannot be deleted.

Overrides:
_renderNode in class BasicNodeController
Parameters:
node - The node to render.
Returns:
the newly created figure.