From 98aa72f5875ac98ead12c155e87b655af7777d83 Mon Sep 17 00:00:00 2001 From: nlisker <37422899+nlisker@users.noreply.github.com> Date: Sat, 1 Aug 2026 04:01:14 +0300 Subject: [PATCH 1/2] Initial commit --- .../scene/input/doc-files/mouse_events.svg | 1 + .../java/javafx/scene/input/MouseEvent.java | 217 ++++++++++-------- 2 files changed, 122 insertions(+), 96 deletions(-) create mode 100644 modules/javafx.graphics/src/main/docs/javafx/scene/input/doc-files/mouse_events.svg diff --git a/modules/javafx.graphics/src/main/docs/javafx/scene/input/doc-files/mouse_events.svg b/modules/javafx.graphics/src/main/docs/javafx/scene/input/doc-files/mouse_events.svg new file mode 100644 index 00000000000..ed6f5188326 --- /dev/null +++ b/modules/javafx.graphics/src/main/docs/javafx/scene/input/doc-files/mouse_events.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java b/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java index 7827eff0c68..9c10e75a3f7 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java @@ -25,106 +25,131 @@ package javafx.scene.input; +import java.io.IOException; + +import com.sun.javafx.scene.input.InputEventUtils; import com.sun.javafx.tk.Toolkit; + import javafx.beans.NamedArg; +import javafx.event.EventDispatcher; import javafx.event.EventTarget; import javafx.event.EventType; import javafx.geometry.Point3D; -import com.sun.javafx.scene.input.InputEventUtils; -import java.io.IOException; - -// PENDING_DOC_REVIEW -/** - * When a mouse event occurs, the top-most node under cursor is picked and - * the event is delivered to it through capturing and bubbling phases - * described at {@link javafx.event.EventDispatcher 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 {@code 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 the default. It's best used to allow - * changing the size of a shape, dragging it around and so on. The whole - * press-drag-release gesture is delivered to one node. When a mouse - * button is pressed, the top-most node is picked and all subsequent - * mouse events are delivered to that 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 a 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 - * {@link javafx.scene.input.MouseDragEvent MouseDragEvent} which contains - * the events delivered to the gesture targets. - *
- * The third gesture type is the 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 {@link javafx.scene.input.DragEvent DragEvent}. - *
- * In summary, simple press-drag-release gestures are activated - * automatically when a mouse button is pressed and delivers all - * {@code MouseEvent}s to the gesture source. When you start dragging, - * eventually the {@code DRAG_DETECTED} event arrives. In its handler, - * you can either start a full press-drag-release gesture by calling the - * {@code startFullDrag} method on a node or scene - the {@code MouseDragEvent}s - * start to be delivered to gesture targets, or you can start drag and drop - * gesture by calling {@code startDragAndDrop} method on a node or scene - - * the system switches into the drag and drop mode and {@code DragEvent}s start - * to be delivered instead of {@code 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 - * {@code isSynthesized()} method may be used to detect the problem and make the - * dragging handlers behave accordingly. - * - *
- * When the mouse enters a node, the node gets a {@code MOUSE_ENTERED} event, when - * it leaves, it gets a {@code 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 capturing or bubbling is desired, there are - * {@code MOUSE_ENTERED_TARGET}/{@code MOUSE_EXITED_TARGET} events. These events - * go through capturing/bubbling phases normally. This means that a parent may - * receive the {@code MOUSE_ENTERED_TARGET} event when the mouse entered - * either the parent itself or some of its children. To distinguish between - * these two cases, the event target can be tested on equality with the node. - *
- * These two types are closely connected: - * {@code MOUSE_ENTERED}/{@code MOUSE_EXITED} are subtypes - * of {@code MOUSE_ENTERED_TARGET}/{@code MOUSE_EXITED_TARGET}. - * During capturing phase, - * {@code 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 - * {@code MOUSE_ENTERED}. Then the type is switched back to - * {@code 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 - * {@code MOUSE_ENTERED_TARGET} event handler will receive the - * {@code MOUSE_ENTERED} event on target. - * - *
| Name | +///Involved | +///Usage example | +///Start method | +///Event class | +///
|---|---|---|---|---|
| PDR | +///Source node/scene | +///Resize or move a shape | +///+/// | {@code MouseEvent} | +///
| Full PDR | +///Any node/scene | +///Connecting nodes or dropping a node on another | +///{@code startFullDrag} | +///{@code MouseDragEvent} | +///
| DnD | +///Any node/scene and OS applications | +///Copy/move text between applications | +///{@code startDragAndDrop} | +///{@code DragEvent} | +///
* Note that his event is generated based on dragging the mouse over a From 4b6503b038d72f59eebdc23f546e476ec5f604ed Mon Sep 17 00:00:00 2001 From: nlisker <37422899+nlisker@users.noreply.github.com> Date: Tue, 4 Aug 2026 03:36:24 +0300 Subject: [PATCH 2/2] Review clarifications --- .../src/main/java/javafx/scene/input/MouseEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java b/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java index 9c10e75a3f7..6e2254015fc 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/input/MouseEvent.java @@ -57,7 +57,7 @@ /// /// ## Button events /// A mouse button can be [pressed][#MOUSE_PRESSED] and [released][#MOUSE_RELEASED]. A button [click][#MOUSE_CLICKED] -/// occurs when these happen over the same node. Button events can still be produced during a drag gesture. +/// occurs after these happen over the same node. Button events can still be produced during a drag gesture. /// /// Not all buttons on the mouse are supported, such as macro buttons or buttons that change the DPI. /// @@ -69,8 +69,8 @@ /// /// There are 3 types of drag gestures that can be chosen from within the `DRAG_DETECTED` handler: /// -/// 1. Simple press-drag-release (PDR), in which the source (picked) node is the only node involved. It receives all the -/// events in the PDR gesture, including button events even when they occur over other nodes. +/// 1. Simple press-drag-release (PDR), in which the source (picked) node receives all the events in the PDR gesture, +/// including click events even when they occur over other nodes. /// During the gesture, [#MOUSE_DRAGGED] events are delivered. /// PDR is best used to allow changing the size of a shape, dragging it around etc. /// This gesture starts when no designated method is invoked within the event handler.