ptolemy.vergil.actor
Class ActorGraphModel

java.lang.Object
  extended by diva.graph.AbstractGraphModel
      extended by diva.graph.modular.ModularGraphModel
          extended by ptolemy.vergil.basic.AbstractBasicGraphModel
              extended by ptolemy.vergil.actor.ActorGraphModel
All Implemented Interfaces:
GraphModel, ChangeListener
Direct Known Subclasses:
GTFrameController.GTActorGraphModel

public class ActorGraphModel
extends AbstractBasicGraphModel

This class represents one level of hierarchy of a Ptolemy II model. The graph model represents attributes, ports, entities and relations as nodes. Entities and attributes are represented in the model by the icon that is used to visually depict them. Relations are represented in the model by its vertices (which are visual elements that generally exist in multiple places in a visual rendition). Ports represent themselves in the model.

In the terminology of diva, the graph elements are "nodes" (icons, vertices, and ports), and the "edges" link them. Edges are represented in the model by instances of the Link class. Edges may link a port and a vertex, or a port and another port. For visual simplicity, both types of edges are represented by an instance of the Link class. If an edge is placed between a port and a vertex then the Link represents a Ptolemy II link between the port and the vertex's Relation. However, if an edge is placed between two ports, then it represents a relation (with no vertex) and links from the relation to each port (in Ptolemy II, this is called a "connection").

This model uses a ptolemy change listener to detect changes to the model that do not originate from this model. These changes are propagated as structure changed graph events to all graphListeners registered with this model. This mechanism allows a graph visualization of a ptolemy model to remain synchronized with the state of a mutating model.

Since:
Ptolemy II 2.0
Version:
$Id: ActorGraphModel.java,v 1.75 2007/12/16 07:29:48 cxh Exp $
Author:
Steve Neuendorffer, Contributor: Edward A. Lee
Accepted Rating:
Red (johnr)
Proposed Rating:
Yellow (neuendor)

Nested Class Summary
 class ActorGraphModel.ExternalPortModel
          The model for ports that make external connections to this graph.
static class ActorGraphModel.IconModel
          The model for an icon that contains ports.
 class ActorGraphModel.LinkModel
          The model for links that connect two ports, or a port and a vertex.
 class ActorGraphModel.PortModel
          The model for ports that are contained in icons in this graph.
 class ActorGraphModel.VertexModel
          The model for vertexes that are contained within the relations of the ptolemy model.
 
Field Summary
 
Fields inherited from class diva.graph.AbstractGraphModel
_graphListeners
 
Constructor Summary
ActorGraphModel(NamedObj composite)
          Construct a new graph model whose root is the given composite entity.
 
Method Summary
protected  java.util.Set<?> _getLinkSet()
          Get an unmodifiable copy of the link set.
protected  void _removeLink(Link link)
          Remove a link from the link set.
protected  boolean _update()
          Update the graph model.
 void disconnectEdge(java.lang.Object eventSource, java.lang.Object edge)
          Disconnect an edge from its two enpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.
 CompositeModel getCompositeModel(java.lang.Object composite)
          Return the model for the given composite object.
 java.lang.String getDeleteEdgeMoML(java.lang.Object edge)
          Return a MoML String that will delete the given edge from the Ptolemy model.
 java.lang.String getDeleteNodeMoML(java.lang.Object node)
          Return a MoML String that will delete the given node from the Ptolemy model.
 EdgeModel getEdgeModel(java.lang.Object edge)
          Return the model for the given edge object.
 ActorGraphModel.ExternalPortModel getExternalPortModel()
          Get the external port model.
 ActorGraphModel.IconModel getIconModel()
          Get the icon model.
 ActorGraphModel.LinkModel getLinkModel()
          Return the model for edge objects that are instance of Link.
 NodeModel getNodeModel(java.lang.Object node)
          Return the node model for the given object.
 ActorGraphModel.PortModel getPortModel()
          Get the port model.
 java.lang.Object getSemanticObject(java.lang.Object element)
          Return the semantic object corresponding to the given node, edge, or composite.
 ActorGraphModel.VertexModel getVertexModel()
          Get the vertex model.
 void removeNode(java.lang.Object eventSource, java.lang.Object node)
          Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event.
 
Methods inherited from class ptolemy.vergil.basic.AbstractBasicGraphModel
_getLocation, changeExecuted, changeFailed, getProperty, getPtolemyModel, isNode, removeListeners, setProperty, setSemanticObject
 
Methods inherited from class diva.graph.modular.ModularGraphModel
containsNode, getHead, getNodeCount, getParent, getRoot, getTail, inEdges, isComposite, isDirected, isEdge, nodes, nodesAfterEdges, nodesBeforeEdges, outEdges
 
Methods inherited from class diva.graph.AbstractGraphModel
addGraphListener, dispatchGraphEvent, removeGraphListener, setDispatchEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActorGraphModel

