Search this API

y.layout
Class FixNodeLayoutStage

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.FixNodeLayoutStage
All Implemented Interfaces:
Layouter, LayoutStage

public class FixNodeLayoutStage
extends AbstractLayoutStage

FixNodeLayoutStage fixes the initial position of either a single node or the alignment of the bounding box of several nodes (but not the positions of the individual nodes).

The absolute coordinates of the fix point are the same before and after invoking the core layout algorithm. However, the relative coordinates of the nodes are altered by the core layout algorithm.

 
Sample Graphs:

Fixing a single node in different layouts

Fixing a single node in different layouts

Field Summary
static byte FIX_POINT_POLICY_CENTER
          Fix point calculation policy specifying that the center of a rectangle containing all fixed nodes is considered the fix point.
static byte FIX_POINT_POLICY_LOWER_LEFT
          Fix point calculation policy specifying that the lower left corner of a rectangle containing all fixed nodes is considered the fix point.
static byte FIX_POINT_POLICY_LOWER_RIGHT
          Fix point calculation policy specifying that the lower right corner of a rectangle containing all fixed nodes is considered the fix point.
static byte FIX_POINT_POLICY_UPPER_LEFT
          Fix point calculation policy specifying that the upper left corner of a rectangle containing all fixed nodes is considered the fix point.
static byte FIX_POINT_POLICY_UPPER_RIGHT
          Fix point calculation policy specifying that the upper right corner of a rectangle containing all fixed nodes is considered the fix point.
static java.lang.Object FIXED_NODE_DPKEY
          A DataProvider key for determining the nodes that should be considered fixed
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
FixNodeLayoutStage()
          Creates a new FixNodeLayoutStage instance with default settings.
FixNodeLayoutStage(Layouter coreLayouter)
          Creates a new FixNodeLayoutStage instance using the given algorithm as core layout algorithm.
 
Method Summary
protected  java.awt.geom.Rectangle2D calculateBounds(LayoutGraph graph, NodeList fixed)
          Calculates the bounding box of the specified nodes.
protected  YPoint calculateFixPoint(LayoutGraph graph, NodeList fixed)
          Calculates the fix point for the specified nodes in the specified graph.
protected  YPoint calculateFixPoint(java.awt.geom.Rectangle2D bounds)
          Calculates the fix point of the specified rectangle according to the policy returned by getFixPointPolicy().
 boolean canLayout(LayoutGraph graph)
          Accepts all graphs that can be handled by the core layout algorithm.
 void doLayout(LayoutGraph graph)
          Delegates to the core layout algorithm and moves the fixed point back to its initial location.
 byte getFixPointPolicy()
          Returns the fix point calculation policy used in calculateFixPoint(Rectangle2D) to determine which point in the corresponding rectangle should be considered fixed.
 boolean isIncludingEdges()
          Returns whether or not subgraph edges are taken into account when calculating the bounding box of the fixed nodes.
 boolean isIncludingLabels()
          Returns whether or not label geometries are taken into account when calculating the bounding box of the fixed nodes.
 void setFixPointPolicy(byte policy)
          Specifies the fix point calculation policy used in calculateFixPoint(Rectangle2D) to determine which point in the corresponding rectangle should be considered fixed.
 void setIncludingEdges(boolean includingEdges)
          Specifies whether or not subgraph edges are taken into account when calculating the bounding box of the fixed nodes.
 void setIncludingLabels(boolean includingLabels)
          Specifies whether or not label geometries are taken into account when calculating the bounding box of the fixed nodes.
 
Methods inherited from class y.layout.AbstractLayoutStage
canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_NODE_DPKEY

public static final java.lang.Object FIXED_NODE_DPKEY
A DataProvider key for determining the nodes that should be considered fixed


FIX_POINT_POLICY_CENTER

public static final byte FIX_POINT_POLICY_CENTER
Fix point calculation policy specifying that the center of a rectangle containing all fixed nodes is considered the fix point.

See Also:
setFixPointPolicy(byte), Constant Field Values

FIX_POINT_POLICY_UPPER_LEFT

public static final byte FIX_POINT_POLICY_UPPER_LEFT
Fix point calculation policy specifying that the upper left corner of a rectangle containing all fixed nodes is considered the fix point.

See Also:
setFixPointPolicy(byte), Constant Field Values

FIX_POINT_POLICY_UPPER_RIGHT

public static final byte FIX_POINT_POLICY_UPPER_RIGHT
Fix point calculation policy specifying that the upper right corner of a rectangle containing all fixed nodes is considered the fix point.

See Also:
setFixPointPolicy(byte), Constant Field Values

FIX_POINT_POLICY_LOWER_RIGHT

public static final byte FIX_POINT_POLICY_LOWER_RIGHT
Fix point calculation policy specifying that the lower right corner of a rectangle containing all fixed nodes is considered the fix point.

See Also:
setFixPointPolicy(byte), Constant Field Values

FIX_POINT_POLICY_LOWER_LEFT

public static final byte FIX_POINT_POLICY_LOWER_LEFT
Fix point calculation policy specifying that the lower left corner of a rectangle containing all fixed nodes is considered the fix point.

