org.jgraph.util
Class JGraphUtilities
java.lang.Object
org.jgraph.util.JGraphUtilities
- public class JGraphUtilities
- extends java.lang.Object
Method Summary |
static java.awt.geom.Rectangle2D |
align(int constraint,
java.awt.geom.Rectangle2D cellBounds,
java.awt.geom.Rectangle2D bounds)
|
static void |
alignCells(JGraph graph,
java.lang.Object[] cells,
int constraint)
|
static void |
applyLayout(JGraph sourceGraph,
JGraphLayoutAlgorithm layout)
|
static void |
connect(JGraph graph,
DefaultGraphCell prototype,
java.lang.Object[] cells)
|
static CostFunction |
createDefaultCostFunction(JGraph graph)
|
static UnionFind |
getComponents(GraphModel model)
|
static java.lang.Object[] |
getEdges(GraphModel model)
|
static java.lang.Object[] |
getEdges(JGraph graph,
java.lang.Object[] cells)
Returns all edges in cells . |
static java.lang.Object[] |
getShortestPath(GraphModel model,
java.lang.Object from,
java.lang.Object to,
CostFunction cf,
boolean directed)
Returns the ShortestPath between two cells or their descendants. |
static java.lang.Object[] |
getSpanningTree(JGraph graph,
CostFunction cf)
Returns the shortest spanning tree. |
static java.lang.Object[] |
getVertices(GraphModel model,
java.lang.Object[] cells)
|
static boolean |
isGroup(JGraph graph,
java.lang.Object cell)
|
static boolean |
isVertex(JGraph graph,
java.lang.Object cell)
|
static java.util.SortedSet |
sort(JGraph graph,
java.lang.Object[] cells,
CostFunction cf)
|
static java.awt.image.BufferedImage |
toImage(JGraph graph,
java.awt.Color bg,
int inset)
If bg is null then a transparent background is applied to the image, else
the background is filled with the bg color. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ALIGN_LEFT
public static final int ALIGN_LEFT
- See Also:
- Constant Field Values
ALIGN_RIGHT
public static final int ALIGN_RIGHT
- See Also:
- Constant Field Values
ALIGN_TOP
public static final int ALIGN_TOP
- See Also:
- Constant Field Values
ALIGN_BOTTOM
public static final int ALIGN_BOTTOM
- See Also:
- Constant Field Values
ALIGN_CENTER
public static final int ALIGN_CENTER
- See Also:
- Constant Field Values
ALIGN_MIDDLE
public static final int ALIGN_MIDDLE
- See Also:
- Constant Field Values
JGraphUtilities
public JGraphUtilities()
toImage
public static java.awt.image.BufferedImage toImage(JGraph graph,
java.awt.Color bg,
int inset)
- If bg is null then a transparent background is applied to the image, else
the background is filled with the bg color.
- Returns:
getVertices
public static java.lang.Object[] getVertices(GraphModel model,
java.lang.Object[] cells)
- Returns:
- Returns all vertices in
cells
.
getEdges
public static java.lang.Object[] getEdges(GraphModel model)
- Returns:
- Returns all edges in
model
.
getEdges
public static java.lang.Object[] getEdges(JGraph graph,
java.lang.Object[] cells)
- Returns all edges in
cells
. Note: Use
DefaultGraphModel.getEdges() to get all connected edges.
- Returns:
isVertex
public static boolean isVertex(JGraph graph,
java.lang.Object cell)
- Returns:
isGroup
public static boolean isGroup(JGraph graph,
java.lang.Object cell)
- Returns:
createDefaultCostFunction
public static CostFunction createDefaultCostFunction(JGraph graph)
- Returns:
getComponents
public static UnionFind getComponents(GraphModel model)
- Returns:
getShortestPath
public static java.lang.Object[] getShortestPath(GraphModel model,
java.lang.Object from,
java.lang.Object to,
CostFunction cf,
boolean directed)
- Returns the ShortestPath between two cells or their descendants.
Implemented with the Dijkstra Algorithm Give the method your graph, the
starting cell, the finishing cell, your cost function ( if null you'll
use the default ) and whether or not you want to travel only from source
to target ports across edges.
If no cost function is provided then the default cost per edge is 1. Here
is an example of how to use this with the DefaultCostFunction:
CostFunction cf = createDefaultCostFunction(graph);Object[] path = getShortestPath(graph.getModel(), graph.getSelectionCell(), sinkCell, cf, true);
The above code returns the shortest directed path between the selected
cell (eg. a vertex) and a predefined sink (typically a vertex with no
outgoing edges).
getSpanningTree
public static java.lang.Object[] getSpanningTree(JGraph graph,
CostFunction cf)
- Returns the shortest spanning tree. Implemented with the Kruskal
Algorithm
sort
public static java.util.SortedSet sort(JGraph graph,
java.lang.Object[] cells,
CostFunction cf)
- Returns:
connect
public static void connect(JGraph graph,
DefaultGraphCell prototype,
java.lang.Object[] cells)
- Returns:
alignCells
public static void alignCells(JGraph graph,
java.lang.Object[] cells,
int constraint)
- Returns:
align
public static java.awt.geom.Rectangle2D align(int constraint,
java.awt.geom.Rectangle2D cellBounds,
java.awt.geom.Rectangle2D bounds)
- Returns:
applyLayout
public static void applyLayout(JGraph sourceGraph,
JGraphLayoutAlgorithm layout)
- Returns: