|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.graph.tm.GraphUtils
public class GraphUtils
An utility class for manipulating and traversing graphs, composed of static methods. This class currently contains one method for graph traversal and one for loading external Topic Maps from a TNode.
Contrast the traverse(TNode,int,int) method here with
Traverser, which is designed to traverse the
underlying Topic Map, not the visualized graph.
In some graph representations, such as unmodified TouchGraph (hereafter "TG", the graph toolkit extended for use in Ceryle), there are simply Nodes and Edges (the Edges being the lines between Nodes):
Node3
/
/
Node1----Node2
\
\
Node4
Figure 1.
Strictly speaking, graphs consist of nodes and edges (aka "arcs"). The
semantics of Ceryle's graph representation is based on a
Topic Map model. The Topic Map
graph is composed of Topics and Associations (between Topics). These are
represented here as TNodes (TNode) and ANodes
(ANode) respectively, though the graphic
correlation (ie., the way this is displayed) between graph edges and ANodes
is not direct: an ANode is not displayed as simply an edge. In order for
graph edges to contain labels and be easier to differentiate and select,
an edge is composed of an ANode connected to its member TNodes via two
graphical "edges." Therefore, the equivalent of the above diagram in this
mode of displaying a graph is as follows:
TNode3
/
/
ANode
/
/
TNode1----ANode----TNode2
\
\
ANode
\
\
TNode4
Figure 2.
Because this style of graph never connects TNodes directly to other TNodes or ANodes directly to other ANodes, one only finds TNode-to-ANode-to-TNode connections. This makes graph traversal (code-wise) a bit more complicated, as one must traverse the TouchGraph Edges to see what is at the other end.
There could be optimizations made here. Erring on the side of caution, the methods of this class generally check to be sure that the expected node type actually occurs where expected, throwing GraphExceptions when things are amiss. This overhead incurs processing time, and in traversing large graphs this could be significant. A subclass of GraphUtils might be in order, or perhaps a "lazy" processing mode.
Note: Traversal currently does not include Scope Nodes (SNodes), which are avoided/ignored. This also pays no attention to the semantics of the traversal, only any potential direction (ie., traversal will not occur against an edge when the ANode indicates that its relationship has direction.
Copyright 2001-2007 Murray Altheim. All Rights Reserved.
See LICENSE included with distribution.
| Field Summary | |
|---|---|
static boolean |
hilight_traversed_edges
A static boolean that when true, causes specifically-traversed edges to be hilighted. |
static int |
TRAVERSE_ANY
An enumerated int indicating traversal direction, "any" meaning in any direction, ignoring arrow directions. |
static int |
TRAVERSE_DOWN
An enumerated int indicating traversal direction, "downstream" meaning in the direction of arrows, from-to-to. |
static int |
TRAVERSE_UP
An enumerated int indicating traversal direction, "UP" meaning against the direction of arrows, to-to-from. |
| Constructor Summary | |
|---|---|
GraphUtils()
|
|
| Method Summary | |
|---|---|
static Point2D.Double |
getMidPoint(GraphNode n1,
GraphNode n2)
Return the point halfway between the two GraphNodes. |
static void |
loadTopicMap(TMLayoutPanel tmlp,
TNode tnode)
Loads the topic map referenced by the provided link node, selecting the topic ID if its URI includes one. |
static StackSet |
traverse(TNode tnode,
int direction,
int depth)
Returns a Set containing references to all TNodes the provided TNode tnode is connected to via ANodes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int TRAVERSE_DOWN
public static final int TRAVERSE_UP
public static final int TRAVERSE_ANY
public static boolean hilight_traversed_edges
| Constructor Detail |
|---|
public GraphUtils()
| Method Detail |
|---|
public static StackSet traverse(TNode tnode,
int direction,
int depth)
throws GraphException
The depth of traversal depth should be set to 1 to return only those TNodes one association away from tnode. Setting it to zero (or less) returns null.
As mentioned above, allowable values for direction include TRAVERSE_DOWN (in the direction of arrows, from-to-to; TRAVERSE_UP (against the direction of arrows, to-to-from; or TRAVERSE_ANY (in any direction).
Notes:
A TNode is connected to another TNode only via an ANode (see
Figure 2). Therefore, whereas getEdges()
would in a plain TouchGraph graph provide connections with other Nodes,
here we must locate what's on the other side of the ANode;
cf. Edge.getOtherEndpt(Node), which doesn't
even check to see if the provided node is connected to the edge in question.
If this TNode is a leaf Node (ie., it is only connected to one other Node), or if due to direction nodes are not traversable, or if the "other end" is not an ANode or SNode (which is currently ignored), a GraphException is thrown.
tnode - the TNode from which the traversal beginsdirection - an enumerated int indicating traversal directiondepth - an int setting recursion depth (eg., '1' is one level from tnode)
GraphException
public static void loadTopicMap(TMLayoutPanel tmlp,
TNode tnode)
NOTE: This is not the same as merging two or more topic maps, this may result in the current graph containing two separate (but potentially linked) maps.
public static Point2D.Double getMidPoint(GraphNode n1,
GraphNode n2)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||