public abstract class AbstractNodeStyle extends Object implements INodeStyle, Cloneable
INodeStyle
.
The only method that needs to be implemented by subclasses is createVisual(IRenderContext, INode)
, however to
improve rendering performance it is highly recommended to implement at least
updateVisual(IRenderContext, Node, INode)
, too.
This implementation differs from the straightforward INodeStyle
implementation in that there is no visible
separation between the style and its
INodeStyleRenderer
. Instead the renderer used by the base class is fixed and delegates all calls back to the
style instance.
Modifier | Constructor and Description |
---|---|
protected |
AbstractNodeStyle()
Initializes a new instance of the
AbstractNodeStyle class. |
Modifier and Type | Method and Description |
---|---|
AbstractNodeStyle |
clone()
Creates a new object that is a copy of the current instance.
|
protected abstract Node |
createVisual(IRenderContext context,
INode node)
Callback that creates the visual.
|
protected RectD |
getBounds(ICanvasContext context,
INode node)
Gets the bounds of the visual for the node in the given context.
|
protected PointD |
getIntersection(INode node,
PointD inner,
PointD outer)
Gets the intersection of a line with the visual representation of the node.
|
protected GeneralPath |
getOutline(INode node)
Gets the outline of the visual style.
|
INodeStyleRenderer |
getRenderer()
Gets the renderer implementation for this instance.
|
protected boolean |
isHit(IInputModeContext context,
PointD location,
INode node)
Determines whether the visual representation of the node has been hit at the given location.
|
protected boolean |
isInBox(IInputModeContext context,
RectD rectangle,
INode node)
Determines whether the visualization for the specified node is included in the marquee selection.
|
protected boolean |
isInside(INode node,
PointD location)
Determines whether the provided point is geometrically inside the visual bounds of the node.
|
protected boolean |
isVisible(ICanvasContext context,
RectD rectangle,
INode node)
Determines whether the visualization for the specified node is visible in the context.
|
protected Object |
lookup(INode node,
Class type)
Performs the
ILookup.lookup(Class) operation for the INodeStyleRenderer.getContext(INode, INodeStyle)
that has been queried from the Renderer . |
protected Node |
updateVisual(IRenderContext context,
Node oldVisual,
INode node)
Callback that updates the visual previously created by
createVisual(IRenderContext, INode) . |
protected AbstractNodeStyle()
AbstractNodeStyle
class.public AbstractNodeStyle 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, INode node)
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.node
- The node to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.updateVisual(IRenderContext, Node, INode)
protected RectD getBounds(ICanvasContext context, INode node)
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 the
Layout
.
context
- The canvas context.node
- The node to which this style instance is assigned.protected PointD getIntersection(INode node, PointD inner, PointD outer)
This method is called in response to a IShapeGeometry.getIntersection(PointD, PointD)
call to the instance that
has been queried from the Renderer
. This implementation simply uses the outline
to determine the intersection or the Layout
if the outline is null
. If it is feasible
to determine the intersection point for the current shape, this method should be implemented in addition to getOutline(INode)
to improve performance.
node
- The node to which this style instance is assigned.inner
- The coordinates of a point lying inside
the shape.outer
- The coordinates of a point lying outside the shape.null
, otherwise.isInside(INode, PointD)
protected GeneralPath getOutline(INode node)
This implementation yields null
to indicate that the Layout
depicts the outline.
Implementing this method influences the behavior of isInside(INode, PointD)
and getIntersection(INode, PointD, PointD)
since the default implementations delegate to it.
node
- The node to which this style instance is assigned.null
.public final INodeStyleRenderer getRenderer()
The private implementation will delegate all API calls back to this instance.
getRenderer
in interface INodeStyle
protected boolean isHit(IInputModeContext context, PointD location, INode node)
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 uses the outline
to determine whether the node has been hit.
context
- The canvas context.location
- The point to test.node
- The node to which this style instance is assigned.true
if the specified node representation is hit; false
otherwise.protected boolean isInBox(IInputModeContext context, RectD rectangle, INode node)
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 simply tests whether the bounds
intersect the marquee box.
context
- The input mode context.rectangle
- The marquee selection box.node
- The node to which this style instance is assigned.true
if the specified node is visible is selected by the marquee rectangle; false
otherwise.protected boolean isInside(INode node, PointD location)
This method is called in response to a IShapeGeometry.isInside(PointD)
call to the instance that has been
queried from the Renderer
. This implementation simply uses the outline
to determine whether the point is contained or the Layout
if the outline is null
. If
it is feasible to determine whether a given point lies inside the shape, this method should be implemented in addition
to getOutline(INode)
to improve performance.
node
- The node to which this style instance is assigned.location
- The point to test.protected boolean isVisible(ICanvasContext context, RectD rectangle, INode node)
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.node
- The node to which this style instance is assigned.true
if the specified node is visible in the clipping rectangle; false
otherwise.protected Object lookup(INode node, Class type)
ILookup.lookup(Class)
operation for the INodeStyleRenderer.getContext(INode, INodeStyle)
that has been queried from the Renderer
.
This implementation yields null
for everything but:
IHitTestable
IVisualCreator
IBoundsProvider
IVisibilityTestable
IMarqueeTestable
ILookup
IShapeGeometry
For these interfaces an implementation will be returned that delegates to the methods in this instance.
node
- The node to use for the context lookup.type
- The type to query.type
or null
.protected Node updateVisual(IRenderContext context, Node oldVisual, INode node)
createVisual(IRenderContext, INode)
.
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, INode)
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, INode)
.node
- The node to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.createVisual(IRenderContext, INode)