y.layout.tree
Class DefaultNodePlacer

java.lang.Object
  extended by y.layout.tree.AbstractNodePlacer
      extended by y.layout.tree.DefaultNodePlacer
All Implemented Interfaces:
Cloneable, NodePlacer

public class DefaultNodePlacer
extends AbstractNodePlacer
implements NodePlacer, Cloneable

Versatile default implementation of NodePlacer used by GenericTreeLayouter. This implementation provides a couple of related styles for laying out subtrees in a tree layout. The styles can be customized easily using a wealth of different options. This implementation is capable of dealing with PortConstraints correctly.

 
Your browser does not support SVG content.

Field Summary
static byte ALIGNMENT_CENTER
          alignment byte constant used for the rootAlignment property.
static byte ALIGNMENT_LEADING
          alignment byte constant used for the rootAlignment property.
static byte ALIGNMENT_LEADING_OFFSET
          alignment byte constant used for the rootAlignment property.
static byte ALIGNMENT_MEDIAN
          alignment byte constant used for the rootAlignment property.
static byte ALIGNMENT_TRAILING
          alignment byte constant used for the rootAlignment property.
static byte ALIGNMENT_TRAILING_OFFSET
          alignment byte constant used for the rootAlignment property.
static byte PLACEMENT_HORIZONTAL_DOWNWARD
          placement byte constant used for the childPlacement property.
static byte PLACEMENT_HORIZONTAL_UPWARD
          placement byte constant used for the childPlacement property.
static byte PLACEMENT_VERTICAL_TO_LEFT
          placement byte constant used for the childPlacement property.
static byte PLACEMENT_VERTICAL_TO_RIGHT
          placement byte constant used for the childPlacement property.
static byte ROUTING_FORK
          routing style byte constant used for the routingStyle property.
static byte ROUTING_FORK_AT_ROOT
          routing style byte constant used for the routingStyle property.
static byte ROUTING_POLY_LINE
          routing style byte constant used for the routingStyle property.
static byte ROUTING_STRAIGHT
          routing style byte constant used for the routingStyle property.
 
Fields inherited from class y.layout.tree.AbstractNodePlacer
graph
 
Fields inherited from interface y.layout.tree.NodePlacer
DIRECTION_ANY, DIRECTION_EAST, DIRECTION_NONE, DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_WEST
 
Constructor Summary
DefaultNodePlacer()
          Creates a new DefaultNodePlacer with default alignment (ALIGNMENT_CENTER), default child placement (PLACEMENT_HORIZONTAL_DOWNWARD), and default edge routing (ROUTING_FORK) and a horizontal and vertical distance of 40.0d.
DefaultNodePlacer(byte childPlacement, byte rootAlignment, byte routingStyle, double verticalDistance, double horizontalDistance)
          Creates a new DefaultNodePlacer.
DefaultNodePlacer(byte childPlacement, byte rootAlignment, double verticalDistance, double horizontalDistance)
          Creates a new DefaultNodePlacer with default edge routing (ROUTING_FORK).
DefaultNodePlacer(byte childPlacement, double verticalDistance, double horizontalDistance)
          Creates a new DefaultNodePlacer with default alignment (ALIGNMENT_CENTER) and default edge routing (ROUTING_FORK).
 
Method Summary
protected  void calcParentConnector(LayoutGraph graph, Node localRoot, NodeLayout rootLayout, GenericTreeLayouter.SubtreeShape subtreeShape, Edge parentEdge, EdgeLayout parentEdgeLayout, byte direction)
          Calculates the connector the the parent node.
protected  void calcSourceEdgeLayout(NodeLayout rootLayout, GenericTreeLayouter.SubtreeShape childShape, Edge edge)
          Performs the routing of the source side of the edge to the given child node.
