public class MouseEvent extends InputEvent
EventDispatcher
.
The mouse (pointer's) location is available relative to several
coordinate systems: x,y - relative to the origin of the
MouseEvent's node, sceneX,sceneY - relative to to the
origin of the Scene
that contains the node,
screenX,screenY - relative to origin of the screen that
contains the mouse pointer.
There are three types of dragging gestures. They are all initiated by a mouse press event and terminated as a result of a mouse released event, the source node decides which gesture will take place.
The simple press-drag-release gesture is default. It's best used to allow changing size of a shape, dragging it around and so on. Whole press-drag-release gesture is delivered to one node. When mouse button is pressed, the top-most node is picked and all subsequent mouse events are delivered to the same node until the button is released. If a mouse clicked event is generated from these events, it is still delivered to the same node.
During simple press-drag-release gesture, the other nodes are not involved
and don't get any events. If these nodes need to be involved in the gesture,
full press-drag-release gesture has to be activated. This gesture is
best used for connecting nodes by "wires", dragging nodes to other nodes etc.
This gesture type is more closely described at
MouseDragEvent
which contains
the events delivered to the gesture targets.
The third gesture type is platform-supported drag-and-drop gesture. It serves
best to transfer data and works also between (not necessarily FX)
applications. This gesture type is more closely described
at DragEvent
.
In a short summary, simple press-drag-release gesture is activated
automatically when a mouse button is pressed and delivers all
MouseEvent
s to the gesture source. When you start dragging,
eventually the DRAG_DETECTED
event arrives. In its handler
you can either start full press-drag-release gesture by calling
startFullDrag
method on a node or scene - the MouseDragEvent
s
start to be delivered to gesture targets, or you can start drag and drop
gesture by calling startDragAndDrop
method on a node or scene -
the system switches into the drag and drop mode and DragEvent
s start
to be delivered instead of MouseEvent
s. If you don't call any of
those methods, the simple press-drag-release gesture continues.
Note that dragging a finger over touch screen produces mouse dragging events,
but also scroll gesture events. If it means a conflict in an application
(the physical dragging action is handled by two different handlers), the
isSynthesized()
method may be used to detect the problem and make the
dragging handlers behave accordingly.
When mouse enters a node, the node gets MOUSE_ENTERED
event, when
it leaves, it gets MOUSE_EXITED
event. These events are delivered
only to the entered/exited node and seemingly don't go through the
capturing/bubbling phases. This is the most common use-case.
When the capturing or bubbling is desired, there are
MOUSE_ENTERED_TARGET
/MOUSE_EXITED_TARGET
events. These events
go through capturing/bubbling phases normally. This means that parent may
receive the MOUSE_ENTERED_TARGET
event when mouse entered
either the parent itself or some of its children. To distinguish between
these two cases event target can be tested on equality with the node.
These two types are closely connected:
MOUSE_ENTERED
/MOUSE_EXITED
are subtypes
of MOUSE_ENTERED_TARGET
/MOUSE_EXITED_TARGET
.
During capturing phase,
MOUSE_ENTERED_TARGET
is delivered to the
parents. When the event is delivered to the event target (the node that
has actually been entered), its type is switched to
MOUSE_ENTERED
. Then the type is switched back to
MOUSE_ENTERED_TARGET
for the bubbling phase.
It's still one event just switching types, so if it's filtered or consumed,
it affects both event variants. Thanks to the subtype-relationship, a
MOUSE_ENTERED_TARGET
event handler will receive the
MOUSE_ENTERED
event on target.
ContextMenuEvent
.Modifier and Type | Class and Description |
---|---|
private static class |
MouseEvent.Flags
These properties need to live in a separate object shared among all the
copied events to make sure that the values are propagated to the
original event.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
altDown
Whether or not the Alt modifier is down on this event.
|
static <any> |
ANY
Common supertype for all mouse event types.
|
private MouseButton |
button
Which, if any, of the mouse buttons is responsible for this event.
|
private int |
clickCount
Number of mouse clicks associated with this event.
|
private boolean |
controlDown
Whether or not the Control modifier is down on this event.
|
static <any> |
DRAG_DETECTED
This event is delivered to a node that is identified as a source of a
dragging gesture.
|
private MouseEvent.Flags |
flags |
private boolean |
metaDown
Whether or not the Meta modifier is down on this event.
|
private boolean |
middleButtonDown
true if middle button (button 2) is currently pressed. |
static <any> |
MOUSE_CLICKED
This event occurs when mouse button has been clicked (pressed and
released on the same node).
|
static <any> |
MOUSE_DRAGGED
This event occurs when mouse moves with a pressed button.
|
static <any> |
MOUSE_ENTERED
This event occurs when mouse enters a node.
|
static <any> |
MOUSE_ENTERED_TARGET
This event occurs when mouse enters a node.
|
static <any> |
MOUSE_EXITED
This event occurs when mouse exits a node.
|
static <any> |
MOUSE_EXITED_TARGET
This event occurs when mouse exits a node.
|
static <any> |
MOUSE_MOVED
This event occurs when mouse moves within a node and no buttons
are pressed.
|
static <any> |
MOUSE_PRESSED
This event occurs when mouse button is pressed.
|
static <any> |
MOUSE_RELEASED
This event occurs when mouse button is released.
|
private PickResult |
pickResult
Information about the pick if the picked
Node is a
Shape3D node and its pickOnBounds is false. |
private boolean |
popupTrigger
Whether or not this mouse event is the popup menu
trigger event for the platform.
|
private boolean |
primaryButtonDown
true if primary button (button 1, usually the left) is currently
pressed. |
private double |
sceneX
Horizontal x position of the event relative to the
origin of the
Scene that contains the MouseEvent's node. |
private double |
sceneY
Vertical y position of the event relative to the
origin of the
Scene that contains the MouseEvent's node. |
private double |
screenX
Absolute horizontal x position of the event.
|
private double |
screenY
Absolute vertical y position of the event.
|
private boolean |
secondaryButtonDown
true if secondary button (button 3, usually the right) is currently
pressed. |
private static long |
serialVersionUID |
private boolean |
shiftDown
Whether or not the Shift modifier is down on this event.
|
private boolean |
stillSincePress
Whether the mouse cursor left the hysteresis region since the previous
press.
|
private boolean |
synthesized |
private double |
x
Horizontal x position of the event relative to the
origin of the MouseEvent's node.
|
private double |
y
Vertical y position of the event relative to the
origin of the MouseEvent's node.
|
private double |
z
Depth z position of the event relative to the
origin of the MouseEvent's node.
|
Constructor and Description |
---|
MouseEvent(<any> eventType,
double x,
double y,
double screenX,
double screenY,
MouseButton button,
int clickCount,
boolean shiftDown,
boolean controlDown,
boolean altDown,
boolean metaDown,
boolean primaryButtonDown,
boolean middleButtonDown,
boolean secondaryButtonDown,
boolean synthesized,
boolean popupTrigger,
boolean stillSincePress,
PickResult pickResult)
Constructs new MouseEvent event with null source and target.
|
MouseEvent(java.lang.Object source,
EventTarget target,
<any> eventType,
double x,
double y,
double screenX,
double screenY,
MouseButton button,
int clickCount,
boolean shiftDown,
boolean controlDown,
boolean altDown,
boolean metaDown,
boolean primaryButtonDown,
boolean middleButtonDown,
boolean secondaryButtonDown,
boolean synthesized,
boolean popupTrigger,
boolean stillSincePress,
PickResult pickResult)
Constructs new MouseEvent event.
|
Modifier and Type | Method and Description |
---|---|
MouseEvent |
copyFor(java.lang.Object newSource,
EventTarget newTarget)
Copies this event for a different source and target.
|
MouseEvent |
copyFor(java.lang.Object newSource,
EventTarget newTarget,
<any> eventType)
Creates a copy of the given event with the given fields substituted.
|
static MouseDragEvent |
copyForMouseDragEvent(MouseEvent e,
java.lang.Object source,
EventTarget target,
<any> type,
java.lang.Object gestureSource,
PickResult pickResult)
Creates a copy of this mouse event of MouseDragEvent type
|
MouseButton |
getButton()
Which, if any, of the mouse buttons is responsible for this event.
|
int |
getClickCount()
Returns number of mouse clicks associated with this event.
|
<any> |
getEventType() |
PickResult |
getPickResult()
Returns information about the pick.
|
double |
getSceneX()
Returns horizontal position of the event relative to the
origin of the
Scene that contains the MouseEvent's source. |
double |
getSceneY()
Returns vertical position of the event relative to the
origin of the
Scene that contains the MouseEvent's source. |
double |
getScreenX()
Returns absolute horizontal position of the event.
|
double |
getScreenY()
Returns absolute vertical position of the event.
|
double |
getX()
Horizontal position of the event relative to the
origin of the MouseEvent's source.
|
double |
getY()
Vertical position of the event relative to the
origin of the MouseEvent's source.
|
double |
getZ()
Depth position of the event relative to the
origin of the MouseEvent's source.
|
boolean |
isAltDown()
Whether or not the Alt modifier is down on this event.
|
boolean |
isControlDown()
Whether or not the Control modifier is down on this event.
|
boolean |
isDragDetect()
Determines whether this event will be followed by
DRAG_DETECTED
event. |
boolean |
isMetaDown()
Whether or not the Meta modifier is down on this event.
|
boolean |
isMiddleButtonDown()
Returns
true if middle button (button 2)
is currently pressed. |
boolean |
isPopupTrigger()
Returns
true if this mouse event is the popup menu
trigger event for the platform. |
boolean |
isPrimaryButtonDown()
Returns
true if primary button (button 1, usually the left)
is currently pressed. |
boolean |
isSecondaryButtonDown()
Returns
true if secondary button (button 3, usually the right)
is currently pressed. |
boolean |
isShiftDown()
Whether or not the Shift modifier is down on this event.
|
boolean |
isShortcutDown()
Returns whether or not the host platform common shortcut modifier is
down on this event.
|
boolean |
isStillSincePress()
Indicates whether the mouse cursor stayed in the system-provided
hysteresis area since last pressed event that occurred before this event.
|
boolean |
isSynthesized()
Indicates whether this event is synthesized from using a touch screen
instead of usual mouse event source devices like mouse or track pad.
|
private void |
readObject(java.io.ObjectInputStream in) |
(package private) void |
recomputeCoordinatesToSource(MouseEvent oldEvent,
java.lang.Object newSource)
Fills the given event by this event's coordinates recomputed to the given
source object
|
void |
setDragDetect(boolean dragDetect)
Augments drag detection behavior.
|
java.lang.String |
toString()
Returns a string representation of this
MouseEvent object. |
private static final long serialVersionUID
public static final <any> ANY
public static final <any> MOUSE_PRESSED
public static final <any> MOUSE_RELEASED
public static final <any> MOUSE_CLICKED
public static final <any> MOUSE_ENTERED_TARGET
MOUSE_ENTERED
event handler should
be used.public static final <any> MOUSE_ENTERED
MOUSE_ENTERED_TARGET
.public static final <any> MOUSE_EXITED_TARGET
MOUSE_EXITED
event handler should
be used.public static final <any> MOUSE_EXITED
MOUSE_EXITED_TARGET
.public static final <any> MOUSE_MOVED
public static final <any> MOUSE_DRAGGED
public static final <any> DRAG_DETECTED
startFullDrag()
of startDragAndDrop()
method).
If none of them is called, simple press-drag-release gesture will continue.
Note that his event is generated based on dragging the mouse over a
platform-specific distance threshold. You can modify this behavior
by calling setDragDetect
method on any MOUSE_PRESSED or
MOUSE_DRAGGED event.
private final MouseEvent.Flags flags
private transient double x
private transient double y
private transient double z
private final double screenX
private final double screenY
private final double sceneX
Scene
that contains the MouseEvent's node.
If the node is not in a Scene
, then the value is relative to
the boundsInParent of the root-most parent of the MouseEvent's node.private final double sceneY
Scene
that contains the MouseEvent's node.
If the node is not in a Scene
, then the value is relative to
the boundsInParent of the root-most parent of the MouseEvent's node.private final MouseButton button
private final int clickCount
private final boolean stillSincePress
private final boolean shiftDown
private final boolean controlDown
private final boolean altDown
private final boolean metaDown
private final boolean synthesized
private final boolean popupTrigger
Note: Popup menus are triggered differently
on different systems. Therefore, popupTrigger
should be checked in both onMousePressed
and mouseReleased
for proper cross-platform functionality.
private final boolean primaryButtonDown
true
if primary button (button 1, usually the left) is currently
pressed. Note that this is different from the button
variable in that the button
variable indicates which button press was
responsible for this event while this variable indicates whether the
primary button is depressed.private final boolean secondaryButtonDown
true
if secondary button (button 3, usually the right) is currently
pressed. Note that this is different from the button
variable in that the button
variable indicates which button press was
responsible for this event while this variable indicates whether the
primary button is depressed.private final boolean middleButtonDown
true
if middle button (button 2) is currently pressed.
Note that this is different from the button
variable in
that the button
variable indicates which button press was
responsible for this event while this variable indicates whether the
middle button is depressed.private PickResult pickResult
Node
is a
Shape3D
node and its pickOnBounds is false.public MouseEvent(<any> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, boolean stillSincePress, PickResult pickResult)
eventType
- The type of the event.x
- The x with respect to the scene.y
- The y with respect to the scene.screenX
- The x coordinate relative to screen.screenY
- The y coordinate relative to screen.button
- the mouse button usedclickCount
- number of click countsshiftDown
- true if shift modifier was pressed.controlDown
- true if control modifier was pressed.altDown
- true if alt modifier was pressed.metaDown
- true if meta modifier was pressed.primaryButtonDown
- true if primary button was pressed.middleButtonDown
- true if middle button was pressed.secondaryButtonDown
- true if secondary button was pressed.synthesized
- if this event was synthesizedpopupTrigger
- whether this event denotes a popup trigger for current platformstillSincePress
- see isStillSincePress()
pickResult
- pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinatespublic MouseEvent(java.lang.Object source, EventTarget target, <any> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, boolean stillSincePress, PickResult pickResult)
source
- the source of the event. Can be null.target
- the target of the event. Can be null.eventType
- The type of the event.x
- The x with respect to the source. Should be in scene coordinates if source == null or source is not a Node.y
- The y with respect to the source. Should be in scene coordinates if source == null or source is not a Node.screenX
- The x coordinate relative to screen.screenY
- The y coordinate relative to screen.button
- the mouse button usedclickCount
- number of click countsshiftDown
- true if shift modifier was pressed.controlDown
- true if control modifier was pressed.altDown
- true if alt modifier was pressed.metaDown
- true if meta modifier was pressed.primaryButtonDown
- true if primary button was pressed.middleButtonDown
- true if middle button was pressed.secondaryButtonDown
- true if secondary button was pressed.synthesized
- if this event was synthesizedpopupTrigger
- whether this event denotes a popup trigger for current platformstillSincePress
- see isStillSincePress()
pickResult
- pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinates and targetvoid recomputeCoordinatesToSource(MouseEvent oldEvent, java.lang.Object newSource)
newEvent
- Event whose coordinates are to be fillednewSource
- Source object to compute coordinates forpublic <any> getEventType()
getEventType
in class InputEvent
public MouseEvent copyFor(java.lang.Object newSource, EventTarget newTarget)
newSource
- New event sourcenewTarget
- New event targetpublic MouseEvent copyFor(java.lang.Object newSource, EventTarget newTarget, <any> eventType)
newSource
- the new source of the copied eventnewTarget
- the new target of the copied eventeventType
- the new eventTypepublic static MouseDragEvent copyForMouseDragEvent(MouseEvent e, java.lang.Object source, EventTarget target, <any> type, java.lang.Object gestureSource, PickResult pickResult)
e
- the mouse event to copysource
- the new source of the copied eventtarget
- the new target of the copied eventtype
- the new MouseDragEvent typegestureSource
- the new source of the gesturepickResult
- pick result. Can be null, in this case a 2D pick result
without any further values is constructed
based on the scene coordinatespublic boolean isDragDetect()
DRAG_DETECTED
event. It has effect only with MOUSE_PRESSED
and
MOUSE_DRAGGED
events.DRAG_DETECTED
event will followpublic void setDragDetect(boolean dragDetect)
DRAG_DETECTED
event. It has effect only
with MOUSE_PRESSED
and MOUSE_DRAGGED
events.dragDetect
- Whether DRAG_DETECTED
event will followpublic final double getX()
public final double getY()
public final double getZ()
public final double getScreenX()
public final double getScreenY()
public final double getSceneX()
Scene
that contains the MouseEvent's source.
If the node is not in a Scene
, then the value is relative to
the boundsInParent of the root-most parent of the MouseEvent's node.
Note that in 3D scene, this represents the flat coordinates after
applying the projection transformations.Scene
that contains the MouseEvent's sourcepublic final double getSceneY()
Scene
that contains the MouseEvent's source.
If the node is not in a Scene
, then the value is relative to
the boundsInParent of the root-most parent of the MouseEvent's node.
Note that in 3D scene, this represents the flat coordinates after
applying the projection transformations.Scene
that contains the MouseEvent's sourcepublic final MouseButton getButton()
public final int getClickCount()
public final boolean isStillSincePress()
Click event is generated for a node if mouse was both pressed and
released over the node, regardless of mouse movements between the press
and release. If a node wants to react differently on a simple click and
on a mouse drag, it should use a system-supplied short distance
threshold to decide between click and drag (users often perform
inadvertent tiny movements during a click). It can be easily achieved
by ignoring all drags with this method returning true
and
ignoring all clicks with this method returning false
.
public final boolean isShiftDown()
public final boolean isControlDown()
public final boolean isAltDown()
public final boolean isMetaDown()
public boolean isSynthesized()
public final boolean isShortcutDown()
control
on Windows and meta
(command key) on Mac.true
if the shortcut modifier is down, false
otherwisepublic final boolean isPopupTrigger()
true
if this mouse event is the popup menu
trigger event for the platform.
Note: Popup menus are triggered differently
on different systems. Therefore, popupTrigger
should be checked in both onMousePressed
and mouseReleased
for proper cross-platform functionality.
true
if this mouse event is the popup menu
trigger event for the platformpublic final boolean isPrimaryButtonDown()
true
if primary button (button 1, usually the left)
is currently pressed. Note that this is different from the
getButton()
method that indicates which button press was
responsible for this event while this method indicates whether the
primary button is depressed.true
if primary button (button 1, usually the left)
is currently pressedpublic final boolean isSecondaryButtonDown()
true
if secondary button (button 3, usually the right)
is currently pressed. Note that this is different from the
getButton()
method that indicates which button press was
responsible for this event while this method indicates whether the
secondary button is depressed.true
if secondary button (button 3, usually the right)
is currently pressedpublic final boolean isMiddleButtonDown()
true
if middle button (button 2)
is currently pressed. Note that this is different from the
getButton()
method that indicates which button press was
responsible for this event while this method indicates whether the
middle button is depressed.true
if middle button (button 2) is currently pressedpublic java.lang.String toString()
MouseEvent
object.MouseEvent
object.public final PickResult getPickResult()
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException