public final class PointEditHandle extends Object implements AutoCloseable, IEditHandle
Point
on the Map
and can be visualized using an icon.
It can be moved around, or react to mouse events.
The handle executes IPointEditAction
, based on mouse input events. IEditHandles
implementations configure concrete IPointEditAction
implementations on this handle to make sure they result in geometry or feature changes. For example, when this handle is dragged around on the Map
, an IEditHandles
implementation for polylines
can make sure that the second point of the polyline is moved.
This class supports the following gestures:
This handle is painted using an icon
at its current location.
Modifier and Type | Class and Description |
---|---|
static interface |
PointEditHandle.IVisualAidProvider
This interface allows to calculate a visual aid line based on the location of the handle.
|
Constructor and Description |
---|
PointEditHandle(Observable<Point> locationProvider)
Creates a new
PointEditHandle without associated actions. |
PointEditHandle(Point initialLocation)
Creates a new
PointEditHandle without associated actions. |
Modifier and Type | Method and Description |
---|---|
void |
addEditStateObserver(IInvalidationCallback observer)
Adds an observer that is called when the
edit state of this handle has changed. |
EditActionBinder |
addOnClickAction(IPointEditAction action,
long clickCount)
Adds an action that will be triggered when the handle is clicked or tapped (touch).
|
EditActionBinder |
addOnDragAction(IPointEditAction action)
Adds an action that will be triggered when the handle is dragged.
|
EditActionBinder |
addOnMouseMoveAction(IPointEditAction action)
Adds an action that will be executed on every mouse move.
|
EditActionBinder |
addOnTouchLongPressAction(IPointEditAction action)
Adds an action that will be triggered when a long press is performed on a handle.
|
void |
close() |
protected void |
finalize() |
IIcon |
getActiveIcon() |
ComplexStrokeLineStyle |
getActiveVisualAidComplexStrokeLineStyle()
Returns the visual aid complex stroke line style to use when this handle is in an
active state. |
LineStyle |
getActiveVisualAidLineStyle()
Returns the visual aid line style to use when this handle is in an
active state. |
EditHandleState |
getEditState() |
IIcon |
getHighlightedIcon() |
ComplexStrokeLineStyle |
getHighlightedVisualAidComplexStrokeLineStyle()
Returns the visual aid complex stroke line style to use when this handle is in a
highlighted state. |
LineStyle |
getHighlightedVisualAidLineStyle()
Returns the visual aid line style to use when this handle is in a
highlighted state. |
Point |
getLocation()
Returns the current location of this handle.
|
Observable<Point> |
getLocationProvider()
Returns the location provider of this handle.
|
Observable<Point> |
getLocationProviderWhenActive() |
MouseCursor |
getMouseCursor() |
EditMoveConstraint |
getMoveConstraint() |
IIcon |
getRegularIcon() |
ComplexStrokeLineStyle |
getRegularVisualAidComplexStrokeLineStyle()
Returns the visual aid complex stroke line style to use when this handle is in an
inactive state. |
LineStyle |
getRegularVisualAidLineStyle()
Returns the visual aid line style to use when this handle is in an
inactive state. |
PointEditHandle.IVisualAidProvider |
getVisualAidLineProvider() |
int |
getZOrder() |
boolean |
isUseFeatureAsHandle() |
EventResult |
onEvent(IInputEvent inputEvent,
FeatureEditContext context)
Handles the given event, and returns if the event was consumed or not.
|
void |
paint(FeatureCanvas canvas,
FeatureEditContext context)
Paints this handle on the given canvas.
|
void |
removeEditStateObserver(IInvalidationCallback observer)
Removes the given observer.
|
void |
setActiveIcon(IIcon icon)
Sets the icon to paint when the handle is in an active state.
|
void |
setActiveVisualAidComplexStrokeLineStyle(ComplexStrokeLineStyle lineStyle)
Sets the visual aid line style to use when this handle is in an
active state. |
void |
setActiveVisualAidLineStyle(LineStyle lineStyle)
Sets the visual aid line style to use when this handle is in an
active state. |
void |
setHighlightedIcon(IIcon icon)
Sets the icon to paint when the handle is in a highlighted state.
|
void |
setHighlightedVisualAidComplexStrokeLineStyle(ComplexStrokeLineStyle lineStyle)
Sets the visual aid line style to use when this handle is in a
highlighted state. |
void |
setHighlightedVisualAidLineStyle(LineStyle lineStyle)
Sets the visual aid line style to use when this handle is in a
highlighted state. |
void |
setInvalidationCallback(IInvalidationCallback invalidationCallback)
Sets the callback for the handle to call when its visual representation or cursor has changed.
|
void |
setLocationProviderWhenActive(Observable<Point> locationProviderWhenActive) |
void |
setMoveConstraint(EditMoveConstraint moveConstraint) |
void |
setRegularIcon(IIcon icon)
Sets the icon to paint when the handle is in a regular state.
|
void |
setRegularVisualAidComplexStrokeLineStyle(ComplexStrokeLineStyle lineStyle)
Sets the visual aid line style to use when this handle is in an
inactive state. |
void |
setRegularVisualAidLineStyle(LineStyle lineStyle)
Sets the visual aid line style to use when this handle is in an
inactive state. |
void |
setUseFeatureAsHandle(boolean useFeatureAsHandle) |
void |
setVisualAidLineProvider(PointEditHandle.IVisualAidProvider provider)
Sets a visual aid line provider that allows to paint a visual aid line together with this handle.
|
void |
setZOrder(int zOrder)
Sets the Z-order that is used for this handle's paint calls to the
FeatureCanvas . |
public PointEditHandle(@NotNull Point initialLocation)
PointEditHandle
without associated actions.initialLocation
- the initial location of the handle, cannot be null
public PointEditHandle(@NotNull Observable<Point> locationProvider)
PointEditHandle
without associated actions.locationProvider
- the location provider of the handle. The handle assumes the location of this point upon construction, while also observing
the point to adjust its own location whenever the observable point changes; cannot be null
.public void close()
close
in interface AutoCloseable
@NotNull public EventResult onEvent(@NotNull IInputEvent inputEvent, @NotNull FeatureEditContext context) throws NullPointerException
While handling events, IEditHandles
can mark themselves as highlighted or as Active. Related to event handling, the main effect of this is that highlighted or active handles get a higher priority compared to other handles: they get the chance to consume events first. See EditHandleState
onEvent
in interface IEditHandle
inputEvent
- the event to handle, cannot be null
context
- the context, cannot be null
NullPointerException
- when null
is passed.public void paint(@NotNull FeatureCanvas canvas, @NotNull FeatureEditContext context)
This method is called when
IEditHandles
fires an EditHandlesEvent
containing this handle, when the handle is newly added or removed for example.
invalidation callback
.
This method only gets called on the UI thread, so there is no need for additional synchronization.
paint
in interface IEditHandle
canvas
- the canvas on which this handle gets painted.context
- the context, cannot be null
@NotNull public EditHandleState getEditState()
getEditState
in interface IEditHandle
@Nullable public MouseCursor getMouseCursor()
getMouseCursor
in interface IEditHandle
null
can be returned.public void setInvalidationCallback(@Nullable IInvalidationCallback invalidationCallback)
Calling this callback triggers a new call to this handle's paint
method.
setInvalidationCallback
in interface IEditHandle
invalidationCallback
- the callback for the handle to call when its visual representation has changedpublic void addEditStateObserver(@NotNull IInvalidationCallback observer) throws IllegalArgumentException
edit state
of this handle has changed.
Adding the same observer twice is forbidden, and will cause an exception to be thrown.
addEditStateObserver
in interface IEditHandle
observer
- an observerIllegalArgumentException
- when the observer was already added.public void removeEditStateObserver(@NotNull IInvalidationCallback observer) throws IllegalArgumentException
If the given observer was never added, an exception is thrown.
removeEditStateObserver
in interface IEditHandle
observer
- an observerIllegalArgumentException
- when the observer is not known.@Nullable public Point getLocation()
Note that this location is not necessarily equal to the location provider
at all times. For example, they may differ when the handle is dragged around and no location changes are triggered in the location provider.
@NotNull public Observable<Point> getLocationProvider()
Note that the handle's current location
is not necessarily equal to this location provider
at all times. For example, they may differ when the handle is dragged around and no location changes are triggered in this location provider. Additionally, the handle may have a different location provider when it is active. See getLocationProviderWhenActive
.
null
.@Nullable public Observable<Point> getLocationProviderWhenActive()
active
, or null
if no distinct location provider is set for when the handle is active.public void setLocationProviderWhenActive(@Nullable Observable<Point> locationProviderWhenActive)
locationProviderWhenActive
- the location provider to use when the handle is active
. If set, this overrides the regular location provider
when the handle is active, Can be null
.@NotNull public EditMoveConstraint getMoveConstraint()
public void setMoveConstraint(@NotNull EditMoveConstraint moveConstraint)
moveConstraint
- the move constraint of this point handle. By default, this is EditMoveConstraint#XY
.public int getZOrder()
FeatureCanvas
.setZOrder
,
FeatureCanvas
,
FeatureCanvas.IconDrawCommand#zOrder
public void setZOrder(int zOrder)
FeatureCanvas
.
This Z-order determines which handles are painted on top, when multiple handles overlap. Edit handles with a higher Z-order are painted on top of handles with a lower Z-order. Note: highlighted
edit handles are always painted above regular handles, and active
handles are always painted above highlighted handles. The default value is 0.
zOrder
- the Z-order that is used for this handle's paint calls to the FeatureCanvas
. Must be between [-1000,1000].FeatureCanvas
,
FeatureCanvas.IconDrawCommand#zOrder
@Nullable public IIcon getRegularIcon()
setRegularIcon
public void setRegularIcon(@Nullable IIcon icon)
This icon is only used when setUseFeatureAsHandle
is set to false.
icon
- the icon to paint when the handle is in a regular (i.e. non-highlighted, non-active) state.@Nullable public IIcon getHighlightedIcon()
setHighlightedIcon
public void setHighlightedIcon(@Nullable IIcon icon)
This icon is only used when setUseFeatureAsHandle
is set to false.
icon
- the icon to paint when the handle is in a highlighted state.@Nullable public IIcon getActiveIcon()
setActiveIcon
public void setActiveIcon(@Nullable IIcon icon)
This icon is only used when setUseFeatureAsHandle
is set to false.
icon
- the icon to paint when the handle is in an active statepublic boolean isUseFeatureAsHandle()
setUseFeatureAsHandle
public void setUseFeatureAsHandle(boolean useFeatureAsHandle)
useFeatureAsHandle
- when this is set to true, this handle does not paint any icons for itself. In this case, the handle considers the feature that is being edited for determining whether it is touched or not. Otherwise, when this is set to false, the handle paints itself as an icon and only considers that icon for deciding whether it is touched. By default, this is false.public void setVisualAidLineProvider(@Nullable PointEditHandle.IVisualAidProvider provider)
It is not possible to interact with this line. The line style can be configured using setRegularVisualAidLineStyle
. The given provider is allowed
The default is null
.
provider
- the visual aid line provider. If null
, no visual aid line is painted.@Nullable public PointEditHandle.IVisualAidProvider getVisualAidLineProvider()
setVisualAidLineProvider
@Nullable public LineStyle getRegularVisualAidLineStyle()
inactive
state.
This method is linked to the getRegularVisualAidComplexStrokeLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
inactive
state.setRegularVisualAidLineStyle
@Nullable public ComplexStrokeLineStyle getRegularVisualAidComplexStrokeLineStyle()
inactive
state.
This method is linked to the getRegularVisualAidLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
inactive
state.setRegularVisualAidComplexStrokeLineStyle
public void setRegularVisualAidLineStyle(@Nullable LineStyle lineStyle)
inactive
state.
This style is only used when a visual aid line is set
.
Only one regular line style can be set, if this function is called with a non null
value when a ComplexStrokeLineStyle
has already been set, it will be overwritten.
The default is a small, grey line.
lineStyle
- the visual aid line style to use when this handle is in an inactive
state.public void setRegularVisualAidComplexStrokeLineStyle(@Nullable ComplexStrokeLineStyle lineStyle)
inactive
state.
This style is only used when a visual aid line is set
.
Only one regular line style can be set, if this function is called with a non null
value when a LineStyle
has already been set, it will be overwritten.
The default is null
, as a linestyle
is used as default regular visual aid style.
lineStyle
- the visual aid complex stroke line style to use when this handle is in an inactive
state.@Nullable public LineStyle getHighlightedVisualAidLineStyle()
highlighted
state.
This method is linked to the getHighlightedVisualAidComplexStrokeLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
highlighted
state.setHighlightedVisualAidLineStyle
@Nullable public ComplexStrokeLineStyle getHighlightedVisualAidComplexStrokeLineStyle()
highlighted
state.
This method is linked to the getHighlightedVisualAidLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
highlighted
state.setHighlightedVisualAidComplexStrokeLineStyle
public void setHighlightedVisualAidLineStyle(@Nullable LineStyle lineStyle)
highlighted
state.
This style is only used when a visual aid line is set
.
Only one regular line style can be set, if this function is called with a non null
value when a ComplexStrokeLineStyle
has already been set, it will be overwritten.
The default is a small, grey line.
lineStyle
- the visual aid line style to use when this handle is in a highlighted
state.public void setHighlightedVisualAidComplexStrokeLineStyle(@Nullable ComplexStrokeLineStyle lineStyle)
highlighted
state.
This style is only used when a visual aid line is set
.
Only one highlighted line style can be set, if this function is called with a non null
value when a LineStyle
has already been set, it will be overwritten.
The default is null
, as a linestyle
is used as default highlighted visual aid style.
lineStyle
- the visual aid complex stroke line style to use when this handle is in a highlighted
state.@Nullable public LineStyle getActiveVisualAidLineStyle()
active
state.
This method is linked to the getActiveVisualAidComplexStrokeLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
active
state.setActiveVisualAidLineStyle
@Nullable public ComplexStrokeLineStyle getActiveVisualAidComplexStrokeLineStyle()
active
state.
This method is linked to the getActiveVisualAidLineStyle
method:
null
, no visual aid line is painted
null
, that line style is used
null
value: they are mutually exclusive
active
state.setActiveVisualAidComplexStrokeLineStyle
public void setActiveVisualAidLineStyle(@Nullable LineStyle lineStyle)
active
state.
This style is only used when a visual aid line is set
.
Only one active line style can be set, if this function is called with a non null
value when a ComplexStrokeLineStyle
has already been set, it will be overwritten.
The default is a small, grey line.
lineStyle
- the visual aid line style to use when this handle is in an active
state.public void setActiveVisualAidComplexStrokeLineStyle(@Nullable ComplexStrokeLineStyle lineStyle)
active
state.
This style is only used when a visual aid line is set
.
Only one active line style can be set, if this function is called with a non null
value when a LineStyle
has already been set, it will be overwritten.
The default is null
, as a linestyle
is used as default active visual aid style.
lineStyle
- the visual aid complex stroke line style to use when this handle is in a EditHandleState#Active
state.@NotNull public EditActionBinder addOnClickAction(@NotNull IPointEditAction action, long clickCount)
action
- the action to be performed on click, cannot be null
.clickCount
- the action will only be performed when an event is received with this click count@NotNull public EditActionBinder addOnTouchLongPressAction(@NotNull IPointEditAction action)
action
- the action to be performed, cannot be null
.@NotNull public EditActionBinder addOnDragAction(@NotNull IPointEditAction action)
The given action is executed at least when the drag gesture starts
and ends
, and if EditActionBinder#performOnIntermediateEvents
is set to true, it also gets executed on every intermediate
drag event. The action is always called with an EventStatus
parameter corresponding to the drag event.
action
- the action to be performed on drag, cannot be null
.@NotNull public EditActionBinder addOnMouseMoveAction(@NotNull IPointEditAction action)
action
- the action to be performed during the mouse move, cannot be null
.