protected  void calcTargetEdgeLayout(NodeLayout rootLayout, GenericTreeLayouter.SubtreeShape childShape, Edge edge)
          Performs the routing of the target side of the edge to the given child node.
 Object clone()
          Overwritten to support cloning.
 Comparator createComparator()
          Returns a Comparator instance that can be used to register with the GenericTreeLayouter.
protected  byte determineChildConnector(Node child)
          This method must be implemented by subclasses.
 byte getChildPlacement()
          Returns the current placement byte constant.
 double getHorizontalDistance()
          Returns the current horizontal distance this NodePlacer should use for the arrangement of the elements.
 byte getRootAlignment()
          Returns the current rootAlignment byte constant.
 byte getRoutingStyle()
          Returns the current routingStyle byte constant.
 double getVerticalDistance()
          Returns the current vertical distance this NodePlacer should use for the arrangement of the elements.
protected  GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot, byte parentConnectorDirection)
          The main placeSubtree method that must be implemented by subclasses.
 void setChildPlacement(byte childPlacement)
          Sets the new placement byte constant.
 void setHorizontalDistance(double horizontalDistance)
          Sets the new horizontalDistance distance this NodePlacer should use for the arrangement of the elements.
 void setRootAlignment(byte rootAlignment)
          Sets the new rootAlignment byte constant.
 void setRoutingStyle(byte routingStyle)
          Setter for property routingStyle.
 void setVerticalDistance(double verticalDistance)
          Sets the new vertical distance this NodePlacer should use for the arrangement of the elements.
 
Methods inherited from class y.layout.tree.AbstractNodePlacer
createProcessor, determineChildConnectors, getNodeShape, getSubtreeShape, placeSubtree
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.layout.tree.NodePlacer
createProcessor, determineChildConnectors, placeSubtree
 

Field Detail

PLACEMENT_VERTICAL_TO_LEFT

public static final byte PLACEMENT_VERTICAL_TO_LEFT
placement byte constant used for the childPlacement property. This placement strategy arranges child subtrees vertically beneath each other to the left of the root node.

See Also:
Constant Field Values

PLACEMENT_VERTICAL_TO_RIGHT

public static final byte PLACEMENT_VERTICAL_TO_RIGHT
placement byte constant used for the childPlacement property. This placement strategy arranges child subtrees vertically beneath each other to the right of the root node.

See Also:
Constant Field Values

PLACEMENT_HORIZONTAL_UPWARD

public static final byte PLACEMENT_HORIZONTAL_UPWARD
placement byte constant used for the childPlacement property. This placement strategy arranges child subtrees horizontally next to each other above the root node.

See Also:
Constant Field Values

PLACEMENT_HORIZONTAL_DOWNWARD

public static final byte PLACEMENT_HORIZONTAL_DOWNWARD
placement byte constant used for the childPlacement property. This placement strategy arranges child subtrees horizontally next to each other below the root node.

See Also:
Constant Field Values

ALIGNMENT_LEADING_OFFSET

public static final byte ALIGNMENT_LEADING_OFFSET
alignment byte constant used for the rootAlignment property. This constant places the root ahead of all the child subtrees.

See Also:
Constant Field Values

ALIGNMENT_LEADING

public static final byte ALIGNMENT_LEADING
alignment byte constant used for the rootAlignment property. This constant aligns the root with the first of its subtrees.

See Also:
Constant Field Values

ALIGNMENT_CENTER

public static final byte ALIGNMENT_CENTER
alignment byte constant used for the rootAlignment property. This constant aligns the root at the center of its subtrees.

See Also:
Constant Field Values

ALIGNMENT_MEDIAN

public static final byte ALIGNMENT_MEDIAN
alignment byte constant used for the rootAlignment property. This constant aligns the root at the median of the connection points to its subtrees.

See Also:
Constant Field Values

ALIGNMENT_TRAILING

public static final byte ALIGNMENT_TRAILING
alignment byte constant used for the rootAlignment property. This constant aligns the root at with the last of its subtrees.

See Also:
Constant Field Values

ALIGNMENT_TRAILING_OFFSET

