diva.graphx
Class GraphModel

java.lang.Object
  extended by diva.graphx.GraphModel
Direct Known Subclasses:
BasicGraphModel

public abstract class GraphModel
extends Object

The class that represents a graph. An instance of this class contains one or more NodeAdapters and EdgeAdapters, as returned by the (abstract) getNodeAdapter() and getEdgeAdapter(). To tailor this class to a specific type of graph, it must be subclasses and these two methods over-ridden.

Operations on nodes and edges can be performed by accessing the appropriate NodeAdapter or EdgeAdapter and calling their methods. The GraphModel class provides an event notification mechanism over the top of this basic functionality. Specifically, any operations that modify the graph, such as adding a node or edge, should be performed through the interface in GraphModel so that events are generated for listeners. Many methods are also provided that delegate to the appropriate adapter method; in these case, documentation here is incomplete, and the adaptor method is referred to.

Event dispatching can also be done explicitly by calling the dispatchEvent() method. This can be used if a series of graph modifications will be performed and it is preferable to just generate a single event. Event dispatching can also be turned on or off with the setDispatchEnabled() method (by default, dispatching is on).

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

Field Summary
protected  GraphEventMulticaster _graphListeners
          The list of graph listeners.
 
Constructor Summary
GraphModel()
           
 
Method Summary
 boolean acceptHead(Object edge, Object node)
          Return true if the head of the given edge can be attached to the given node.
 boolean acceptTail(Object edge, Object node)
          Return true if the tail of the given edge can be attached to the given node.
 void addEdge(Object eventSource, Object edge, Object parent)
          Add a edge to the graph.
 void addGraphListener(GraphListener l)
          Add a graph listener to the model.
 void addNode(Object eventSource, Object node, Object parent)
          Add a node to the graph.
 void connectEdge(Object eventSource, Object edge, Object tailNode, Object headNode)
          Deprecated.  
 void disconnectEdge(Object eventSource, Object edge)
          Deprecated.  
 void dispatchGraphEvent(GraphEvent e)
          Send an graph event to all of the graph listeners.
abstract  EdgeAdapter getEdgeAdapter(Object edge)
          Return the adapter for the given edge object.
 Object getHead(Object edge)
          Return the head node of the given edge.
abstract  NodeAdapter getNodeAdapter(Object node)
          Return the adapter for the given node object.
 int getNodeCount(Object node)
          Return the number of nodes contained in the given node.
 Object getParent(Object node)
          Return the parent graph of this node, return null if there is no parent.
 Object getRoot()
          Return the root graph of this graph model.
 Object getTail(Object edge)
          Return the tail node of this edge.
 Iterator inEdges(Object node)
          Return an iterator over the in edges of this node.
 boolean isComposite(Object node)
          Return true if the given object is a composite node in this model, i.e.
 boolean isDispatchEnabled()
          Test if dispatching is enabled
 boolean isEdge(Object o)
          Return true if the given object is a node in this model.
 boolean isNode(Object o)
          Return true if the given object is a node in this model.
 Iterator nodes(Object node)
          Provide an iterator over the nodes in the given node.
 Iterator outEdges(Object node)
          Return an iterator over the out edges of this node.
 void removeGraphListener(GraphListener l)
          Remove the given listener from this graph model.
 void removeNode(Object eventSource, Object node)
          Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event.
 void setDispatchEnabled(boolean val)
          Turn on/off all event dispatches from this graph model, for use in an inner-loop algorithm.
 void setHead(Object eventSource, Object edge, Object head)
          Connect an edge to the given head node.
protected  void setRoot(Object root)
          Set the root of the graph.
 void setTail(Object eventSource, Object edge, Object tail)
          Connect an edge to the given tail node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_graphListeners

protected GraphEventMulticaster _graphListeners
The list of graph listeners.

Constructor Detail

GraphModel

public GraphModel()
Method Detail

acceptHead

public boolean acceptHead(Object edge,
                          Object node)
Return true if the head of the given edge can be attached to the given node.


acceptTail

public boolean acceptTail(Object edge,
                          Object node)
