public class DefaultPortAllocator extends Object implements IPortAllocator
IPortAllocator
implementation.
It is used by HierarchicLayoutCore
after the sequencing phase.
Constructor and Description |
---|
DefaultPortAllocator()
Creates a new instance of
DefaultPortAllocator with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
assignPorts(LayoutGraph graph,
ILayers layers,
ILayoutDataProvider ldp,
IItemFactory itemFactory)
Assigns source and target port coordinates to each edge of the graph.
|
double |
getDefaultPortBorderGapRatio()
Gets the border gap ratio for the default port.
|
protected double |
getPortBorderGap(LayoutGraph graph,
ILayoutDataProvider ldp,
Node node,
int sideIndex,
double sideLength,
int edgeCount)
Callback method used for determining the port border gap for each node and side.
|
protected double |
getPortBorderGapRatio(LayoutGraph graph,
ILayoutDataProvider ldp,
Node node,
int sideIndex,
double sideLength,
int edgeCount)
Callback method used for determining the port border gap ratio.
|
protected double |
getPortDistanceDelta(LayoutGraph graph,
ILayoutDataProvider ldp,
Node node,
int sideIndex,
double sideLength,
int edgeCount,
double portBorderGap)
Callback method used for determining the distance between two adjacent ports.
|
void |
setDefaultPortBorderGapRatio(double value)
Sets the border gap ratio for the default port.
|
public DefaultPortAllocator()
DefaultPortAllocator
with default settings.setDefaultPortBorderGapRatio(double)
public void assignPorts(LayoutGraph graph, ILayers layers, ILayoutDataProvider ldp, IItemFactory itemFactory)
This method assigns:
PortSide.ANY
ports to appropriate sides.Weak
ports to appropriate positions between strong ones.
This method is called by HierarchicLayoutCore
after the sequencing phase.
assignPorts
in interface IPortAllocator
graph
- the input graphlayers
- the given ILayers
instance containing the layering structureldp
- the ILayoutDataProvider
containing information about the nodes and edges of the graphitemFactory
- the IItemFactory
used for creating and destroying helper structurespublic double getDefaultPortBorderGapRatio()
This ratio determines the gap between a corner of the node and the first assigned port.
The ratio should be greater than 0
.
A value of 0.0d
results in ports being placed directly on the corner of the node (if there is more than one
port).
A value of 0.5d
results in ports being distributed along the side of the node so that the distance between the
corner of the node and the first port is half as wide as the distance between two adjacent ports.
A value of Double.POSITIVE_INFINITY
results in all ports being centered at the side in one point.
IllegalArgumentException
- if the given ratio is negativesetDefaultPortBorderGapRatio(double)
protected double getPortBorderGap(LayoutGraph graph, ILayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount)
It may be overridden for a custom calculation of port border gap on a given node.
graph
- the input graphldp
- the ILayoutDataProvider
containing information about the nodes and edges of the graphnode
- the given nodesideIndex
- the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)sideLength
- the width/height of the sideedgeCount
- the number of edges/ports that connect to this sidegetPortDistanceDelta(LayoutGraph, ILayoutDataProvider, Node, int, double, int, double)
protected double getPortBorderGapRatio(LayoutGraph graph, ILayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount)
See DefaultPortBorderGapRatio
for an explanation.
It may be overridden for a custom calculation of port border gap ratio on a given node.
NodeLayoutDescriptor
instance registered for the given node, this implementation returns the
same value as NodeLayoutDescriptor.getPortBorderGapRatio(int)
. Else, returns the same value as
DefaultPortBorderGapRatio
.graph
- the input graphldp
- the ILayoutDataProvider
containing information about the nodes and edges of the graphnode
- the given nodesideIndex
- the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)sideLength
- the width/height of the sideedgeCount
- the number of edges/ports that connect to this sideprotected double getPortDistanceDelta(LayoutGraph graph, ILayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount, double portBorderGap)
It may be overridden for a custom calculation of the distance between two adjacent ports..
graph
- the input graphldp
- the ILayoutDataProvider
containing information about the nodes and edges of the graphnode
- the given nodesideIndex
- the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)sideLength
- the width/height of the sideedgeCount
- the number of edges/ports that connect to this sideportBorderGap
- the previously calculated port border gappublic void setDefaultPortBorderGapRatio(double value)
This ratio determines the gap between a corner of the node and the first assigned port.
The ratio should be greater than 0
.
A value of 0.0d
results in ports being placed directly on the corner of the node (if there is more than one
port).
A value of 0.5d
results in ports being distributed along the side of the node so that the distance between the
corner of the node and the first port is half as wide as the distance between two adjacent ports.
A value of Double.POSITIVE_INFINITY
results in all ports being centered at the side in one point.
IllegalArgumentException
- if the given ratio is negativevalue
- the border gap ratiogetDefaultPortBorderGapRatio()