public abstract class AbstractEdgeStyle extends Object implements IEdgeStyle, Cloneable
IEdgeStyle
.
The only method that needs to be implemented by subclasses is createVisual(IRenderContext, IEdge)
, however to
improve rendering performance it is highly recommended to implement at least
updateVisual(IRenderContext, Node, IEdge)
, too.
This implementation differs from the straightforward IEdgeStyle
implementation in that there is no visible
separation between the style and its
IEdgeStyleRenderer
. Instead the renderer used by the base class is fixed and delegates all calls back to the
style instance.
Modifier | Constructor and Description |
---|---|
protected |
AbstractEdgeStyle()
Initializes a new instance of the
AbstractEdgeStyle class. |
Modifier and Type | Method and Description |
---|---|
protected void |
addArrows(IRenderContext context,
VisualGroup group,
IEdge edge,
GeneralPath edgePath,
IArrow sourceArrow,
IArrow targetArrow)
Convenience method that adds the arrows to a given container.
|
AbstractEdgeStyle |
clone()
Creates a new object that is a copy of the current instance.
|
protected abstract Node |
createVisual(IRenderContext context,
IEdge edge)
Callback that creates the visual.
|
protected GeneralPath |
cropPath(IEdge edge,
IArrow sourceArrow,
IArrow targetArrow,
GeneralPath path)
Convenience method that crops the edge's path at the nodes.
|
protected RectD |
getBounds(ICanvasContext context,
IEdge edge)
Gets the bounds of the visual for the edge in the given context.
|
protected GeneralPath |
getPath(IEdge edge)
Gets the path of the edge.
|
IEdgeStyleRenderer |
getRenderer()
Gets the renderer implementation for this instance.
|
protected int |
getSegmentCount(IEdge edge)
Gets the number of segments of the edge.
|
protected Tangent |
getSourceArrowAnchor(GeneralPath path,
IArrow arrow)
Convenience method that calculates the source arrow anchor and direction for a a given arrow and path.
|
protected Tangent |
getTangent(IEdge edge,
double ratio)
Gets the tangent to the edge at the specified ratio and the corresponding touch point.
|
protected Tangent |
getTangent(IEdge edge,
int segmentIndex,
double ratio)
Gets the tangent to the edge at the specified ratio of a segment of the edge and the corresponding touch point.
|
protected Tangent |
getTargetArrowAnchor(GeneralPath path,
IArrow arrow)
Convenience method that calculates the target arrow anchor and direction for a a given arrow and path.
|
protected boolean |
isHit(IInputModeContext context,
PointD location,
IEdge edge)
Determines whether the visual representation of the edge has been hit at the given location.
|
protected boolean |
isInBox(IInputModeContext context,
RectD rectangle,
IEdge edge)
Determines whether the visualization for the specified edge is included in the marquee selection.
|
protected boolean |
isVisible(ICanvasContext context,
RectD rectangle,
IEdge edge)
Determines whether the visualization for the specified edge is visible in the context.
|
protected Object |
lookup(IEdge edge,
Class type)
Performs the
ILookup.lookup(Class) operation for the IEdgeStyleRenderer.getContext(IEdge, IEdgeStyle)
that has been queried from the Renderer . |
protected void |
updateArrows(IRenderContext context,
VisualGroup group,
IEdge edge,
GeneralPath edgePath,
IArrow sourceArrow,
IArrow targetArrow)
Convenience method that updates the arrows in a given container.
|
protected Node |
updateVisual(IRenderContext context,
Node oldVisual,
IEdge edge)
Callback that updates the visual previously created by
createVisual(IRenderContext, IEdge) . |
protected AbstractEdgeStyle()
AbstractEdgeStyle
class.protected void addArrows(IRenderContext context, VisualGroup group, IEdge edge, GeneralPath edgePath, IArrow sourceArrow, IArrow targetArrow)
context
- The context for the rendering.group
- The container to which the arrows should be added.edge
- The edge that is being rendered.edgePath
- The edge path.sourceArrow
- The source arrow.targetArrow
- The target arrow.public AbstractEdgeStyle clone()
Immutable subclasses should consider returning this
.
clone
in interface ICloneable
clone
in class Object
Object.clone()
.Object.clone()
protected abstract Node createVisual(IRenderContext context, IEdge edge)
This method is called in response to a IVisualCreator.createVisual(IRenderContext)
call to the instance that has
been queried from the Renderer
.
context
- The render context.edge
- The edge to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.updateVisual(IRenderContext, Node, IEdge)
protected GeneralPath cropPath(IEdge edge, IArrow sourceArrow, IArrow targetArrow, 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.
edge
- The edge that is being rendered.path
- The path that should be cropped.sourceArrow
- The source arrow instance.targetArrow
- The target arrow instance.protected RectD getBounds(ICanvasContext context, IEdge edge)
This method is called in response to a IBoundsProvider.getBounds(ICanvasContext)
call to the instance that has
been queried from the Renderer
. This implementation simply yields a rectangle
containing. the locations of the source port
and the target port
of the edge and the locations of all its bends
.
context
- The canvas context.edge
- The edge to which this style instance is assigned.protected GeneralPath getPath(IEdge edge)
edge
- The edge.public final IEdgeStyleRenderer getRenderer()
The private implementation will delegate all API calls back to this instance.
getRenderer
in interface IEdgeStyle
protected int getSegmentCount(IEdge edge)
edge
- The edge.protected Tangent getSourceArrowAnchor(GeneralPath path, IArrow arrow)
path
- The path of the edge.arrow
- The arrow.protected Tangent getTangent(IEdge edge, double ratio)
edge
- The edge.ratio
- A value between 0 and 1 inclusively that indicates a ratio from the beginning to the end of the path of the edge.protected Tangent getTangent(IEdge edge, int segmentIndex, double ratio)
edge
- The edge.segmentIndex
- Index of the segment of the edge.ratio
- A value between 0 and 1 inclusively that indicates a ratio from the beginning to the end of the segment of the edge.protected Tangent getTargetArrowAnchor(GeneralPath path, IArrow arrow)
path
- The path of the edge.arrow
- The arrow.protected boolean isHit(IInputModeContext context, PointD location, IEdge edge)
This method is called in response to a IHitTestable.isHit(IInputModeContext, PointD)
call to the instance that
has been queried from the Renderer
.
This implementation returns the result of the PointD.hitsPolyline(java.lang.Iterable, double)
method of class PointD
with the polygonal line defined by the source port, the target port and the bends of the edge and the HitTestRadius
of the canvas context
.
context
- The input mode context.location
- The point to test.edge
- The edge to which this style instance is assigned.true
if the specified edge representation is hit; false
otherwise.PointD.hitsPolyline(java.lang.Iterable, double)
protected boolean isInBox(IInputModeContext context, RectD rectangle, IEdge edge)
This method is called in response to a IMarqueeTestable.isInBox(IInputModeContext, RectD)
call to the instance
that has been queried from the Renderer
.
This implementation returns the result of the RectD.intersectsPolyline(java.lang.Iterable)
method of class RectD
with the polygonal line defined by the source port, the target port and the bends of the edge.
context
- The input mode context.rectangle
- The marquee selection box.edge
- The edge to which this style instance is assigned.true
if the specified edge is visible is selected by the marquee rectangle; false
otherwise.protected boolean isVisible(ICanvasContext context, RectD rectangle, IEdge edge)
This method is called in response to a IVisibilityTestable.isVisible(ICanvasContext, RectD)
call to the instance
that has been queried from the Renderer
. This implementation simply tests whether the bounds
intersect the clip.
context
- The canvas context.rectangle
- The clipping rectangle.edge
- The edge to which this style instance is assigned.true
if the specified edge is visible in the clipping rectangle; false
otherwise.protected Object lookup(IEdge edge, Class type)
ILookup.lookup(Class)
operation for the IEdgeStyleRenderer.getContext(IEdge, IEdgeStyle)
that has been queried from the Renderer
.
This implementation yields null
for everything but:
IHitTestable
IVisualCreator
IBoundsProvider
IVisibilityTestable
IMarqueeTestable
ILookup
IPathGeometry
For these interfaces an implementation will be returned that delegates to the methods in this instance.
edge
- The edge to use for the context lookup.type
- The type to query.type
or null
.protected void updateArrows(IRenderContext context, VisualGroup group, IEdge edge, GeneralPath edgePath, IArrow sourceArrow, IArrow targetArrow)
context
- The context for the rendering.group
- The container to which the arrows should be added.edge
- The edge that is being rendered.edgePath
- The edge path.sourceArrow
- The source arrow.targetArrow
- The target arrow.protected Node updateVisual(IRenderContext context, Node oldVisual, IEdge edge)
createVisual(IRenderContext, IEdge)
.
This method is called in response to a IVisualCreator.updateVisual(IRenderContext, Node)
call to the instance
that has been queried from the Renderer
. This implementation simply delegates to createVisual(IRenderContext, IEdge)
so subclasses should override to improve rendering performance.
context
- The render context.oldVisual
- The visual that has been created in the call to createVisual(IRenderContext, IEdge)
.edge
- The edge to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.createVisual(IRenderContext, IEdge)