public class TemplatePortStyleRenderer extends Object implements IPortStyleRenderer, IBoundsProvider, IVisibilityTestable, IMarqueeTestable, IHitTestable, ILookup, IVisualCreator
IPortStyleRenderer
interface that can render TemplatePortStyle
instances.TemplatePortStyle
EMPTY, UNBOUNDED
ALWAYS, NEVER
ALWAYS, NEVER
ALWAYS, NEVER
Constructor and Description |
---|
TemplatePortStyleRenderer() |
Modifier and Type | Method and Description |
---|---|
protected void |
arrange(Node portControl)
Arranges the port control according to the location of the port and the
getRenderSize() . |
protected void |
configure()
Prepares this instance for subsequent calls after the style and port have been initialized.
|
Node |
createVisual(IRenderContext context)
Creates the visual by delegating to
TemplatePortStyle.createControl(IRenderContext, IPort) and then initializing
the control with the context. |
RectD |
getBounds(ICanvasContext context)
Returns a tight rectangular area where the whole rendering would fit into.
|
IBoundsProvider |
getBoundsProvider(IPort port,
IPortStyle style)
|
protected PointD |
getCenter()
Gets the center of the port.
|
ILookup |
getContext(IPort port,
IPortStyle style)
|
IHitTestable |
getHitTestable(IPort port,
IPortStyle style)
|
IMarqueeTestable |
getMarqueeTestable(IPort port,
IPortStyle style)
|
protected GeneralPath |
getNormalizedOutline(TemplatePortStyle style)
Gets the normalized outline by delegating to
NormalizedOutline . |
protected IPort |
getPort()
Gets the currently configured port.
|
protected SizeD |
getPreferredSize(IRenderContext context)
Gets the preferred size for the current configuration.
|
SizeD |
getPreferredSize(IRenderContext context,
IPort port,
TemplatePortStyle style)
Calculates the preferred size for the given port and style.
|
protected SizeD |
getRenderSize()
Gets the size of the rendering from the style.
|
protected TemplatePortStyle |
getStyle()
Gets the currently configured style.
|
IVisibilityTestable |
getVisibilityTestable(IPort port,
IPortStyle style)
|
IVisualCreator |
getVisualCreator(IPort port,
IPortStyle style)
|
boolean |
isHit(IInputModeContext context,
PointD location)
Determines if something has been hit at the given coordinates in the world coordinate system.
|
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 Port using the Style for a visible
intersection with the clip bounds. |
<TLookup> TLookup |
lookup(Class<TLookup> type)
Implements the
ILookup interface. |
protected Object |
lookupContext(TemplatePortStyle style,
IPort port,
Class type)
Delegates to the
TemplatePortStyle 's
ContextLookup . |
protected void |
setPort(IPort value)
Sets the currently configured port.
|
protected void |
setStyle(TemplatePortStyle value)
Sets the currently configured style.
|
Node |
updateVisual(IRenderContext context,
Node oldVisual)
Updates the
Node correspondingly. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fromRectangle
create
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
protected void arrange(Node portControl)
getRenderSize()
.portControl
- The port control.protected void configure()
Upon invocation the Style
and Port
properties have been populated by the
getVisualCreator(IPort, IPortStyle)
, getBoundsProvider(IPort, IPortStyle)
,
getHitTestable(IPort, IPortStyle)
, or getMarqueeTestable(IPort, IPortStyle)
methods.
public final Node createVisual(IRenderContext context)
TemplatePortStyle.createControl(IRenderContext, IPort)
and then initializing
the control with the context.createVisual
in interface IVisualCreator
context
- The context for the creation.IVisualCreator.updateVisual(IRenderContext, Node)
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(IPort port, IPortStyle style)
getBoundsProvider
in interface IPortStyleRenderer
port
- The port to retrieve the bounds provider for. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
getBounds(ICanvasContext)
protected final PointD getCenter()
public ILookup getContext(IPort port, IPortStyle style)
style
and port
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 IPortStyleRenderer
port
- The port to query the context for. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
lookup(Class)
public IHitTestable getHitTestable(IPort port, IPortStyle style)
getHitTestable
in interface IPortStyleRenderer
port
- The port to query hit test with. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
isHit(IInputModeContext, PointD)
public IMarqueeTestable getMarqueeTestable(IPort port, IPortStyle style)
getMarqueeTestable
in interface IPortStyleRenderer
port
- The port to query marquee intersection tests. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
isInBox(IInputModeContext, RectD)
protected GeneralPath getNormalizedOutline(TemplatePortStyle style)
NormalizedOutline
.protected final IPort getPort()
setPort(IPort)
protected SizeD getPreferredSize(IRenderContext context)
public SizeD getPreferredSize(IRenderContext context, IPort port, TemplatePortStyle style)
context
- The render context which can be null
.port
- The port instance.style
- The style instance to apply.getPreferredSize(IRenderContext)
protected SizeD getRenderSize()
RenderSize
.protected final TemplatePortStyle getStyle()
setStyle(TemplatePortStyle)
public IVisibilityTestable getVisibilityTestable(IPort port, IPortStyle style)
style
and port
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 IPortStyleRenderer
port
- The port to query visibility tests. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
isVisible(ICanvasContext, RectD)
public IVisualCreator getVisualCreator(IPort port, IPortStyle style)
getVisualCreator
in interface IPortStyleRenderer
port
- The port to retrieve the IVisualCreator
for. The value will be stored in the Port
property.style
- The style to associate with the port. The value will be stored in the Style
property.this
createVisual(IRenderContext)
,
updateVisual(IRenderContext, Node)
public boolean isHit(IInputModeContext context, PointD location)
IHitTestable
Implementations should inspect the HitTestRadius
and
take the value into account when performing hit tests. This allows the user to hit elements even if the zoom level is
very small and allows for accurate hit tests at greater zoom levels.
isHit
in interface IHitTestable
context
- the context the hit test is performed inlocation
- the coordinates in world coordinate systempublic 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 Port
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 port may be painted within the clip bounds.getVisibilityTestable(IPort, IPortStyle)
public <TLookup> TLookup lookup(Class<TLookup> type)
ILookup
interface.
This method will be used by default if getContext(IPort, IPortStyle)
has been queried for a lookup
implementation. Note that it cannot be assumed that configure()
has already been invoked. However, normally Port
and Style
will be correctly configured if invoked directly after GetContext
. Subclass
implementations should make sure to configure this instance before they return this
as a result of a successful
lookup. This implementation will check if type.IsInstanceOfType(this)
and will call configure()
on
success and return this
.
protected Object lookupContext(TemplatePortStyle style, IPort port, Class type)
TemplatePortStyle
's
ContextLookup
.protected final void setPort(IPort value)
value
- The Port to set.getPort()
protected final void setStyle(TemplatePortStyle value)
value
- The Style to set.getStyle()
public final Node updateVisual(IRenderContext context, Node oldVisual)
Node
correspondingly.updateVisual
in interface IVisualCreator
context
- The context for the creation.oldVisual
- The currently rendered visual.IVisualCreator.createVisual(IRenderContext)
,
ICanvasObjectDescriptor
,
CanvasControl