public class DefaultPortCandidateDescriptor extends Object implements ICanvasObjectDescriptor, IVisualCreator, IBoundsProvider, IHitTestable, IVisibilityTestable, IMarqueeTestable
ICanvasObjectDescriptor
that can be used to draw IPortCandidate
instances in a
CanvasControl
.Modifier and Type | Field and Description |
---|---|
static ResourceKey |
CANDIDATE_DRAWING_INVALID_FOCUSED_KEY
A
ResourceKey that can be used by instances of the DefaultPortCandidateDescriptor to look up a IVisualTemplate
that will be used for rendering a invalid, focused IPortCandidate . |
static ResourceKey |
CANDIDATE_DRAWING_INVALID_NON_FOCUSED_KEY
A
ResourceKey that can be used by instances of the DefaultPortCandidateDescriptor to look up a IVisualTemplate
that will be used for rendering an invalid, non-focused IPortCandidate . |
static ResourceKey |
CANDIDATE_DRAWING_VALID_FOCUSED_KEY
A
ResourceKey that can be used by instances of the DefaultPortCandidateDescriptor to look up a IVisualTemplate
that will be used for rendering a valid, focused IPortCandidate . |
static ResourceKey |
CANDIDATE_DRAWING_VALID_NON_FOCUSED_KEY
A
ResourceKey that can be used by instances of the DefaultPortCandidateDescriptor to look up a IVisualTemplate
that will be used for rendering a valid, non-focused IPortCandidate . |
ALWAYS_DIRTY_INSTANCE, ALWAYS_DIRTY_LOOKUP, DYNAMIC_DIRTY_INSTANCE, DYNAMIC_DIRTY_LOOKUP, VISUAL, VOID
EMPTY, UNBOUNDED
ALWAYS, NEVER
ALWAYS, NEVER
ALWAYS, NEVER
Constructor and Description |
---|
DefaultPortCandidateDescriptor()
Instantiates a new descriptor.
|
Modifier and Type | Method and Description |
---|---|
Node |
createVisual(IRenderContext context)
This method is called by the framework to create a
Node that will be included into the IRenderContext . |
RectD |
getBounds(ICanvasContext context)
Returns a tight rectangular area where the whole rendering would fit into.
|
IBoundsProvider |
getBoundsProvider(Object forUserObject)
Returns an implementation of
IBoundsProvider that can determine the visible bounds of the rendering of the user
object. |
IHitTestable |
getHitTestable(Object forUserObject)
Returns an implementation of
IHitTestable that can determine whether the rendering of the user object has been
hit at a given coordinate. |
double |
getSize()
Gets the logical size of the candidate.
|
IVisibilityTestable |
getVisibilityTestable(Object forUserObject)
Returns an implementation of
IVisibilityTestable that can determine if the rendering of the user object would be
visible in a given context. |
IVisualCreator |
getVisualCreator(Object forUserObject)
Returns an implementation of
IVisualCreator that will create the Node tree for the user
object. |
boolean |
isCurrentCandidate()
Gets a property that determines whether this descriptor uses the "current" candidates.
|
boolean |
isDirty(ICanvasContext context,
ICanvasObject canvasObject)
Determines whether the given canvas object is deemed dirty and needs updating.
|
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)
Determines whether an element might intersect the visible region for a given context.
|
void |
setCurrentCandidate(boolean value)
Sets a property that determines whether this descriptor uses the "current" candidates.
|
void |
setSize(double value)
Sets the logical size of the candidate.
|
void |
setTemplate(ResourceKey resourceKey,
IVisualTemplate template)
Sets the
IVisualTemplate to use for the given ResourceKey by this instance. |
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
public static final ResourceKey CANDIDATE_DRAWING_INVALID_FOCUSED_KEY
ResourceKey
that can be used by instances of the DefaultPortCandidateDescriptor
to look up a IVisualTemplate
that will be used for rendering a invalid, focused IPortCandidate
.
The drawing returned should be centered around (0,0)
.
public static final ResourceKey CANDIDATE_DRAWING_INVALID_NON_FOCUSED_KEY
ResourceKey
that can be used by instances of the DefaultPortCandidateDescriptor
to look up a IVisualTemplate
that will be used for rendering an invalid, non-focused IPortCandidate
.
The drawing returned should be centered around (0,0)
.
public static final ResourceKey CANDIDATE_DRAWING_VALID_FOCUSED_KEY
ResourceKey
that can be used by instances of the DefaultPortCandidateDescriptor
to look up a IVisualTemplate
that will be used for rendering a valid, focused IPortCandidate
.
The drawing returned should be centered around (0,0)
.
public static final ResourceKey CANDIDATE_DRAWING_VALID_NON_FOCUSED_KEY
ResourceKey
that can be used by instances of the DefaultPortCandidateDescriptor
to look up a IVisualTemplate
that will be used for rendering a valid, non-focused IPortCandidate
.
The drawing returned should be centered around (0,0)
.
public DefaultPortCandidateDescriptor()
public final 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)
public final 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 final IBoundsProvider getBoundsProvider(Object forUserObject)
ICanvasObjectDescriptor
IBoundsProvider
that can determine the visible bounds of the rendering of the user
object.
This method may always return the same instance. By contract, clients will not cache instances returned, but will always call this method before the methods on the instance will be called. This contract enables the use of the fly-weight design pattern. Implementations of this class can always return the same instance and reconfigure this instance upon each call to this method.
getBoundsProvider
in interface ICanvasObjectDescriptor
forUserObject
- the user object to query the bounds fornull
if the bounds are not known, in which case the bounds are treated as infinitepublic final IHitTestable getHitTestable(Object forUserObject)
ICanvasObjectDescriptor
IHitTestable
that can determine whether the rendering of the user object has been
hit at a given coordinate.
This method may always return the same instance. By contract, clients will not cache instances returned, but will always call this method before the methods on the instance will be called. This contract enables the use of the fly-weight design pattern. Implementations of this class can always return the same instance and reconfigure this instance upon each call to this method.
getHitTestable
in interface ICanvasObjectDescriptor
forUserObject
- the user object to do the hit testing fornull
if the rendering cannot be hit testedpublic final double getSize()
This size is used for hit testing, visibility tests, etc. The default is 3
.
setSize(double)
public final IVisibilityTestable getVisibilityTestable(Object forUserObject)
ICanvasObjectDescriptor
IVisibilityTestable
that can determine if the rendering of the user object would be
visible in a given context.
This method may always return the same instance. By contract clients will not cache instances returned but will always call this method before the methods on the instance will be called. This contract enables the use of the fly-weight design pattern. Implementations of this class can always return the same instance and reconfigure this instance upon each call to this method.
getVisibilityTestable
in interface ICanvasObjectDescriptor
forUserObject
- the user object to query the bounds fornull
if the bounds are not known, in which case the bounds are treated as infinitepublic final IVisualCreator getVisualCreator(Object forUserObject)
ICanvasObjectDescriptor
IVisualCreator
that will create the Node
tree for the user
object.
This method may always return the same instance. By contract, clients will not cache instances returned, but will always call this method before the methods on the instance will be called. This contract enables the use of the fly-weight design pattern. Implementations of this class can always return the same instance and reconfigure this instance upon each call to this method.
getVisualCreator
in interface ICanvasObjectDescriptor
forUserObject
- the user object to create a Visual fornull
if nothing shall be renderedpublic final boolean isCurrentCandidate()
setCurrentCandidate(boolean)
public final boolean isDirty(ICanvasContext context, ICanvasObject canvasObject)
ICanvasObjectDescriptor
isDirty
in interface ICanvasObjectDescriptor
context
- The context that will be used for the update.canvasObject
- The object to check.public final 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 final 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 final boolean isVisible(ICanvasContext context, RectD rectangle)
IVisibilityTestable
Conservative implementations can always return true
.
isVisible
in interface IVisibilityTestable
context
- The context to determine the visibility for.rectangle
- The visible region clip.false
if and only if it is safe not to paint the element because it would not affect the given clipping region.public final void setCurrentCandidate(boolean value)
value
- The CurrentCandidate to set.isCurrentCandidate()
public final void setSize(double value)
This size is used for hit testing, visibility tests, etc. The default is 3
.
value
- The Size to set.getSize()
public final void setTemplate(ResourceKey resourceKey, IVisualTemplate template)
IVisualTemplate
to use for the given ResourceKey
by this instance.
This method can be used to reconfigure the visualization for the various keys that are declared by this class.
resourceKey
- The key to reconfigure. This is one of CANDIDATE_DRAWING_VALID_NON_FOCUSED_KEY
,
CANDIDATE_DRAWING_INVALID_NON_FOCUSED_KEY
, CANDIDATE_DRAWING_INVALID_FOCUSED_KEY
,
CANDIDATE_DRAWING_VALID_FOCUSED_KEY
.template
- The template to use instead of the default.public final 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