mapss.dif.graph
Class HierarchyToDot

java.lang.Object
  extended by mapss.dif.graph.HierarchyToDot
Direct Known Subclasses:
DIFHierarchyToDot

public class HierarchyToDot
extends java.lang.Object

DOT file generator for Hierarchy objects. It is used to create dot files as an input to GraphViz tools. A dot file is created by first defining an Hierarchy object and then using the toFile(java.lang.String) method. Underlying hierarchy object is cached during the constructor call and cannot be changed afterwards.

Version:
$Id: HierarchyToDot.java 409 2007-05-13 19:47:16Z plishker $
Author:
Fuat Keceli

Field Summary
protected  DotGenerator _dotGenerator
          Dot generator object.
protected  Hierarchy _hierarchy
          Cached hierarchy object.
 
Constructor Summary
protected HierarchyToDot()
           
  HierarchyToDot(Hierarchy hierarchy, java.util.Collection flattenSet, boolean useElementNames)
          Creates a DotGenerator object from a Hierarchy object.
 
Method Summary
protected  java.lang.String _elementName(mocgraph.Element element)
          Returns the name of an element if it is stored in a special way.
static DotGenerator hierarchyGraphToDot(Hierarchy hierarchy)
          Draw the hierarchy graph starting from this hierarchy.
 void toFile(java.lang.String fileName)
          Creates a "dot" file from the given hierarchy.
 java.lang.String toString()
          Creates a Dot string from the given hierarchy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_hierarchy

protected Hierarchy _hierarchy
Cached hierarchy object.


_dotGenerator

protected DotGenerator _dotGenerator
Dot generator object.

Constructor Detail

HierarchyToDot

protected HierarchyToDot()

HierarchyToDot

public HierarchyToDot(Hierarchy hierarchy,
                      java.util.Collection flattenSet,
                      boolean useElementNames)
Creates a DotGenerator object from a Hierarchy object.

Parameters:
hierarchy - Original hierarchy from which this generator is created. It is cached during constructor call.
flattenSet - Runs flatten on the given set of nodes and draws them as clusters. This parameter can be left null.
useElementNames - If true, _elementName(mocgraph.Element) method will be used to get element names of the graph. Otherwise node/edge labels in Graph will be used.
Method Detail

hierarchyGraphToDot

public static DotGenerator hierarchyGraphToDot(Hierarchy hierarchy)
Draw the hierarchy graph starting from this hierarchy. The hierarchy graph should be obtained using the Hierarchy.hierarchyGraph() method.

Parameters:
hierarchy - The top level hierarchy.
Returns:
The dot generator object.
Throws:
CyclicHierarchyException - If hierarchy structure is found to be cyclic. The relation causing this exception can be obtained via a method in CyclicHierarchyException.
See Also:
Hierarchy.hierarchyGraph(), DotGenerator

toFile

public void toFile(java.lang.String fileName)
            throws java.io.IOException
Creates a "dot" file from the given hierarchy.

Parameters:
fileName - Name of the dot file to be created. A ".dot" extension will be appended to this name.
Throws:
java.io.IOException - If file cannot be created.

toString

public java.lang.String toString()
Creates a Dot string from the given hierarchy.

Overrides:
toString in class java.lang.Object
Returns:
A "dot" string representation of the hierarchy.

_elementName

protected java.lang.String _elementName(mocgraph.Element element)
Returns the name of an element if it is stored in a special way. This implementation assumes the weight of the graph element is a String and uses it as the name. Other implementations can change this assumption.

Parameters:
element - An element (node or an edge) included in the backing graph of the hierarchy.
Returns:
Weight of the element printed as a String using its toString method.