public class DefaultEdgePathCropper extends Object implements IEdgePathCropper
IEdgePathCropper
.Modifier and Type | Field and Description |
---|---|
static IEdgePathCropper |
INSTANCE
A singleton instance.
|
Constructor and Description |
---|
DefaultEdgePathCropper() |
Modifier and Type | Method and Description |
---|---|
protected double |
calculateTotalCropLength(IArrow arrow,
boolean atSource)
Calculates the total length the edge path is cropped.
|
GeneralPath |
cropEdgePath(IEdge edge,
boolean atSource,
IArrow arrow,
GeneralPath path)
Crops the provided
path at one end of an edge. |
GeneralPath |
cropEdgePathAtArrow(boolean atSource,
IArrow arrow,
GeneralPath path)
Crops an edge's path at the source or target side with respect to the given arrow.
|
protected GeneralPath |
cropEdgePathAtPortGeometry(IEdge edge,
boolean atSource,
IArrow arrow,
GeneralPath path)
Crops an edge's path at the source or target side at the
port geometry with respect to
the given arrow. |
double |
getExtraCropLength()
Gets an extra length the edge is cropped.
|
protected PointD |
getIntersection(INode node,
IShapeGeometry nodeShapeGeometry,
IEdge edge,
PointD inner,
PointD outer)
Finds the intersection between a node and the edge.
|
protected IShapeGeometry |
getNodeGeometry(INode node)
Returns the
geometry that is used to crop the edge at the node outline. |
protected IShapeGeometry |
getPortGeometry(IPort port)
Returns the
geometry that is used to crop the edge at the port outline if CroppingAtPortEnabled
is set to true . |
protected GeneralPath |
handleEmptyPath(IEdge edge,
boolean atSource,
IArrow arrow,
GeneralPath path)
Handles the edge path cropping if
cropEdgePath(IEdge, boolean, IArrow, GeneralPath) would result in a cleared
path. |
boolean |
isCroppingAtPortEnabled()
Gets the value that determines if the edge path is cropped at the port or at the node bounds.
|
protected boolean |
isInside(PointD location,
INode node,
IShapeGeometry nodeShapeGeometry,
IEdge edge)
Checks whether a given point is inside a node's shape geometry with respect to the edge that is being calculated.
|
void |
setCroppingAtPortEnabled(boolean value)
Sets the value that determines if the edge path is cropped at the port or at the node bounds.
|
void |
setExtraCropLength(double value)
Sets an extra length the edge is cropped.
|
public static final IEdgePathCropper INSTANCE
Note that this is an immutable instance that cannot be cast to the DefaultEdgePathCropper
type.
protected double calculateTotalCropLength(IArrow arrow, boolean atSource)
This method can be overridden to change the length that is cropped from an edge. The default implementation returns the
sum of ExtraCropLength
, arrow length
and
arrow crop length
arrow
- The arrow at this edge end.atSource
- True
if the crop length should be calculated at the edge source. False
otherwise.cropEdgePath(IEdge, boolean, IArrow, GeneralPath)
,
cropEdgePathAtArrow(boolean, IArrow, GeneralPath)
public final GeneralPath cropEdgePath(IEdge edge, boolean atSource, IArrow arrow, GeneralPath path)
path
at one end of an edge.
If CroppingAtPortEnabled
is True
this implementation delegates to
cropEdgePathAtPortGeometry(IEdge, boolean, IArrow, GeneralPath)
. Otherwise the edge path is cropped at the
node geometry
. If this would result in an empty path, the cropping is delegated to handleEmptyPath(IEdge, boolean, IArrow, GeneralPath)
instead.
cropEdgePath
in interface IEdgePathCropper
edge
- The edge whose path is to be cropped.atSource
- Whether to crop the source or target side of the path.arrow
- The arrow that is used at the end of the edge.path
- The path to crop.public final GeneralPath cropEdgePathAtArrow(boolean atSource, IArrow arrow, GeneralPath path)
The path
is cropped by the length calculateTotalCropLength(IArrow, boolean)
returns for arrow
and atSource
.
atSource
- if set to true
the source side is cropped.arrow
- The arrow to consider for the cropping.path
- The edge's path to crop.protected GeneralPath cropEdgePathAtPortGeometry(IEdge edge, boolean atSource, IArrow arrow, GeneralPath path)
port geometry
with respect to
the given arrow.edge
- The edge whose path is to be cropped.atSource
- Whether to crop the source or target side of the path.arrow
- The arrow that is used at the end of the edge.path
- The path to crop.public final double getExtraCropLength()
The default value is 0.
setExtraCropLength(double)
protected PointD getIntersection(INode node, IShapeGeometry nodeShapeGeometry, IEdge edge, PointD inner, PointD outer)
protected IShapeGeometry getNodeGeometry(INode node)
geometry
that is used to crop the edge at the node outline.
The default implementation queries the node style renderer
for an implementation of IShapeGeometry
. This method can be overridden to return an arbitrary geometry
for a node.
node
- The node the edge should be cropped at.geometry
of the node.protected IShapeGeometry getPortGeometry(IPort port)
geometry
that is used to crop the edge at the port outline if CroppingAtPortEnabled
is set to true
.
The default implementation returns null
. This method can be overridden to return an arbitrary geometry
for a port.
port
- The port the edge should be cropped at.geometry
of the port.isCroppingAtPortEnabled()
protected GeneralPath handleEmptyPath(IEdge edge, boolean atSource, IArrow arrow, GeneralPath path)
cropEdgePath(IEdge, boolean, IArrow, GeneralPath)
would result in a cleared
path.
This method is called by cropEdgePath(IEdge, boolean, IArrow, GeneralPath)
if CroppingAtPortEnabled
is False
and cropping the edge path at the node geometry
would result in an
empty path.
The default implementation is to GeneralPath.clear()
the edge path.
edge
- The edge whose path is to be cropped.atSource
- Whether to crop the source or target side of the path.arrow
- The arrow that is used at the end of the edge.path
- The path to crop.public final boolean isCroppingAtPortEnabled()
The default is false
.
setCroppingAtPortEnabled(boolean)
protected boolean isInside(PointD location, INode node, IShapeGeometry nodeShapeGeometry, IEdge edge)
public final void setCroppingAtPortEnabled(boolean value)
The default is false
.
value
- The CroppingAtPortEnabled to set.isCroppingAtPortEnabled()
public final void setExtraCropLength(double value)
The default value is 0.
value
- The ExtraCropLength to set.getExtraCropLength()