org.tigris.gef.graph
Class MutableGraphSupport

java.lang.Object
  extended by org.tigris.gef.graph.MutableGraphSupport
All Implemented Interfaces:
java.io.Serializable, BaseGraphModel, GraphModel, MutableGraphModel
Direct Known Subclasses:
AdjacencyListGraphModel, DefaultGraphModel

public abstract class MutableGraphSupport
extends java.lang.Object
implements MutableGraphModel, java.io.Serializable

An abstract class that makes it easier to implement your own version of MutableGraphModel. This class basically includes the code for event notifications, so that you don't have to write that. It also provides a few utility methods.

See Also:
Serialized Form

Constructor Summary
MutableGraphSupport()
           
MutableGraphSupport(ConnectionConstrainer cc)
           
 
Method Summary
 void addEdge(java.lang.Object edge)
          Add the given edge to the graph, if valid.
 void addGraphEventListener(GraphListener listener)
           
 void addNode(java.lang.Object node)
          Add the given node to the graph, if valid.
 boolean canChangeConnectedNode(java.lang.Object newNode, java.lang.Object oldNode, java.lang.Object edge)
          Return true if the connection to the old node can be rerouted to the new node.
 boolean canConnect(java.lang.Object fromPort, java.lang.Object toPort, java.lang.Class edgeClass)
          Determine if the two given ports can be connected by the given kind of edge.
 boolean canConnect(java.lang.Object fromPort, java.lang.Object toPort, java.lang.Object edgeType)
          Determine if the two given ports can be connected by the given kind of edge.
 boolean canDragNode(java.lang.Object node)
          Return true if the type of the given node can be mapped to a type supported by this type of diagram
 void changeConnectedNode(java.lang.Object newNode, java.lang.Object oldNode, java.lang.Object edge, boolean isSource)
          Reroutes the connection to the old node to be connected to the new node.
 java.lang.Object connect(java.lang.Object fromPort, java.lang.Object toPort, java.lang.Object edgeClass)
          Contruct and add a new edge of the given kind.
 java.lang.Object connect(java.lang.Object fromPort, java.lang.Object toPort, java.lang.Object edgeType, java.util.Map styleAttributes)
          Construct and add a new edge of the given kind and connect the given ports.
 boolean containsEdge(java.lang.Object edge)
          Return true if the given object is present as a edge in the graph
 boolean containsEdgePort(java.lang.Object port)
           
 boolean containsNode(java.lang.Object node)
          Return true if the given object is present as a node in the graph
 boolean containsNodePort(java.lang.Object port)
           
 boolean containsPort(java.lang.Object port)
           
 java.lang.Object createNode(java.lang.String name, java.util.Hashtable args)
          Return a valid node in this graph TODO Should throw a GraphModelException or InvalidArgumentException
 void dragNode(java.lang.Object node)
          Create a new node based on the given one and add it to the graph.
 void fireEdgeAdded(java.lang.Object edge)
           
 void fireEdgeRemoved(java.lang.Object edge)
           
 void fireGraphChanged()
           
 void fireNodeAdded(java.lang.Object node)
           
 void fireNodeRemoved(java.lang.Object node)
           
protected  ConnectionConstrainer getConnectionConstrainer()
           
 java.util.List getGraphListeners()
           
 boolean isEnclosable(java.lang.Object handle, java.lang.Object encloser)
          Returns true if handle can be enclosed into encloser.
 void removeAll()
          Remove all nodes and edges to reset the graph.
 void removeAllEdges()
          Remove all the edges from the graph.
 void removeAllNodes()
          Remove all the nodes from the graph.
 void removeEdge(java.lang.Object edge)
          Remove the given edge from the graph.
 void removeFig(Fig fig)
          Remove the given edge from the graph.
 void removeGraphEventListener(GraphListener listener)
           
 void removeNode(java.lang.Object node)
          Remove the given node from the graph.
 void setConnectionConstrainer(ConnectionConstrainer cc)
          Apply the object containing the ruleset for what edges and ports can connect in the graph
static void setSaveAction(javax.swing.Action action)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.tigris.gef.graph.MutableGraphModel
addNodeRelatedEdges, canAddEdge, canAddNode, canConnect, connect, connect
 
Methods inherited from interface org.tigris.gef.graph.GraphModel
getEdges, getInEdges, getNodes, getOutEdges, getPorts
 
Methods inherited from interface org.tigris.gef.graph.BaseGraphModel
getDestPort, getOwner, getSourcePort
 

Constructor Detail

MutableGraphSupport

public MutableGraphSupport()

MutableGraphSupport

public MutableGraphSupport(ConnectionConstrainer cc)
Method Detail

getGraphListeners

public java.util.List getGraphListeners()

createNode

public java.lang.Object createNode(java.lang.String name,
                                   java.util.Hashtable args)
Return a valid node in this graph TODO Should throw a GraphModelException or InvalidArgumentException

Specified by:
createNode in interface MutableGraphModel

getConnectionConstrainer

protected ConnectionConstrainer getConnectionConstrainer()

setConnectionConstrainer

public void setConnectionConstrainer(ConnectionConstrainer cc)
Apply the object containing the ruleset for what edges and ports can connect in the graph

Specified by:
setConnectionConstrainer in interface GraphModel
Parameters:
cc - A connection constrainer

canDragNode