public ActorGraphModel(NamedObj composite)
Construct a new graph model whose root is the given composite entity.

Parameters:
composite - The top-level composite entity for the model.
Method Detail

disconnectEdge

public void disconnectEdge(java.lang.Object eventSource,
                           java.lang.Object edge)
Disconnect an edge from its two enpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.

Specified by:
disconnectEdge in class AbstractBasicGraphModel
Parameters:
eventSource - The source of the event that will be dispatched, e.g. the view that made this call.
edge - The edge.
Throws:
GraphException - If the operation fails.

getDeleteEdgeMoML

public java.lang.String getDeleteEdgeMoML(java.lang.Object edge)
Return a MoML String that will delete the given edge from the Ptolemy model.

Specified by:
getDeleteEdgeMoML in class AbstractBasicGraphModel
Parameters:
edge - The edge.
Returns:
A valid MoML string.

getDeleteNodeMoML

public java.lang.String getDeleteNodeMoML(java.lang.Object node)
Return a MoML String that will delete the given node from the Ptolemy model.

Specified by:
getDeleteNodeMoML in class AbstractBasicGraphModel
Parameters:
node - The node.
Returns:
A valid MoML string.

getCompositeModel

public CompositeModel getCompositeModel(java.lang.Object composite)
Return the model for the given composite object. In this class, return an instance of CompositePtolemyModel if the object is the root object of this graph model, and return an instance of IconModel if the object is a location contained by an entity. Otherwise return null.

Overrides:
getCompositeModel in class AbstractBasicGraphModel
Parameters:
composite - A composite object.
Returns:
A model of a composite node.

getEdgeModel

public EdgeModel getEdgeModel(java.lang.Object edge)
Return the model for the given edge object. If the object is not an edge, then return null.

Specified by:
getEdgeModel in class ModularGraphModel
Parameters:
edge - An object which is assumed to be in this graph model.
Returns:
An instance of LinkModel if the object is a Link. Otherwise return null.

getLinkModel

public ActorGraphModel.LinkModel getLinkModel()
Return the model for edge objects that are instance of Link. This will return the same object as getEdgeModel() when the argument is a link.

Returns:
The model for links.

getNodeModel

public NodeModel getNodeModel(java.lang.Object node)
Return the node model for the given object. If the object is not a node, then return null. The argument should be either an instance of Port or Vertex, or it implements Locatable.

Overrides:
getNodeModel in class AbstractBasicGraphModel
Parameters:
node - An object which is assumed to be in this graph model.
Returns:
The node model for the specified node, or null if there is none.

getSemanticObject

public java.lang.Object getSemanticObject(java.lang.Object element)
Return the semantic object corresponding to the given node, edge, or composite. A "semantic object" is an object associated with a node in the graph. In this case, if the node is icon, the semantic object is an entity. If it is a vertex or a link, the semantic object is a relation. If it is a port, then the semantic object is the port itself.

Specified by:
getSemanticObject in interface GraphModel
Overrides:
getSemanticObject in class AbstractBasicGraphModel
Parameters:
element - A graph element.
Returns:
The semantic object associated with this element, or null if the object is not recognized.
See Also:
AbstractBasicGraphModel.setSemanticObject(Object, Object)

removeNode

public void removeNode(java.lang.Object eventSource,
                       java.lang.Object node)
Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event.

Specified by:
removeNode in class AbstractBasicGraphModel
Parameters:
eventSource - The source of the event that will be dispatched, e.g. the view that made this call.
node - The node.
Throws:
GraphException - If the operation fails.

getIconModel

public ActorGraphModel.IconModel getIconModel()
Get the icon model.

Returns:
The icon model.

getPortModel

public ActorGraphModel.PortModel getPortModel()
Get the port model.

Returns:
The port model.

getExternalPortModel

public ActorGraphModel.ExternalPortModel getExternalPortModel()
Get the external port model.

Returns:
The external port model.

getVertexModel

public ActorGraphModel.VertexModel getVertexModel()
Get the vertex model.

Returns:
The vertex model.

_getLinkSet

protected java.util.Set<?> _getLinkSet()
Get an unmodifiable copy of the link set.

Returns:
The link set.

_removeLink

protected void _removeLink(Link link)
Remove a link from the link set. This function is not made synchronized. Concurrent modification on the link set should be avoided.

Parameters:
link - The link to be removed.

_update

protected boolean _update()
Update the graph model. This is called whenever a change request is executed. In this class the internal set of link objects is created to represent each of the links in the graph, and to remove any link objects that are incorrect (e.g., do not have both ends in the model). This method is usually called just before issuing a graph event. If this method returns false, then the graph event should not be issued, because further changes are necessary.

Overrides:
_update in class AbstractBasicGraphModel
Returns:
True if the model was successfully updated, or false if further change requests were queued.