ptolemy.vergil.actor
Class ActorGraphModel

java.lang.Object
  extended bydiva.graph.AbstractGraphModel
      extended bydiva.graph.modular.ModularGraphModel
          extended byptolemy.vergil.basic.AbstractBasicGraphModel
              extended byptolemy.vergil.actor.ActorGraphModel
All Implemented Interfaces:
GraphModel

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.43.2.1 2004/06/18 00:49:26 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.
 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.
 
Nested classes inherited from class ptolemy.vergil.basic.AbstractBasicGraphModel
AbstractBasicGraphModel.GraphChangeListener
 
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  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()
           
 ActorGraphModel.IconModel getIconModel()
           
 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()
           
 java.lang.Object getSemanticObject(java.lang.Object element)
          Return the semantic object corresponding to the given node, edge, or composite.
 ActorGraphModel.VertexModel getVertexModel()
           
 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, 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, 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.
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
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
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.

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.
Throws:
GraphException - If the operation fails.

getIconModel

public ActorGraphModel.IconModel getIconModel()

getPortModel

public ActorGraphModel.PortModel getPortModel()

getExternalPortModel

public ActorGraphModel.ExternalPortModel getExternalPortModel()

getVertexModel

public ActorGraphModel.VertexModel getVertexModel()

_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 verified to be correct. 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.