com.jgraph.example
Class JGraphGraphFactory

java.lang.Object
  extended by com.jgraph.example.JGraphGraphFactory
Direct Known Subclasses:
FastGraphFactory

public class JGraphGraphFactory
extends java.lang.Object

A helper class that creates graphs. Currently supports tree graphs and a random graph where all edges are connected at least once


Nested Class Summary
 class JGraphGraphFactory.FactoryConfigDialog
          Simple Dialog that configures how many nodes and edges the graph factory is to create
 
Field Summary
static int FLOW
           
static int FULLY_CONNECTED
           
static int RANDOM_CONNECTED
           
static int TREE
           
 
Constructor Summary
JGraphGraphFactory()
          Default constructor
 
Method Summary
static void center(java.awt.Window wnd)
           
 int getMaxNodesPerTreeLevel()
           
 int getNumEdges()
           
 int getNumNodes()
           
static void insert(org.jgraph.graph.GraphModel model, java.lang.Object[] cells)
          Inserts the specified cells into the graph model.
static void insert(org.jgraph.graph.GraphModel model, java.lang.Object[] cells, java.util.Map nested, org.jgraph.graph.ConnectionSet cs, org.jgraph.graph.ParentMap pm)
          Variant of the insert method that allows to pass a default connection set and parent map and nested map.
 void insertConnectedGraphSampleData(org.jgraph.JGraph graph, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          clears the graph and inserts a random graph.
 void insertFullyConnectedGraphSampleData(org.jgraph.JGraph graph, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          clears the graph and inserts a fully connected graph.
 void insertGraph(org.jgraph.JGraph graph, int graphType, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          Entry method for inserting a sample graph
 void insertSampleFlowGraph(org.jgraph.JGraph graph, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          clears the graph and inserts a fully connected graph.
 java.lang.Object insertTreeSampleData(org.jgraph.graph.GraphModel model, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          clears the graph and inserts a random tree.
 java.lang.Object insertTreeSampleData(org.jgraph.JGraph graph, java.util.Map defaultVertexAttributes, java.util.Map defaultEdgeAttributes)
          clears the graph and inserts a random tree.
 boolean isInsertIntoModel()
           
 void setInsertIntoModel(boolean insertIntoModel)
           
 void setMaxNodesPerTreeLevel(int maxNodesPerTreeLevel)
           
 void setNumEdges(int numEdges)
           
 void setNumNodes(int numNodes)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FULLY_CONNECTED

public static final int FULLY_CONNECTED
See Also:
Constant Field Values

RANDOM_CONNECTED

public static final int RANDOM_CONNECTED
See Also:
Constant Field Values

TREE

public static final int TREE
See Also:
Constant Field Values

FLOW

public static final int FLOW
See Also:
Constant Field Values
Constructor Detail

JGraphGraphFactory

public JGraphGraphFactory()
Default constructor

Method Detail

insertGraph

public void insertGraph(org.jgraph.JGraph graph,
                        int graphType,
                        java.util.Map defaultVertexAttributes,
                        java.util.Map defaultEdgeAttributes)
Entry method for inserting a sample graph

Parameters:
graph - the JGraph to perform the insert on
graphType - which sample graph type is to be inserted
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges

insertTreeSampleData

public java.lang.Object insertTreeSampleData(org.jgraph.JGraph graph,
                                             java.util.Map defaultVertexAttributes,
                                             java.util.Map defaultEdgeAttributes)
clears the graph and inserts a random tree. The nodes are initially placed a grid with the root node selected. The algorithm used is not recursive as the number of nodes per level are not know at the size. A DFS search would not work, since we don't know where the leaves are. Cells are inserted over edges for clarity

Parameters:
graph - the JGraph to perform the insert on
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges
Returns:
the root node of the tree

insertTreeSampleData

public java.lang.Object insertTreeSampleData(org.jgraph.graph.GraphModel model,
                                             java.util.Map defaultVertexAttributes,
                                             java.util.Map defaultEdgeAttributes)
clears the graph and inserts a random tree. The nodes are initially placed a grid with the root node selected. The algorithm used is not recursive as the number of nodes per level are not know at the size. A DFS search would not work, since we don't know where the leaves are. Cells are inserted over edges for clarity

Parameters:
model - the model to perform the insert on
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges
Returns:
the root node of the tree

insertConnectedGraphSampleData

public void insertConnectedGraphSampleData(org.jgraph.JGraph graph,
                                           java.util.Map defaultVertexAttributes,
                                           java.util.Map defaultEdgeAttributes)
clears the graph and inserts a random graph. The nodes are initially placed a grid with no node selected. If there are at least as many edges as nodes then all cells have at least one edge connected to them.

Parameters:
graph - the JGraph instance to act upon
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges

insertFullyConnectedGraphSampleData

public void insertFullyConnectedGraphSampleData(org.jgraph.JGraph graph,
                                                java.util.Map defaultVertexAttributes,
                                                java.util.Map defaultEdgeAttributes)
clears the graph and inserts a fully connected graph. The nodes are initially placed a grid. There are the same number of cells and edges in the graph, all cells have at least one edge connected to them.

Parameters:
graph - the JGraph instance to act upon
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges

insertSampleFlowGraph

public void insertSampleFlowGraph(org.jgraph.JGraph graph,
                                  java.util.Map defaultVertexAttributes,
                                  java.util.Map defaultEdgeAttributes)
clears the graph and inserts a fully connected graph. The nodes are initially placed a grid. There are the same number of cells and edges in the graph, all cells have at least one edge connected to them.

Parameters:
graph - the JGraph instance to act upon
defaultVertexAttributes - the default attributes to use for vertices
defaultEdgeAttributes - the default attributes to use for edges

insert

public static void insert(org.jgraph.graph.GraphModel model,
                          java.lang.Object[] cells)
Inserts the specified cells into the graph model. This method is a general implementation of cell insertion. If the source and target port are null, then no connection set is created. The method uses the attributes from the specified edge and the egdge's children to construct the insert call. This example shows how to insert an edge with a special arrow between two known vertices:
 Object source = graph.getDefaultPortForCell(sourceVertex).getCell();
 Object target = graph.getDefaultPortForCell(targetVertex).getCell();
 DefaultEdge edge = new DefaultEdge("Hello, world!");
 edge.setSource(source);
 edge.setTarget(target);
 Map attrs = edge.getAttributes();
 GraphConstants.setLineEnd(attrs, GraphConstants.ARROW_TECHNICAL);
 graph.getGraphLayoutCache().insert(edge);
 


insert

public static void insert(org.jgraph.graph.GraphModel model,
                          java.lang.Object[] cells,
                          java.util.Map nested,
                          org.jgraph.graph.ConnectionSet cs,
                          org.jgraph.graph.ParentMap pm)
Variant of the insert method that allows to pass a default connection set and parent map and nested map.


isInsertIntoModel

public boolean isInsertIntoModel()
Returns:
Returns the insertIntoModel.

setInsertIntoModel

public void setInsertIntoModel(boolean insertIntoModel)
Parameters:
insertIntoModel - The insertIntoModel to set.

getNumEdges

public int getNumEdges()
Returns:
Returns the numEdges.

setNumEdges

public void setNumEdges(int numEdges)
Parameters:
numEdges - The numEdges to set.

getNumNodes

public int getNumNodes()
Returns:
Returns the numNodes.

setNumNodes

public void setNumNodes(int numNodes)
Parameters:
numNodes - The numNodes to set.

getMaxNodesPerTreeLevel

public int getMaxNodesPerTreeLevel()
Returns:
Returns the maxNodesPerTreeLevel.

setMaxNodesPerTreeLevel

public void setMaxNodesPerTreeLevel(int maxNodesPerTreeLevel)
Parameters:
maxNodesPerTreeLevel - The maxNodesPerTreeLevel to set.

center

public static void center(java.awt.Window wnd)