Search this API

y.layout.tree
Class DefaultPortAssignment

java.lang.Object
  extended by y.layout.tree.DefaultPortAssignment
All Implemented Interfaces:
PortAssignment

public class DefaultPortAssignment
extends Object
implements PortAssignment

This class provides simple default port assignment strategies.


Field Summary
static byte MODE_NONE
          Mode constant describing the strategy where all ports are reset to the center of their nodes.
static byte MODE_PORT_CONSTRAINTS
          Mode constant describing the strategy where edges having a weak port constraint, i.e., effectively a side constraint, will be anchored at the center of that side no port constraint set will be anchored at the center of the node Edges having a strong port constraint are anchored at that coordinates.
static byte MODE_PORT_DISTRIBUTED_EAST
          Mode constant describing the strategy where edges are distributed evenly at the eastern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_NORTH
          Mode constant describing the strategy where edges are distributed evenly at the northern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_SOUTH
          Mode constant describing the strategy where edges are distributed evenly at the southern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_WEST
          Mode constant describing the strategy where edges are distributed evenly at the western side of their nodes.
 
Constructor Summary
DefaultPortAssignment()
          Creates a new DefaultPortAssignment instance using mode MODE_NONE.
DefaultPortAssignment(byte mode)
          Creates a new DefaultPortAssignment instance using the given mode and the default value for the ratio of the gap between the border and the ports and the gap between the ports themselves.
DefaultPortAssignment(byte mode, double ratio)
          Creates a new DefaultPortAssignment instance using the given mode and a given value for the ratio of the gap between the border and the ports and the gap between the ports themselves.
 
Method Summary
protected  void assignChildEdgeSourcePort(LayoutGraph graph, Node node, Edge edge, int index)
          This method assigns the source port of an edge that goes to a child node.
protected  void assignParentEdgeTargetPort(LayoutGraph graph, Node node, Edge edge)
          This method assigns the target port of the edge that goes to the parent node.
 void assignPorts(LayoutGraph graph, Node node)
          Called by GenericTreeLayouter before the actual layout of the graph takes place.
 double getBorderGapToPortGapRatio()
          Returns the ratio of the gap between the border of the node and the next port and the gap between the ports.
 byte getMode()
          Returns the port assignment mode.
protected  double getPortBorderGap(double sideLength, int edgeCount)
          Callback method used to determine the port border gap for each node and side.
protected  double getPortDistanceDelta(double sideLength, int edgeCount, double portBorderGap)
          Callback method used to determine the distance between two adjacent ports
protected  PortConstraint getSourcePortConstraint(LayoutGraph graph, Edge edge, int index)
          Returns the PortConstraint for the given edge or null if no PortConstraint is set.
protected  PortConstraint getTargetPortConstraint(LayoutGraph graph, Edge edge)
          Returns the PortConstraint for the given edge or null if no PortConstraint is set.
 boolean isReversedPortOrder()
          Indicates if the port assignment is set to reversed order.
 void setBorderGapToPortGapRatio(double borderGapToPortGapRatio)
          Sets the ratio of the gap between the border of the node and the next port and the gap between the ports.
 void setMode(byte mode)
          Sets the port assignment mode.
 void setReversedPortOrder(boolean reversedPortOrder)
          Sets if the port assignment should use a reversed order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_PORT_CONSTRAINTS

public static final byte MODE_PORT_CONSTRAINTS
Mode constant describing the strategy where edges having Edges having a strong port constraint are anchored at that coordinates.

See Also:
Constant Field Values

MODE_PORT_DISTRIBUTED_NORTH

public static final byte MODE_PORT_DISTRIBUTED_NORTH
Mode constant describing the strategy where edges are distributed evenly at the northern side of their nodes.

See Also:
Constant Field Values

MODE_PORT_DISTRIBUTED_SOUTH

public static final byte MODE_PORT_DISTRIBUTED_SOUTH
Mode constant describing the strategy where edges are distributed evenly at the southern side of their nodes.

See Also:
Constant Field Values

MODE_PORT_DISTRIBUTED_EAST

public static final byte MODE_PORT_DISTRIBUTED_EAST
Mode constant describing the strategy where edges are distributed evenly at the eastern side of their nodes.

See Also:
Constant Field Values

MODE_PORT_DISTRIBUTED_WEST

public static final byte MODE_PORT_DISTRIBUTED_WEST
Mode constant describing the strategy where edges are distributed evenly at the western side of their nodes.

See Also:
Constant Field Values

MODE_NONE

public static final byte MODE_NONE
Mode constant describing the strategy where all ports are reset to the center of their nodes.

