org.graffiti.plugins.algorithms.reingoldtilford
Class ReingoldTilfordAlgorithm

java.lang.Object
  extended by org.graffiti.plugin.AbstractParametrizable
      extended by org.graffiti.plugin.algorithm.AbstractAlgorithm
          extended by org.graffiti.plugins.algorithms.reingoldtilford.ReingoldTilfordAlgorithm
All Implemented Interfaces:
Algorithm, Parametrizable

public class ReingoldTilfordAlgorithm
extends AbstractAlgorithm

ReingoldTilfordAlgorithm implements an extended version of the Reingold-Tilford algorithm, which hierarchically lays out a rooted tree of unbounded degree and with arbitrary node sizes.

Throughout this package, the terms 'width' and 'height' of (sub)trees refer to dimensions of the tree layout rather than graph-theoretic properties.

The behavior is influenced by various parameters:

In all classes except ReingoldTilfordAlgorithm and Orientation, the tree is considered as growing from top to bottom, i.e. the root has the y-coordinate 0 and children have greater y-coordinates than their parents. In order to achieve different orientations, the coordinates and dimensions of the nodes, the edges and the ports are transformed by the respective descendants of Orientation. Therefore Tree and descendants of ChildOrderStrategy, EdgeLayoutStrategy and Levelling must not directly query or set coordinates or dimensions but rather use the methods getNodePosition(Node), getNodeDimension(Node), setNodePosition(Node, double, double), createPort(String, double, double) and createCoordinateAttribute(String, double, double).

Version:
$Revision$ $Date$
Author:
Andreas Gleißner
See Also:
ReingoldTilfordPlugin

Constructor Summary
ReingoldTilfordAlgorithm()
          Constructs a ReingoldTilfordAlgorithm object.
 
Method Summary
 void check()
          Checks whether all preconditions of the current graph are satisfied.
 CoordinateAttribute createCoordinateAttribute(String id, double x, double y)
          Creates a CoordinateAttribute at the specified coordinates.
 Port createPort(String name, double x, double y)
          Creates a Port at the specified coordinates.
 Set<Tree> createSet()
          Creates an empty Set<Tree>.
 Set<Tree> createSet(Collection<Tree> collection)
          Creates an Set<Tree> containing the elements of collection.
 void execute()
          Executes the algorithm.
 Tree find(TreeVisitor<Boolean> visitor)
          Returns the first tree layout for which visitor returns true.
 Parameter<?>[] getAlgorithmParameters()
          
 String getName()
          Returns the name (id) of this Parametrizable.
 Point2D.Double getNodeDimension(Node node)
          Returns the size of node.
 Point2D.Double getNodePosition(Node node)
          Return the position of node.
 boolean isConsiderFlipping()
          Returns true, if instances of ChildOrderPolicy may flip complete subtrees in addition to reordering them.
 void reset()
          Resets the internal state of the algorithm.
 void setAlgorithmParameters(Parameter<?>[] params)
          
 void setRoot(Node root)
           
 
Methods inherited from class org.graffiti.plugin.algorithm.AbstractAlgorithm
attach, getAnimation, supportsAnimation
 
Methods inherited from class org.graffiti.plugin.AbstractParametrizable
copyParameters, getDefaultParameters, getParameters, getUserParameters, saveUserParameters, saveUserParameters, setParameters
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graffiti.plugin.Parametrizable
getDefaultParameters, getParameters, setParameters
 

Constructor Detail

ReingoldTilfordAlgorithm

public ReingoldTilfordAlgorithm()
Constructs a ReingoldTilfordAlgorithm object.

Method Detail

getAlgorithmParameters

public Parameter<?>[] getAlgorithmParameters()

Overrides:
getAlgorithmParameters in class AbstractParametrizable

setAlgorithmParameters

public void setAlgorithmParameters(Parameter<?>[] params)

Overrides:
setAlgorithmParameters in class AbstractParametrizable

check

public void check()
           throws PreconditionException
Checks whether all preconditions of the current graph are satisfied.

