Search this API

y.layout.tree
Class DefaultNodePlacer

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

public class DefaultNodePlacer
extends AbstractNodePlacer
implements FromSketchNodePlacer, 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.


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_LEADING_ON_BUS
          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 ALIGNMENT_TRAILING_ON_BUS
          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, byte routingStyle, double verticalDistance, double horizontalDistance, double minFirstSegmentLength, double minLastSegmentLength, double minSlope, double minSlopeHeight)
          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 calcSlopedSourceEdgeLayout(NodeLayout rootLayout, GenericTreeLayouter.SubtreeShape childShape, Edge edge, double childForkCoordinate, double rootForkCoordinate)
          Performs the routing of the source side of the edge to the given child 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.
 Comparator createComparator()
          Returns a Comparator instance that can be used to register with the GenericTreeLayouter.
 Comparator createFromSketchComparator()
          Creates a comparator for edges.
protected  byte determineChildConnector(Node child)
          This method must be implemented by subclasses.
 byte getChildPlacement()
          Returns the child node placement policy.
 double getHorizontalDistance()
          Returns the horizontal distance this NodePlacer should use for the arrangement of the elements.
 double getMinFirstSegmentLength()
          Returns the minimum length of the segment between the parent node port and the first bend of the edge.
 double getMinLastSegmentLength()
          Returns the minimum length of the segment between the last bend of the slope and the port of the child node..
 double getMinSlope()
          Returns the minimum slope of edges.
 double getMinSlopeHeight()
          Returns the minimum height for slopes of edges.
 byte getRootAlignment()
          Returns the root node alignment policy.
 byte getRoutingStyle()
          Returns the current routing style byte constant.
 double getVerticalDistance()
          Returns the 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 child node placement policy.
 void setHorizontalDistance(double horizontalDistance)
          Sets the horizontal distance this NodePlacer should use for the arrangement of the elements.
 void setMinFirstSegmentLength(double minFirstSegmentLength)
          Sets the minimum length of the segment between the parent node port and the first bend of the edge.
 void setMinLastSegmentLength(double minLastSegmentLength)
          Sets the minimum length of the segment between the last bend of the slope and the port of the child node.
 void setMinSlope(double minSlope)
          Sets the minimum slope of edges.
 void setMinSlopeHeight(double minSlopeHeight)
          Sets the minimum height for slopes of edges.
 void setRootAlignment(byte rootAlignment)
          Sets the root node alignment policy.
 void setRoutingStyle(byte routingStyle)
          Specifies the current routing style.
 void setVerticalDistance(double verticalDistance)
          Sets the vertical distance this NodePlacer should use for the arrangement of the elements.
 
Methods inherited from class y.layout.tree.AbstractNodePlacer
clone, 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:
setChildPlacement(byte), getChildPlacement(), 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:
setChildPlacement(byte), getChildPlacement(), 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:
setChildPlacement(byte), getChildPlacement(), 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:
setChildPlacement(byte), getChildPlacement(), 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:
setRootAlignment(byte), getRootAlignment(), 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:
setRootAlignment(byte), getRootAlignment(), 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:
setRootAlignment(byte), getRootAlignment(), 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:
setRootAlignment(byte), getRootAlignment(), 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:
setRootAlignment(byte), getRootAlignment(), 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:
setRootAlignment(byte), getRootAlignment(), Constant Field Values

ALIGNMENT_TRAILING_ON_BUS

public static final byte ALIGNMENT_TRAILING_ON_BUS
Alignment byte constant used for the rootAlignment property. This constant places the root after all of its subtrees and centered on the bus.

Note: The vertical/horizontal distance between the root node and the subtree shapes depend on the value of parameters verticalDistance/horizontalDistance passed to the Constructor.

See Also:
setRootAlignment(byte), getRootAlignment(), Constant Field Values

ALIGNMENT_LEADING_ON_BUS

public static final byte ALIGNMENT_LEADING_ON_BUS
Alignment byte constant used for the rootAlignment property. This constant places the root ahead of all the child subtrees and centered on the bus.

