Search this API

y.layout.tree
Class AbstractRotatableNodePlacer

java.lang.Object
  extended by y.layout.tree.AbstractRotatableNodePlacer
All Implemented Interfaces:
FromSketchNodePlacer, NodePlacer
Direct Known Subclasses:
AssistantPlacer, BusPlacer, DelegatingNodePlacer, DoubleLinePlacer, FreePlacer, GridNodePlacer, LayeredNodePlacer, LeftRightPlacer, SimpleNodePlacer

public abstract class AbstractRotatableNodePlacer
extends java.lang.Object
implements FromSketchNodePlacer

Abstract base class for NodePlacers that support rotations of the subtrees.

The direction specified in this AbstractRotatableNodePlacer (defined by a transformation matrix) rotates the subtree that is placed. This is the final direction of this subtree. Rotations are not accumulated.

NodePlacers of this type will only implement the default direction (i.e. top-to-bottom). The other directions are calculated using the specified modification AbstractRotatableNodePlacer.Matrix. The direction used by the implementing NodePlacers is called the model direction while the actual direction in the graph is the real direction.

Note that using rotatable NodePlacers has some pitfalls. Calculations must be aware of the rotations. Especially operations on BorderLines should not be called directly (e.g. BorderLine.mergeWithMin(y.geom.BorderLine), BorderLine.mergeWithMax(y.geom.BorderLine)). The corresponding methods of AbstractRotatableNodePlacer already support the different directions.

Subclasses just need to override the following two abstract methods: placeSubtree(Node, byte) and determineChildConnectors(Node, DataMap).

 

Nested Class Summary
static class AbstractRotatableNodePlacer.Matrix
          A matrix describes the rotation of the subtree handled by AbstractRotatableNodePlacer.
static class AbstractRotatableNodePlacer.RootAlignment
          A AbstractRotatableNodePlacer.RootAlignment describes how a local root node is arranged in relation to its children.
 
Field Summary
protected  java.util.List createdChildren
          The list containing the created children.
protected  LayoutGraph graph
          The graph instance this NodePlacer is working on.
protected  AbstractRotatableNodePlacer.Matrix modificationMatrix
          The active modification matrix.
protected  DataProvider nodeShapeProvider
          The provider of GenericTreeLayouter.SubtreeShapes for single nodes.
protected  double spacing
          The spacing between subtrees used for the different moving operations.
protected  DataProvider subtreeShapeProvider
          The provider of GenericTreeLayouter.SubtreeShapes for whole subtrees.
 
Fields inherited from interface y.layout.tree.NodePlacer
DIRECTION_ANY, DIRECTION_EAST, DIRECTION_NONE, DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_WEST
 
Constructor Summary
protected AbstractRotatableNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
          Creates a new instance of AbstractRotatableNodePlacer whose direction is specified by the given modification matrix.
 
Method Summary
 java.util.Comparator createComparator()
          Creates a Comparator for outgoing edges that takes the rotation into account.
 java.util.Comparator createFromSketchComparator()
          Delegates to createComparator().
 Processor createProcessor(GenericTreeLayouter layouter, LayoutGraph graph, Node currentRoot)
          Creates an optional Processor for pre- and post-processing.
protected  y.layout.tree.SubtreeShapeRotated createRootNodeShape(Node node)
          Returns the rotated subtree shape for the given node.
protected  y.layout.tree.SubtreeShapeRotated createSubtreeShape(Node node)
          Returns the rotated subtree shape for the subtree rooted at the given node.
protected abstract  byte determineChildConnector(Node child)
          Determines a connector direction for the given child node.
 void determineChildConnectors(Node localRoot, DataMap connectorMap)
          Provides the direction of the connector to the SubtreeShape for each child node.
 AbstractRotatableNodePlacer.Matrix getModificationMatrix()
          Returns the modification matrix that defines the direction of the subtree.
protected  PortConstraint getPortConstraint(Node localRoot)
          Returns the target PortConstraint for the local root's incoming edge.
protected  YPoint getSourcePointAbs(Edge edge)
          Returns the absolute source point of the given edge depending on the rotation of this NodePlacer.
 double getSpacing()
          Returns the spacing between subtrees.
 GenericTreeLayouter.SubtreeShape placeSubtree(DataProvider nodeShapeProvider, DataProvider subtreeShapeProvider, LayoutGraph graph, Node localRoot, byte parentConnectorDirection)
          Initializes the local data structures and then delegates the work to the abstract variant of this method (placeSubtree(Node, byte)).
