public class ClickInputMode extends Object implements IInputMode
Clients register to Clicked
to get notified of mouse clicks. The ActiveButtons
property can be used to switch between the detection of right and left mouse clicks.
This mode can be instructed to swallow clicks
if they lead happen shortly
after the control gained focus. This is useful to prevent accidental clicks from being processed if the user wanted to
put the focus into the control, only.
This mode is Exclusive
by default.
Constructor and Description |
---|
ClickInputMode()
Creates a new instance of this mode that detects left mouse clicks.
|
Modifier and Type | Method and Description |
---|---|
void |
addClickedListener(IEventHandler<ClickEventArgs> clickedEvent)
Adds the given listener for the
Clicked event that occurs once a click has been detected. |
void |
addDoubleClickedListener(IEventHandler<ClickEventArgs> doubleClickedEvent)
Adds the given listener for the
DoubleClicked event that occurs once a double-click has been detected. |
void |
addLeftClickedListener(IEventHandler<ClickEventArgs> leftClickedEvent)
Adds the given listener for the
LeftClicked event that occurs once a left click has been detected. |
void |
addLeftDoubleClickedListener(IEventHandler<ClickEventArgs> leftDoubleClickedEvent)
Adds the given listener for the
LeftDoubleClicked event that occurs once a left double-click has been detected. |
void |
addRightClickedListener(IEventHandler<ClickEventArgs> rightClickedEvent)
Adds the given listener for the
RightClicked event that occurs once a right click has been detected. |
void |
addRightDoubleClickedListener(IEventHandler<ClickEventArgs> rightDoubleClickedEvent)
Adds the given listener for the
RightDoubleClicked event that occurs once a right double-click has been
detected. |
void |
cancel()
Cancels the editing of this mode.
|
protected IEventRecognizer |
createClickRecognizer()
Creates the event recognizer that is used to recognize the clicks for this instance.
|
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.
|
MouseButtons |
getActiveButtons()
Determines for which button(s) mouse clicks should be processed.
|
PointD |
getClickLocation()
Gets the location of the last click.
|
protected ConcurrencyController |
getController()
Gets the installed
Controller . |
DoubleClickPolicy |
getDoubleClickPolicy()
Gets the click handling mode that determines the triggering behavior of
Clicked
and DoubleClicked . |
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
ModifierKeys |
getModifiers()
Returns the state of the modifier keys at the time of the end of the gesture.
|
int |
getPriority()
The priority of this input mode.
|
Cursor |
getValidClickHitCursor()
Gets the cursor to use when hovering over a valid hit region.
|
IHitTestable |
getValidClickHitTestable()
Gets a hit test that determines where this mode should recognize clicks.
|
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 |
isFocusClickSwallowingEnabled()
Gets a property that determines whether clicks 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 |
isLeftClick()
Deprecated.
|
protected boolean |
isValidClick(Object src,
IEventArgs arg)
Determines whether the given event is a valid click event.
|
protected boolean |
isValidPress(Object eventSource,
IEventArgs eventArg)
Determines whether the given event is a valid press event.
|
protected boolean |
isValidRelease(Object src,
IEventArgs arg)
Determines whether the given event is a valid release event.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a click gesture.
|
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onDoubleClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a double-click gesture.
|
protected void |
onLeftClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a left click gesture.
|
protected void |
onLeftDoubleClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a left double-click gesture.
|
protected void |
onRightClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a right click gesture.
|
protected void |
onRightDoubleClicked(ClickEventArgs eventArgs)
Called once this mode has recognized a double-click gesture.
|
protected void |
onStopped()
Called after
stop() has been called. |
void |
preventNextDoubleClick()
Prevents a double-click event from being issued if the next click would do so and sends only a single click instead.
|
protected boolean |
queryAndResetPreventNextDoubleClick()
Returns and resets the flag set by
preventNextDoubleClick() . |
void |
removeClickedListener(IEventHandler<ClickEventArgs> clickedEvent)
Removes the given listener for the
Clicked event that occurs once a click has been detected. |
void |
removeDoubleClickedListener(IEventHandler<ClickEventArgs> doubleClickedEvent)
Removes the given listener for the
DoubleClicked event that occurs once a double-click has been detected. |
void |
removeLeftClickedListener(IEventHandler<ClickEventArgs> leftClickedEvent)
Removes the given listener for the
LeftClicked event that occurs once a left click has been detected. |
void |
removeLeftDoubleClickedListener(IEventHandler<ClickEventArgs> leftDoubleClickedEvent)
Removes the given listener for the
LeftDoubleClicked event that occurs once a left double-click has been
detected. |
void |
removeRightClickedListener(IEventHandler<ClickEventArgs> rightClickedEvent)
Removes the given listener for the
RightClicked event that occurs once a right click has been detected. |
void |
removeRightDoubleClickedListener(IEventHandler<ClickEventArgs> rightDoubleClickedEvent)
Removes the given listener for the
RightDoubleClicked event that occurs once a right double-click has been
detected. |
void |
setActiveButtons(MouseButtons value)
Determines for which button(s) mouse clicks should be processed.
|
void |
setDoubleClickPolicy(DoubleClickPolicy value)
Sets the click handling mode that determines the triggering behavior of
Clicked
and DoubleClicked . |
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 |
setFocusClickSwallowingEnabled(boolean value)
Sets a property that determines whether clicks 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 |
setRequestingMutexOnClickEnabled(boolean value)
Whether to
request the mutex on a click. |
void |
setValidClickHitCursor(Cursor value)
Sets the cursor to use when hovering over a valid hit region.
|
void |
setValidClickHitTestable(IHitTestable value)
Sets a hit test that determines where this mode should recognize clicks.
|
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 ClickInputMode()
public final void addClickedListener(IEventHandler<ClickEventArgs> clickedEvent)
Clicked
event that occurs once a click has been detected.clickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeClickedListener(IEventHandler)
public final void addDoubleClickedListener(IEventHandler<ClickEventArgs> doubleClickedEvent)
DoubleClicked
event that occurs once a double-click has been detected.doubleClickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeDoubleClickedListener(IEventHandler)
public final void addLeftClickedListener(IEventHandler<ClickEventArgs> leftClickedEvent)
LeftClicked
event that occurs once a left click has been detected.leftClickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeLeftClickedListener(IEventHandler)
public final void addLeftDoubleClickedListener(IEventHandler<ClickEventArgs> leftDoubleClickedEvent)
LeftDoubleClicked
event that occurs once a left double-click has been detected.leftDoubleClickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeLeftDoubleClickedListener(IEventHandler)
public final void addRightClickedListener(IEventHandler<ClickEventArgs> rightClickedEvent)
RightClicked
event that occurs once a right click has been detected.rightClickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeRightClickedListener(IEventHandler)
public final void addRightDoubleClickedListener(IEventHandler<ClickEventArgs> rightDoubleClickedEvent)
RightDoubleClicked
event that occurs once a right double-click has been
detected.rightDoubleClickedEvent
- The listener to add.ClickEventArgs
,
getDoubleClickPolicy()
,
removeRightDoubleClickedListener(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 createClickRecognizer()
protected IEventRecognizer createPressRecognizer()
protected IEventRecognizer createReleaseRecognizer()
public final MouseButtons getActiveButtons()
Default value is MouseButtons.LEFT
createClickRecognizer()
,
setActiveButtons(MouseButtons)
public final PointD getClickLocation()
protected final ConcurrencyController getController()
Controller
.IInputMode.install(IInputModeContext, ConcurrencyController)
public final DoubleClickPolicy getDoubleClickPolicy()
Clicked
and DoubleClicked
.DoubleClickPolicy.BOTH_SINGLE_CLICKS_AND_DOUBLE_CLICK
getDoubleClickPolicy()
,
setDoubleClickPolicy(DoubleClickPolicy)
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 ModifierKeys getModifiers()
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 Cursor getValidClickHitCursor()
The default is null
and the current cursor is used instead.
setValidClickHitCursor(Cursor)
public final IHitTestable getValidClickHitTestable()
This implementation is tested during the isValidPress(Object, IEventArgs)
to determine whether it is valid to
click here. The default implementation is IHitTestable.ALWAYS
.
setValidClickHitTestable(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 Controller
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 isFocusClickSwallowingEnabled()
The default is false
. If set to true
clicks are discarded within 100 ms after the focus entered.
setFocusClickSwallowingEnabled(boolean)
protected boolean isInvalidPress(Object eventSource, IEventArgs eventArg)
getValidClickHitTestable()
@Deprecated public final boolean isLeftClick()
request the mutex
on a click.
If set to true
this will detect only left mouse clicks, otherwise, only right clicks are detected.
createClickRecognizer()
,
#setLeftClick(boolean)
protected boolean isValidClick(Object src, IEventArgs arg)
getValidClickHitTestable()
protected boolean isValidPress(Object eventSource, IEventArgs eventArg)
protected boolean isValidRelease(Object src, IEventArgs arg)
getValidClickHitTestable()
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 onClicked(ClickEventArgs eventArgs)
This method will trigger the Clicked
event.
eventArgs
- The arguments.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 onDoubleClicked(ClickEventArgs eventArgs)
This method will trigger the DoubleClicked
event.
eventArgs
- The arguments.protected void onLeftClicked(ClickEventArgs eventArgs)
This method will trigger the LeftClicked
event.
eventArgs
- The arguments.protected void onLeftDoubleClicked(ClickEventArgs eventArgs)
This method will trigger the LeftDoubleClicked
event.
eventArgs
- The arguments.protected void onRightClicked(ClickEventArgs eventArgs)
This method will trigger the RightClicked
event.
eventArgs
- The arguments.protected void onRightDoubleClicked(ClickEventArgs eventArgs)
This method will trigger the RightDoubleClicked
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.
public final void preventNextDoubleClick()
The intention is for "breaking" a double click if an input mode using ClickInputMode
performs actions that would
lead to surprising behavior if the next click would lead to a double-click. Examples of this are
GraphEditorInputMode
's selection cycling where several clicks in short
succession may occur, as well as creating a node by clicking on the canvas and selecting it immediately afterwards with
another click.
This method's effect is very short-lived. It really only prevents a double-click event for the very next click that this input mode handles. The internal flag set by this method is re-set on every click received. This also means that if you call this method and the next click is just a regular single-click the flag is cleared nonetheless.
protected boolean queryAndResetPreventNextDoubleClick()
preventNextDoubleClick()
.
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 removeClickedListener(IEventHandler<ClickEventArgs> clickedEvent)
Clicked
event that occurs once a click has been detected.clickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addClickedListener(IEventHandler)
public final void removeDoubleClickedListener(IEventHandler<ClickEventArgs> doubleClickedEvent)
DoubleClicked
event that occurs once a double-click has been detected.doubleClickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addDoubleClickedListener(IEventHandler)
public final void removeLeftClickedListener(IEventHandler<ClickEventArgs> leftClickedEvent)
LeftClicked
event that occurs once a left click has been detected.leftClickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addLeftClickedListener(IEventHandler)
public final void removeLeftDoubleClickedListener(IEventHandler<ClickEventArgs> leftDoubleClickedEvent)
LeftDoubleClicked
event that occurs once a left double-click has been
detected.leftDoubleClickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addLeftDoubleClickedListener(IEventHandler)
public final void removeRightClickedListener(IEventHandler<ClickEventArgs> rightClickedEvent)
RightClicked
event that occurs once a right click has been detected.rightClickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addRightClickedListener(IEventHandler)
public final void removeRightDoubleClickedListener(IEventHandler<ClickEventArgs> rightDoubleClickedEvent)
RightDoubleClicked
event that occurs once a right double-click has been
detected.rightDoubleClickedEvent
- The listener to remove.ClickEventArgs
,
getDoubleClickPolicy()
,
addRightDoubleClickedListener(IEventHandler)
public final void setActiveButtons(MouseButtons value)
Default value is MouseButtons.LEFT
value
- The ActiveButtons to set.createClickRecognizer()
,
getActiveButtons()
public final void setDoubleClickPolicy(DoubleClickPolicy value)
Clicked
and DoubleClicked
.value
- The click handling mode to use for this instance. The default is
DoubleClickPolicy.BOTH_SINGLE_CLICKS_AND_DOUBLE_CLICK
getDoubleClickPolicy()
,
getDoubleClickPolicy()
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 setFocusClickSwallowingEnabled(boolean value)
The default is false
. If set to true
clicks are discarded within 100 ms after the focus entered.
value
- The FocusClickSwallowingEnabled to set.isFocusClickSwallowingEnabled()
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 setRequestingMutexOnClickEnabled(boolean value)
request the mutex
on a click.
If set to true
this will detect only left mouse clicks, otherwise, only right clicks are detected.
value
- The LeftClick to set.createClickRecognizer()
,
isLeftClick()
public final void setValidClickHitCursor(Cursor value)
The default is null
and the current cursor is used instead.
value
- The ValidClickHitCursor to set.getValidClickHitCursor()
public final void setValidClickHitTestable(IHitTestable value)
This implementation is tested during the isValidPress(Object, IEventArgs)
to determine whether it is valid to
click here. The default implementation is IHitTestable.ALWAYS
.
value
- The ValidClickHitTestable to set.getValidClickHitTestable()
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.