public class MultiplexingInputMode extends Object implements IInputMode
IInputMode
implementation that additionally can deal with Exclusive
instances.
Instances of this class can install(IInputModeContext, ConcurrencyController)
and uninstall(IInputModeContext)
multiple IInputMode
s. Child input modes can be added using the add(IInputMode)
method. By providing priorities
to the different modes, their installation
order
can be influenced. Input modes with lower priorities are handled earlier.
Child input modes can run exclusively while they hold the mutex. Other exclusive input modes are temporarily deactivated
until the mutex is released. This can be controlled by setting the Exclusive
property on the controller. Input modes that disable the Exclusive
property
will always run concurrently with all other input modes.
This class itself implements the IInputMode
interface so that hierarchies of instances of this class can easily
be built. This class will request the input mutex if one of its child modes requests the mutex. Also if the instance
itself gets disabled
, it will stop or cancel the current
owner of the mutex
.
getMutexOwner()
,
add(IInputMode)
Constructor and Description |
---|
MultiplexingInputMode()
Creates an instance with no initial modes.
|
Modifier and Type | Method and Description |
---|---|
void |
add(IInputMode mode)
Adds the given
mode . |
void |
adjustCursor()
Adjusts the cursor of the
CanvasControl according to the current input mutex owner or the first mode in the list
whose ConcurrencyController returns a non-null
PreferredCursor . |
void |
cancel()
Cancels all modes.
|
protected Object |
childInputModeContextLookup(Class type)
Callback method that will be used by the
child context's ILookup.lookup(Class)
method. |
protected IInputModeContext |
createChildInputModeContext()
Yields an
IInputModeContext for the child modes of 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 . |
Cursor |
getDefaultCursor()
Gets the cursor to use whenever no child mode prefers a different cursor.
|
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
IInputMode |
getMutexOwner()
Gets the
IInputMode that currently owns the mutex. |
int |
getPriority()
The priority of this input mode.
|
List<IInputMode> |
getSortedModes()
Returns a list of all modes managed by this instance in sorted order.
|
protected void |
initialize()
Performs one-time initialization of this instance.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into the given context that is provided by the canvas.
|
protected void |
invalidate()
Convenience method for subclass implementations that invalidates the canvas this mode is currently installed in.
|
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.
|
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
void |
remove(IInputMode mode)
Removes the given mode from this compound mode.
|
void |
setDefaultCursor(Cursor value)
Sets the cursor to use whenever no child mode prefers a different cursor.
|
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 all modes.
|
protected void |
subModePriorityChanged()
|
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the given context.
|
public MultiplexingInputMode()
public final void add(IInputMode mode)
mode
.
The input modes will be ordered according to their Priority
: Input modes with lower
priority will be installed
earlier.
Input modes will run exclusively if the Exclusive
property of their installed controller
is set to true
. Otherwise they can not and will not be deactivated if another IInputMode
acquires the
mutex.
IllegalArgumentException
- If the same mode
has is already added to this instance.mode
- The input mode to add to this mode.public void adjustCursor()
CanvasControl
according to the current input mutex owner or the first mode in the list
whose ConcurrencyController
returns a non-null
PreferredCursor
.
This method will set DefaultCursor
as the current cursor if no other PreferredCursor
has been specified.
public void cancel()
cancel
in interface IInputMode
protected Object childInputModeContextLookup(Class type)
child context's
ILookup.lookup(Class)
method.type
- The type argument passed to ILookup.lookup(Class)
.null
.createChildInputModeContext()
protected IInputModeContext createChildInputModeContext()
IInputModeContext
for the child modes of this mode.
This method is called during installation
to create a new
context for the child modes and can be used by client code to obtain a suitable context object. The InputModeContext
property is already set, when this method is called. ILookup.lookup(Class)
calls for the created context will be
resolved by this instance's childInputModeContextLookup(Class)
method.
parent's context.
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
.public final Cursor getDefaultCursor()
The default is null
adjustCursor()
,
setDefaultCursor(Cursor)
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 IInputMode getMutexOwner()
IInputMode
that currently owns the mutex.IInputMode
that currently owns the mutex or null
.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 List<IInputMode> getSortedModes()
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)
IInputMode
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.
When this instance gets uninstalled
from the context the same context instance
will be passed to it.
Implementations may hold a reference to the context
instance and use it while they are being installed.
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)
protected void invalidate()
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)
protected void onConcurrencyControllerActivated()
Active
property of the installed ConcurrencyController
has been set to true
.
This implementation reenabled previously disabled concurrent child modes.
protected void onConcurrencyControllerDeactivated()
Active
property of the installed ConcurrencyController
has been set to false
.
This implementation sets the PreferredCursor
property to null
and releases
the mutex if the mutex is currently owned by this instance.
Also, all concurrent child modes will be disabled.
public final void remove(IInputMode mode)
mode
- The mode to remove.public final void setDefaultCursor(Cursor value)
The default is null
value
- The DefaultCursor to set.adjustCursor()
,
getDefaultCursor()
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()
stop
in interface IInputMode
true
if and only if the editing has been stopped or there was no edit in progressIInputMode.cancel()
protected final void subModePriorityChanged()
Priority
of an installed
sub mode has
changed.
This implementation uninstalls
all sub modes and then re-installs
them according to their new priorities.
public void uninstall(IInputModeContext context)
IInputMode
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.
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.