public static final byte ALIGNMENT_TRAILING_OFFSET
alignment byte constant used for the rootAlignment property. This constant places the root after all of its subtrees.

See Also:
Constant Field Values

ROUTING_FORK

public static final byte ROUTING_FORK
routing style byte constant used for the routingStyle property. Using this value will result in orthogonally routed child node connectors where the bends are placed in the channel between the root node and the child nodes.

See Also:
Constant Field Values

ROUTING_FORK_AT_ROOT

public static final byte ROUTING_FORK_AT_ROOT
routing style byte constant used for the routingStyle property. Using this value will result in orthogonally routed child node connectors with one bend each placed next to the root node.

See Also:
Constant Field Values

ROUTING_STRAIGHT

public static final byte ROUTING_STRAIGHT
routing style byte constant used for the routingStyle property. Using this value will result in straight connections to the child nodes. Edges may overlap nodes in this case.

See Also:
Constant Field Values

ROUTING_POLY_LINE

public static final byte ROUTING_POLY_LINE
routing style byte constant used for the routingStyle property. Using this value will result in straight connections to the connector of the subtree.

See Also:
Constant Field Values
Constructor Detail

DefaultNodePlacer

public DefaultNodePlacer()
Creates a new DefaultNodePlacer with default alignment (ALIGNMENT_CENTER), default child placement (PLACEMENT_HORIZONTAL_DOWNWARD), and default edge routing (ROUTING_FORK) and a horizontal and vertical distance of 40.0d.


DefaultNodePlacer

public DefaultNodePlacer(byte childPlacement,
                         double verticalDistance,
                         double horizontalDistance)
Creates a new DefaultNodePlacer with default alignment (ALIGNMENT_CENTER) and default edge routing (ROUTING_FORK).

Parameters:
childPlacement - placement constant describing the style of the arrangement
verticalDistance - the vertical distance between the root node and the subtree shapes or between subtree shapes in case of vertical child placement
horizontalDistance - the horizontal distance between the root node and the subtree shapes or between subtree shapes in case of horizontal child placement

DefaultNodePlacer

public DefaultNodePlacer(byte childPlacement,
                         byte rootAlignment,
                         double verticalDistance,
                         double horizontalDistance)
Creates a new DefaultNodePlacer with default edge routing (ROUTING_FORK).

Parameters:
childPlacement - placement constant describing the style of the arrangement
rootAlignment - alignment constant describing the position of the root nod with respect to the subtrees
verticalDistance - the vertical distance between the root node and the subtree shapes or between subtree shapes in case of vertical child placement
horizontalDistance - the horizontal distance between the root node and the subtree shapes or between subtree shapes in case of horizontal child placement

DefaultNodePlacer

public DefaultNodePlacer(byte childPlacement,
                         byte rootAlignment,
                         byte routingStyle,
                         double verticalDistance,
                         double horizontalDistance)
Creates a new DefaultNodePlacer.

Parameters:
routingStyle - routing style constant
childPlacement - placement constant describing the style of the arrangement
rootAlignment - alignment constant describing the position of the root nod with respect to the subtrees
verticalDistance - the vertical distance between the root node and the subtree shapes or between subtree shapes in case of vertical child placement
horizontalDistance - the horizontal distance between the root node and the subtree shapes or between subtree shapes in case of horizontal child placement
Method Detail

placeSubtree

protected GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot,
                                                        byte parentConnectorDirection)
Description copied from class: AbstractNodePlacer
The main placeSubtree method that must be implemented by subclasses.

Specified by:
placeSubtree in class AbstractNodePlacer
Parameters:
localRoot - the local root node
parentConnectorDirection - the direction of the connector shape
Returns:
a SubtreeShape instance that describes the shape of the whole subtree

calcParentConnector

