org._3pq.jgrapht.ext

Class JGraphModelAdapter


public class JGraphModelAdapter
extends DefaultGraphModel

An adapter that reflects a JGraphT graph as a JGraph graph. This adapter is useful when using JGraph in order to visualize JGraphT graphs. For more about JGraph see http://jgraph.sourceforge.net

Modifications made to the underlying JGraphT graph are reflected to this JGraph model if and only if the underlying JGraphT graph is a ListenableGraph. If the underlying JGraphT graph is not ListenableGraph, then this JGraph model represent a snapshot if the graph at the time of its creation.

Changes made to this JGraph model are also reflected back to the underlying JGraphT graph. To avoid confusion, variables are prefixed according to the JGraph/JGraphT object(s) they are referring to.

KNOWN BUGS: There is a small issue to be aware of. JGraph allows 'dangling edges' incident with just one vertex; JGraphT doesn't. Such a configuration can arise when adding an edge or removing a vertex. The code handles this by removing the newly-added dangling edge or removing all edges incident with the vertex before actually removing the vertex, respectively. This works very well, only it doesn't play all that nicely with the undo-manager in the JGraph: for the second situation where you remove a vertex incident with some edges, if you undo the removal, the vertex is 'unremoved' but the edges aren't.

Author:
Barak Naveh
Since:
Aug 2, 2003

Nested Class Summary

static interface
JGraphModelAdapter.CellFactory
Creates the JGraph cells that reflect the respective JGraphT elements.
static class
JGraphModelAdapter.DefaultCellFactory
A simple default cell factory.

Constructor Summary

JGraphModelAdapter(Graph jGraphTGraph)
Constructs a new JGraph model adapter for the specified JGraphT graph.
JGraphModelAdapter(Graph jGraphTGraph, AttributeMap defaultVertexAttributes, AttributeMap defaultEdgeAttributes)
Constructs a new JGraph model adapter for the specified JGraphT graph.
JGraphModelAdapter(Graph jGraphTGraph, AttributeMap defaultVertexAttributes, AttributeMap defaultEdgeAttributes, JGraphModelAdapter.CellFactory cellFactory)
Constructs a new JGraph model adapter for the specified JGraphT graph.

Method Summary

static AttributeMap
createDefaultEdgeAttributes(Graph jGraphTGraph)
Creates and returns a map of attributes to be used as defaults for edge attributes, depending on the specified graph.
static AttributeMap
createDefaultVertexAttributes()
Creates and returns a map of attributes to be used as defaults for vertex attributes.
void
edit(Map attrs)
Deprecated. this method will be deleted in the future.
JGraphModelAdapter.CellFactory
getCellFactory()
Returns the cell factory used to create the JGraph cells.
AttributeMap
getDefaultEdgeAttributes()
Returns the default edge attributes used for creating new JGraph edges.
AttributeMap
getDefaultVertexAttributes()
Returns the default vertex attributes used for creating new JGraph vertices.
DefaultEdge
getEdgeCell(Edge jGraphTEdge)
Returns the JGraph edge cell that corresponds to the specified JGraphT edge.
DefaultGraphCell
getVertexCell(Object jGraphTVertex)
Returns the JGraph vertex cell that corresponds to the specified JGraphT vertex.
DefaultPort
getVertexPort(Object jGraphTVertex)
Returns the JGraph port cell that corresponds to the specified JGraphT vertex.
void
setDefaultEdgeAttributes(AttributeMap defaultEdgeAttributes)
Sets the default edge attributes used for creating new JGraph edges.
void
setDefaultVertexAttributes(AttributeMap defaultVertexAttributes)
Sets the default vertex attributes used for creating new JGraph vertices.

Constructor Details

JGraphModelAdapter

public JGraphModelAdapter(Graph jGraphTGraph)
Constructs a new JGraph model adapter for the specified JGraphT graph.
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to be created. null is NOT permitted.

JGraphModelAdapter

public JGraphModelAdapter(Graph jGraphTGraph,
                          AttributeMap defaultVertexAttributes,
                          AttributeMap defaultEdgeAttributes)
