The Meta-Environment API

nl.cwi.sen1.gui.plugin.prefusedot
Class DotAdapter

java.lang.Object
  extended by prefuse.data.tuple.AbstractTupleSet
      extended by prefuse.data.tuple.CompositeTupleSet
          extended by prefuse.data.Graph
              extended by nl.cwi.sen1.gui.plugin.prefusedot.DotAdapter
All Implemented Interfaces:
prefuse.data.tuple.TupleSet

public class DotAdapter
extends prefuse.data.Graph

Author:
Jurgen Vinju This class wraps a prefuse Graph in order to provide a bridge to AT&T's graphviz. The idea is to build a graph via this interface and call the doDotLayout() method after constructing the graph in memory. This will start a session with the external dot tool via pipes, and annotate the graph with x,y position information, and store the locations for the curved edges also.
See Also:
for how this information will later be used to actually layout the graph.

Nested Class Summary
private static class DotAdapter.Patterns
          This private class stores pre-compiled regular expressions for parsing the dot -Tplain output format.
 
Nested classes/interfaces inherited from class prefuse.data.Graph
prefuse.data.Graph.Listener
 
Field Summary
static java.lang.String DOT_CURVE_POINTS
           
static java.lang.String DOT_HEIGHT
           
static java.lang.String DOT_ID
           
static java.lang.String DOT_LABEL
           
static java.lang.String DOT_SHAPE
           
static java.lang.String DOT_WIDTH
           
static java.lang.String DOT_X
           
static java.lang.String DOT_Y
           
private static int dpi
           
private  java.util.Map<java.lang.String,prefuse.data.Node> nodeIds
           
private  double scale
           
 
Fields inherited from class prefuse.data.Graph
DEFAULT_NODE_KEY, DEFAULT_SOURCE_KEY, DEFAULT_TARGET_KEY, EDGES, INDEGREE, INEDGES, INLINKS, LINKS_SCHEMA, m_directed, m_edgeTuples, m_links, m_longKey, m_nidx, m_nkey, m_nodeTuples, m_skey, m_spanning, m_tkey, NODES, OUTDEGREE, OUTEDGES, OUTLINKS, UNDIRECTED
 
Fields inherited from interface prefuse.data.tuple.TupleSet
EMPTY_ARRAY
 
Constructor Summary
DotAdapter()
           
 
Method Summary
 void doDotLayout()
          Run the Dot layout algorithm and store the results as attributes in the graph table.
private  java.lang.String escape(java.lang.String string)
           
private  void executeDot()
           
 java.util.List<java.lang.Integer> getAllEdges(int source, int target)
          Returns a list of edges from the source node to the target node.
 java.util.List<prefuse.data.Edge> getAllEdges(prefuse.data.Node source, prefuse.data.Node target)
          Returns a list of edges between the source and target node
private  prefuse.data.Node getNode(java.lang.String id)
           
private  java.lang.String idFromDot(java.lang.String id)
           
private  java.lang.String idToDot(java.lang.String string)
           
static void main(java.lang.String[] args)
           
private  void parseDot(java.io.InputStream in)
           
private  void parseEdge(java.lang.String toString, java.lang.String fromString, java.lang.String pointCount, java.lang.String pointsStr)
           
private  java.awt.geom.Point2D[] parseEdgePoints(int count, java.lang.String rest)
           
private  void parseNode(java.lang.String id, java.lang.String xstr, java.lang.String ystr, java.lang.String widthStr, java.lang.String heightStr)
           
private  void parseStart(java.lang.String scaleStr, java.lang.String heightStr)
           
 void printDot(java.io.PrintStream b)
          Prints out the prefuse graph to Graphviz Dot format
private  void printEdges(java.io.PrintStream b)
           
private  void printNodes(java.io.PrintStream b)
           
 void setNodeAttribute(prefuse.data.Node node, java.lang.String key, java.lang.Object value)
          A safe method to set an attribute of a node.
private  void storeNode(java.lang.String id, prefuse.data.Node node)
           
 
Methods inherited from class prefuse.data.Graph
addEdge, addEdge, addGraphModelListener, addLink, addNode, addNodeRow, clear, clearEdges, clearSpanningTree, createLinkTable, dispose, edgeCheck, edgeRows, edgeRows, edgeRows, edges, edges, fireGraphEvent, getAdjacentNode, getAdjacentNode, getDegree, getDegree, getEdge, getEdge, getEdge, getEdgeCount, getEdges, getEdgeSourceField, getEdgeTable, getEdgeTargetField, getInDegree, getInDegree, getKey, getNode, getNodeCount, getNodeFromKey, getNodeIndex, getNodeKeyField, getNodes, getNodeTable, getOutDegree, getOutDegree, getSourceNode, getSourceNode, getSpanningTree, getSpanningTree, getTargetNode, getTargetNode, inEdgeRows, inEdges, init, initLinkTable, inNeighbors, isDirected, neighbors, nodeCheck, nodeRows, nodes, outEdgeRows, outEdges, outNeighbors, remLink, removeEdge, removeEdge, removeGraphModelListener, removeNode, removeNode, removeTuple, setEdgeTable, setTupleManagers, tuples, tuples, updateDegrees, updateDegrees, updateNodeData
 