public boolean canDragNode(java.lang.Object node)
Return true if the type of the given node can be mapped to a type supported by this type of diagram

Specified by:
canDragNode in interface MutableGraphModel

dragNode

public void dragNode(java.lang.Object node)
Create a new node based on the given one and add it to the graph.

Specified by:
dragNode in interface MutableGraphModel

canChangeConnectedNode

public boolean canChangeConnectedNode(java.lang.Object newNode,
                                      java.lang.Object oldNode,
                                      java.lang.Object edge)
Return true if the connection to the old node can be rerouted to the new node.

Specified by:
canChangeConnectedNode in interface MutableGraphModel

canConnect

public boolean canConnect(java.lang.Object fromPort,
                          java.lang.Object toPort,
                          java.lang.Object edgeType)
Determine if the two given ports can be connected by the given kind of edge. This delegates either to the registered ConnectionConstrainer or if unregistered then ignores edgeClass and calls canConnect(port,port).

Specified by:
canConnect in interface MutableGraphModel
Parameters:
fromPort - the source port for which to test
toPort - the destination port for which to test
edgeType - An identifier indicating the type of edge to create

canConnect

public boolean canConnect(java.lang.Object fromPort,
                          java.lang.Object toPort,
                          java.lang.Class edgeClass)
Determine if the two given ports can be connected by the given kind of edge. This delegates either to the registered ConnectionConstrainer or if unregistered then ignores edgeClass and calls canConnect(port,port).

Parameters:
fromPort - the source port for which to test
toPort - the destination port for which to test
edgeClass - The edge class for which test

changeConnectedNode

public void changeConnectedNode(java.lang.Object newNode,
                                java.lang.Object oldNode,
                                java.lang.Object edge,
                                boolean isSource)
Reroutes the connection to the old node to be connected to the new node.

Specified by:
changeConnectedNode in interface MutableGraphModel

connect

public java.lang.Object connect(java.lang.Object fromPort,
                                java.lang.Object toPort,
                                java.lang.Object edgeClass)
Contruct and add a new edge of the given kind. By default ignore edgeClass and call connect(port,port).

Specified by:
connect in interface MutableGraphModel

connect

public java.lang.Object connect(java.lang.Object fromPort,
                                java.lang.Object toPort,
                                java.lang.Object edgeType,
                                java.util.Map styleAttributes)
Construct and add a new edge of the given kind and connect the given ports. By default ignore edgeClass and call connect(port,port).

Specified by:
connect in interface MutableGraphModel
Parameters:
fromPort - The originating port to connect
toPort - The destination port to connect
edgeType - Some indicator of the type of edge to create. This could be a Class or some other value as input to a factory to create the required edge model.
styleAttributes - key/value pairs from which to create the edge.
Returns:
The type of edge created (the same as edgeClass if we succeeded, null otherwise)

containsNode

public boolean containsNode(java.lang.Object node)
Description copied from interface: MutableGraphModel
Return true if the given object is present as a node in the graph

Specified by:
containsNode in interface MutableGraphModel

containsEdge

public boolean containsEdge(java.lang.Object edge)
Description copied from interface: MutableGraphModel
Return true if the given object is present as a edge in the graph

Specified by:
containsEdge in interface MutableGraphModel

containsNodePort

public boolean containsNodePort(java.lang.Object port)

containsEdgePort

public boolean containsEdgePort(java.lang.Object port)

containsPort

public boolean containsPort(java.lang.Object port)

addGraphEventListener

public void addGraphEventListener(GraphListener listener)
Specified by:
addGraphEventListener in interface BaseGraphModel

removeGraphEventListener

public void removeGraphEventListener(GraphListener listener)
Specified by:
removeGraphEventListener in interface BaseGraphModel

fireNodeAdded

public void fireNodeAdded(java.lang.Object node)

fireNodeRemoved

public void fireNodeRemoved(java.lang.Object node)

fireEdgeAdded

public void fireEdgeAdded(java.lang.Object edge)

fireEdgeRemoved

public void fireEdgeRemoved(java.lang.Object edge)

fireGraphChanged

public void fireGraphChanged()

setSaveAction

public static void setSaveAction(javax.swing.Action action)

removeNode

public void removeNode(java.lang.Object node)
Description copied from interface: MutableGraphModel
Remove the given node from the graph. Sends a notification.

Specified by:
removeNode in interface MutableGraphModel

addNode

public void addNode(java.lang.Object node)
Add the given node to the graph, if valid.

Specified by:
addNode in interface MutableGraphModel

addEdge

public void addEdge(java.lang.Object edge)
Add the given edge to the graph, if valid.

Specified by:
addEdge in interface MutableGraphModel

removeEdge

public void removeEdge(java.lang.Object edge)
Remove the given edge from the graph.

Specified by:
removeEdge in interface MutableGraphModel

removeFig

public void removeFig(Fig fig)
Remove the given edge from the graph.


removeAllNodes

public void removeAllNodes()
Remove all the nodes from the graph.


removeAllEdges

public void removeAllEdges()
Remove all the edges from the graph.


removeAll

public void removeAll()
Remove all nodes and edges to reset the graph.


isEnclosable

public boolean isEnclosable(java.lang.Object handle,
                            java.lang.Object encloser)
Returns true if handle can be enclosed into encloser.

Specified by:
isEnclosable in interface MutableGraphModel