Note: The vertical/horizontal distance between the root node and the subtree shapes depend on the value of parameters verticalDistance/horizontalDistance passed to the Constructor.

See Also:
setRootAlignment(byte), getRootAlignment(), 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:
setRoutingStyle(byte), getRoutingStyle(), 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:
setRoutingStyle(byte), getRoutingStyle(), 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:
setRoutingStyle(byte), getRoutingStyle(), 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:
setRoutingStyle(byte), getRoutingStyle(), 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

DefaultNodePlacer

public DefaultNodePlacer(byte childPlacement,
                         byte rootAlignment,
                         byte routingStyle,
                         double verticalDistance,
                         double horizontalDistance,
                         double minFirstSegmentLength,
                         double minLastSegmentLength,
                         double minSlope,
                         double minSlopeHeight)
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
minFirstSegmentLength - the minimum length of the segment from the parent node port to the bend of the slope
minLastSegmentLength - the minimum length of the segment from the last bend of the slope to the port of the child node
minSlope - the minimum slope between the root node and the subtree shapes
minSlopeHeight - the minimum height of slopes between the root node and the subtree shapes
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

calcSlopedSourceEdgeLayout

protected void calcSlopedSourceEdgeLayout(NodeLayout rootLayout,
                                          GenericTreeLayouter.SubtreeShape childShape,
                                          Edge edge,
                                          double childForkCoordinate,
                                          double rootForkCoordinate)
Performs the routing of the source side of the edge to the given child node. This method delegates to calcSourceEdgeLayout(y.layout.NodeLayout, y.layout.tree.GenericTreeLayouter.SubtreeShape, y.base.Edge) if routingStyle is not ROUTING_FORK 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
rootForkCoordinate - the y-coordinate of the first bend of the edge if the placement is horizontal and the x-coordinate otherwise.
childForkCoordinate - the y-coordinate of the second (= last) bend of the edge if the placement is horizontal and the x-coordinate otherwise.

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 child node placement policy.


setChildPlacement

public void setChildPlacement(byte childPlacement)
Sets the child node placement policy.


getRootAlignment

public byte getRootAlignment()
Returns the root node alignment policy.


setRootAlignment

public void setRootAlignment(byte rootAlignment)
Sets the root node alignment policy.


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 routing style byte constant.

Returns:
the current routing style byte constant.

setRoutingStyle

public void setRoutingStyle(byte routingStyle)
Specifies the current routing style.

Parameters:
routingStyle - the set routing style byte constant.

getVerticalDistance

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


setVerticalDistance

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


getMinFirstSegmentLength

public double getMinFirstSegmentLength()
Returns the minimum length of the segment between the parent node port and the first bend of the edge.


setMinFirstSegmentLength

public void setMinFirstSegmentLength(double minFirstSegmentLength)
Sets the minimum length of the segment between the parent node port and the first bend of the edge.


getMinLastSegmentLength

public double getMinLastSegmentLength()
Returns the minimum length of the segment between the last bend of the slope and the port of the child node..


setMinLastSegmentLength

public void setMinLastSegmentLength(double minLastSegmentLength)
Sets the minimum length of the segment between the last bend of the slope and the port of the child node.


getMinSlope

public double getMinSlope()
Returns the minimum slope of edges.


setMinSlope

public void setMinSlope(double minSlope)
Sets the minimum slope of edges.


getMinSlopeHeight

public double getMinSlopeHeight()
Returns the minimum height for slopes of edges.


setMinSlopeHeight

public void setMinSlopeHeight(double minSlopeHeight)
Sets the minimum height for slopes of edges.


getHorizontalDistance

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


setHorizontalDistance

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


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.

createFromSketchComparator

public Comparator createFromSketchComparator()
Description copied from interface: FromSketchNodePlacer
Creates a comparator for edges. This comparator is used to sort the outgoing edges of a node before the placement of the node's subtree is calculated.

Specified by:
createFromSketchComparator in interface FromSketchNodePlacer
Returns:
a comparator for edges.

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