public class PortCandidateSet extends Object
PortCandidate
s with the nodes of a graph.
PortCandidate
s defined on nodes specify sides or even exact locations at which edges can be connected. This
means that an edge can be connected to any of the available node ports (unless edge PortCandidate
s are specified
too). Each node PortCandidate
has a capacity, i.e., a maximum number of edges allowed to connect to it.
Information about PortCandidate
s on nodes is held by a IDataProvider
that
stores a PortCandidateSet
for each node and is registered with the graph using key
NODE_PORT_CANDIDATE_SET_DPKEY
.
The PortCandidate
s are retrieved from the PortCandidateSet
through a PortCandidateSet.IEntry
that holds the information about the actual PortCandidate
. This object is also used for retrieving the best
candidate from a PortCandidateSet
based on the cost (lower costs are considered first) and the available
capacity of each candidate. Custom searching for the best PortCandidate
can be achieved by implementing PortCandidateSet.ICandidateMatcher
interface.
Example of node port candidates. Circular ports represent node port candidates on source nodes of each edge. Square and rectangular ports are possible port candidates on the target node. Rectangular ports have zero cost of usage and unit capacity whereas square rectangles have unit cost and capacity.
Not all layout and routing algorithms are able to handle PortCandidate
s. Major layout algorithms that obey them
are HierarchicLayout
,
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.Modifier and Type | Class and Description |
---|---|
static interface |
PortCandidateSet.ICandidateMatcher
|
static interface |
PortCandidateSet.IEntry
This interface represents an entry of a
PortCandidateSet and provides access to the actual PortCandidate
instance and the maximum number of edges allowed to connect to it. |
Modifier and Type | Field and Description |
---|---|
static NodeDpKey<PortCandidateSet> |
NODE_PORT_CANDIDATE_SET_DPKEY
A
DataProvider key for specifying a port candidate set for each node.
|
Constructor and Description |
---|
PortCandidateSet()
Creates a new empty
PortCandidateSet instance. |
Modifier and Type | Method and Description |
---|---|
void |
add(PortCandidate p)
Adds a
PortCandidate with the given capacity to this PortCandidateSet . |
void |
add(PortCandidate p,
int connections)
Adds a
PortCandidate with the given capacity to this PortCandidateSet . |
PortCandidateSet.ICandidateMatcher |
createMatcher()
|
int |
getConnectionCount()
Gets the total number of connections allowed by the
PortCandidate s described by this PortCandidateSet or
Integer.MAX_VALUE if the number is unbounded. |
protected double |
getCost(PortCandidateSet.IEntry entry,
Edge edge,
boolean source,
double xOffset,
double yOffset)
Calculates the penalty cost for the usage of the given
entry and the given parameters. |
IEnumerator<Object> |
getEntries()
|
protected double |
getPriority(PortCandidateSet.IEntry entry,
Edge edge,
boolean source)
Calculates the priority of the given
entry . |
void |
remove(PortCandidateSet.IEntry entry)
Removes the given
entry from the list of candidate entries. |
public static final NodeDpKey<PortCandidateSet> NODE_PORT_CANDIDATE_SET_DPKEY
DataProvider
key for specifying a port candidate set for each node.
public PortCandidateSet()
PortCandidateSet
instance.
Addition of PortCandidate
s to this set
can be performed using
add(PortCandidate, int)
.
public final void add(PortCandidate p)
PortCandidate
with the given capacity to this PortCandidateSet
.
The capacity value defines the maximum number of edges allowed to connect to the candidate. If no limitation for this
number exists, Integer.MAX_VALUE
can be used.
The capacity must be greater than zero.
IllegalArgumentException
- if the given capacity is less than or equal to zerop
- the PortCandidate
to addpublic void add(PortCandidate p, int connections)
PortCandidate
with the given capacity to this PortCandidateSet
.
The capacity value defines the maximum number of edges allowed to connect to the candidate. If no limitation for this
number exists, Integer.MAX_VALUE
can be used.
The capacity must be greater than zero.
IllegalArgumentException
- if the given capacity is less than or equal to zerop
- the PortCandidate
to addconnections
- the capacity of the given portpublic PortCandidateSet.ICandidateMatcher createMatcher()
PortCandidateSet.ICandidateMatcher
that retrieves entries
from this PortCandidateSet
.
Each next best matching candidate is determined based on its cost, its current available capacity and based on whether or not its direction is consistent with the desired one.
This method may be overridden to support custom implementations of PortCandidateSet.ICandidateMatcher
.
PortCandidateSet.ICandidateMatcher
instancepublic int getConnectionCount()
PortCandidate
s described by this PortCandidateSet
or
Integer.MAX_VALUE
if the number is unbounded.PortCandidateSet
protected double getCost(PortCandidateSet.IEntry entry, Edge edge, boolean source, double xOffset, double yOffset)
entry
and the given parameters.
The cost is equal to the cost of usage
of the
associated port candidate
.
This method may be overridden to customize the calculation of the cost of usage of an entry
.
entry
- the entry for which the cost is computededge
- the edge that will connect to the PortCandidate
associated with the entrysource
- true
if the given edge connects to its source node, false
otherwisexOffset
- the preferred X-offset of the port relative to the center of the nodeyOffset
- the preferred Y-offset of the port relative to the center of the nodePortCandidateSet.IEntry
public IEnumerator<Object> getEntries()
IEnumerator
over the list of PortCandidateSet.IEntry
sprotected double getPriority(PortCandidateSet.IEntry entry, Edge edge, boolean source)
entry
.
Higher priority means that the entry will be considered earlier by a PortCandidateSet.ICandidateMatcher
.
This method may be overridden to customize the calculation of the priority of entries
.
entry
- the entry for which the cost is computededge
- the edge that will connect to the PortCandidate
associated with the entrysource
- true
if the given edge connects to its source node, false
otherwisePortCandidateSet.IEntry
public void remove(PortCandidateSet.IEntry entry)
entry
from the list of candidate entries.entry
- the entry to remove