diva.graph
Class AbstractGraphModel

java.lang.Object
  extended by diva.graph.AbstractGraphModel
All Implemented Interfaces:
GraphModel
Direct Known Subclasses:
ModularGraphModel

public abstract class AbstractGraphModel
extends java.lang.Object
implements GraphModel

An abstract implementation of the GraphModel interface that provides the basic event notification system

Version:
$Id: AbstractGraphModel.java 54721 2009-06-26 22:32:23Z cxh $
Author:
Steve Neuendorffer, Contributor Bert Rodiers
Accepted Rating:
Red

Field Summary
private  boolean _dispatch
          Whether or not to dispatch events.
protected  GraphEventMulticaster _graphListeners
          The list of graph listeners.
private  java.util.LinkedList<GraphEvent> otherEvents
           
private  java.util.LinkedList<GraphEvent> structuralChangeEvents
           
 
Constructor Summary
AbstractGraphModel()
           
 
Method Summary
private  boolean _addEvent(GraphEvent e)
          Add a GraphEvent to be processed.
private  GraphEvent _getEvent()
          Get a GraphEvent to process it.
 void addGraphListener(GraphListener l)
          Add a graph listener to the model.
 void dispatchGraphEvent(GraphEvent e)
          Send an graph event to all of the graph listeners.
 void removeGraphListener(GraphListener l)
          Remove the given listener from this graph model.
 void setDispatchEnabled(boolean val)
          Turn on/off all event dispatches from this graph model, for use in an inner-loop algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.graph.GraphModel
containsNode, getHead, getNodeCount, getParent, getProperty, getRoot, getSemanticObject, getTail, inEdges, isComposite, isDirected, isEdge, isNode, nodes, nodesAfterEdges, nodesBeforeEdges, outEdges, setProperty, setSemanticObject
 

Field Detail

_dispatch

private boolean _dispatch
Whether or not to dispatch events.


_graphListeners

protected GraphEventMulticaster _graphListeners
The list of graph listeners.


structuralChangeEvents

private java.util.LinkedList<GraphEvent> structuralChangeEvents

otherEvents

private java.util.LinkedList<GraphEvent> otherEvents
Constructor Detail

AbstractGraphModel

public AbstractGraphModel()
Method Detail

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.

Specified by:
addGraphListener in interface GraphModel

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.

Specified by:
dispatchGraphEvent in interface GraphModel
See Also:
setDispatchEnabled(boolean)

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.

Specified by:
removeGraphListener in interface GraphModel

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.

Specified by:
setDispatchEnabled in interface GraphModel
See Also:
dispatchGraphEvent(GraphEvent)

_addEvent

private boolean _addEvent(GraphEvent e)
Add a GraphEvent to be processed. These elements will be put in a queue if necessary (some repaints are not necessary).

Parameters:
e - The GraphEvent to be processed.
Returns:
true when the GraphEvent has been added to the queue.

_getEvent

private GraphEvent _getEvent()
Get a GraphEvent to process it. If there are no such events null will be returned.

Returns:
The GraphEvent to process.