TStyle
- The exact type of style to use for this instance.public abstract class PathBasedEdgeStyleRenderer<TStyle extends IEdgeStyle> extends Object implements IEdgeStyleRenderer, IPathGeometry, IBoundsProvider, IVisibilityTestable, IMarqueeTestable, IHitTestable, ILookup, IVisualCreator, IObstacleProvider
IEdgeStyleRenderer
implementations that are based on the calculation of a
GeneralPath
.Modifier and Type | Field and Description |
---|---|
protected GeneralPath |
path
The path instance that this instance is working with.
|
EMPTY, UNBOUNDED
ALWAYS, NEVER
ALWAYS, NEVER
ALWAYS, NEVER
Constructor and Description |
---|
PathBasedEdgeStyleRenderer(Class<TStyle> edgeStyleType) |
Modifier and Type | Method and Description |
---|---|
protected void |
configure()
Prepares this instance for subsequent calls after the style and edge have been initialized.
|
protected abstract GeneralPath |
createPath()
This method should create the basic uncropped path given the control points.
|
protected static GeneralPath |
createRectangleSelfLoop(double sx,
double sy,
double oppositeX,
double oppositeY,
double tx,
double ty)
Static utility method that creates a rectangular self loop path.
|
protected static GeneralPath |
createRoundSelfLoop(double sx,
double sy,
double oppositeX,
double oppositeY,
double tx,
double ty)
Static utility method that creates a round self loop path.
|
protected GeneralPath |
createSelfLoopPath(boolean roundSelfLoop)
Special implementation that will create a self loop path.
|
Node |
createVisual(IRenderContext context)
This method is called by the framework to create a
Node that will be included into the IRenderContext . |
protected GeneralPath |
cropPath(GeneralPath path)
Crops the edge's path at the nodes.
|
RectD |
getBounds(ICanvasContext context)
Returns a tight rectangular area where the whole rendering would fit into.
|
IBoundsProvider |
getBoundsProvider(IEdge edge,
IEdgeStyle style)
|
protected IBridgeCreator |
getBridgeCreator()
|
ILookup |
getContext(IEdge edge,
IEdgeStyle style)
|
protected IEdge |
getEdge()
Gets the currently configured edge.
|
IHitTestable |
getHitTestable(IEdge edge,
IEdgeStyle style)
Configures the
style and edge parameters and returns this . |
IMarqueeTestable |
getMarqueeTestable(IEdge edge,
IEdgeStyle style)
|
GeneralPath |
getObstacles(IRenderContext context)
Returns
createPath() unless isVisible(ICanvasContext, RectD) yields false for the provided
context and Clip . |
GeneralPath |
getPath()
Returns a representation of the visible path of the edge in form of a
GeneralPath . |
IPathGeometry |
getPathGeometry(IEdge edge,
IEdgeStyle style)
Gets an implementation of the
IPathGeometry interface that can handle the provided edge and its associated
style. |
protected abstract Pen |
getPen()
Gets the pen to use to render the path.
|
abstract int |
getSegmentCount()
Returns the number of "segments" this edge's path consists of.
|
double |
getSelfLoopDistance()
Gets the distance between the node's layout and its self loop control points.
|
protected double |
getSmoothingLength()
Gets the value that determines the radius of the smoothing arcs that can be added to the path at the bends.
|
protected abstract IArrow |
getSourceArrow()
Gets the source arrow from the style.
|
protected Tangent |
getSourceArrowAnchor(IArrow arrow)
Calculate and update the anchor and the source arrow's direction vector.
|
protected TStyle |
getStyle()
Gets the currently configured style.
|
abstract Tangent |
getTangent(double ratio)
Calculates the tangent on the edge's path at the given ratio point.
|
abstract Tangent |
getTangent(int segmentIndex,
double ratio)
Calculates the tangent on the edge's path at the given ratio point for the given segment.
|
protected abstract IArrow |
getTargetArrow()
Gets the target arrow from the style.
|
protected Tangent |
getTargetArrowAnchor(IArrow arrow)
Calculate and update the anchor and the target arrow's direction vector.
|
IVisibilityTestable |
getVisibilityTestable(IEdge edge,
IEdgeStyle style)
|
IVisualCreator |
getVisualCreator(IEdge edge,
IEdgeStyle style)
|
protected boolean |
isAddingBridgesEnabled()
Determines whether the rendered path should use the
BridgeManager to
add bridges to it. . |
boolean |
isHit(IInputModeContext context,
PointD location)
This method is overridden for performance reasons.
|
boolean |
isInBox(IInputModeContext context,
RectD rectangle)
This callback returns
true if the corresponding item is considered to intersect the given rectangular box. |
boolean |
isVisible(ICanvasContext context,
RectD rectangle)
Calls
configure() and test the Edge using the Style for a visible
intersection with the clip bounds. |
<TLookup> TLookup |
lookup(Class<TLookup> type)
Returns an instance that implements the given type or
null . |
protected void |
setEdge(IEdge value)
Sets the currently configured edge.
|
void |
setSelfLoopDistance(double value)
Sets the distance between the node's layout and its self loop control points.
|
protected void |
setStyle(TStyle value)
Sets the currently configured style.
|
Node |
updateVisual(IRenderContext context,
Node oldVisual)
This method updates or replaces a previously created
Node for inclusion in the IRenderContext . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fromRectangle
create
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
protected GeneralPath path
protected void configure()
Upon invocation the Style
and Edge
properties have been populated by the
getVisualCreator(IEdge, IEdgeStyle)
, getBoundsProvider(IEdge, IEdgeStyle)
,
getHitTestable(IEdge, IEdgeStyle)
, or getMarqueeTestable(IEdge, IEdgeStyle)
methods.
Subclasses which override this method have to call the base implementation, first.
protected abstract GeneralPath createPath()
protected static final GeneralPath createRectangleSelfLoop(double sx, double sy, double oppositeX, double oppositeY, double tx, double ty)
sx
- The x coordinate of the source port.sy
- The y coordinate of the source port.oppositeX
- The x coordinate of the single control point.oppositeY
- The y coordinate of the single control point.tx
- The x coordinate of the target port.ty
- The y coordinate of the target port.createSelfLoopPath(boolean)
protected static final GeneralPath createRoundSelfLoop(double sx, double sy, double oppositeX, double oppositeY, double tx, double ty)
sx
- The x coordinate of the source port.sy
- The y coordinate of the source port.oppositeX
- The x coordinate of the single control point.oppositeY
- The y coordinate of the single control point.tx
- The x coordinate of the target port.ty
- The y coordinate of the target port.createSelfLoopPath(boolean)
protected GeneralPath createSelfLoopPath(boolean roundSelfLoop)
public Node createVisual(IRenderContext context)
IVisualCreator
Node
that will be included into the IRenderContext
.
CanvasControl
uses this interface through the ICanvasObjectDescriptor
to populate the visual canvas object tree.
createVisual
in interface IVisualCreator
context
- The context that describes where the visual will be used.null
.IVisualCreator.updateVisual(IRenderContext, Node)
protected GeneralPath cropPath(GeneralPath path)
This implementation uses the IEdgePathCropper
instances found in the ILookup.lookup(Class)
of the source
and target port of the edge to perform the actual cropping.
path
- The path that should be cropped.public RectD getBounds(ICanvasContext context)
IBoundsProvider
If calculating the bounds is too expensive or the rendering is not bound to a certain area, this method may return
RectD.INFINITE
. If nothing is rendered, this method should return an empty rectangle, where either or both
the width and height is non-positive or RectD.EMPTY
.
getBounds
in interface IBoundsProvider
context
- the context to calculate the bounds forRectD.EMPTY
to indicate an unbound areapublic IBoundsProvider getBoundsProvider(IEdge edge, IEdgeStyle style)
getBoundsProvider
in interface IEdgeStyleRenderer
edge
- The edge to retrieve the bounds provider for. The value will be stored in the Edge
property.style
- The style to associate with the edge. The value will be stored in the Style
property.this
getBounds(ICanvasContext)
protected IBridgeCreator getBridgeCreator()
IBridgeCreator
to use for adding bridges
to the
created path
.
The return value of this method (which may be null
) will be passed to the BridgeManager
's BridgeManager.addBridges(IRenderContext, GeneralPath, IBridgeCreator)
method.
null
.public ILookup getContext(IEdge edge, IEdgeStyle style)
style
and edge
parameters, does not call configure()
and returns
this
.
As this method may be called often it will not automatically call configure()
, instead subclasses should ensure
that in the lookup(Class)
method call they should call configure()
only if needed, i.e. if they decide
to return this
or an instance that depends on a correctly configured this
.
getContext
in interface IEdgeStyleRenderer
edge
- The edge to query the context for. The value will be stored in the Edge
property.style
- The style to associate with the edge. The value will be stored in the Style
property.this
lookup(Class)
protected final IEdge getEdge()
setEdge(IEdge)
public IHitTestable getHitTestable(IEdge edge, IEdgeStyle style)
style
and edge
parameters and returns this
.
This implementation does not call configure()
. If subclasses depend on a configured instance in an override of
isHit(IInputModeContext, PointD)
, they need to override this method, too and call configure()
if
the base call returns a non-null
value.
getHitTestable
in interface IEdgeStyleRenderer
edge
- The edge to provide an instance forstyle
- The style to use for the querying hit testsnull
to indicate that the edge cannot be hit tested.isHit(IInputModeContext, PointD)
,
configure()
,
IEdgeStyleRenderer.getHitTestable(IEdge, IEdgeStyle)
public IMarqueeTestable getMarqueeTestable(IEdge edge, IEdgeStyle style)
getMarqueeTestable
in interface IEdgeStyleRenderer
edge
- The edge to query marquee intersection tests. The value will be stored in the Edge
property.style
- The style to associate with the edge. The value will be stored in the Style
property.this
isInBox(IInputModeContext, RectD)
public GeneralPath getObstacles(IRenderContext context)
createPath()
unless isVisible(ICanvasContext, RectD)
yields false
for the provided
context and Clip
.getObstacles
in interface IObstacleProvider
context
- The context to yield the obstacles for.null
or the result of createPath()
.IObstacleProvider
public GeneralPath getPath()
IPathGeometry
GeneralPath
.getPath
in interface IPathGeometry
null
if this is not applicable for the current geometry.public final IPathGeometry getPathGeometry(IEdge edge, IEdgeStyle style)
IPathGeometry
interface that can handle the provided edge and its associated
style.getPathGeometry
in interface IEdgeStyleRenderer
edge
- The edge to provide an instance forstyle
- The style to use for the paintingthis
configure()
,
getTangent(double)
,
getTangent(int, double)
,
getSegmentCount()
,
getPath()
protected abstract Pen getPen()
null
.public abstract int getSegmentCount()
This method is part of the IPathGeometry
interface, that is implemented by this class. This interface will be
returned by getPathGeometry(IEdge, IEdgeStyle)
.
getSegmentCount
in interface IPathGeometry
-1
if there is no such thing as a segment for this edge.getPathGeometry(IEdge, IEdgeStyle)
public final double getSelfLoopDistance()
setSelfLoopDistance(double)
protected double getSmoothingLength()
This implementation returns 0.0d
, which effectively turns off path smoothing.
protected abstract IArrow getSourceArrow()
protected Tangent getSourceArrowAnchor(IArrow arrow)
arrow
- The arrow to calculate the anchor for.protected final TStyle getStyle()
setStyle(IEdgeStyle)
public abstract Tangent getTangent(double ratio)
This method is part of the IPathGeometry
interface, that is implemented by this class. This interface will be
returned by getPathGeometry(IEdge, IEdgeStyle)
.
getTangent
in interface IPathGeometry
ratio
- a value in [0,1] where 0 is the source's end and 1 is at the target's end of the visible edge pathgetPathGeometry(IEdge, IEdgeStyle)
public abstract Tangent getTangent(int segmentIndex, double ratio)
This method is part of the IPathGeometry
interface, that is implemented by this class. This interface will be
returned by getPathGeometry(IEdge, IEdgeStyle)
.
getTangent
in interface IPathGeometry
segmentIndex
- the segment to use for the calculationratio
- a value in [0,1] where 0 is the source's end and 1 is at the target's end of the segmentgetTangent(double)
,
getSegmentCount()
,
getPathGeometry(IEdge, IEdgeStyle)
protected abstract IArrow getTargetArrow()
protected Tangent getTargetArrowAnchor(IArrow arrow)
arrow
- The arrow to calculate the anchor for.public IVisibilityTestable getVisibilityTestable(IEdge edge, IEdgeStyle style)
style
and edge
parameters, does not call configure()
and returns
this
.
Unlike most of the other methods this implementation does not call configure()
. If the subclass
implementation depends on this instance to be configured, it needs to call Configure
in
isVisible(ICanvasContext, RectD)
.
getVisibilityTestable
in interface IEdgeStyleRenderer
edge
- The edge to query visibility tests. The value will be stored in the Edge
property.style
- The style to associate with the edge. The value will be stored in the Style
property.this
isVisible(ICanvasContext, RectD)
public IVisualCreator getVisualCreator(IEdge edge, IEdgeStyle style)
getVisualCreator
in interface IEdgeStyleRenderer
edge
- The edge to retrieve the IVisualCreator
for. The value will be stored in the Edge
property.style
- The style to associate with the edge. The value will be stored in the Style
property.this
createVisual(IRenderContext)
,
updateVisual(IRenderContext, Node)
protected boolean isAddingBridgesEnabled()
BridgeManager
to
add bridges to it.
.getBridgeCreator()
public boolean isHit(IInputModeContext context, PointD location)
This implementation uses isVisible(ICanvasContext, RectD)
as an early exit indicator. If IsVisible
returns false
for a certain rectangle, the instance will not be configured but a non-hit will be assumed.
Otherwise this instance will be configured and the standard path based hit test routine
Subclasses should not depend on the fact that configure()
has already been called. This may not be the case.
If your subclass depends on Configure being called, override getHitTestable(IEdge, IEdgeStyle)
and call configure()
after the base class call.
isHit
in interface IHitTestable
context
- the context the hit test is performed inlocation
- the coordinates in world coordinate systemgetHitTestable(IEdge, IEdgeStyle)
,
configure()
public boolean isInBox(IInputModeContext context, RectD rectangle)
IMarqueeTestable
true
if the corresponding item is considered to intersect the given rectangular box.
This method may return false
if the item cannot be selected using a selection marquee or optionally if the item
is only partially contained within the box.
Implementations should respect the HitTestRadius
if
marquee selections should behave differently on different zoom levels.
isInBox
in interface IMarqueeTestable
context
- the current input mode contextrectangle
- the box describing the marquee's boundstrue
if the item is considered to be captured by the marqueepublic boolean isVisible(ICanvasContext context, RectD rectangle)
configure()
and test the Edge
using the Style
for a visible
intersection with the clip bounds.
This simple implementation uses getBounds(ICanvasContext)
to determine the visibility. Subclasses may choose to
override this behavior for improved performance but need to make sure to call configure()
if they depend
on a configured instance.
isVisible
in interface IVisibilityTestable
context
- the current canvas contextrectangle
- the clip boundstrue
if the edge may be painted within the clip bounds.getVisibilityTestable(IEdge, IEdgeStyle)
public <TLookup> TLookup lookup(Class<TLookup> type)
ILookup
null
.
Typically, this method will be called in order to obtain a different view or
aspect of the current instance. This is quite similar to casting or using
a super type or interface of this instance, but is not limited to inheritance or
compile time constraints. An instance implementing this method is not
required to return non-null
implementations for the types, nor does it
have to return the same instance any time. Also it depends on the
type and context whether the instance returned stays up to date or needs to
be reobtained for subsequent use.protected final void setEdge(IEdge value)
value
- The Edge to set.getEdge()
public final void setSelfLoopDistance(double value)
value
- The SelfLoopDistance to set.getSelfLoopDistance()
protected final void setStyle(TStyle value)
value
- The Style to set.getStyle()
public Node updateVisual(IRenderContext context, Node oldVisual)
IVisualCreator
Node
for inclusion in the IRenderContext
.
The CanvasControl
uses this method to give implementations a chance to update an existing
Visual that has previously been created by the same instance during a call to IVisualCreator.createVisual(IRenderContext)
.
Implementation may update the oldVisual
and return that same reference, or create a new visual and return the
new instance or null
.
updateVisual
in interface IVisualCreator
context
- The context that describes where the visual will be used in.oldVisual
- The visual instance that had been returned the last time the IVisualCreator.createVisual(IRenderContext)
method was called on
this instance.oldVisual
, if this instance modified the visual, or a new visual that should replace the existing one in the
canvas object visual tree.IVisualCreator.createVisual(IRenderContext)
,
ICanvasObjectDescriptor
,
CanvasControl