public abstract class AbstractInputMode extends Object implements IInputMode
IInputMode
that can be used concurrently with other IInputMode
implementations if its Exclusive
property is true
.
This class adds convenience methods for derived classes.
Modifier | Constructor and Description |
---|---|
protected |
AbstractInputMode()
Initializes a new instance of the
AbstractInputMode class that is Exclusive by default. |
protected |
AbstractInputMode(boolean exclusive)
Initializes a new instance of the
AbstractInputMode class. |
Modifier and Type | Method and Description |
---|---|
void |
addCanceledListener(IEventHandler<InputModeEventArgs> canceledEvent)
Adds the given listener for the
Canceled event that occurs after the call to cancel() . |
void |
addInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Adds the given listener for the
Initialized event that occurs after the call to initialize() . |
void |
addInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Adds the given listener for the
Initializing event that occurs before the call to initialize() . |
void |
addStoppedListener(IEventHandler<InputModeEventArgs> stoppedEvent)
Adds the given listener for the
Stopped event that occurs after the call to stop() . |
void |
cancel()
Cancels the editing of this mode by first disabling and afterwards reenabling the installed
Controller . |
protected boolean |
canRequestMutex()
Determines whether this instance can request the mutex.
|
protected IInputModeContext |
createChildInputModeContext()
Creates an implementation of
IInputModeContext that is specific to this mode. |
protected InputModeEventArgs |
createInputModeEventArgs(IInputModeContext context)
Helper method that yields a suitably configured
InputModeEventArgs for this input mode. |
protected ConcurrencyController |
getController()
Returns the installed
Controller . |
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.
|
protected boolean |
hasMutex()
Determines whether this instance owns the input mutex.
|
protected void |
initialize()
Performs one-time initialization of this instance.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into a
CanvasControl using the provided IInputModeContext . |
boolean |
isActive()
Returns if this mode is active.
|
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 |
isInstalled()
Returns whether this mode is currently installed so a call to
Canvas will yield a non-null
result. |
protected void |
onCanceled(InputModeEventArgs eventArgs)
Event dispatch method that will dispatch the
Canceled event. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onInitialized(InputModeEventArgs eventArgs)
Event dispatch method that will dispatch the
Initialized event. |
protected void |
onInitializing(InputModeEventArgs eventArgs)
Event dispatch method that will dispatch the
Initializing event. |
protected void |
onMutexObtained()
Called when this instance obtains the mutex.
|
protected void |
onMutexReleased()
Called when this instance released the mutex.
|
protected void |
onStopped(InputModeEventArgs eventArgs)
Event dispatch method that will dispatch the
Stopped event. |
protected void |
releaseKeyboard()
Releases previously captured keyboard input.
|
protected void |
releaseMutex()
Releases the mutex that is currently owned by this instance.
|
protected void |
releasePointer()
Releases previously captured mouse and touch input.
|
void |
removeCanceledListener(IEventHandler<InputModeEventArgs> canceledEvent)
Removes the given listener for the
Canceled event that occurs after the call to cancel() . |
void |
removeInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Removes the given listener for the
Initialized event that occurs after the call to initialize() . |
void |
removeInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Removes the given listener for the
Initializing event that occurs before the call to initialize() . |
void |
removeStoppedListener(IEventHandler<InputModeEventArgs> stoppedEvent)
Removes the given listener for the
Stopped event that occurs after the call to stop() . |
protected void |
requestKeyboard()
Requests capturing of all keyboard input that happens in the
CanvasControl . |
protected void |
requestMutex()
Requests the mutex from the current
Controller . |
protected void |
requestPointer()
Requests capturing of all mouse and touch input that happens in the
CanvasControl . |
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 |
setPriority(int value)
The priority of this input mode.
|
boolean |
stop()
Tries to stop the editing.
|
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the canvas.
|
protected AbstractInputMode()
AbstractInputMode
class that is Exclusive
by default.protected AbstractInputMode(boolean exclusive)
AbstractInputMode
class.exclusive
- Iff this mode should be Exclusive
.public final void addCanceledListener(IEventHandler<InputModeEventArgs> canceledEvent)
Canceled
event that occurs after the call to cancel()
.
Clients can use this event to perform post cleanup steps of the instance shortly after the mode has been canceled.
canceledEvent
- The listener to add.onCanceled(InputModeEventArgs)
,
cancel()
,
stop()
,
addStoppedListener(IEventHandler)
,
removeCanceledListener(IEventHandler)
public final void addInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Initialized
event that occurs after the call to initialize()
.
Clients can use this event to perform post configuration steps of the instance shortly after the initialization has been performed.
initializedEvent
- The listener to add.install(IInputModeContext, ConcurrencyController)
,
removeInitializedListener(IEventHandler)
public final void addInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Initializing
event that occurs before the call to initialize()
.
Clients can use this event to perform configuration of the instance shortly before the initialization begins.
initializingEvent
- The listener to add.install(IInputModeContext, ConcurrencyController)
,
removeInitializingListener(IEventHandler)
public final void addStoppedListener(IEventHandler<InputModeEventArgs> stoppedEvent)
Stopped
event that occurs after the call to stop()
.
Clients can use this event to perform post cleanup steps of the instance shortly after the mode has been stopped.
stoppedEvent
- The listener to add.onStopped(InputModeEventArgs)
,
cancel()
,
stop()
,
addCanceledListener(IEventHandler)
,
removeStoppedListener(IEventHandler)
public void cancel()
Controller
.
This implementation disables and reenables the Controller
and fires the onCanceled(InputModeEventArgs)
event afterwards. Classes that need to perform clean-up should override the onConcurrencyControllerDeactivated()
method and invoke base.OnConcurrencyControllerDeactivated as the last statement.
cancel
in interface IInputMode
onCanceled(InputModeEventArgs)
,
addCanceledListener(IEventHandler)
protected final boolean canRequestMutex()
This will return true, iff a Controller
has been injected and the helper allows requesting the
mutex.
requestMutex()
would currently succeed.protected IInputModeContext createChildInputModeContext()
IInputModeContext
that is specific to this mode.
This is needed for events that are triggered by this InputMode to signalize where the event is coming from. A common
usage for this is for example in IHitTestable.isHit(IInputModeContext, com.yworks.yfiles.geometry.PointD)
calls.
The result can be given to IHitTestable.isHit(IInputModeContext, com.yworks.yfiles.geometry.PointD)
or CanvasControl.hitElementsAt(IInputModeContext, com.yworks.yfiles.geometry.PointD, com.yworks.yfiles.view.ICanvasObjectGroup, java.util.function.Predicate)
to let implementations of IHitTestable
get access to the current
IInputModeContext
. This can be done by looking up IInputModeContext
from the
ICanvasContext
's ILookup.lookup(Class)
method or simply downcasting.
IInputModeContext
.CanvasControl.hitElementsAt(IInputModeContext, com.yworks.yfiles.geometry.PointD, com.yworks.yfiles.view.ICanvasObjectGroup, java.util.function.Predicate)
,
IHitTestable.isHit(IInputModeContext, com.yworks.yfiles.geometry.PointD)
,
IInputModeContext
protected InputModeEventArgs createInputModeEventArgs(IInputModeContext context)
InputModeEventArgs
for this input mode.context
- An input mode context that is available in the InputModeEventArgs
.
Can be null
in which case a new context for this instance is created automatically.
protected final ConcurrencyController getController()
Controller
.requestMutex()
,
releaseMutex()
,
hasMutex()
,
canRequestMutex()
public final IInputModeContext getInputModeContext()
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. One
such instance can be obtained through helper method createChildInputModeContext()
.
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
protected final boolean hasMutex()
If no Controller
had been associated with this instance upon the call to requestMutex()
this method will return false
.
protected void initialize()
This method should not be invoked by subclasses. This will be done automatically upon first installation
of this mode.
This code will be executed only once per instance. The Canvas
property and InputModeContext
property will be null
when this code is executed. This method should not be used to install this mode into a
specific canvas. Subclasses should always call base.Initialize()
first.
public void install(IInputModeContext context, ConcurrencyController controller)
CanvasControl
using the provided IInputModeContext
.
Subclasses should override this method and callbase.Install(context)
, first. One-time initialization should be
performed in the initialize()
method. This implementation will call the initialize()
method the first
time this mode gets installed. The initialization will be surrounded by calls to onInitializing(InputModeEventArgs)
and onInitialized(InputModeEventArgs)
to trigger the corresponding events.
install
in interface IInputMode
context
- the context to install this mode intocontroller
- The Controller
for this mode.getCanvas()
,
getInputModeContext()
,
CanvasControl.getInputMode()
public final boolean isActive()
This mode is active if a Controller
is installed and is
Active
.
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 isInstalled()
Canvas
will yield a non-null
result.install(IInputModeContext, ConcurrencyController)
protected void onCanceled(InputModeEventArgs eventArgs)
Canceled
event.
This method is called by subclasses when the editing process has been cancel()
ed.
eventArgs
- The event arguments.initialize()
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 onInitialized(InputModeEventArgs eventArgs)
Initialized
event.
This method will be called by install(IInputModeContext, ConcurrencyController)
for the first installation
directly after initialize()
has returned.
eventArgs
- The event arguments.initialize()
protected void onInitializing(InputModeEventArgs eventArgs)
Initializing
event.
This method will be called by install(IInputModeContext, ConcurrencyController)
for the first installation
directly before initialize()
is invoked.
eventArgs
- The event arguments.initialize()
protected void onMutexObtained()
If no Controller
had been associated with this instance upon the call to requestMutex()
this method will not be called.
protected void onMutexReleased()
If no Controller
had been associated with this instance upon the call to requestMutex()
this method will not be called.
protected void onStopped(InputModeEventArgs eventArgs)
Stopped
event.
This method will be called by stop()
or can be called by subclasses during a stop()
operation.
eventArgs
- The event arguments.stop()
,
addStoppedListener(IEventHandler)
protected void releaseKeyboard()
protected final void releaseMutex()
This will trigger the onMutexReleased()
method if this instance previously owned the mutex.
protected void releasePointer()
public final void removeCanceledListener(IEventHandler<InputModeEventArgs> canceledEvent)
Canceled
event that occurs after the call to cancel()
.
Clients can use this event to perform post cleanup steps of the instance shortly after the mode has been canceled.
canceledEvent
- The listener to remove.onCanceled(InputModeEventArgs)
,
cancel()
,
stop()
,
addStoppedListener(IEventHandler)
,
addCanceledListener(IEventHandler)
public final void removeInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Initialized
event that occurs after the call to initialize()
.
Clients can use this event to perform post configuration steps of the instance shortly after the initialization has been performed.
initializedEvent
- The listener to remove.install(IInputModeContext, ConcurrencyController)
,
addInitializedListener(IEventHandler)
public final void removeInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Initializing
event that occurs before the call to initialize()
.
Clients can use this event to perform configuration of the instance shortly before the initialization begins.
initializingEvent
- The listener to remove.install(IInputModeContext, ConcurrencyController)
,
addInitializingListener(IEventHandler)
public final void removeStoppedListener(IEventHandler<InputModeEventArgs> stoppedEvent)
Stopped
event that occurs after the call to stop()
.
Clients can use this event to perform post cleanup steps of the instance shortly after the mode has been stopped.
stoppedEvent
- The listener to remove.onStopped(InputModeEventArgs)
,
cancel()
,
stop()
,
addCanceledListener(IEventHandler)
,
addStoppedListener(IEventHandler)
protected void requestKeyboard()
CanvasControl
.
This sets the AllKeyboardInputCapturingEnabled
property to
true
, which will prevent visuals inside the canvas from stealing key strokes.
releaseKeyboard()
protected final void requestMutex()
Controller
.
This implementation will call the onMutexObtained()
method if the mutex has been successfully obtained. If the
mutex cannot be obtained this method will trigger an exception.
RuntimeException
- If the mutex could not be obtained.protected void requestPointer()
CanvasControl
.
This sets the AllPointerInputCapturingEnabled
property to
true
, which will prevent visuals inside the canvas from stealing mouse input.
releasePointer()
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 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 boolean stop()
This implementation returns if this instance does not currently have the input mutex
.
This implementation calls onStopped(InputModeEventArgs)
. Subclasses that want to prevent a stop or need to do
special clean up should do this here if the base class implementation of stop()
returns
true
. A typical implementation should follow this idiom if it wants to stop:
and if it doesn't want to stop simply return false
immediately.
Calling this method raises the Stopped
event.
stop
in interface IInputMode
true
iff this instance does not own the mutex
.onStopped(InputModeEventArgs)
public void uninstall(IInputModeContext context)
Subclasses should always call base.Uninstall(context)
as the last statement.
uninstall
in interface IInputMode
context
- The context to remove this mode from. This is the same instance that has been passed to
install(IInputModeContext, ConcurrencyController)
.