See Also:
setFixPointPolicy(byte), Constant Field Values
Constructor Detail

FixNodeLayoutStage

public FixNodeLayoutStage()
Creates a new FixNodeLayoutStage instance with default settings.


FixNodeLayoutStage

public FixNodeLayoutStage(Layouter coreLayouter)
Creates a new FixNodeLayoutStage instance using the given algorithm as core layout algorithm.

Parameters:
coreLayouter - the core layout algorithm
Method Detail

getFixPointPolicy

public byte getFixPointPolicy()
Returns the fix point calculation policy used in calculateFixPoint(Rectangle2D) to determine which point in the corresponding rectangle should be considered fixed.

Returns:
one of the valid fix point calculation policies
See Also:
setFixPointPolicy(byte)

setFixPointPolicy

public void setFixPointPolicy(byte policy)
Specifies the fix point calculation policy used in calculateFixPoint(Rectangle2D) to determine which point in the corresponding rectangle should be considered fixed.

Default Value:
The default value is FIX_POINT_POLICY_CENTER
Parameters:
policy - one of the valid fix point calculation policies
Throws:
java.lang.IllegalArgumentException - if the specified policy is unknown

isIncludingEdges

public boolean isIncludingEdges()
Returns whether or not subgraph edges are taken into account when calculating the bounding box of the fixed nodes.

Returns:
true if subgraph edges are taken into account, false otherwise
See Also:
setIncludingEdges(boolean), calculateBounds(LayoutGraph, NodeList)

setIncludingEdges

public void setIncludingEdges(boolean includingEdges)
Specifies whether or not subgraph edges are taken into account when calculating the bounding box of the fixed nodes.

Default Value:
The default value is false. Subgraph edges are not taken into account.
Parameters:
includingEdges - true if subgraph edges should be taken into account, false otherwise
See Also:
calculateBounds(LayoutGraph, NodeList)

isIncludingLabels

public boolean isIncludingLabels()
Returns whether or not label geometries are taken into account when calculating the bounding box of the fixed nodes.

Returns:
true if label geometries are taken into account, false otherwise
See Also:
setIncludingLabels(boolean), calculateBounds(LayoutGraph, NodeList)

setIncludingLabels

public void setIncludingLabels(boolean includingLabels)
Specifies whether or not label geometries are taken into account when calculating the bounding box of the fixed nodes.

Default Value:
The default value is false. Label geometries are not taken into account.
Parameters:
includingLabels - true if label geometries should be taken into account, false otherwise
See Also:
calculateBounds(LayoutGraph, NodeList)

canLayout

public boolean canLayout(LayoutGraph graph)
Accepts all graphs that can be handled by the core layout algorithm.

If there is no core layout algorithm, all graphs are accepted.

Parameters:
graph - the input graph
Returns:
true if there is no core layout algorithm or the core layout algorithm accepts the graph, false otherwise
See Also:
Layouter.doLayout(LayoutGraph)

doLayout

public void doLayout(LayoutGraph graph)
Delegates to the core layout algorithm and moves the fixed point back to its initial location.

Parameters:
graph - the input graph
See Also:
Layouter.canLayout(LayoutGraph)

calculateFixPoint

protected YPoint calculateFixPoint(LayoutGraph graph,
                                   NodeList fixed)
Calculates the fix point for the specified nodes in the specified graph.

The default implementation calls calculateBounds(LayoutGraph, NodeList) and calculateFixPoint(Rectangle2D).

This method is called by doLayout(LayoutGraph) to determine the point that will have the same coordinates before and after invoking the core layout algorithm. It may be overridden to introduce a custom policy for retrieving the fix point.

Parameters:
graph - the graph associated with the specified nodes
fixed - the list of nodes for which a fix point has to be determined
Returns:
the fix point for the specified nodes in the specified graph
See Also:
getFixPointPolicy(), calculateBounds(LayoutGraph, NodeList), calculateFixPoint(Rectangle2D)

calculateFixPoint

protected YPoint calculateFixPoint(java.awt.geom.Rectangle2D bounds)
Calculates the fix point of the specified rectangle according to the policy returned by getFixPointPolicy().

If the specified rectangle is null or the rectangle has negative width or negative height then null will be returned.

This method is called by calculateFixPoint(LayoutGraph, NodeList). It may be overridden to introduce a custom policy for retrieving the fix point.

Parameters:
bounds - the rectangle for which to determine the fix point
Returns:
the fix point of the specified rectangle or null if nothing should be fixed
Throws:
java.lang.IllegalArgumentException - if the current fix point policy is invalid
See Also:
getFixPointPolicy()

calculateBounds

protected java.awt.geom.Rectangle2D calculateBounds(LayoutGraph graph,
                                                    NodeList fixed)
Calculates the bounding box of the specified nodes.

The calculated bounds may contain edges and/or labels.

This method is called by calculateFixPoint(LayoutGraph, NodeList) and may be overridden to customize the size of the bounds.

Parameters:
graph - the graph associated with the specified nodes
fixed - the list of nodes for which to determine the bounding box
Returns:
the bounding box of the specified nodes
See Also:
isIncludingEdges(), isIncludingLabels(), calculateFixPoint(LayoutGraph, NodeList)

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