Class MouseGestureRecognizer
- All Implemented Interfaces:
AutoCloseable
High level events are subclasses of IInputEvent such as MouseClickEvent. Low levels are used to create those high level events and are dropped afterwards.
For example, a mouse pressed + (possibly multiple) mouse moved + a mouse released sequence is recognized as a drag gesture. A mouse pressed + a mouse released sequence is recognized as a click gesture. This class is useful when adding integration with a platform that does not provide these more high-level events.
A typical use of such a class is to wire it to a UI framework specific class (such as Qt , see QQuickMapObject in the sample code) and make the controller react to the high level event instead of every low level event the framework can fire.
The use of the MouseGestureRecognizer is optional. Events containing MouseButton#unknown() as the mouse button are not processed. A controller implementation can use custom conversion code if needed, for example if you want to manage the low level events yourself and create other high level IInputEvent instances.
The events passed to this class are expected to be defined in device independent pixels.
-
Constructor Summary
ConstructorsConstructorDescriptionMouseGestureRecognizer(IInputEventCallback callback) Creates aMouseGestureRecognizerthat passes the generated high levelIInputEvents to the given callback. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanprotected voidfinalize()doubleReturns the display scale factor.doublegetDpi()Returns the display pixel density, expressed in dots per inch.Returns the screen distance that is used as threshold to detect if a drag is performed.longReturns the interval (in milliseconds) used to detect multiple clicks.inthashCode()voidonKeyEvent(KeyEvent keyEvent) Entry point for the key events of the gesture recognizer.voidonMouseMoveEvent(MouseMoveEvent mouseMoveEvent) Entry point for the mouse move events of the gesture recognizer.voidonMousePressedEvent(MousePressedEvent mousePressedEvent) Entry point for the mouse pressed events of the gesture recognizer.voidonMouseReleasedEvent(MouseReleasedEvent mouseReleasedEvent) Entry point for the mouse released events of the gesture recognizer.voidonScrollEvent(ScrollEvent scrollEvent) Entry point for the scroll events of the gesture recognizer.voidsetDisplayScale(double scale) Sets the display scale factor.voidsetDpi(double dpi) Sets the display pixel density, expressed in dots per inch.voidsetDragThreshold(ScreenDistance threshold) Sets the screen distance that is used as threshold to detect if a drag is performed.voidsetMultiClickInterval(long interval) Sets the interval (in milliseconds) used to detect multiple clicks.
-
Constructor Details
-
MouseGestureRecognizer
Creates aMouseGestureRecognizerthat passes the generated high levelIInputEvents to the given callback.- Parameters:
callback- the callback that receive generatedIInputEvents. Can not benull.- Throws:
NullPointerException- If callback isnull.
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
onMousePressedEvent
Entry point for the mouse pressed events of the gesture recognizer.- Parameters:
mousePressedEvent- the low level mouse press event.
-
onMouseReleasedEvent
Entry point for the mouse released events of the gesture recognizer.- Parameters:
mouseReleasedEvent- the low level mouse released event.
-
onMouseMoveEvent
Entry point for the mouse move events of the gesture recognizer.- Parameters:
mouseMoveEvent- the low level mouse move event.
-
onScrollEvent
Entry point for the scroll events of the gesture recognizer.- Parameters:
scrollEvent- the low level mouse scroll event.
-
onKeyEvent
Entry point for the key events of the gesture recognizer.- Parameters:
keyEvent- the low level key event.
-
setMultiClickInterval
public void setMultiClickInterval(long interval) Sets the interval (in milliseconds) used to detect multiple clicks.The default is 400 ms. If the interval is set to 0, no multiple clicks will be detected.
- Parameters:
interval- the maximum time (in milliseconds) between multiple clicks.
-
getMultiClickInterval
public long getMultiClickInterval()Returns the interval (in milliseconds) used to detect multiple clicks.- Returns:
- the interval (in milliseconds) used to detect multiple clicks.
-
setDragThreshold
Sets the screen distance that is used as threshold to detect if a drag is performed.It means that the mouse cursor has to move at least that amount of pixels before it can be detected as a drag gesture.
The default value in device independent pixels is 2 pixels.
- Parameters:
threshold- the threshold
-
getDragThreshold
Returns the screen distance that is used as threshold to detect if a drag is performed.It means that the mouse cursor has to move at least that distance before it can be detected as a drag gesture.
- Returns:
- the screen distance that is used as threshold to detect if a drag is performed.
-
setDpi
public void setDpi(double dpi) Sets the display pixel density, expressed in dots per inch.If no value is provided, the platform standard pixel density is assumed.
- Parameters:
dpi- the pixel density in dots per inch
-
getDpi
public double getDpi()Returns the display pixel density, expressed in dots per inch.- Returns:
- the display pixel density, expressed in dots per inch.
-
setDisplayScale
public void setDisplayScale(double scale) Sets the display scale factor.If no value is provided, a scale factor of 1.0 is assumed.
- Parameters:
scale- the display scale factor
-
getDisplayScale
public double getDisplayScale()Returns the display scale factor.- Returns:
- the display scale factor.
-
hashCode
public int hashCode() -
equals
-