1 /*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.input;
27
28 import com.sun.javafx.scene.input.InputEventUtils;
29 import java.io.IOException;
30 import java.io.Serializable;
31 import javafx.beans.NamedArg;
32 import javafx.event.EventTarget;
33 import javafx.geometry.Point3D;
34 import javafx.scene.Node;
35 import javafx.scene.Scene;
36
37 /**
38 * Touch point represents a single point of a multi-touch action, typically
39 * one finger touching a screen. It is contained in {@link TouchEvent}.
40 * <p>
41 * The touch point has its coordinates, state (see {@link State}) and ID. The
42 * ID is sequential number of this touch point unique in scope of a single
43 * multi-touch gesture.
44 * <p>
45 * Each touch point is by default delivered to a single node during its whole
46 * trajectory - to the node on which it was pressed. There is a grabbing API
47 * to modify this behavior. The above means that when touch point is pressed,
48 * it is automatically grabbed by the top-most node on the press coordinates.
49 * Any time during the gesture {@code grab()} and {@code ungrab()} methods
50 * can be used to alter the event delivery target. When grabbed by a different
51 * node, it will next time be targeted to it; when ungrabbed, it will be
52 * always targeted to the top-most node on the current location.
53 *
54 * @since JavaFX 2.2
55 */
56 public final class TouchPoint implements Serializable{
57
58 private transient EventTarget target;
59 private transient Object source;
60
61 /**
62 * Creates new instance of TouchPoint.
63 * @param id ID of the new touch point
64 * @param state state of the new touch point
65 * @param x The x with respect to the scene.
66 * @param y The y with respect to the scene.
67 * @param screenX The x coordinate relative to screen.
68 * @param screenY The y coordinate relative to screen.
69 * @param pickResult pick result. Can be null, in this case a 2D pick result
70 * without any further values is constructed
71 * based on the scene coordinates and target
72 * @since JavaFX 8.0
73 */
74 public TouchPoint(@NamedArg("id") int id, @NamedArg("state") State state, @NamedArg("x") double x, @NamedArg("y") double y, @NamedArg("screenX") double screenX,
75 @NamedArg("screenY") double screenY, @NamedArg("target") EventTarget target, @NamedArg("pickResult") PickResult pickResult) {
76 this.target = target;
77 this.id = id;
118 */
119 public boolean belongsTo(EventTarget target) {
120
121 if (this.target instanceof Node) {
122 Node n = (Node) this.target;
123
124 if (target instanceof Scene) {
125 return n.getScene() == target;
126 }
127 while (n != null) {
128 if (n == target) {
129 return true;
130 }
131 n = n.getParent();
132 }
133 }
134
135 return target == this.target;
136 }
137
138 /**
139 * @treatAsPrivate implementation detail
140 * @deprecated This is an internal API that is not intended for use and will be removed in the next version
141 */
142 @Deprecated
143 public void impl_reset() {
144 final Point3D p = InputEventUtils.recomputeCoordinates(pickResult, null);
145 x = p.getX();
146 y = p.getY();
147 z = p.getZ();
148 }
149
150 private EventTarget grabbed = null;
151
152 /**
153 * Gets event target which has grabbed this touch point.
154 * @return The current grabbed target, null if the touch point is ungrabbed
155 */
156 public EventTarget getGrabbed() {
157 return grabbed;
158 }
159
160 /**
161 * Grabs this touch point by current event source. Next event containing
162 * this touch point will be targeted to the same node whose event handler
163 * called this method.
|
1 /*
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.input;
27
28 import com.sun.javafx.scene.input.InputEventUtils;
29 import com.sun.javafx.scene.input.TouchPointHelper;
30 import java.io.IOException;
31 import java.io.Serializable;
32 import javafx.beans.NamedArg;
33 import javafx.event.EventTarget;
34 import javafx.geometry.Point3D;
35 import javafx.scene.Node;
36 import javafx.scene.Scene;
37
38 /**
39 * Touch point represents a single point of a multi-touch action, typically
40 * one finger touching a screen. It is contained in {@link TouchEvent}.
41 * <p>
42 * The touch point has its coordinates, state (see {@link State}) and ID. The
43 * ID is sequential number of this touch point unique in scope of a single
44 * multi-touch gesture.
45 * <p>
46 * Each touch point is by default delivered to a single node during its whole
47 * trajectory - to the node on which it was pressed. There is a grabbing API
48 * to modify this behavior. The above means that when touch point is pressed,
49 * it is automatically grabbed by the top-most node on the press coordinates.
50 * Any time during the gesture {@code grab()} and {@code ungrab()} methods
51 * can be used to alter the event delivery target. When grabbed by a different
52 * node, it will next time be targeted to it; when ungrabbed, it will be
53 * always targeted to the top-most node on the current location.
54 *
55 * @since JavaFX 2.2
56 */
57 public final class TouchPoint implements Serializable{
58
59 static {
60 // This is used by classes in different packages to get access to
61 // private and package private methods.
62 TouchPointHelper.setTouchPointAccessor(new TouchPointHelper.TouchPointAccessor() {
63
64 @Override
65 public void reset(TouchPoint touchPoint) {
66 touchPoint.reset();
67 }
68 });
69 }
70
71 private transient EventTarget target;
72 private transient Object source;
73
74 /**
75 * Creates new instance of TouchPoint.
76 * @param id ID of the new touch point
77 * @param state state of the new touch point
78 * @param x The x with respect to the scene.
79 * @param y The y with respect to the scene.
80 * @param screenX The x coordinate relative to screen.
81 * @param screenY The y coordinate relative to screen.
82 * @param pickResult pick result. Can be null, in this case a 2D pick result
83 * without any further values is constructed
84 * based on the scene coordinates and target
85 * @since JavaFX 8.0
86 */
87 public TouchPoint(@NamedArg("id") int id, @NamedArg("state") State state, @NamedArg("x") double x, @NamedArg("y") double y, @NamedArg("screenX") double screenX,
88 @NamedArg("screenY") double screenY, @NamedArg("target") EventTarget target, @NamedArg("pickResult") PickResult pickResult) {
89 this.target = target;
90 this.id = id;
131 */
132 public boolean belongsTo(EventTarget target) {
133
134 if (this.target instanceof Node) {
135 Node n = (Node) this.target;
136
137 if (target instanceof Scene) {
138 return n.getScene() == target;
139 }
140 while (n != null) {
141 if (n == target) {
142 return true;
143 }
144 n = n.getParent();
145 }
146 }
147
148 return target == this.target;
149 }
150
151 private void reset() {
152 final Point3D p = InputEventUtils.recomputeCoordinates(pickResult, null);
153 x = p.getX();
154 y = p.getY();
155 z = p.getZ();
156 }
157
158 private EventTarget grabbed = null;
159
160 /**
161 * Gets event target which has grabbed this touch point.
162 * @return The current grabbed target, null if the touch point is ungrabbed
163 */
164 public EventTarget getGrabbed() {
165 return grabbed;
166 }
167
168 /**
169 * Grabs this touch point by current event source. Next event containing
170 * this touch point will be targeted to the same node whose event handler
171 * called this method.
|