public class DefaultPortAssignment extends Object implements IPortAssignment
DefaultPortAssignment provides some simple port assignment styles.
Ports are either centered on the node, distributed at one side of the node or placed
considering PortConstraints.
| Constructor and Description |
|---|
DefaultPortAssignment()
Creates a new
DefaultPortAssignment instance with default settings. |
DefaultPortAssignment(PortAssignmentMode mode)
Creates a new
DefaultPortAssignment instance using the given port assignment mode and ratio between the border
and the ports and the gap between the ports themselves. |
DefaultPortAssignment(PortAssignmentMode mode,
double ratio)
Creates a new
DefaultPortAssignment instance using the given port assignment mode and ratio between the border
and the ports and the gap between the ports themselves. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
assignChildEdgeSourcePort(LayoutGraph graph,
Node node,
Edge edge,
int index)
Assigns relative coordinates to the source port of the outgoing edge to a child of the given node.
|
protected void |
assignParentEdgeTargetPort(LayoutGraph graph,
Node node,
Edge edge)
Assigns relative coordinates to the target port of the incoming edge from the parent of the given node.
|
void |
assignPorts(LayoutGraph graph,
Node node)
Places the ports of edges connecting to the given node according to the
port assignment mode. |
double |
getBorderGapToPortGapRatio()
Gets the ratio of the border gap (distance between the outer ports to the node border) to the port gap
(distance between adjacent ports).
|
PortAssignmentMode |
getMode()
Gets the mode that describes how ports are placed.
|
protected double |
getPortBorderGap(double sideLength,
int edgeCount)
Determines the distance between the outer ports and the border of the node.
|
protected double |
getPortDistanceDelta(double sideLength,
int edgeCount,
double portBorderGap)
Determines the distance between two adjacent ports.
|
protected PortConstraint |
getSourcePortConstraint(LayoutGraph graph,
Edge edge,
int index)
Retrieves the source
PortConstraint for the given edge. |
protected PortConstraint |
getTargetPortConstraint(LayoutGraph graph,
Edge edge)
Retrieves the target
PortConstraint for the given edge. |
boolean |
isReversedPortOrderEnabled()
Gets whether or not the port assignment should reverse the order of the ports.
|
void |
setBorderGapToPortGapRatio(double value)
Sets the ratio of the border gap (distance between the outer ports to the node border) to the port gap
(distance between adjacent ports).
|
void |
setMode(PortAssignmentMode value)
Sets the mode that describes how ports are placed.
|
void |
setReversedPortOrderEnabled(boolean value)
Sets whether or not the port assignment should reverse the order of the ports.
|
public DefaultPortAssignment()
DefaultPortAssignment instance with default settings.public DefaultPortAssignment(PortAssignmentMode mode)
DefaultPortAssignment instance using the given port assignment mode and ratio between the border
and the ports and the gap between the ports themselves.IllegalArgumentException - if an unknown mode is specified or if the specified ratio is negativemode - one of the predefined port assignment specifierspublic DefaultPortAssignment(PortAssignmentMode mode, double ratio)
DefaultPortAssignment instance using the given port assignment mode and ratio between the border
and the ports and the gap between the ports themselves.IllegalArgumentException - if an unknown mode is specified or if the specified ratio is negativemode - one of the predefined port assignment specifiersratio - the ratio of the distance between outer ports and the border to the distance between any two portsprotected void assignChildEdgeSourcePort(LayoutGraph graph, Node node, Edge edge, int index)
This method is called by assignPorts(LayoutGraph, Node) for each outgoing edge of the given node. It may be
overridden to assign a custom location to the source port of outgoing edges.
PortConstraints despite the
port assignment mode.graph - the input graphnode - the nodeedge - the edge to the child nodeindex - the zero-based index of the child edgeIEdgeLayout.setSourcePoint(YPoint)protected void assignParentEdgeTargetPort(LayoutGraph graph, Node node, Edge edge)
This method is called by assignPorts(LayoutGraph, Node) if the given node has a parent node. It may be
overridden to assign a custom location to the target port of the incoming edge.
PortConstraints despite the
port assignment mode.graph - the input graphnode - the nodeedge - the edge from the parent nodeIEdgeLayout.setTargetPoint(YPoint)public void assignPorts(LayoutGraph graph, Node node)
port assignment mode.assignPorts in interface IPortAssignmentgraph - the input graphnode - the node whose adjacent edges' ports should be placedgetMode()public double getBorderGapToPortGapRatio()
The ratio must have a positive value. When the ratio is 0 the ports will be distributed along the whole side of
the node without a gap between the last port and the corner.
IllegalArgumentException - if the specified ratio is negativePortAssignmentMode.DISTRIBUTED_NORTH).setBorderGapToPortGapRatio(double)public PortAssignmentMode getMode()
IllegalArgumentException - if an unknown mode is specifiedPortAssignmentMode.NONEsetMode(PortAssignmentMode)protected double getPortBorderGap(double sideLength,
int edgeCount)
This implementation calculates the gap according to the number of edges at one side of the node. It also includes the
ratio between border gap and port gap.
This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) to calculate the location of
the first port. It may be overridden to implement a different distribution of ports on the node's side.
sideLength - the width/height of the sideedgeCount - the number of edges that connect to this sideassignChildEdgeSourcePort(LayoutGraph, Node, Edge, int),
getBorderGapToPortGapRatio()protected double getPortDistanceDelta(double sideLength,
int edgeCount,
double portBorderGap)
This implementation calculates the gap according to the number of edges at one side of the node. The edges are distributed keeping the given gap to the border of the node.
This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) to calculate the distance
between two ports. It may be overridden to implement a different distribution of ports on the node's side.
sideLength - the width/height of the sideedgeCount - the number of edges/ports that connect to this sideportBorderGap - the port border gap (i.e. calculated by getPortBorderGap(double, int))assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int),
getPortBorderGap(double, int)protected PortConstraint getSourcePortConstraint(LayoutGraph graph, Edge edge, int index)
PortConstraint for the given edge.
This implementation accesses the IDataProvider registered with
PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY.
This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) in
PortAssignmentMode.PORT_CONSTRAINT.
graph - the input graphedge - the edgeindex - the index of the child that is the target of the given edgePortConstraint or null if no source PortConstraint is specifiedPortConstraint,
PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY,
assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int)protected PortConstraint getTargetPortConstraint(LayoutGraph graph, Edge edge)
PortConstraint for the given edge.
This implementation accesses the IDataProvider registered with
PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY.
This method is called by assignParentEdgeTargetPort(LayoutGraph, Node, Edge) in
PortAssignmentMode.PORT_CONSTRAINT.
graph - the input graphedge - the edgePortConstraint or null if no target PortConstraint is specifiedPortConstraint,
PortConstraintKeys.TARGET_PORT_CONSTRAINT_DPKEY,
assignParentEdgeTargetPort(LayoutGraph, Node, Edge)public boolean isReversedPortOrderEnabled()
The normal order is from left to right and from top to bottom. It will be reversed if this option is enabled.
PortAssignmentMode.DISTRIBUTED_NORTH).false. The normal order is used for the ports.true if the order of the ports are reversed, false otherwisesetReversedPortOrderEnabled(boolean)public void setBorderGapToPortGapRatio(double value)
The ratio must have a positive value. When the ratio is 0 the ports will be distributed along the whole side of
the node without a gap between the last port and the corner.
IllegalArgumentException - if the specified ratio is negativePortAssignmentMode.DISTRIBUTED_NORTH).value - the ratio of the border gap (gap between ports and border) to the port gap (gap between two ports)getBorderGapToPortGapRatio()public void setMode(PortAssignmentMode value)
IllegalArgumentException - if an unknown mode is specifiedPortAssignmentMode.NONEvalue - one of the predefined port assignment specifiersgetMode()public void setReversedPortOrderEnabled(boolean value)
The normal order is from left to right and from top to bottom. It will be reversed if this option is enabled.
PortAssignmentMode.DISTRIBUTED_NORTH).false. The normal order is used for the ports.value - true if the order of the ports are reversed, false otherwiseisReversedPortOrderEnabled()