Search this API

y.layout.tree
Class GenericTreeLayouter

java.lang.Object
  extended by y.layout.CanonicMultiStageLayouter
      extended by y.layout.tree.GenericTreeLayouter
All Implemented Interfaces:
Layouter

public class GenericTreeLayouter
extends CanonicMultiStageLayouter

This class implements the basis of a generic tree layout algorithm. It can be customized easily to control the placement and order of child nodes, the edge routing and port assignment on a per node basis.
Using DataProviders, one can specify objects that implement the NodePlacer interface. Those instances are responsible for the arrangement of the subtrees of the node's they are registered with and the routing of the connecting edges.
Likewise instances of PortAssignment are responsible for the assignment of the ports and Comparator instances can be used to sort the outgoing edges of each node.
Customization of this class should be done via own implementations of the NodePlacer, possibly PortAssignment, and Comparator instances.

Here is an example output that shows multiple different configurations in one layout using DefaultNodePlacer instances:

See Also:
NodePlacer, DefaultNodePlacer, PortAssignment, DefaultPortAssignment

Nested Class Summary
static class GenericTreeLayouter.SubtreeShape
          Instances of this class are used to represent the shape of subtrees during the layout.
 
Field Summary
static Object CHILD_COMPARATOR_DPKEY
          DataProvider key that can be registered with the graph to provide each node with its own Comparator instance that will be used to sort its outgoing edges.
protected  LayoutGraph graph
          the graph this layout is running on
static Object NODE_PLACER_DPKEY
          DataProvider key that can be registered with the graph to provide each node with its own NodePlacer instance.
static Object PORT_ASSIGNMENT_DPKEY
          DataProvider key that can be registered with the graph to provide each node with its own PortAssignment instance.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
GenericTreeLayouter()
          Creates a new GenericTreeLayouter with a default NodePlacer, a default PortAssignment instance and no default edge comparator.
 
Method Summary
protected  boolean canLayoutCore(LayoutGraph graph)
          Subclasses have to provide information whether or not they can layout the given graph.
protected  EdgeList directTree()
          This method is called initially with the graph to calculate a rooted tree.
protected  void doLayoutCore(LayoutGraph graph)
          Subclasses have to provide core layout code in this method.
protected  Comparator getChildNodeInEdgeComparator(Node localRoot)
          This method returns a Comparator instance or null that will be used for the sorting of the outgoing edges at the given Node.
 Comparator getDefaultChildComparator()
          Returns the default Comparator instance or null that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.
 NodePlacer getDefaultLeafPlacer()
          Returns the default NodePlacer instance that will be used for the leaf nodes of the tree.
 NodePlacer getDefaultNodePlacer()
          Returns the default NodePlacer instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.
 PortAssignment getDefaultPortAssignment()
          Returns the default PortAssignment instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.
protected  NodePlacer getNodePlacer(Node localRoot)
          This method returns a NodePlacer instance that will be used for the placement of the root node and the subtree shapes.
protected  GenericTreeLayouter.SubtreeShape getNodeShape(Node node)
          Factory method that creates a SubtreeShape for a given node, that consists of the bounds of the node only.
protected  PortAssignment getPortAssignment(Node localRoot)
          This method returns a PortAssignment instance that will be used for the port assignments at the given Node.
protected  Node[] getRootsArray(Node root)
          Returns the array of the nodes to be laid out.