protected abstract  y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot, byte parentConnectorDirection)
          Arranges the local root relative to the rotated subtree shapes of its children.
 void setSpacing(double spacing)
          Specifies the spacing between subtrees.
protected  byte translateDirectionToModel(byte realDirection)
          Translates the given real direction of the resulting layout to the model direction of this AbstractRotatableNodePlacer.
protected  byte translateDirectionToReal(byte modelDirection)
          Translates the given model direction to the real direction in the resulting layout.
static YPoint translatePoint(AbstractRotatableNodePlacer.Matrix modificationMatrix, YPoint realWorldPoint)
          Translates a point from the real layout direction to the model direction using the given modification matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spacing

protected double spacing
The spacing between subtrees used for the different moving operations.


graph

protected LayoutGraph graph
The graph instance this NodePlacer is working on.


modificationMatrix

protected final AbstractRotatableNodePlacer.Matrix modificationMatrix
The active modification matrix.


subtreeShapeProvider

protected DataProvider subtreeShapeProvider
The provider of GenericTreeLayouter.SubtreeShapes for whole subtrees.


nodeShapeProvider

protected DataProvider nodeShapeProvider
The provider of GenericTreeLayouter.SubtreeShapes for single nodes.


createdChildren

protected java.util.List createdChildren
The list containing the created children.

Constructor Detail

AbstractRotatableNodePlacer

protected AbstractRotatableNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
Creates a new instance of AbstractRotatableNodePlacer whose direction is specified by the given modification matrix.

Parameters:
modificationMatrix - the transformation matrix for the NodePlacer
Method Detail

createProcessor

public Processor createProcessor(GenericTreeLayouter layouter,
                                 LayoutGraph graph,
                                 Node currentRoot)
Creates an optional Processor for pre- and post-processing.

This implementation returns null. Hence, no pre- or post-processing is done.

Specified by:
createProcessor in interface NodePlacer
Parameters:
layouter - the current GenericTreeLayouter instance
graph - the input graph
currentRoot - the root node handled by this NodePlacer
Returns:
null

getSourcePointAbs

protected YPoint getSourcePointAbs(Edge edge)
Returns the absolute source point of the given edge depending on the rotation of this NodePlacer.

This method translates the source point according to the rotation described by the modification matrix. It should be used instead of LayoutGraph.getSourcePointAbs(Edge).

It can be used in an implementation of placeSubtree(Node, byte).

Parameters:
edge - the edge whose absolute source point should be calculated
Returns:
the translated absolute source point for the given edge and current modification matrix

placeSubtree

protected abstract y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot,
                                                                  byte parentConnectorDirection)
Arranges the local root relative to the rotated subtree shapes of its children.

This is the main method that must be implemented by subclasses. For calculations and locations subclasses should use the corresponding methods of AbstractRotatableNodePlacer which already consider the modification matrix.

Parameters:
localRoot - the local root node
parentConnectorDirection - the direction specifier for the connector of the local root node to its parent node
Returns:
the merged subtree shape that contains the local root node and all its children

createRootNodeShape

protected y.layout.tree.SubtreeShapeRotated createRootNodeShape(Node node)
Returns the rotated subtree shape for the given node.

This is a convenience method that retrieves a rotated subtree shape for a single node from the corresponding DataProvider. This shape may be modified and returned by placeSubtree(Node, byte).

 
This method can first be called during the execution of placeSubtree(Node, byte). Otherwise, the DataProvider for querying results will not have been initialized yet.
Parameters:
node - the node
Returns:
the subtree shape for the given node

createSubtreeShape

protected y.layout.tree.SubtreeShapeRotated createSubtreeShape(Node node)
Returns the rotated subtree shape for the subtree rooted at the given node.

This is a convenience method that retrieves a subtree shape of a complete subtree from the corresponding DataProvider.

 
This method can first be called during the execution of placeSubtree(Node, byte). Before, the DataProvider for querying results will not have been initialized yet.
Parameters:
node - the local root node
Returns:
the rotated subtree shape of the subtree rooted at the given local root node

determineChildConnectors

public void determineChildConnectors(Node localRoot,
                                     DataMap connectorMap)
Provides the direction of the connector to the SubtreeShape for each child node.

This implementation uses determineChildConnector(Node) and the modification matrix to retrieve the direction for the connectors.

