public class PortConstraint extends Object
PortConstraint
represents a constraint for the source or target port of an edge path.
It determines the location at which an edge path can be connected to its source and/or target node. There exist two
different types of PortConstraint
s:
PortConstraint
s determine the side of the node to which an edge can be connected.PortConstraint
s determine the exact coordinates of the point to which an edge path can be connected. These
coordinates are determined at the time the edge is processed by a layout or routing algorithm and are always interpreted
relative to a node's center.
Sample output of weak port constraints. For both edges, source port constraints are associated with side PortSide.EAST
while target port constraints are associated with side PortSide.WEST
. Red rectangles indicate that edges can be
connected to any point of these sides. Black rectangles represent the selected ports.
Sample output of strong port constraints. For both edges, source port constraints are associated with side PortSide.EAST
while target port constraints are associated with side
PortSide.WEST
. Black rectangles indicate the exact points on the corresponding sides of the nodes to which
edges can be connected.
Information about PortConstraint
s is held by IDataProvider
s that are registered with the graph using
keys PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY
(to specify PortConstraint
s for an edge on its
source node) and PortConstraintKeys.TARGET_PORT_CONSTRAINT_DPKEY
(to specify
PortConstraint
s for an edge on its target node).
Not all layout and routing algorithms are able to handle PortConstraint
s. Major layout algorithms that obey them
are HierarchicLayout
, TreeLayout
,
EdgeRouter
, ChannelEdgeRouter
and BusRouter
.
PortPlacementStage
can be appended to any layout algorithm that cannot handle port constraints in order to
assign edges to the ports specified by PortConstraint
s or
PortCandidate
s after calling the core layout algorithm.PortConstraint
s and
PortCandidate
s (on edges and/or nodes) are defined for a graph, the layout or the routing algorithm will try
to match both of them in order to find an appropriate port. The matching process depends on the actual algorithm.PortConstraintKeys
Modifier and Type | Method and Description |
---|---|
static PortConstraint |
create(PortSide side)
Creates a new
PortConstraint that constrains the edge to connect to the given side of a node and that can be
either strong or weak. |
static PortConstraint |
create(PortSide side,
boolean strong)
Creates a new
PortConstraint that constrains the edge to connect to the given side of a node and that can be
either strong or weak. |
boolean |
equals(Object other)
Returns whether or not this
PortConstraint is equal to another PortConstraint based on whether they are
both strong constraints or not and the side attribute. |
PortSide |
getSide()
Gets the side of the node to which an edge should connect.
|
static PortConstraint |
getSPC(LayoutGraph graph,
Edge e)
Returns the source
PortConstraint associated with the given edge. |
static PortConstraint |
getTPC(LayoutGraph graph,
Edge e)
Returns the target
PortConstraint associated with the given edge. |
int |
hashCode()
Returns a hash code value for this
PortConstraint instance based on whether it is a strong constraint or not and
the side attribute. |
static boolean |
hasPC(LayoutGraph graph,
Edge e)
Checks whether or not there exist source or target
PortConstraint s associated with the given edge. |
static boolean |
hasSPC(LayoutGraph graph,
Edge e)
Checks whether or not there exist source
PortConstraint s associated with the given edge. |
static boolean |
hasTPC(LayoutGraph graph,
Edge e)
Checks whether or not there exist target
PortConstraint s associated with the given edge. |
boolean |
isAtAnySide()
Gets whether or not this
PortConstraint instance is associated with side PortSide.ANY . |
boolean |
isAtEast()
Gets whether or not this
PortConstraint instance is associated with side PortSide.EAST . |
boolean |
isAtNorth()
Gets whether or not this
PortConstraint instance is associated with side PortSide.NORTH . |
boolean |
isAtSouth()
Gets whether or not this
PortConstraint instance is associated with side PortSide.SOUTH . |
boolean |
isAtWest()
Gets whether or not this
PortConstraint instance is associated with side PortSide.WEST . |
boolean |
isStrong()
Gets whether or not this
PortConstraint instance represents a strong constraint. |
String |
toString()
Returns a
String representation of this PortConstraint instance. |
public static final PortConstraint create(PortSide side)
PortConstraint
that constrains the edge to connect to the given side of a node and that can be
either strong or weak.
If the PortConstraint
is strong, the layout or routing algorithm should use the port coordinates of this
constraint.
IllegalArgumentException
- if an unknown side is givenside
- one of the default side specifiersPortConstraint
instancepublic static final PortConstraint create(PortSide side, boolean strong)
PortConstraint
that constrains the edge to connect to the given side of a node and that can be
either strong or weak.
If the PortConstraint
is strong, the layout or routing algorithm should use the port coordinates of this
constraint.
IllegalArgumentException
- if an unknown side is givenside
- one of the default side specifiersstrong
- true
if this PortConstraint
is strong, false
otherwisePortConstraint
instancepublic boolean equals(Object other)
PortConstraint
is equal to another PortConstraint
based on whether they are
both strong constraints or not and the side attribute.equals
in class Object
other
- the reference PortConstraint
object with which to comparetrue
if this PortConstraint
is equal to the given PortConstraint
argument, false
otherwisepublic PortSide getSide()
public static final PortConstraint getSPC(LayoutGraph graph, Edge e)
PortConstraint
associated with the given edge.
To retrieve the IDataProvider
that holds information about source PortConstraint
s, key PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY
is used.
graph
- the input graphe
- the edgePortConstraint
of the given edge or null
if there is nonepublic static final PortConstraint getTPC(LayoutGraph graph, Edge e)
PortConstraint
associated with the given edge.
To retrieve the IDataProvider
that holds information about target PortConstraint
s, key PortConstraintKeys.TARGET_PORT_CONSTRAINT_DPKEY
is used.
graph
- the input graphe
- the edgePortConstraint
of the given edge or null
if there is nonepublic int hashCode()
PortConstraint
instance based on whether it is a strong constraint or not and
the side attribute.public static final boolean hasPC(LayoutGraph graph, Edge e)
PortConstraint
s associated with the given edge.
To retrieve the IDataProvider
s that hold information about source or target PortConstraint
s, keys PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY
and PortConstraintKeys.TARGET_PORT_CONSTRAINT_DPKEY
are used.
PortConstraint
that allows any side
is not considered to be a real constraint and
ignored during this check.graph
- the input graphe
- the edgetrue
if the edge has source or target PortConstraint
s, false
otherwisepublic static final boolean hasSPC(LayoutGraph graph, Edge e)
PortConstraint
s associated with the given edge.
To retrieve the IDataProvider
that holds information about source PortConstraint
s, key PortConstraintKeys.SOURCE_PORT_CONSTRAINT_DPKEY
is used.
PortConstraint
that allows any side
is not considered to be a real constraint and
ignored during this check.graph
- the input graphe
- the edgetrue
if the edge has source PortConstraint
s, false
otherwisepublic static final boolean hasTPC(LayoutGraph graph, Edge e)
PortConstraint
s associated with the given edge.
To retrieve the IDataProvider
that holds information about target PortConstraint
s, key PortConstraintKeys.TARGET_PORT_CONSTRAINT_DPKEY
is used.
PortConstraint
that allows any side
is not considered to be a real constraint and
ignored during this check.graph
- the input graphe
- the edgetrue
if the edge has target PortConstraint
s, false
otherwisepublic boolean isAtAnySide()
PortConstraint
instance is associated with side PortSide.ANY
.true
if the associated side is PortSide.ANY
, false
otherwisepublic boolean isAtEast()
PortConstraint
instance is associated with side PortSide.EAST
.true
if the associated side is PortSide.EAST
, false
otherwisepublic boolean isAtNorth()
PortConstraint
instance is associated with side PortSide.NORTH
.true
if the associated side is PortSide.NORTH
, false
otherwisepublic boolean isAtSouth()
PortConstraint
instance is associated with side PortSide.SOUTH
.true
if the associated side is PortSide.SOUTH
, false
otherwisepublic boolean isAtWest()
PortConstraint
instance is associated with side PortSide.WEST
.true
if the associated side is PortSide.WEST
, false
otherwisepublic boolean isStrong()
PortConstraint
instance represents a strong constraint.
A strong PortConstraint
determines the exact coordinates where the edge path's end should be located.
true
if this PortConstraint
is strong, false
if it is a weak onepublic String toString()
String
representation of this PortConstraint
instance.toString
in class Object
String
representation of the PortConstraint