ptolemy.vergil.basic
Class AbstractBasicGraphModel

ptolemy.vergil.basic.AbstractBasicGraphModel
Direct Known Subclasses:
ActorGraphModel, FSMGraphModel

public abstract class AbstractBasicGraphModel

This base class provides some common services for visual notations for Ptolemy II models. It assumes that the semantic object of a particular graph object is fixed, and provides facilities for making changes to the model via a change request. It supports visible attributes.

This class uses a change listener to detect changes to the Ptolemy model that do not originate from this class. 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: AbstractBasicGraphModel.java,v 1.7.2.1 2002/03/22 16:01:46 cxh Exp $
Author:
Steve Neuendorffer, Contributor: Edward A. Lee

Inner Class Summary
 class AbstractBasicGraphModel.GraphChangeListener
          Mutations may happen to the ptolemy model without the knowledge of this model.
 
Constructor Summary
AbstractBasicGraphModel(CompositeEntity composite)
          Create a graph model for the specified Ptolemy II model.
 
Method Summary
protected static NamedObj _getChangeRequestParent(NamedObj object)
          Return the context for which a change request concerning the given object should be made.
protected  Location _getLocation(NamedObj object)
          Return the location attribute contained in the given object, or a new location contained in the given object if there was no location.
protected  boolean _update()
          Update the graph model.
abstract  void disconnectEdge(java.lang.Object eventSource, java.lang.Object edge)
          Disconnect an edge from its two endpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.
 diva.graph.modular.CompositeModel getCompositeModel(java.lang.Object composite)
          Return the model for the given composite object.
 diva.graph.modular.NodeModel getNodeModel(java.lang.Object node)
          Return the node model for the given object.
 java.lang.Object getProperty(java.lang.Object object, java.lang.String propertyName)
          Return the property of the object associated with the given property name.
 CompositeEntity getPtolemyModel()
          Return the Ptolemy II model associated with this graph model.
 java.lang.Object getSemanticObject(java.lang.Object element)
          Return the semantic object corresponding to the given node, edge, or composite.
 void removeListeners()
          Remove any listeners we have created.
abstract  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.
 void setProperty(java.lang.Object object, java.lang.String propertyName, java.lang.Object value)
          Set the property of the given graph object associated with the given property name to the given value.
 void setSemanticObject(java.lang.Object object, java.lang.Object semantic)
          Set the semantic object corresponding to the given node, edge, or composite.
 

Constructor Detail

AbstractBasicGraphModel

public AbstractBasicGraphModel(CompositeEntity composite)
Create a graph model for the specified Ptolemy II model.
Parameters:
composite - The Ptolemy II model.
Method Detail

disconnectEdge

public abstract void disconnectEdge(java.lang.Object eventSource,
                                    java.lang.Object edge)
Disconnect an edge from its two endpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.
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.

getCompositeModel

public diva.graph.modular.CompositeModel getCompositeModel(java.lang.Object composite)
Return the model for the given composite object. In this base class, return an instance of CompositeEntityModel if the object is the root object of this graph model. Otherwise return null.
Parameters:
composite - A composite object.
Returns:
An instance of CompositeEntityModel if the object is the root object of this graph model. Otherwise return null.

getNodeModel

public diva.graph.modular.NodeModel getNodeModel(java.lang.Object node)
Return the node model for the given object. If the object is an attribute, then return an attribute model. Otherwise, return null.
Parameters:
node - An object which is assumed to be in this graph model.
Returns:
An instance of the inner class AttributeNodeModel if the object is an instance of Location whose container is an instance of Attribute, and otherwise, null.

getProperty

public java.lang.Object getProperty(java.lang.Object object,
                                    java.lang.String propertyName)
Return the property of the object associated with the given property name. In this implementation properties are stored in variables of the graph object (which is always a Ptolemy NamedObj). If no variable with the given name exists in the object, then return null. Otherwise retrieve the token from the variable. If the token is an instance of ObjectToken, then get the value from the token and return it. Otherwise, return the result of calling toString on the token.
Parameters:
object - The graph object, which is assumed to be an instance of NamedObj.
propertyName - The name of the new property.

getPtolemyModel

public CompositeEntity getPtolemyModel()
Return the Ptolemy II model associated with this graph model.
Returns:
The Ptolemy II model.

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 base class, if the argument is an instance of Port, then return the port. If the argument is an instance of Location, then return the container of the location.
Parameters:
element - A graph element.
Returns:
The semantic object associated with this element, or null if the object is not recognized.

removeNode

public abstract 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.
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.

setProperty

public void setProperty(java.lang.Object object,
                        java.lang.String propertyName,
                        java.lang.Object value)
Set the property of the given graph object associated with the given property name to the given value. In this implementation properties are stored in variables of the graph object (which is always a Ptolemy NamedObj). If no variable with the given name exists in the graph object, then create a new variable contained by the graph object with the given name. If the value is a string, then set the expression of the variable to that string. Otherwise create a new object token contained the value and place that in the variable instead. The operation is performed in a ptolemy change request.
Parameters:
object - The graph object.
propertyName - The property name.
value - The new value of the property.

setSemanticObject

public void setSemanticObject(java.lang.Object object,
                              java.lang.Object semantic)
Set the semantic object corresponding to the given node, edge, or composite. The semantic objects in this graph model are fixed, so this method throws an UnsupportedOperationException.
Parameters:
object - The graph object that represents a node or an edge.
semantic - The semantic object to associate with the given graph object.

removeListeners

public void removeListeners()
Remove any listeners we have created. The frame displaying this graph model should call this function when the frame is closed.

_getChangeRequestParent

protected static NamedObj _getChangeRequestParent(NamedObj object)
Return the context for which a change request concerning the given object should be made. This is the first container above the object in the hierarchy that defers its MoML definition, or the immediate parent if there is none.
Parameters:
object - The object to change.
Returns:
The context for a change request.

_getLocation

protected Location _getLocation(NamedObj object)
Return the location attribute contained in the given object, or a new location contained in the given object if there was no location.
Parameters:
object - The object for which a location is needed.
Returns:
The location of the object, or a new location if none.

_update

protected boolean _update()
Update the graph model. This is called whenever a change request is executed. Subclasses will override this to update internal data structures that may be cached.
Returns:
True if the graph model changes (always true in this base class).