Specified by:
determineChildConnectors in interface NodePlacer
Parameters:
localRoot - the local root
connectorMap - the map that must be used for storing the direction specifiers of the child nodes
See Also:
determineChildConnector(Node)

getPortConstraint

protected PortConstraint getPortConstraint(Node localRoot)
Returns the target PortConstraint for the local root's incoming edge.

This method translates the PortConstraint according to the rotation described by the modification matrix. It should be used instead of PortConstraint.getTPC(LayoutGraph, Edge).

This method may be used in placeSubtree(Node, byte) to route the edges to the according port. It may be overridden to provide constant PortConstraints for each node.

Parameters:
localRoot - the local root
Returns:
the PortConstraint for the incoming edge of the local root or PortConstraint.ANY_SIDE if no PortConstraint is assigned for that edge

translateDirectionToReal

protected byte translateDirectionToReal(byte modelDirection)
Translates the given model direction to the real direction in the resulting layout.

This method is used in determineChildConnectors(Node, DataMap) to be able to return the real connector direction.

Parameters:
modelDirection - the model direction
Returns:
the real direction
Throws:
java.lang.IllegalArgumentException - if translation for the given model direction is not implemented

translateDirectionToModel

protected byte translateDirectionToModel(byte realDirection)
Translates the given real direction of the resulting layout to the model direction of this AbstractRotatableNodePlacer.

This method is used in placeSubtree(Node, byte) to be able to retrieve the model direction for the connector

Parameters:
realDirection - the real direction
Returns:
the model direction
Throws:
java.lang.IllegalArgumentException - if translation for the given real direction is not implemented

determineChildConnector

protected abstract byte determineChildConnector(Node child)
Determines a connector direction for the given child node.

This method is called by determineChildConnectors(Node, DataMap) and must be implemented by subclasses. Implementations can assume the default direction (top-to-bottom) for their arrangement.

Parameters:
child - the child node
Returns:
a direction specifier as defined in the NodePlacer interface

placeSubtree

public GenericTreeLayouter.SubtreeShape placeSubtree(DataProvider nodeShapeProvider,
                                                     DataProvider subtreeShapeProvider,
                                                     LayoutGraph graph,
                                                     Node localRoot,
                                                     byte parentConnectorDirection)
Initializes the local data structures and then delegates the work to the abstract variant of this method (placeSubtree(Node, byte)).

Specified by:
placeSubtree in interface NodePlacer
Parameters:
nodeShapeProvider - the DataProvider for obtaining an initial shape of the root node
subtreeShapeProvider - the DataProvider for accessing the pre-calculated shapes of the subtrees
graph - the input graph
localRoot - the root of the subtree that should be arranged by this method
parentConnectorDirection - the direction specifier for the connector of the local root node to its parent node
Returns:
the merged GenericTreeLayouter.SubtreeShape for the subtree rooted at the local root node
See Also:
placeSubtree(Node, byte)

getModificationMatrix

public AbstractRotatableNodePlacer.Matrix getModificationMatrix()
Returns the modification matrix that defines the direction of the subtree.

Returns:
the modification matrix

createComparator

public java.util.Comparator createComparator()
Creates a Comparator for outgoing edges that takes the rotation into account.

Returns:
the Comparator that considers the rotation

translatePoint

public static YPoint translatePoint(AbstractRotatableNodePlacer.Matrix modificationMatrix,
                                    YPoint realWorldPoint)
Translates a point from the real layout direction to the model direction using the given modification matrix.

Parameters:
modificationMatrix - the modification matrix to use for the translation
realWorldPoint - the point with coordinates from the real world
Returns:
the translated point with coordinates from the model

getSpacing

public double getSpacing()
Returns the spacing between subtrees.

The spacing needs to be non-negative.

Returns:
the distance between subtrees
See Also:
setSpacing(double)

setSpacing

public void setSpacing(double spacing)
Specifies the spacing between subtrees.

The spacing needs to be non-negative.

Default Value:
The default value is 20.
Parameters:
spacing - the distance between subtrees
Throws:
java.lang.IllegalArgumentException - if the given spacing is negative
Sample Graphs:

Spacing 20 using SimpleNodePlacer

Spacing 50 using SimpleNodePlacer

createFromSketchComparator

public java.util.Comparator createFromSketchComparator()
Delegates to createComparator().

Specified by:
createFromSketchComparator in interface FromSketchNodePlacer
Returns:
the From Sketch Comparator
See Also:
createComparator()

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