protected  DataAcceptor getSourcePortConstraintDataAcceptor()
          Returns a DataAcceptor implementation that can be used to overwrite the source port constraint (PortConstraint temporarily for use during the layout.
protected  GenericTreeLayouter.SubtreeShape getSubtreeShape(Node localRoot)
          Provides access to the SubTreeShape instances for each node.
protected  DataAcceptor getTargetPortConstraintDataAcceptor()
          Returns a DataAcceptor implementation that can be used to overwrite the target port constraint (PortConstraint temporarily for use during the layout.
 boolean isGroupingSupported()
          Returns true if grouping support is enabled.
 boolean isIntegratedEdgeLabeling()
          Returns whether integrated edge labeling is enabled (extension of the shapes of subtrees with the labels of the edges).
 boolean isIntegratedNodeLabeling()
          Returns whether integrated node labeling is enabled (extension of the shapes of the nodes with its labels).
protected  GenericTreeLayouter.SubtreeShape layoutRoot(Node localRoot)
          This is the core method of the algorithm.
protected  void reverseEdges(EdgeList reversedEdges)
          This method is used for the actual reversal of edges.
 void setDefaultChildComparator(Comparator defaultChildComparator)
          Sets the default Comparator instance that will be used for those subtrees that don't have their own specific instance set via the appropriate DataProvider.
 void setDefaultLeafPlacer(NodePlacer defaultLeafPlacer)
          Sets the default NodePlacer instance that will be used for the leaf nodes of the tree.
 void setDefaultNodePlacer(NodePlacer defaultNodePlacer)
          Sets the default NodePlacer instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.
 void setDefaultPortAssignment(PortAssignment defaultPortAssignment)
          Sets the default PortAssignment instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.
 void setGroupingSupported(boolean groupingSupported)
          Whether or not grouping support should be enabled.
 void setIntegratedEdgeLabeling(boolean integratedEdgeLabeling)
          Specifies whether or not to use integrated edge labeling (extension of the shapes of the subtrees with the labels for the edges).
 void setIntegratedNodeLabeling(boolean integratedNodeLabeling)
          Specifies whether or not to use integrated node labeling.
 
Methods inherited from class y.layout.CanonicMultiStageLayouter
appendStage, calcLayout, calcLayout, canLayout, checkGroupNodeSize, checkNodeSize, doLayout, doLayout, enableOnlyCore, getComponentLayouter, getGroupNodeHider, getLabelLayouter, getLayoutOrientation, getOrientationLayouter, getParallelEdgeLayouter, getSelfLoopLayouter, getSubgraphLayouter, isComponentLayouterEnabled, isGroupNodeHidingEnabled, isLabelLayouterEnabled, isOrientationLayouterEnabled, isParallelEdgeLayouterEnabled, isSelfLoopLayouterEnabled, isSubgraphLayouterEnabled, prependStage, removeStage, setComponentLayouter, setComponentLayouterEnabled, setGroupNodeHider, setGroupNodeHidingEnabled, setLabelLayouter, setLabelLayouterEnabled, setLayoutOrientation, setOrientationLayouter, setOrientationLayouterEnabled, setParallelEdgeLayouter, setParallelEdgeLayouterEnabled, setSelfLoopLayouter, setSelfLoopLayouterEnabled, setSubgraphLayouter, setSubgraphLayouterEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE_PLACER_DPKEY

public static final Object NODE_PLACER_DPKEY
DataProvider key that can be registered with the graph to provide each node with its own NodePlacer instance.


PORT_ASSIGNMENT_DPKEY

public static final Object PORT_ASSIGNMENT_DPKEY
DataProvider key that can be registered with the graph to provide each node with its own PortAssignment instance.


CHILD_COMPARATOR_DPKEY

public static final Object CHILD_COMPARATOR_DPKEY
DataProvider key that can be registered with the graph to provide each node with its own Comparator instance that will be used to sort its outgoing edges.


graph

protected LayoutGraph graph
the graph this layout is running on

Constructor Detail

GenericTreeLayouter

public GenericTreeLayouter()
Creates a new GenericTreeLayouter with a default NodePlacer, a default PortAssignment instance and no default edge comparator.

Method Detail

isGroupingSupported

public boolean isGroupingSupported()
Returns true if grouping support is enabled. Note that the grouping only works correctly, if each group represents a complete subtree. This means that for each group there is a node v such that the group contains exactly v and all its descendants.


setGroupingSupported

public void setGroupingSupported(boolean groupingSupported)
Whether or not grouping support should be enabled. Note that the grouping only works correctly, if each group represents a complete subtree. This means that for each group there is a node v such that the group contains exactly v and all its descendants.

Parameters:
groupingSupported - if true, grouping support is enabled.

canLayoutCore

protected boolean canLayoutCore(LayoutGraph graph)
Description copied from class: CanonicMultiStageLayouter
Subclasses have to provide information whether or not they can layout the given graph.

Specified by:
canLayoutCore in class CanonicMultiStageLayouter

doLayoutCore

protected void doLayoutCore(LayoutGraph graph)
Description copied from class: CanonicMultiStageLayouter
Subclasses have to provide core layout code in this method.

Specified by:
doLayoutCore in class CanonicMultiStageLayouter

getSubtreeShape

protected GenericTreeLayouter.SubtreeShape getSubtreeShape(Node localRoot)
Provides access to the SubTreeShape instances for each node. Those instances should be modified only during the layout of the parent node.

Parameters:
localRoot - the node for which the subtree should be returned
Returns:
the SubTreeShape instance if it has been calculated already or null otherwise

layoutRoot

protected GenericTreeLayouter.SubtreeShape layoutRoot(Node localRoot)
This is the core method of the algorithm. This method is invoked for each node in the tree exactly once in such an order that all of the child nodes of each node have already been calculated by the time of the method invocation.
This method uses the getSubtreeShape(Node) callback to retrieve the shapes of the subtrees of all of the children of localRoot.

Parameters:
localRoot - The root to be laid out together with its SubtreeShapes
Returns:
the combined SubtreeShape of the local root node and all of its children and connecting edges

getPortAssignment

protected PortAssignment getPortAssignment(Node localRoot)
This method returns a PortAssignment instance that will be used for the port assignments at the given Node. This method is allowed to return a shared instance for multiple different nodes, the instances are not used after subsequent calls to this method.

Parameters:
localRoot - the root of the local subtree
Returns:
a readily configured instance of PortAssignment that can be used to assign the ports of the edges at the given local root node.

getChildNodeInEdgeComparator

protected Comparator getChildNodeInEdgeComparator(Node localRoot)
This method returns a Comparator instance or null that will be used for the sorting of the outgoing edges at the given Node. This method is allowed to return a shared instance for multiple different nodes, the instances are not used after subsequent calls to this method.

Parameters:
localRoot - the root of the local subtree
Returns:
a readily configured instance of Comparator or null that can be used sort the outgoing edges of the given node

getNodePlacer

protected NodePlacer getNodePlacer(Node localRoot)
This method returns a NodePlacer instance that will be used for the placement of the root node and the subtree shapes. This method is allowed to return a shared instance for multiple different nodes, the instances are not used after subsequent calls to this method.

Parameters:
localRoot - the root of the local subtree
Returns:
a readily configured instance of NodePlacer that can be used to layout the subtree under the given local root node.

getNodeShape

protected GenericTreeLayouter.SubtreeShape getNodeShape(Node node)
Factory method that creates a SubtreeShape for a given node, that consists of the bounds of the node only.

Parameters:
node - the node that will be represented by a SubTreeShape instance
Returns:
a newly created SubtreeShape describing the bounds of the given node

getRootsArray

protected Node[] getRootsArray(Node root)
Returns the array of the nodes to be laid out. The order of the elements is chosen so that no parent is laid out before one of its successors.

Parameters:
root - the node that should be used as the root of the tree
Returns:
all nodes in the graph that should be laid out in order

directTree

protected EdgeList directTree()
This method is called initially with the graph to calculate a rooted tree. It returns a list of edges that have to be reversed in order for the graph to become a valid rooted and directed tree.

Returns:
an EdgeList containing all the edges that need to be reversed

getSourcePortConstraintDataAcceptor

protected DataAcceptor getSourcePortConstraintDataAcceptor()
Returns a DataAcceptor implementation that can be used to overwrite the source port constraint (PortConstraint temporarily for use during the layout.

Returns:
an implementation to associate PortConstraints to Edges

getTargetPortConstraintDataAcceptor

protected DataAcceptor getTargetPortConstraintDataAcceptor()
Returns a DataAcceptor implementation that can be used to overwrite the target port constraint (PortConstraint temporarily for use during the layout.

Returns:
an implementation to associate PortConstraints to Edges

reverseEdges

protected void reverseEdges(EdgeList reversedEdges)
This method is used for the actual reversal of edges. It will be called initially after the directTree() method and finally after the layout has been calculated.

Parameters:
reversedEdges - the edges that will be reversed by this method

getDefaultNodePlacer

public NodePlacer getDefaultNodePlacer()
Returns the default NodePlacer instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.

Returns:
the default instance

setDefaultNodePlacer

public void setDefaultNodePlacer(NodePlacer defaultNodePlacer)
Sets the default NodePlacer instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider. This should be non-null, unless it is guaranteed that for any node in the graph there is a specific instance provided by the registered DataProvider instance.

Parameters:
defaultNodePlacer - the new default instance

getDefaultLeafPlacer

public NodePlacer getDefaultLeafPlacer()
Returns the default NodePlacer instance that will be used for the leaf nodes of the tree.

Returns:
The default NodePlacer for all leaves.

setDefaultLeafPlacer

public void setDefaultLeafPlacer(NodePlacer defaultLeafPlacer)
Sets the default NodePlacer instance that will be used for the leaf nodes of the tree.


getDefaultPortAssignment

public PortAssignment getDefaultPortAssignment()
Returns the default PortAssignment instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.

Returns:
the default instance

setDefaultPortAssignment

public void setDefaultPortAssignment(PortAssignment defaultPortAssignment)
Sets the default PortAssignment instance that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider. This should be non-null, unless it is guaranteed that for any node in the graph there is a specific instance provided by the registered DataProvider instance.

Parameters:
defaultPortAssignment - the new default instance

getDefaultChildComparator

public Comparator getDefaultChildComparator()
Returns the default Comparator instance or null that will be used for those subtrees, that don't have their own specific instance set via the appropriate DataProvider.

Returns:
the default instance or null if no such instance is set

setDefaultChildComparator

public void setDefaultChildComparator(Comparator defaultChildComparator)
Sets the default Comparator instance that will be used for those subtrees that don't have their own specific instance set via the appropriate DataProvider. This can be set to null which implies no sorting by default.

Parameters:
defaultChildComparator - the new default instance or null if no such sorting should be done

setIntegratedNodeLabeling

public void setIntegratedNodeLabeling(boolean integratedNodeLabeling)
Specifies whether or not to use integrated node labeling. If set to true, the shape of the nodes will be extended with the shapes of its labels.

Parameters:
integratedNodeLabeling - whether integrated node labeling should be enabled.

isIntegratedNodeLabeling

public boolean isIntegratedNodeLabeling()
Returns whether integrated node labeling is enabled (extension of the shapes of the nodes with its labels).

Returns:
true if intergrated node labeling is enabled; false otherwise.

isIntegratedEdgeLabeling

public boolean isIntegratedEdgeLabeling()
Returns whether integrated edge labeling is enabled (extension of the shapes of subtrees with the labels of the edges).

Returns:
true if enabled; false otherwise.

setIntegratedEdgeLabeling

public void setIntegratedEdgeLabeling(boolean integratedEdgeLabeling)
Specifies whether or not to use integrated edge labeling (extension of the shapes of the subtrees with the labels for the edges).


© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.