public class BridgeManager extends Object
Most notably this feature is used to render crossings of IEdge
s with other edges.
To set up bridges in a GraphControl
at the least the following is necessary:
Furthermore, an edge style that supports bridges is necessary; PolylineEdgeStyle
is a good choice. Various other properties can be set to change the defaults, e.g.
how bridges appear
, or which way bridges point
.
Constructor and Description |
---|
BridgeManager()
Initializes a new instance of the
BridgeManager class. |
Modifier and Type | Method and Description |
---|---|
GeneralPath |
addBridges(IRenderContext context,
GeneralPath path,
IBridgeCreator callback)
Core method that will add bridges to a
GeneralPath using the IBridgeCreator callback to determine the
type of the bridges. |
void |
addObstacleProvider(IObstacleProvider provider)
Adds another
IObstacleProvider to query for obstacles. |
void |
dispose()
Disposes of this instance by resetting the
CanvasControl property to null . |
BridgeCrossingPolicy |
getBridgeCrossingPolicy()
Gets the
BridgeCrossingPolicy mode that is used by this instance. |
CanvasControl |
getCanvasControl()
Gets the
CanvasControl that should be managed by this instance. |
double |
getClipMargin()
Gets the margin by which the
Clip should be enlarged to accommodate for clipped away
lines being taken into account for bridge calculation. |
IBridgeCreator |
getDefaultBridgeCreator()
Gets the default implementation of the
IBridgeCreator that will be used if addBridges(IRenderContext, GeneralPath, IBridgeCreator)
is invoked with a null callback argument. |
BridgeCrossingStyle |
getDefaultBridgeCrossingStyle()
Gets the default
BridgeCrossingStyle that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator property. |
double |
getDefaultBridgeHeight()
Gets the default height of a bridge that will be used by the default implementation of the
IBridgeCreator that
is initially assigned to the DefaultBridgeCreator property. |
BridgeOrientationStyle |
getDefaultBridgeOrientationStyle()
Gets the default
BridgeOrientationStyle for bridges that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator property. |
double |
getDefaultBridgeWidth()
Gets the default width of a bridge that will be used by the default implementation of the
IBridgeCreator that is
initially assigned to the DefaultBridgeCreator property. |
long |
getObstacleHash(IRenderContext context)
Gets a hash code that describes the current state of the obstacles.
|
double |
getZoomThreshold()
Gets a threshold value that determines below which zoom level, there should be no more bridge calculation.
|
void |
insertDefaultCustomBridge(IRenderContext context,
GeneralPath path,
PointD start,
PointD end,
double gapLength)
Implementation that will be called by the default value of the
DefaultBridgeCreator
to satisfy requests to IBridgeCreator.createCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double) . |
protected void |
install(CanvasControl canvas)
Installs this manager for the specified
CanvasControl . |
boolean |
isCurvesConsiderationEnabled()
|
void |
registerObstacle(IRenderContext context,
GeneralPath path)
Convenience method that can be called to dynamically register an obstacle path with the context during the rendering.
|
void |
registerObstacleCubicCurve(IRenderContext context,
PointD p1,
PointD cp1,
PointD cp2,
PointD p2)
Convenience method that can be called to dynamically register a single obstacle cubic curve with the context during the
rendering.
|
void |
registerObstacleLine(IRenderContext context,
PointD p1,
PointD p2)
Convenience method that can be called to dynamically register a single obstacle line with the context during the
rendering.
|
void |
registerObstacleQuadCurve(IRenderContext context,
PointD p1,
PointD cp,
PointD p2)
Convenience method that can be called to dynamically register a single obstacle quadratic curve with the context during
the rendering.
|
protected void |
registerObstacles(IRenderContext context)
Called to initialize the context with the obstacles.
|
void |
removeObstacleProvider(IObstacleProvider provider)
Removes a previously
added IObstacleProvider from the list of
registered providers. |
void |
setBridgeCrossingPolicy(BridgeCrossingPolicy value)
Sets the
BridgeCrossingPolicy mode that is used by this instance. |
void |
setCanvasControl(CanvasControl value)
Sets the
CanvasControl that should be managed by this instance. |
void |
setClipMargin(double value)
Sets the margin by which the
Clip should be enlarged to accommodate for clipped away
lines being taken into account for bridge calculation. |
void |
setCurvesConsiderationEnabled(boolean value)
|
void |
setDefaultBridgeCreator(IBridgeCreator value)
Sets the default implementation of the
IBridgeCreator that will be used if addBridges(IRenderContext, GeneralPath, IBridgeCreator)
is invoked with a null callback argument. |
void |
setDefaultBridgeCrossingStyle(BridgeCrossingStyle value)
Sets the default
BridgeCrossingStyle that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator property. |
void |
setDefaultBridgeHeight(double value)
Sets the default height of a bridge that will be used by the default implementation of the
IBridgeCreator that
is initially assigned to the DefaultBridgeCreator property. |
void |
setDefaultBridgeOrientationStyle(BridgeOrientationStyle value)
Sets the default
BridgeOrientationStyle for bridges that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator property. |
void |
setDefaultBridgeWidth(double value)
Sets the default width of a bridge that will be used by the default implementation of the
IBridgeCreator that is
initially assigned to the DefaultBridgeCreator property. |
void |
setZoomThreshold(double value)
Sets a threshold value that determines below which zoom level, there should be no more bridge calculation.
|
protected void |
uninstall(CanvasControl canvas)
Reverts the
install(CanvasControl) method. |
public BridgeManager()
BridgeManager
class.
Initially the DefaultBridgeCreator
will be set to an instance that will delegate to
the set of Default
properties in this class and the insertDefaultCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double)
method respectively.
public GeneralPath addBridges(IRenderContext context, GeneralPath path, IBridgeCreator callback)
GeneralPath
using the IBridgeCreator
callback to determine the
type of the bridges.
This method may return path
itself if no crossings have been determined. Otherwise it will return a new path
instance that has the bridges added at the corresponding places.
context
- The context to use.path
- The path to calculate the bridged variant for.callback
- The callback or null
that determines the appearance of the bridges.public void addObstacleProvider(IObstacleProvider provider)
IObstacleProvider
to query for obstacles.
The IObstacleProvider.getObstacles(IRenderContext)
method will be invoked during construction of the obstacles.
provider
- The provider instance to use for later queries.registerObstacles(IRenderContext)
,
removeObstacleProvider(IObstacleProvider)
public void dispose()
CanvasControl
property to null
.public final BridgeCrossingPolicy getBridgeCrossingPolicy()
BridgeCrossingPolicy
mode that is used by this instance.
By default the BridgeCrossingPolicy.HORIZONTAL_BRIDGES_VERTICAL
mode is set.
setBridgeCrossingPolicy(BridgeCrossingPolicy)
public final CanvasControl getCanvasControl()
CanvasControl
that should be managed by this instance.
This method will install(CanvasControl)
a preparation stage
for the IRenderContext
in the provided CanvasControl
via the ILookup.lookup(Class)
mechanism.
setCanvasControl(CanvasControl)
public final double getClipMargin()
Clip
should be enlarged to accommodate for clipped away
lines being taken into account for bridge calculation.
This value should be set to at least half the value of the width of the bridges
used in this context. This is because obstacles might otherwise be clipped from the view and not taken into account for
the calculation of the bridges. By default this value will be 2 more than half of the
DefaultBridgeWidth
.
setClipMargin(double)
public final IBridgeCreator getDefaultBridgeCreator()
IBridgeCreator
that will be used if addBridges(IRenderContext, GeneralPath, IBridgeCreator)
is invoked with a null
callback argument.getDefaultBridgeCrossingStyle()
,
getDefaultBridgeWidth()
,
getDefaultBridgeHeight()
,
insertDefaultCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double)
,
setDefaultBridgeCreator(IBridgeCreator)
public final BridgeCrossingStyle getDefaultBridgeCrossingStyle()
BridgeCrossingStyle
that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator
property.
The default value is BridgeCrossingStyle.ARC
.
IBridgeCreator.getCrossingStyle(IRenderContext)
,
setDefaultBridgeCrossingStyle(BridgeCrossingStyle)
public final double getDefaultBridgeHeight()
IBridgeCreator
that
is initially assigned to the DefaultBridgeCreator
property.
The default value is 5.0d
.
IBridgeCreator.getBridgeHeight(IRenderContext)
,
setDefaultBridgeHeight(double)
public final BridgeOrientationStyle getDefaultBridgeOrientationStyle()
BridgeOrientationStyle
for bridges that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator
property.
The default is BridgeOrientationStyle.UP
.
IBridgeCreator.getOrientationStyle(IRenderContext)
,
setDefaultBridgeOrientationStyle(BridgeOrientationStyle)
public final double getDefaultBridgeWidth()
IBridgeCreator
that is
initially assigned to the DefaultBridgeCreator
property.
The default value is 10.0d
. Setting this value will adjust the ClipMargin
.
IBridgeCreator.getBridgeWidth(IRenderContext)
,
setDefaultBridgeWidth(double)
public long getObstacleHash(IRenderContext context)
This method can be used to get a concise, digest snapshot of the current obstacle locations. Storing that result and
comparing it to another snapshot later allows to determine quickly whether obstacles have changed since the last call.
This is helpful, e.g. in implementations of IEdgeStyle
that support bridges to
not recreate the edge path (including bridges) in IVisualCreator.updateVisual(IRenderContext, javafx.scene.Node)
if no obstacles changed.
context
- The context to inspect.public final double getZoomThreshold()
Since the calculation of the bridges is a costly operation if there are many items visible and bridges are not clearly
visible at low zoom levels, it is convenient to disable the calculation of bridges for these zoom levels to speed up the
rendering process. The default value is 0.3d
.
setZoomThreshold(double)
public void insertDefaultCustomBridge(IRenderContext context, GeneralPath path, PointD start, PointD end, double gapLength)
DefaultBridgeCreator
to satisfy requests to IBridgeCreator.createCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double)
.
This implementation will insert a gap style bridge by first creating a line
to start
and then moving
to end
.
context
- The context for the call.path
- The path to append the next segment to.start
- The coordinates of the starting point of the bridge.end
- The coordinates of the ending point of the bridge.gapLength
- The distance between the starting point and the end point.IBridgeCreator.createCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double)
protected void install(CanvasControl canvas)
CanvasControl
.canvas
- The CanvasControl
.public final boolean isCurvesConsiderationEnabled()
cubic
and
quadratic
) should be considered as obstacles.
This can be a costly operation so the default is false
.
setCurvesConsiderationEnabled(boolean)
public void registerObstacle(IRenderContext context, GeneralPath path)
Normally all obstacles will be registered initially by method
registerObstacles(IRenderContext)
. This method can be called during the rendering phase to register
additional obstacles at a later point in time.
context
- The context to register the obstacles with.path
- The path that describes the obstacles.registerObstacleLine(IRenderContext, PointD, PointD)
public void registerObstacleCubicCurve(IRenderContext context, PointD p1, PointD cp1, PointD cp2, PointD p2)
Normally all obstacles will be registered initially by method
registerObstacles(IRenderContext)
. This method can be called during the rendering phase to register
additional obstacles at a later point in time.
context
- The context to register the obstacles with.p1
- The coordinates of the starting point of the line.cp1
- The coordinates of the first control point of the curve.cp2
- The coordinates of the second control point of the curve.p2
- The coordinates of the ending point of the line.registerObstacleLine(IRenderContext, PointD, PointD)
public void registerObstacleLine(IRenderContext context, PointD p1, PointD p2)
Normally all obstacles will be registered initially by method
registerObstacles(IRenderContext)
. This method can be called during the rendering phase to register
additional obstacles at a later point in time.
context
- The context to register the obstacles with.p1
- The coordinates of the first point of the line.p2
- The coordinates of the second point of the line.registerObstacleLine(IRenderContext, PointD, PointD)
public void registerObstacleQuadCurve(IRenderContext context, PointD p1, PointD cp, PointD p2)
Normally all obstacles will be registered initially by method
registerObstacles(IRenderContext)
. This method can be called during the rendering phase to register
additional obstacles at a later point in time.
context
- The context to register the obstacles with.p1
- The coordinates of the starting point of the line.cp
- The coordinates of the control point of the curve.p2
- The coordinates of the ending point of the line.registerObstacleLine(IRenderContext, PointD, PointD)
protected void registerObstacles(IRenderContext context)
context
- The context that will be used to store the obstacles with.registerObstacle(IRenderContext, GeneralPath)
,
registerObstacleLine(IRenderContext, PointD, PointD)
public void removeObstacleProvider(IObstacleProvider provider)
added
IObstacleProvider
from the list of
registered providers.provider
- The provider instance to remove from this instance.addObstacleProvider(IObstacleProvider)
public final void setBridgeCrossingPolicy(BridgeCrossingPolicy value)
BridgeCrossingPolicy
mode that is used by this instance.
By default the BridgeCrossingPolicy.HORIZONTAL_BRIDGES_VERTICAL
mode is set.
value
- The BridgeCrossingPolicy to set.getBridgeCrossingPolicy()
public final void setCanvasControl(CanvasControl value)
CanvasControl
that should be managed by this instance.
This method will install(CanvasControl)
a preparation stage
for the IRenderContext
in the provided CanvasControl
via the ILookup.lookup(Class)
mechanism.
value
- The CanvasControl to set.getCanvasControl()
public final void setClipMargin(double value)
Clip
should be enlarged to accommodate for clipped away
lines being taken into account for bridge calculation.
This value should be set to at least half the value of the width of the bridges
used in this context. This is because obstacles might otherwise be clipped from the view and not taken into account for
the calculation of the bridges. By default this value will be 2 more than half of the
DefaultBridgeWidth
.
value
- The ClipMargin to set.getClipMargin()
public final void setCurvesConsiderationEnabled(boolean value)
cubic
and
quadratic
) should be considered as obstacles.
This can be a costly operation so the default is false
.
value
- The CurvesConsiderationEnabled to set.isCurvesConsiderationEnabled()
public final void setDefaultBridgeCreator(IBridgeCreator value)
IBridgeCreator
that will be used if addBridges(IRenderContext, GeneralPath, IBridgeCreator)
is invoked with a null
callback argument.value
- The DefaultBridgeCreator to set.getDefaultBridgeCrossingStyle()
,
getDefaultBridgeWidth()
,
getDefaultBridgeHeight()
,
insertDefaultCustomBridge(IRenderContext, GeneralPath, PointD, PointD, double)
,
getDefaultBridgeCreator()
public final void setDefaultBridgeCrossingStyle(BridgeCrossingStyle value)
BridgeCrossingStyle
that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator
property.
The default value is BridgeCrossingStyle.ARC
.
value
- The DefaultBridgeCrossingStyle to set.IBridgeCreator.getCrossingStyle(IRenderContext)
,
getDefaultBridgeCrossingStyle()
public final void setDefaultBridgeHeight(double value)
IBridgeCreator
that
is initially assigned to the DefaultBridgeCreator
property.
The default value is 5.0d
.
value
- The DefaultBridgeHeight to set.IBridgeCreator.getBridgeHeight(IRenderContext)
,
getDefaultBridgeHeight()
public final void setDefaultBridgeOrientationStyle(BridgeOrientationStyle value)
BridgeOrientationStyle
for bridges that will be used by the default implementation of the IBridgeCreator
that is initially assigned to the DefaultBridgeCreator
property.
The default is BridgeOrientationStyle.UP
.
value
- The DefaultBridgeOrientationStyle to set.IBridgeCreator.getOrientationStyle(IRenderContext)
,
getDefaultBridgeOrientationStyle()
public final void setDefaultBridgeWidth(double value)
IBridgeCreator
that is
initially assigned to the DefaultBridgeCreator
property.
The default value is 10.0d
. Setting this value will adjust the ClipMargin
.
value
- The DefaultBridgeWidth to set.IBridgeCreator.getBridgeWidth(IRenderContext)
,
getDefaultBridgeWidth()
public final void setZoomThreshold(double value)
Since the calculation of the bridges is a costly operation if there are many items visible and bridges are not clearly
visible at low zoom levels, it is convenient to disable the calculation of bridges for these zoom levels to speed up the
rendering process. The default value is 0.3d
.
value
- The ZoomThreshold to set.getZoomThreshold()
protected void uninstall(CanvasControl canvas)
install(CanvasControl)
method.canvas
- The CanvasControl
.