protected void calcParentConnector(LayoutGraph graph,
                                   Node localRoot,
                                   NodeLayout rootLayout,
                                   GenericTreeLayouter.SubtreeShape subtreeShape,
                                   Edge parentEdge,
                                   EdgeLayout parentEdgeLayout,
                                   byte direction)
Calculates the connector the the parent node. Subclasses may override this method.

Parameters:
graph - the graph
localRoot - the root whose connector must be calculated and stored in the subtreeShape
rootLayout - the NodeLayout of the root node
subtreeShape - the shape to be used for the connector information
parentEdge - the edge that will later be routed according to the information in the subtreeShape
parentEdgeLayout - the current EdgeLayout of the edge
direction - the direction byte constant as defined in the NodePlacer interface which should be used for the connector

calcTargetEdgeLayout

protected void calcTargetEdgeLayout(NodeLayout rootLayout,
                                    GenericTreeLayouter.SubtreeShape childShape,
                                    Edge edge)
Performs the routing of the target side of the edge to the given child node. This method does nothing but resets the current EdgeLayout.

Parameters:
rootLayout - the NodeLayout of the local root node
childShape - the SubtreeShape instance of the corresponding child's subtree
edge - the edge

calcSourceEdgeLayout

protected void calcSourceEdgeLayout(NodeLayout rootLayout,
                                    GenericTreeLayouter.SubtreeShape childShape,
                                    Edge edge)
Performs the routing of the source side of the edge to the given child node. This method calculates the source bends according to the current routingStyle, and connects the bends of the child SubtreeShape connector to the EdgeLayout.

Parameters:
rootLayout - the NodeLayout of the local root node
childShape - the SubtreeShape instance of the corresponding child's subtree
edge - the edge

getChildPlacement

public byte getChildPlacement()
Returns the current placement byte constant.

Returns:
the current value

setChildPlacement

public void setChildPlacement(byte childPlacement)
Sets the new placement byte constant.

Parameters:
childPlacement - New value of property childPlacement.

getRootAlignment

public byte getRootAlignment()
Returns the current rootAlignment byte constant.

Returns:
the current value

setRootAlignment

public void setRootAlignment(byte rootAlignment)
Sets the new rootAlignment byte constant.

Parameters:
rootAlignment - the new value

determineChildConnector

protected byte determineChildConnector(Node child)
Description copied from class: AbstractNodePlacer
This method must be implemented by subclasses. It assigns a connector shape direction to each child.

Specified by:
determineChildConnector in class AbstractNodePlacer
Parameters:
child - the child node
Returns:
a byte constant as defined in the NodePlacer interface

getRoutingStyle

public byte getRoutingStyle()
Returns the current routingStyle byte constant.

Returns:
the current value

setRoutingStyle

public void setRoutingStyle(byte routingStyle)
Setter for property routingStyle.

Parameters:
routingStyle - New value of property routingStyle.

getVerticalDistance

public double getVerticalDistance()
Returns the current vertical distance this NodePlacer should use for the arrangement of the elements.

Returns:
the current value

setVerticalDistance

public void setVerticalDistance(double verticalDistance)
Sets the new vertical distance this NodePlacer should use for the arrangement of the elements.

Parameters:
verticalDistance - the new value

getHorizontalDistance

public double getHorizontalDistance()
Returns the current horizontal distance this NodePlacer should use for the arrangement of the elements.

Returns:
the current value

setHorizontalDistance

public void setHorizontalDistance(double horizontalDistance)
Sets the new horizontalDistance distance this NodePlacer should use for the arrangement of the elements.

Parameters:
horizontalDistance - the new value

createComparator

public Comparator createComparator()
Returns a Comparator instance that can be used to register with the GenericTreeLayouter. The returned instance can be used to sort the child nodes in such a way that the layout will look like the current arrangement of the nodes. This is especially useful for interactive or incremental layouts.

Returns:
a Comparator instance that can be used for the current configuration of this instance.

clone

public Object clone()
Overwritten to support cloning.

Overrides:
clone in class Object
Returns:
an exact copy of this instance

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