Constructs a new JGraph model adapter for the specified JGraphT graph.
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to be created. null is NOT permitted.
defaultVertexAttributes - a default map of JGraph attributes to format vertices. null is NOT permitted.
defaultEdgeAttributes - a default map of JGraph attributes to format edges. null is NOT permitted.

JGraphModelAdapter

public JGraphModelAdapter(Graph jGraphTGraph,
                          AttributeMap defaultVertexAttributes,
                          AttributeMap defaultEdgeAttributes,
                          JGraphModelAdapter.CellFactory cellFactory)
Constructs a new JGraph model adapter for the specified JGraphT graph.
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to be created. null is NOT permitted.
defaultVertexAttributes - a default map of JGraph attributes to format vertices. null is NOT permitted.
defaultEdgeAttributes - a default map of JGraph attributes to format edges. null is NOT permitted.
cellFactory - a JGraphModelAdapter.CellFactory to be used to create the JGraph cells. null is NOT permitted.

Method Details

createDefaultEdgeAttributes

public static AttributeMap createDefaultEdgeAttributes(Graph jGraphTGraph)
Creates and returns a map of attributes to be used as defaults for edge attributes, depending on the specified graph.
Parameters:
jGraphTGraph - the graph for which default edge attributes to be created.
Returns:
a map of attributes to be used as default for edge attributes.

createDefaultVertexAttributes

public static AttributeMap createDefaultVertexAttributes()
Creates and returns a map of attributes to be used as defaults for vertex attributes.
Returns:
a map of attributes to be used as defaults for vertex attributes.

edit

public void edit(Map attrs)

Deprecated. this method will be deleted in the future. Use DefaultGraphModel#edit instead.

Applies the specified attributes to the model, as in the DefaultGraphModel.edit(java.util.Map, org.jgraph.graph.ConnectionSet, org.jgraph.graph.ParentMap, javax.swing.undo.UndoableEdit[]) method.
Parameters:
attrs - the attributes to be applied to the model.

getCellFactory

public JGraphModelAdapter.CellFactory getCellFactory()
Returns the cell factory used to create the JGraph cells.
Returns:
the cell factory used to create the JGraph cells.

getDefaultEdgeAttributes

public AttributeMap getDefaultEdgeAttributes()
Returns the default edge attributes used for creating new JGraph edges.
Returns:
the default edge attributes used for creating new JGraph edges.

getDefaultVertexAttributes

public AttributeMap getDefaultVertexAttributes()
Returns the default vertex attributes used for creating new JGraph vertices.
Returns:
the default vertex attributes used for creating new JGraph vertices.

getEdgeCell

public DefaultEdge getEdgeCell(Edge jGraphTEdge)
Returns the JGraph edge cell that corresponds to the specified JGraphT edge. If no corresponding cell found, returns null.
Parameters:
jGraphTEdge - a JGraphT edge of the JGraphT graph.
Returns:
the JGraph edge cell that corresponds to the specified JGraphT edge, or null if no corresponding cell found.

getVertexCell

public DefaultGraphCell getVertexCell(Object jGraphTVertex)
Returns the JGraph vertex cell that corresponds to the specified JGraphT vertex. If no corresponding cell found, returns null.
Parameters:
jGraphTVertex - a JGraphT vertex of the JGraphT graph.
Returns:
the JGraph vertex cell that corresponds to the specified JGraphT vertex, or null if no corresponding cell found.

getVertexPort

public DefaultPort getVertexPort(Object jGraphTVertex)
Returns the JGraph port cell that corresponds to the specified JGraphT vertex. If no corresponding port found, returns null.
Parameters:
jGraphTVertex - a JGraphT vertex of the JGraphT graph.
Returns:
the JGraph port cell that corresponds to the specified JGraphT vertex, or null if no corresponding cell found.

setDefaultEdgeAttributes

public void setDefaultEdgeAttributes(AttributeMap defaultEdgeAttributes)
Sets the default edge attributes used for creating new JGraph edges.
Parameters:
defaultEdgeAttributes - the default edge attributes to set.

setDefaultVertexAttributes

public void setDefaultVertexAttributes(AttributeMap defaultVertexAttributes)
Sets the default vertex attributes used for creating new JGraph vertices.
Parameters:
defaultVertexAttributes - the default vertex attributes to set.