Specified by:
check in interface Algorithm
Overrides:
check in class AbstractAlgorithm
Throws:
PreconditionException - if the preconditions of the current graph are not satisfied.
See Also:
Algorithm.check()

execute

public void execute()
Executes the algorithm.

At first levellingStrategy inspects the tree to possibly calculate the levels where the nodes will be placed at.

The actual job is done by constructing a Tree for the root, which recursively constructs instances of Tree for its children. In doing so, the tree layout is created in a bottom-up manner.

Finally the layout is applied to the graph by a call to Tree.draw(ReingoldTilfordAlgorithm, double, double).

See Also:
Algorithm.execute()

getName

public String getName()
Returns the name (id) of this Parametrizable.

Returns:
DOCUMENT ME!

reset

public void reset()
Resets the internal state of the algorithm.

Specified by:
reset in interface Algorithm
Overrides:
reset in class AbstractAlgorithm
See Also:
Algorithm.reset()

isConsiderFlipping

public boolean isConsiderFlipping()
Returns true, if instances of ChildOrderPolicy may flip complete subtrees in addition to reordering them.

Returns:
considersFlipping.

getNodeDimension

public Point2D.Double getNodeDimension(Node node)
Returns the size of node. Tree and descendants of ChildOrderStrategy, EdgeLayoutStrategy and Levelling must not directly query the dimension of a node but rather use this method. See Orientation for further explanation.

Parameters:
node - the node whoose size is to be returned.
Returns:
the size of node.

getNodePosition

public Point2D.Double getNodePosition(Node node)
Return the position of node. Tree and descendants of ChildOrderStrategy, EdgeLayoutStrategy and Levelling must not directly query the position of a node but rather use this method. See Orientation for further explanation.

Parameters:
node - the node whoose position is to be returned.
Returns:
the position of node.

createPort

public Port createPort(String name,
                       double x,
                       double y)
Creates a Port at the specified coordinates. Tree and descendants of ChildOrderStrategy, EdgeLayoutStrategy and Levelling must not directly create ports, but rather use this method. See Orientation for further explanation.

Parameters:
name - the name of the new port.
x - the x-coordinate of the new port.
y - the y-coordinate of the new port.
Returns:
the created port.

createCoordinateAttribute

public CoordinateAttribute createCoordinateAttribute(String id,
                                                     double x,
                                                     double y)
Creates a CoordinateAttribute at the specified coordinates. Tree and descendants of ChildOrderStrategy, EdgeLayoutStrategy and Levelling must not directly create coordinate attributes, but rather use this method. See Orientation for further explanation.

Parameters:
id - the id of the new coordinate attribute.
x - the x-coordinate of the new coordinate attribute.
y - the y-coordinate of the new coordinate attribute.
Returns:
the created coordinate attribute.

createSet

public Set<Tree> createSet()
Creates an empty Set<Tree>.

Returns:
a new Set<Tree>. If doesStableOptimization is false, a HashSet is created so that the iteration order of the returned set is random. Otherwise, a LinkedHashSet with an iteration order depending on the insertion order is created. See doesStableOptimization for further explanation.

createSet

public Set<Tree> createSet(Collection<Tree> collection)
Creates an Set<Tree> containing the elements of collection.

Parameters:
collection - the elements of this collection are inserted into the new set.
Returns:
a new Set<Tree>. If doesStableOptimization is false, a HashSet is created so that the iteration order of the returned set is random. Otherwise, a LinkedHashSet with an iteration order depending on the insertion order is created. The set does initially contain the elements of collection. See doesStableOptimization for further explanation.

find

public Tree find(TreeVisitor<Boolean> visitor)
Returns the first tree layout for which visitor returns true. The tree is searched in a depth-first manner.

Parameters:
visitor - is called with the layout of each subtree until it returns true. It may return false for every tree layout.
Returns:
the first tree for which visitor returns true, or null if visitor returns false for the layout of each subtree.

setRoot

public void setRoot(Node root)


Generated at 2012-05-30 11:01:25 PM CEST