Return true if the tail of the given edge can be attached to the given node.


addGraphListener

public void addGraphListener(GraphListener l)
Add a graph listener to the model. Graph listeners are notified with a GraphEvent any time the graph is modified.


addEdge

public void addEdge(Object eventSource,
                    Object edge,
                    Object parent)
Add a edge to the graph. Graph listeners are notified with an EDGE_ADDED event.


addNode

public void addNode(Object eventSource,
                    Object node,
                    Object parent)
Add a node to the graph. Graph listeners are notified with a NODE_ADDED event.


connectEdge

public void connectEdge(Object eventSource,
                        Object edge,
                        Object tailNode,
                        Object headNode)
Deprecated. 

Connect the given edge to the given tail and head nodes, then dispatch events to the listeners.


disconnectEdge

public void disconnectEdge(Object eventSource,
                           Object edge)
Deprecated. 

Disconnect an edge from its two endpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event.


dispatchGraphEvent

public void dispatchGraphEvent(GraphEvent e)
Send an graph event to all of the graph listeners. This allows manual control of sending graph graph events, or allows the user to send a STRUCTURE_CHANGED after some inner-loop operations.

This method furthermore ensures that all graph events are dispatched in the event thread.

See Also:
setDispatchEnabled(boolean)

getEdgeAdapter

public abstract EdgeAdapter getEdgeAdapter(Object edge)
Return the adapter for the given edge object. If the object is not an edge, then return null.


getHead

public Object getHead(Object edge)
Return the head node of the given edge.


getNodeCount

public int getNodeCount(Object node)
Return the number of nodes contained in the given node. This will be meaningful only if the given node is a composite.


getNodeAdapter

public abstract NodeAdapter getNodeAdapter(Object node)
Return the adapter for the given node object. If the object is not a node, then return null.


getParent

public Object getParent(Object node)
Return the parent graph of this node, return null if there is no parent.


getRoot

public Object getRoot()
Return the root graph of this graph model.


getTail

public Object getTail(Object edge)
Return the tail node of this edge.


inEdges

public Iterator inEdges(Object node)
Return an iterator over the in edges of this node. This iterator does not support removal operations. If there are no in-edges, an iterator with no elements is returned.


isComposite

public boolean isComposite(Object node)
Return true if the given object is a composite node in this model, i.e. it contains children.


isDispatchEnabled

public boolean isDispatchEnabled()
Test if dispatching is enabled


isEdge

public boolean isEdge(Object o)
Return true if the given object is a node in this model.


isNode

public boolean isNode(Object o)
Return true if the given object is a node in this model.


nodes

public Iterator nodes(Object node)
Provide an iterator over the nodes in the given node. This iterator does not necessarily support removal operations. The result will be meaningful only of the given node is a composite.


outEdges

public Iterator outEdges(Object node)
Return an iterator over the out edges of this node. This iterator does not support removal operations. If there are no out-edges, an iterator with no elements is returned.


removeGraphListener

public void removeGraphListener(GraphListener l)
Remove the given listener from this graph model. The listener will no longer be notified of changes to the graph.


removeNode

public void removeNode(Object eventSource,
                       Object node)
Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event. This first removes all the edges that are connected to the given node, or some subnode of that node, and then sets the parent of the node to null.


setDispatchEnabled

public void setDispatchEnabled(boolean val)
Turn on/off all event dispatches from this graph model, for use in an inner-loop algorithm. When turning dispatch back on again, if the client has made changes that listeners should know about, he should create an appropriate STRUCTURE_CHANGED and dispatch it using the dispatchGraphEvent() method.

See Also:
dispatchGraphEvent(GraphEvent)

setHead

public void setHead(Object eventSource,
                    Object edge,
                    Object head)
Connect an edge to the given head node. Graph listeners are notified with an EDGE_HEAD_CHANGED event.


setRoot

protected void setRoot(Object root)
Set the root of the graph. For subclass constructor use.


setTail

public void setTail(Object eventSource,
                    Object edge,
                    Object tail)
Connect an edge to the given tail node. Graph listeners are notified with an EDGE_TAIL_CHANGED event.



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