public abstract class AbstractPortStyle extends Object implements IPortStyle, Cloneable
IPortStyle
.
Only createVisual(IRenderContext, IPort)
and getBounds(ICanvasContext, IPort)
need to be implemented
by subclasses, however to improve rendering performance it is highly recommended to implement at least
updateVisual(IRenderContext, Node, IPort)
, too.
This implementation differs from the straightforward IPortStyle
implementation in that there is no visible
separation between the style and its
IPortStyleRenderer
. Instead the renderer used by the base class is fixed and delegates all calls back to the
style instance.
Modifier | Constructor and Description |
---|---|
protected |
AbstractPortStyle()
Initializes a new instance of the
AbstractPortStyle class. |
Modifier and Type | Method and Description |
---|---|
AbstractPortStyle |
clone()
Creates a new object that is a copy of the current instance.
|
protected abstract Node |
createVisual(IRenderContext context,
IPort port)
Callback that creates the visual.
|
protected abstract RectD |
getBounds(ICanvasContext context,
IPort port)
Callback that returns the bounds of the visual for the port in the given context.
|
IPortStyleRenderer |
getRenderer()
Gets the renderer implementation for this instance.
|
protected boolean |
isHit(IInputModeContext context,
PointD location,
IPort port)
Determines whether the visual representation of the port has been hit at the given location.
|
protected boolean |
isInBox(IInputModeContext context,
RectD rectangle,
IPort port)
Determines whether the visualization for the specified port is included in the marquee selection.
|
protected boolean |
isVisible(ICanvasContext context,
RectD rectangle,
IPort port)
Determines whether the visualization for the specified port is visible in the context.
|
protected Object |
lookup(IPort port,
Class type)
Performs the
ILookup.lookup(Class) operation for the IPortStyleRenderer.getContext(IPort, IPortStyle)
that has been queried from the Renderer . |
protected Node |
updateVisual(IRenderContext context,
Node oldVisual,
IPort port)
Callback that updates the visual previously created by
createVisual(IRenderContext, IPort) . |
protected AbstractPortStyle()
AbstractPortStyle
class.public AbstractPortStyle 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, IPort port)
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.port
- The port to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.updateVisual(IRenderContext, Node, IPort)
protected abstract RectD getBounds(ICanvasContext context, IPort port)
context
- The canvas context.port
- The port to which this style instance is assigned.public final IPortStyleRenderer getRenderer()
The private implementation will delegate all API calls back to this instance.
getRenderer
in interface IPortStyle
protected boolean isHit(IInputModeContext context, PointD location, IPort port)
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 bounds
to determine whether the port has been
hit.
context
- The input mode context.location
- The point to test.port
- The port to which this style instance is assigned.true
if the specified port representation is hit; false
otherwise.protected boolean isInBox(IInputModeContext context, RectD rectangle, IPort port)
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.port
- The port to which this style instance is assigned.true
if the specified port is visible is selected by the marquee rectangle; false
otherwise.protected boolean isVisible(ICanvasContext context, RectD rectangle, IPort port)
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.port
- The port to which this style instance is assigned.true
if the specified port is visible in the clipping rectangle; false
otherwise.protected Object lookup(IPort port, Class type)
ILookup.lookup(Class)
operation for the IPortStyleRenderer.getContext(IPort, IPortStyle)
that has been queried from the Renderer
.
This implementation yields null
for everything but:
For these interfaces an implementation will be returned that delegates to the methods in this instance.
port
- The port to use for the context lookup.type
- The type to query.type
or null
.protected Node updateVisual(IRenderContext context, Node oldVisual, IPort port)
createVisual(IRenderContext, IPort)
.
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, IPort)
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, IPort)
.port
- The port to which this style instance is assigned.IVisualCreator.createVisual(IRenderContext)
interface.createVisual(IRenderContext, IPort)