Methods inherited from class prefuse.data.tuple.CompositeTupleSet
addColumn, addColumn, addColumn, addColumn, addSet, addTuple, containsSet, containsTuple, getSet, getTupleCount, hasSet, isAddColumnSupported, removeAllSets, removeSet, setNames, sets, setTuple
 
Methods inherited from class prefuse.data.tuple.AbstractTupleSet
addColumns, addPropertyChangeListener, addPropertyChangeListener, addTupleSetListener, fireTupleEvent, fireTupleEvent, fireTupleEvent, getClientProperty, putClientProperty, removePropertyChangeListener, removePropertyChangeListener, removeTupleSetListener, tuples
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dpi

private static final int dpi
See Also:
Constant Field Values

DOT_CURVE_POINTS

public static final java.lang.String DOT_CURVE_POINTS
See Also:
Constant Field Values

DOT_X

public static final java.lang.String DOT_X
See Also:
Constant Field Values

DOT_Y

public static final java.lang.String DOT_Y
See Also:
Constant Field Values

DOT_WIDTH

public static final java.lang.String DOT_WIDTH
See Also:
Constant Field Values

DOT_HEIGHT

public static final java.lang.String DOT_HEIGHT
See Also:
Constant Field Values

DOT_LABEL

public static final java.lang.String DOT_LABEL
See Also:
Constant Field Values

DOT_ID

public static final java.lang.String DOT_ID
See Also:
Constant Field Values

DOT_SHAPE

public static final java.lang.String DOT_SHAPE
See Also:
Constant Field Values

scale

private double scale

nodeIds

private java.util.Map<java.lang.String,prefuse.data.Node> nodeIds
Constructor Detail

DotAdapter

public DotAdapter()
Method Detail

doDotLayout

public void doDotLayout()
Run the Dot layout algorithm and store the results as attributes in the graph table. These attributes can later be used by a prefuse layout algorithm.

See Also:
and @see DotLabelLayout for details. This method assumes you have added nodes and edges using the @method addNode() and @method addEdge() methods.

executeDot

private void executeDot()

getNode

private prefuse.data.Node getNode(java.lang.String id)

storeNode

private void storeNode(java.lang.String id,
                       prefuse.data.Node node)

parseDot

private void parseDot(java.io.InputStream in)

getAllEdges

public java.util.List<java.lang.Integer> getAllEdges(int source,
                                                     int target)
Returns a list of edges from the source node to the target node.


getAllEdges

public java.util.List<prefuse.data.Edge> getAllEdges(prefuse.data.Node source,
                                                     prefuse.data.Node target)
Returns a list of edges between the source and target node

Parameters:
source - the source Node
target - the target Node
Returns:
an Edge with given source and target nodes, or null if no such edge is found.

parseEdge

private void parseEdge(java.lang.String toString,
                       java.lang.String fromString,
                       java.lang.String pointCount,
                       java.lang.String pointsStr)

parseEdgePoints

private java.awt.geom.Point2D[] parseEdgePoints(int count,
                                                java.lang.String rest)

parseNode

private void parseNode(java.lang.String id,
                       java.lang.String xstr,
                       java.lang.String ystr,
                       java.lang.String widthStr,
                       java.lang.String heightStr)

parseStart

private void parseStart(java.lang.String scaleStr,
                        java.lang.String heightStr)

printDot

public void printDot(java.io.PrintStream b)
Prints out the prefuse graph to Graphviz Dot format

Parameters:
b - PrintStream to output the graph to

printEdges

private void printEdges(java.io.PrintStream b)

printNodes

private void printNodes(java.io.PrintStream b)

escape

private java.lang.String escape(java.lang.String string)

setNodeAttribute

public void setNodeAttribute(prefuse.data.Node node,
                             java.lang.String key,
                             java.lang.Object value)
A safe method to set an attribute of a node. If the attribute's column was not declared yet, it will be declared by this method first.

Parameters:
node -
key -
value -

idToDot

private java.lang.String idToDot(java.lang.String string)

idFromDot

private java.lang.String idFromDot(java.lang.String id)

main

public static void main(java.lang.String[] args)

The Meta-Environment API