See Also:
Constant Field Values
Constructor Detail

DefaultPortAssignment

public DefaultPortAssignment()
Creates a new DefaultPortAssignment instance using mode MODE_NONE.


DefaultPortAssignment

public DefaultPortAssignment(byte mode)
Creates a new DefaultPortAssignment instance using the given mode and the default value for the ratio of the gap between the border and the ports and the gap between the ports themselves. The default value is 0.5.
Possible values for mode are:


DefaultPortAssignment

public DefaultPortAssignment(byte mode,
                             double ratio)
Creates a new DefaultPortAssignment instance using the given mode and a given value for the ratio of the gap between the border and the ports and the gap between the ports themselves.
Possible values for mode are:

Method Detail

assignPorts

public void assignPorts(LayoutGraph graph,
                        Node node)
Description copied from interface: PortAssignment
Called by GenericTreeLayouter before the actual layout of the graph takes place. This method assigns both the single incoming edge's target port as well as all source ports for all outgoing child edges. Note that at the time this method gets invoked, GenericTreeLayouter may have reversed some edges in order to normalize the tree structure.

Specified by:
assignPorts in interface PortAssignment
Parameters:
graph - the graph instance the node is part of
node - the node whose adjacent edges' ports should be set

assignParentEdgeTargetPort

protected void assignParentEdgeTargetPort(LayoutGraph graph,
                                          Node node,
                                          Edge edge)
This method assigns the target port of the edge that goes to the parent node.

Parameters:
graph - the graph which contains the node
node - the node
edge - the edge to the parent node

assignChildEdgeSourcePort

protected void assignChildEdgeSourcePort(LayoutGraph graph,
                                         Node node,
                                         Edge edge,
                                         int index)
This method assigns the source port of an edge that goes to a child node.

Parameters:
graph - the graph which contains the node
node - the parent node
edge - the edge to the child node
index - the zero-based index of the child edge

getPortBorderGap

protected double getPortBorderGap(double sideLength,
                                  int edgeCount)
Callback method used to determine the port border gap for each node and side.

Parameters:
sideLength - the width/height of the side
edgeCount - the number of edges/port that connect to this side
Returns:
the absolute gap to be used on both sides of the ports

getPortDistanceDelta

protected double getPortDistanceDelta(double sideLength,
                                      int edgeCount,
                                      double portBorderGap)
Callback method used to determine the distance between two adjacent ports

Parameters:
sideLength - the width/height of the side
edgeCount - the number of edges/port that connect to this side
portBorderGap - the previously calculated port border gap
Returns:
the absolute distance to be used between two adjacent ports

getSourcePortConstraint

protected PortConstraint getSourcePortConstraint(LayoutGraph graph,
                                                 Edge edge,
                                                 int index)
Returns the PortConstraint for the given edge or null if no PortConstraint is set. This implementation uses the PortConstraint data provider that is bound to the graph, if available.

Parameters:
graph - the graph the edge is part of
edge - the edge whose PortConstraint is to be determined
index - the child's index
Returns:
a PortConstraint or null

getTargetPortConstraint

protected PortConstraint getTargetPortConstraint(LayoutGraph graph,
                                                 Edge edge)
Returns the PortConstraint for the given edge or null if no PortConstraint is set. This implementation uses the PortConstraint data provider that is bound to the graph, if available.

Parameters:
graph - the graph the edge is part of
edge - the edge whose PortConstraint is to be determined
Returns:
a PortConstraint or null

getMode

public byte getMode()
Returns the port assignment mode. Possible values are


setMode

public void setMode(byte mode)
Sets the port assignment mode. Possible values are


getBorderGapToPortGapRatio

public double getBorderGapToPortGapRatio()
Returns the ratio of the gap between the border of the node and the next port and the gap between the ports. For example, the default value, 0.5, indicates that the border gap is as wide as half the gap between the ports.


setBorderGapToPortGapRatio

public void setBorderGapToPortGapRatio(double borderGapToPortGapRatio)
Sets the ratio of the gap between the border of the node and the next port and the gap between the ports. For example, 0.5 sets the border gap as wide as half the gap between the ports. Thus, the lower the value is, the wider "spread" the ports at the side of the node.
Note: This setting is only useful for distributed port assignment.


isReversedPortOrder

public boolean isReversedPortOrder()
Indicates if the port assignment is set to reversed order. The default order is from left to right and from top to bottom. Thus, the default value is false.


setReversedPortOrder

public void setReversedPortOrder(boolean reversedPortOrder)
Sets if the port assignment should use a reversed order. If set to true, the order is from right to left and from bottom to top.
Note: This setting is only useful for distributed port assignment.


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