public class MoveViewportInputMode extends Object implements IInputMode
IInputMode
implementation that can be used to grab and drag the viewport of the control it is installed in.
This implementation will request the mutex as soon as it recognizes a drag with the mouse or touch. Zooming is done with two fingers using the pinch zoom gesture. If the primary pointer is released during pinch, the secondary pointer is used for viewpoint dragging. The pinch zoom then can be restarted by touching another pointer that is recognized as the primary pointer.
This mode is Exclusive
by default.
Constructor and Description |
---|
MoveViewportInputMode()
Creates a new instance of the move viewport mode.
|
Modifier and Type | Method and Description |
---|---|
void |
addDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
Adds the given listener for the
DragCanceled event that occurs when the drag has been canceled. |
void |
addDragCancelingListener(IEventHandler<InputModeEventArgs> dragCancelingEvent)
Adds the given listener for the
DragCanceling event that occurs before the drag will be canceled. |
void |
addDragFinishedListener(IEventHandler<InputModeEventArgs> dragFinishedEvent)
Adds the given listener for the
DragFinished event that occurs once the drag has been finished. |
void |
addDragFinishingListener(IEventHandler<InputModeEventArgs> dragFinishingEvent)
Adds the given listener for the
DragFinishing event that occurs before the drag will be finished. |
void |
addDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Adds the given listener for the
Dragged event that occurs at the end of every drag. |
void |
addDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Adds the given listener for the
Dragging event that occurs at the start of every drag. |
void |
addDragStartedListener(IEventHandler<InputModeEventArgs> dragStartedEvent)
Adds the given listener for the
DragStarted event that occurs once the drag is initialized and has started. |
void |
addDragStartingListener(IEventHandler<InputModeEventArgs> dragStartingEvent)
Adds the given listener for the
DragStarting event that occurs once the drag is starting. |
protected void |
arm()
Called to prepare moving the viewport when the mouse is pressed.
|
void |
cancel()
Cancels navigation.
|
protected void |
disarm()
Called after moving the viewport is finished or canceled.
|
protected ConcurrencyController |
getController()
Returns the installed
Controller . |
Cursor |
getDragCursor()
The cursor to use during the dragging.
|
IEventRecognizer |
getDraggedRecognizer()
Gets the "dragged" recognizer.
|
InertiaPolicies |
getInertia()
Gets the mode that determines when to use inertia when dragging the viewport.
|
double |
getInertiaDamping()
The amount of damping that is applied to the inertia movement.
|
double |
getInertiaFactor()
Gets the factor that determines how much the recent movement data is taken into account for the calculation of inertia
speed and direction.
|
double |
getInertiaThreshold()
Gets the threshold that determines when inertia movement should stop.
|
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
IEventRecognizer |
getPressedRecognizer()
Gets the "pressed" state recognizer.
|
IEventRecognizer |
getPrimaryDownRecognizer()
Gets the
IEventRecognizer that starts the 'move viewport' gesture. |
IEventRecognizer |
getPrimaryMoveRecognizer()
Gets the
IEventRecognizer that moves the viewport or zooms the canvas if a secondary device is down. |
IEventRecognizer |
getPrimaryUpRecognizer()
Gets the
IEventRecognizer that ends the 'move viewport' or 'pinch' gesture. |
int |
getPriority()
The priority of this input mode.
|
IEventRecognizer |
getReleasedRecognizer()
Gets the "released" recognizer.
|
IEventRecognizer |
getSecondaryDownRecognizer()
Gets the
IEventRecognizer that starts the 'pinch' gesture. |
IEventRecognizer |
getSecondaryMoveRecognizer()
Gets the
IEventRecognizer that zooms the canvas using the 'pinch' gesture or moves the viewport if no primary
device is down. |
IEventRecognizer |
getSecondaryUpRecognizer()
Gets the
IEventRecognizer that ends the pinch zoom gesture or ends the move if no primary device is down. |
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 |
isPinchZoomAllowed()
Gets a value indicating whether to allow the pinch zoom gesture.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onDragCanceled(InputModeEventArgs inputModeEventArgs)
Triggers the
DragCanceled event. |
protected void |
onDragCanceling(InputModeEventArgs inputModeEventArgs)
Triggers the
DragCanceling event. |
protected void |
onDragFinished(InputModeEventArgs inputModeEventArgs)
Callback triggered once the drag has been finalized.
|
protected void |
onDragFinishing(InputModeEventArgs inputModeEventArgs)
Callback triggered before the drag will be finalized.
|
protected void |
onDragged(InputModeEventArgs inputModeEventArgs)
Callback triggered at the end of each drag.
|
protected void |
onDragging(InputModeEventArgs inputModeEventArgs)
Callback triggered at the start of each drag.
|
protected void |
onDragStarted(InputModeEventArgs inputModeEventArgs)
Triggers the
DragStarted event. |
protected void |
onDragStarting(InputModeEventArgs inputModeEventArgs)
Triggers the
DragStarting event. |
protected void |
onStopped()
Called after
stop() has been called. |
void |
removeDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
Removes the given listener for the
DragCanceled event that occurs when the drag has been canceled. |
void |
removeDragCancelingListener(IEventHandler<InputModeEventArgs> dragCancelingEvent)
Removes the given listener for the
DragCanceling event that occurs before the drag will be canceled. |
void |
removeDragFinishedListener(IEventHandler<InputModeEventArgs> dragFinishedEvent)
Removes the given listener for the
DragFinished event that occurs once the drag has been finished. |
void |
removeDragFinishingListener(IEventHandler<InputModeEventArgs> dragFinishingEvent)
Removes the given listener for the
DragFinishing event that occurs before the drag will be finished. |
void |
removeDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Removes the given listener for the
Dragged event that occurs at the end of every drag. |
void |
removeDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Removes the given listener for the
Dragging event that occurs at the start of every drag. |
void |
removeDragStartedListener(IEventHandler<InputModeEventArgs> dragStartedEvent)
Removes the given listener for the
DragStarted event that occurs once the drag is initialized and has started. |
void |
removeDragStartingListener(IEventHandler<InputModeEventArgs> dragStartingEvent)
Removes the given listener for the
DragStarting event that occurs once the drag is starting. |
void |
setDragCursor(Cursor value)
The cursor to use during the dragging.
|
void |
setDraggedRecognizer(IEventRecognizer value)
Sets the "dragged" recognizer.
|
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 |
setInertia(InertiaPolicies value)
Sets the mode that determines when to use inertia when dragging the viewport.
|
void |
setInertiaDamping(double value)
The amount of damping that is applied to the inertia movement.
|
void |
setInertiaFactor(double value)
Sets the factor that determines how much the recent movement data is taken into account for the calculation of inertia
speed and direction.
|
void |
setInertiaThreshold(double value)
Sets the threshold that determines when inertia movement should stop.
|
void |
setPinchZoomAllowed(boolean value)
Sets a value indicating whether to allow the pinch zoom gesture.
|
void |
setPressedRecognizer(IEventRecognizer value)
Sets the "pressed" state recognizer.
|
void |
setPrimaryDownRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that starts the 'move viewport' gesture. |
void |
setPrimaryMoveRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that moves the viewport or zooms the canvas if a secondary device is down. |
void |
setPrimaryUpRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that ends the 'move viewport' or 'pinch' gesture. |
void |
setPriority(int value)
The priority of this input mode.
|
void |
setReleasedRecognizer(IEventRecognizer value)
Sets the "released" recognizer.
|
void |
setSecondaryDownRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that starts the 'pinch' gesture. |
void |
setSecondaryMoveRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that zooms the canvas using the 'pinch' gesture or moves the viewport if no primary
device is down. |
void |
setSecondaryUpRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer that ends the pinch zoom gesture or ends the move if no primary device is down. |
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 MoveViewportInputMode()
public final void addDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
DragCanceled
event that occurs when the drag has been canceled.dragCanceledEvent
- The listener to add.removeDragCanceledListener(IEventHandler)
public final void addDragCancelingListener(IEventHandler<InputModeEventArgs> dragCancelingEvent)
DragCanceling
event that occurs before the drag will be canceled.dragCancelingEvent
- The listener to add.removeDragCancelingListener(IEventHandler)
public final void addDragFinishedListener(IEventHandler<InputModeEventArgs> dragFinishedEvent)
DragFinished
event that occurs once the drag has been finished.dragFinishedEvent
- The listener to add.removeDragFinishedListener(IEventHandler)
public final void addDragFinishingListener(IEventHandler<InputModeEventArgs> dragFinishingEvent)
DragFinishing
event that occurs before the drag will be finished.dragFinishingEvent
- The listener to add.removeDragFinishingListener(IEventHandler)
public final void addDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Dragged
event that occurs at the end of every drag.draggedEvent
- The listener to add.removeDraggedListener(IEventHandler)
public final void addDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Dragging
event that occurs at the start of every drag.draggingEvent
- The listener to add.removeDraggingListener(IEventHandler)
public final void addDragStartedListener(IEventHandler<InputModeEventArgs> dragStartedEvent)
DragStarted
event that occurs once the drag is initialized and has started.dragStartedEvent
- The listener to add.removeDragStartedListener(IEventHandler)
public final void addDragStartingListener(IEventHandler<InputModeEventArgs> dragStartingEvent)
DragStarting
event that occurs once the drag is starting.dragStartingEvent
- The listener to add.removeDragStartingListener(IEventHandler)
protected void arm()
This will set the mouse cursor to DragCursor
.
public void cancel()
cancel
in interface IInputMode
protected void disarm()
This will reset the mouse cursor.
protected final ConcurrencyController getController()
Controller
.public final Cursor getDragCursor()
The default is Hand
.
setDragCursor(Cursor)
public final IEventRecognizer getDraggedRecognizer()
This recognizer instance determines when the user is dragging the viewport.
setDraggedRecognizer(IEventRecognizer)
public final InertiaPolicies getInertia()
setInertia(InertiaPolicies)
public final double getInertiaDamping()
The default value is 0.15d
setInertiaDamping(double)
public final double getInertiaFactor()
The default value is 0.02d
setInertiaFactor(double)
public final double getInertiaThreshold()
The default value is 30
setInertiaThreshold(double)
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 IEventRecognizer getPressedRecognizer()
This recognizer instance will be used to determine when the user begins the navigation gesture.
setPressedRecognizer(IEventRecognizer)
public final IEventRecognizer getPrimaryDownRecognizer()
IEventRecognizer
that starts the 'move viewport' gesture.setPrimaryDownRecognizer(IEventRecognizer)
public final IEventRecognizer getPrimaryMoveRecognizer()
IEventRecognizer
that moves the viewport or zooms the canvas if a secondary device is down.setPrimaryMoveRecognizer(IEventRecognizer)
public final IEventRecognizer getPrimaryUpRecognizer()
IEventRecognizer
that ends the 'move viewport' or 'pinch' gesture.setPrimaryUpRecognizer(IEventRecognizer)
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 IEventRecognizer getReleasedRecognizer()
This instance determines when the user has finished dragging the viewport.
setReleasedRecognizer(IEventRecognizer)
public final IEventRecognizer getSecondaryDownRecognizer()
IEventRecognizer
that starts the 'pinch' gesture.setSecondaryDownRecognizer(IEventRecognizer)
public final IEventRecognizer getSecondaryMoveRecognizer()
IEventRecognizer
that zooms the canvas using the 'pinch' gesture or moves the viewport if no primary
device is down.setSecondaryMoveRecognizer(IEventRecognizer)
public final IEventRecognizer getSecondaryUpRecognizer()
IEventRecognizer
that ends the pinch zoom gesture or ends the move if no primary device is down.setSecondaryUpRecognizer(IEventRecognizer)
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 isPinchZoomAllowed()
true
if the pinch zoom gesture is allowed to change the zoom level; otherwise, false
.setPinchZoomAllowed(boolean)
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 onDragCanceled(InputModeEventArgs inputModeEventArgs)
DragCanceled
event.inputModeEventArgs
- The event argument that contains context information.protected void onDragCanceling(InputModeEventArgs inputModeEventArgs)
DragCanceling
event.inputModeEventArgs
- The event argument that contains context information.protected void onDragFinished(InputModeEventArgs inputModeEventArgs)
This method triggers the DragFinished
event.
inputModeEventArgs
- The event argument that contains context information.protected void onDragFinishing(InputModeEventArgs inputModeEventArgs)
This method triggers the DragFinishing
event.
inputModeEventArgs
- The event argument that contains context information.protected void onDragged(InputModeEventArgs inputModeEventArgs)
This method triggers the Dragged
event.
inputModeEventArgs
- The event argument that contains context information.protected void onDragging(InputModeEventArgs inputModeEventArgs)
This method triggers the Dragging
event.
inputModeEventArgs
- The event argument that contains context information.protected void onDragStarted(InputModeEventArgs inputModeEventArgs)
DragStarted
event.inputModeEventArgs
- The event argument that contains context information.protected void onDragStarting(InputModeEventArgs inputModeEventArgs)
DragStarting
event.inputModeEventArgs
- The event argument that contains context information.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 removeDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
DragCanceled
event that occurs when the drag has been canceled.dragCanceledEvent
- The listener to remove.addDragCanceledListener(IEventHandler)
public final void removeDragCancelingListener(IEventHandler<InputModeEventArgs> dragCancelingEvent)
DragCanceling
event that occurs before the drag will be canceled.dragCancelingEvent
- The listener to remove.addDragCancelingListener(IEventHandler)
public final void removeDragFinishedListener(IEventHandler<InputModeEventArgs> dragFinishedEvent)
DragFinished
event that occurs once the drag has been finished.dragFinishedEvent
- The listener to remove.addDragFinishedListener(IEventHandler)
public final void removeDragFinishingListener(IEventHandler<InputModeEventArgs> dragFinishingEvent)
DragFinishing
event that occurs before the drag will be finished.dragFinishingEvent
- The listener to remove.addDragFinishingListener(IEventHandler)
public final void removeDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Dragged
event that occurs at the end of every drag.draggedEvent
- The listener to remove.addDraggedListener(IEventHandler)
public final void removeDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Dragging
event that occurs at the start of every drag.draggingEvent
- The listener to remove.addDraggingListener(IEventHandler)
public final void removeDragStartedListener(IEventHandler<InputModeEventArgs> dragStartedEvent)
DragStarted
event that occurs once the drag is initialized and has started.dragStartedEvent
- The listener to remove.addDragStartedListener(IEventHandler)
public final void removeDragStartingListener(IEventHandler<InputModeEventArgs> dragStartingEvent)
DragStarting
event that occurs once the drag is starting.dragStartingEvent
- The listener to remove.addDragStartingListener(IEventHandler)
public final void setDragCursor(Cursor value)
The default is Hand
.
value
- The DragCursor to set.getDragCursor()
public final void setDraggedRecognizer(IEventRecognizer value)
This recognizer instance determines when the user is dragging the viewport.
value
- The "dragged" recognizer.getDraggedRecognizer()
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 setInertia(InertiaPolicies value)
value
- The Inertia to set.getInertia()
public final void setInertiaDamping(double value)
The default value is 0.15d
value
- A value between 0 and 1 that determines the factor the inertia speed is reduced by after one second.getInertiaDamping()
public final void setInertiaFactor(double value)
The default value is 0.02d
value
- A value between 0 and 1. Lesser values mean less influence of old data.getInertiaFactor()
public final void setInertiaThreshold(double value)
The default value is 30
value
- A positive value that determines the threshold in pixels per second.getInertiaThreshold()
public final void setPinchZoomAllowed(boolean value)
value
- true
if the pinch zoom gesture is allowed to change the zoom level; otherwise, false
.isPinchZoomAllowed()
public final void setPressedRecognizer(IEventRecognizer value)
This recognizer instance will be used to determine when the user begins the navigation gesture.
value
- The "pressed" recognizer.getPressedRecognizer()
public final void setPrimaryDownRecognizer(IEventRecognizer value)
IEventRecognizer
that starts the 'move viewport' gesture.value
- The recognizer instance that identifies the event that starts the viewport moving gesture. The default instance
recognizes if the user presses the primary touch device down.getPrimaryDownRecognizer()
public final void setPrimaryMoveRecognizer(IEventRecognizer value)
IEventRecognizer
that moves the viewport or zooms the canvas if a secondary device is down.value
- The recognizer instance that identifies the event that moves the viewport or zooms the canvas. The default instance
recognizes if the user moves the primary touch device.getPrimaryMoveRecognizer()
public final void setPrimaryUpRecognizer(IEventRecognizer value)
IEventRecognizer
that ends the 'move viewport' or 'pinch' gesture.value
- The recognizer instance that identifies the event that ends the viewport moving or pinch gesture. The default instance
recognizes if the user releases the primary touch device.getPrimaryUpRecognizer()
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 setReleasedRecognizer(IEventRecognizer value)
This instance determines when the user has finished dragging the viewport.
value
- The "released" recognizer.getReleasedRecognizer()
public final void setSecondaryDownRecognizer(IEventRecognizer value)
IEventRecognizer
that starts the 'pinch' gesture.value
- The recognizer instance that identifies the event that starts the pinch gesture. The default instance recognizes if the
user presses the secondary touch device down.getSecondaryDownRecognizer()
public final void setSecondaryMoveRecognizer(IEventRecognizer value)
IEventRecognizer
that zooms the canvas using the 'pinch' gesture or moves the viewport if no primary
device is down.value
- The recognizer instance that identifies the event that zooms the canvas or moves the viewport if no primary device is
down. The default instance recognizes if the user moves the secondary touch device.getSecondaryMoveRecognizer()
public final void setSecondaryUpRecognizer(IEventRecognizer value)
IEventRecognizer
that ends the pinch zoom gesture or ends the move if no primary device is down.value
- The recognizer instance that identifies the event that ends the pinch zoom gesture or ends the move if no primary device
is down. The default instance recognizes if the user releases the secondary touch device.getSecondaryUpRecognizer()
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 final 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.