public class TapInputMode extends Object implements IInputMode
Clients register to Tapped
to get notified of touch taps. This mode can be
instructed to swallow taps
if they lead happen shortly after the control gained
focus. This is useful to prevent accidental taps from being processed if the user wanted to put the focus into the
control, only.
This mode is Exclusive
by default.
Constructor and Description |
---|
TapInputMode()
Creates a new instance of this mode that detects touch taps.
|
Modifier and Type | Method and Description |
---|---|
void |
addDoubleTappedListener(IEventHandler<TapEventArgs> doubleTappedEvent)
Adds the given listener for the
DoubleTapped event that occurs once a double-tap has been detected. |
void |
addTappedListener(IEventHandler<TapEventArgs> tappedEvent)
Adds the given listener for the
Tapped event that occurs once a tap has been detected. |
void |
cancel()
Cancels the editing of this mode.
|
protected IEventRecognizer |
createPressRecognizer()
Creates the event recognizer that is used to recognize the press event for this instance.
|
protected IEventRecognizer |
createReleaseRecognizer()
Creates the event recognizer that is used to recognize the release event for this instance.
|
protected IEventRecognizer |
createTapRecognizer()
Creates the event recognizer that is used to recognize the taps for this instance.
|
protected ConcurrencyController |
getController()
Returns the installed
ConcurrencyController . |
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
int |
getPriority()
The priority of this input mode.
|
TapHandlingPolicy |
getTapHandlingPolicy()
Gets the tap handling policy that determines the triggering behavior of
Tapped
and DoubleTapped . |
PointD |
getTapLocation()
Gets the location of the last tap.
|
IHitTestable |
getValidTapHitTestable()
Gets a hit test that determines where this mode should recognize taps.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into the given context that is provided by the canvas.
|
boolean |
isEnabled()
Gets the enabled state of this input mode.
|
boolean |
isExclusive()
Gets a value indicating whether this mode will be the only one running when it has the mutex.
|
boolean |
isFocusTapSwallowingEnabled()
Gets a property that determines whether taps should be swallowed if they happen within a short amount of time after the
CanvasControl got focus. |
protected boolean |
isInvalidPress(Object eventSource,
IEventArgs eventArg)
Determines whether the given event is a press event that occurred at an invalid location.
|
boolean |
isRequestingMutexOnTapEnabled()
Whether to
request the mutex on a tap. |
protected boolean |
isValidPress(Object eventSource,
IEventArgs eventArg)
Determines whether the given event is a valid press event.
|
protected boolean |
isValidRelease(Object eventSource,
IEventArgs eventArg)
Determines whether the given event is a valid release event.
|
protected boolean |
isValidTap(Object eventSource,
IEventArgs eventArg)
Determines whether the given event is a valid tap event.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onDoubleTapped(TapEventArgs eventArgs)
Called once this mode has recognized a double-tap gesture.
|
protected void |
onStopped()
Called after
stop() has been called. |
protected void |
onTapped(TapEventArgs eventArgs)
Called once this mode has recognized a tap gesture.
|
void |
preventNextDoubleTap()
Prevents a double-tap event from being issued if the next tap would do so and sends only a single tap instead.
|
protected boolean |
queryAndResetPreventNextDoubleTap()
Returns and resets the flag set by
preventNextDoubleTap() . |
void |
removeDoubleTappedListener(IEventHandler<TapEventArgs> doubleTappedEvent)
Removes the given listener for the
DoubleTapped event that occurs once a double-tap has been detected. |
void |
removeTappedListener(IEventHandler<TapEventArgs> tappedEvent)
Removes the given listener for the
Tapped event that occurs once a tap has been detected. |
void |
setEnabled(boolean value)
Sets the enabled state of this input mode.
|
void |
setExclusive(boolean value)
Sets a value indicating whether this mode will be the only one running when it has the mutex.
|
void |
setFocusTapSwallowingEnabled(boolean value)
Sets a property that determines whether taps should be swallowed if they happen within a short amount of time after the
CanvasControl got focus. |
void |
setPriority(int value)
The priority of this input mode.
|
void |
setRequestingMutexOnTapEnabled(boolean value)
Whether to
request the mutex on a tap. |
void |
setTapHandlingPolicy(TapHandlingPolicy value)
Sets the tap handling policy that determines the triggering behavior of
Tapped
and DoubleTapped . |
void |
setValidTapHitTestable(IHitTestable value)
Sets a hit test that determines where this mode should recognize taps.
|
boolean |
stop()
Called by the client in order to stop a current editing progress.
|
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the given context.
|
public TapInputMode()
public final void addDoubleTappedListener(IEventHandler<TapEventArgs> doubleTappedEvent)
DoubleTapped
event that occurs once a double-tap has been detected.doubleTappedEvent
- The listener to add.TapEventArgs
,
getTapHandlingPolicy()
,
removeDoubleTappedListener(IEventHandler)
public final void addTappedListener(IEventHandler<TapEventArgs> tappedEvent)
Tapped
event that occurs once a tap has been detected.tappedEvent
- The listener to add.TapEventArgs
,
getTapHandlingPolicy()
,
removeTappedListener(IEventHandler)
public void cancel()
This implementation releases
the mutex if it is currently owned by this
instance and calls onCanceled()
.
cancel
in interface IInputMode
onCanceled()
protected IEventRecognizer createPressRecognizer()
protected IEventRecognizer createReleaseRecognizer()
protected IEventRecognizer createTapRecognizer()
protected final ConcurrencyController getController()
ConcurrencyController
.public final IInputModeContext getInputModeContext()
IInputMode
null
if this instance is not installed.
Note that this instance should not be passed down to subordinate modes or instances. Instead a corresponding context
that has this instance set as the ParentInputMode
should be used.
getInputModeContext
in interface IInputMode
public final int getPriority()
IInputMode
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
getPriority
in interface IInputMode
public final TapHandlingPolicy getTapHandlingPolicy()
Tapped
and DoubleTapped
.TapHandlingPolicy.BOTH_SINGLE_TAPS_AND_DOUBLE_TAP
getTapHandlingPolicy()
,
setTapHandlingPolicy(TapHandlingPolicy)
public final PointD getTapLocation()
public final IHitTestable getValidTapHitTestable()
This implementation is tested during the isValidPress(Object, IEventArgs)
to determine whether it is valid to
tap here. The default implementation is IHitTestable.ALWAYS
.
setValidTapHitTestable(IHitTestable)
public void install(IInputModeContext context, ConcurrencyController controller)
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation, first.
install
in interface IInputMode
context
- The context that this instance shall be installed into. The same instance will be passed to this instance during
IInputMode.uninstall(IInputModeContext)
. A reference to the context may be kept and queried during the time
the mode is installed.controller
- The ConcurrencyController
for this mode.IInputMode.uninstall(IInputModeContext)
public boolean isEnabled()
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
setEnabled(boolean)
public final boolean isExclusive()
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
setExclusive(boolean)
public final boolean isFocusTapSwallowingEnabled()
CanvasControl
got focus.
The default is false
. If set to true
taps are discarded within 100 ms after the focus entered.
setFocusTapSwallowingEnabled(boolean)
protected boolean isInvalidPress(Object eventSource, IEventArgs eventArg)
getValidTapHitTestable()
public final boolean isRequestingMutexOnTapEnabled()
request the mutex
on a tap.
If set to true
this will discard other concurrent input modes on a tap. The default is true
.
setRequestingMutexOnTapEnabled(boolean)
protected boolean isValidPress(Object eventSource, IEventArgs eventArg)
protected boolean isValidRelease(Object eventSource, IEventArgs eventArg)
protected boolean isValidTap(Object eventSource, IEventArgs eventArg)
protected void onCanceled()
cancel()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
protected void onConcurrencyControllerActivated()
Active
property of the installed ConcurrencyController
has been set to true
.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
protected void onConcurrencyControllerDeactivated()
Active
property of the installed ConcurrencyController
has been set to false
.
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
protected void onDoubleTapped(TapEventArgs eventArgs)
This method will trigger the DoubleTapped
event.
eventArgs
- The arguments.protected void onStopped()
stop()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
protected void onTapped(TapEventArgs eventArgs)
This method will trigger the Tapped
event.
eventArgs
- The arguments.public final void preventNextDoubleTap()
The intention is for "breaking" a double tap if an input mode using TapInputMode
performs actions that would
lead to surprising behavior if the next tap would lead to a double-tap. Examples of this are
GraphEditorInputMode
's selection cycling where several taps in short succession
may occur, as well as creating a node by tapping on the canvas and selecting it immediately afterwards with another
tap.
This method's effect is very short-lived. It really only prevents a double-tap event for the very next tap that this input mode handles. The internal flag set by this method is re-set on every tap received. This also means that if you call this method and the next tap is just a regular single-tap the flag is cleared nonetheless.
protected boolean queryAndResetPreventNextDoubleTap()
preventNextDoubleTap()
.
To ensure that the flag really acts just once, this method resets the flag and returns its value prior to the reset.
public final void removeDoubleTappedListener(IEventHandler<TapEventArgs> doubleTappedEvent)
DoubleTapped
event that occurs once a double-tap has been detected.doubleTappedEvent
- The listener to remove.TapEventArgs
,
getTapHandlingPolicy()
,
addDoubleTappedListener(IEventHandler)
public final void removeTappedListener(IEventHandler<TapEventArgs> tappedEvent)
Tapped
event that occurs once a tap has been detected.tappedEvent
- The listener to remove.TapEventArgs
,
getTapHandlingPolicy()
,
addTappedListener(IEventHandler)
public void setEnabled(boolean value)
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
value
- The Enabled to set.isEnabled()
public final void setExclusive(boolean value)
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
value
- The Exclusive to set.isExclusive()
public final void setFocusTapSwallowingEnabled(boolean value)
CanvasControl
got focus.
The default is false
. If set to true
taps are discarded within 100 ms after the focus entered.
value
- The FocusTapSwallowingEnabled to set.isFocusTapSwallowingEnabled()
public final void setPriority(int value)
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
value
- The Priority to set.getPriority()
public final void setRequestingMutexOnTapEnabled(boolean value)
request the mutex
on a tap.
If set to true
this will discard other concurrent input modes on a tap. The default is true
.
value
- The RequestingMutexOnTapEnabled to set.isRequestingMutexOnTapEnabled()
public final void setTapHandlingPolicy(TapHandlingPolicy value)
Tapped
and DoubleTapped
.value
- The tap handling policy to use for this instance. The default is
TapHandlingPolicy.BOTH_SINGLE_TAPS_AND_DOUBLE_TAP
getTapHandlingPolicy()
,
getTapHandlingPolicy()
public final void setValidTapHitTestable(IHitTestable value)
This implementation is tested during the isValidPress(Object, IEventArgs)
to determine whether it is valid to
tap here. The default implementation is IHitTestable.ALWAYS
.
value
- The ValidTapHitTestable to set.getValidTapHitTestable()
public boolean stop()
IInputMode
This should stop the current edit, if one is in progress and possibly commit all of the changes. If stopping is not
possible, this method can return false
stop
in interface IInputMode
true
if and only if the editing has been stopped or there was no edit in progressIInputMode.cancel()
public void uninstall(IInputModeContext context)
This code should clean up all changes made to the canvas in the IInputMode.install(IInputModeContext, ConcurrencyController)
method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
uninstall
in interface IInputMode
context
- The context to deregister from. This is the same instance that had been passed to IInputMode.install(IInputModeContext, ConcurrencyController)
during installation.