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;
27
28 import com.sun.javafx.stage.FocusUngrabEvent;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.Collection;
32 import javafx.event.ActionEvent;
33 import javafx.event.Event;
34 import javafx.event.EventHandler;
35 import javafx.event.EventType;
36 import javafx.scene.input.ContextMenuEvent;
37 import javafx.scene.input.DragEvent;
38 import javafx.scene.input.GestureEvent;
39 import javafx.scene.input.InputEvent;
40 import javafx.scene.input.InputMethodEvent;
41 import javafx.scene.input.InputMethodTextRun;
42 import javafx.scene.input.KeyCode;
43 import javafx.scene.input.KeyEvent;
44 import javafx.scene.input.MouseButton;
45 import javafx.scene.input.MouseDragEvent;
46 import javafx.scene.input.MouseEvent;
47 import javafx.scene.input.RotateEvent;
48 import javafx.scene.input.ScrollEvent;
49 import javafx.scene.input.SwipeEvent;
50 import javafx.scene.input.TouchEvent;
51 import javafx.scene.input.TouchPoint;
52 import javafx.scene.input.TransferMode;
53 import javafx.scene.input.ZoomEvent;
54 import javafx.scene.shape.Rectangle;
55 import javafx.scene.transform.TransformChangedEvent;
56 import javafx.stage.Stage;
57 import javafx.stage.WindowEvent;
58 import org.junit.runner.RunWith;
59 import org.junit.runners.Parameterized;
60 import org.junit.runners.Parameterized.Parameters;
61 import static org.junit.Assert.assertTrue;
62 import org.junit.Test;
63
64 @RunWith(Parameterized.class)
65 public class EventAnyTest {
66 @Parameters
67 public static Collection getParams() {
68 return Arrays.asList(new Object[][] {
69 { ActionEvent.ANY, actionEvent(), true},
70 { ActionEvent.ANY, focusUngrabEvent(), false},
71 { FocusUngrabEvent.ANY, focusUngrabEvent(), true},
72 { FocusUngrabEvent.ANY, actionEvent(), false},
73 { ContextMenuEvent.ANY, contextMenuEvent(), true},
74 { ContextMenuEvent.ANY, actionEvent(), false},
75 { DragEvent.ANY, dragEvent(), true },
76 { DragEvent.ANY, keyEvent(), false },
77 { InputMethodEvent.ANY, inputMethodEvent(), true },
78 { InputMethodEvent.ANY, keyEvent(), false },
79 { KeyEvent.ANY, keyEvent(), true },
80 { KeyEvent.ANY, inputMethodEvent(), false },
81 { MouseDragEvent.ANY, mouseDragEvent(), true },
82 { MouseDragEvent.ANY, mouseEvent(), false },
83 { MouseEvent.ANY, mouseEvent(), true },
84 { MouseEvent.ANY, mouseDragEvent(), true },
85 { MouseEvent.ANY, keyEvent(), false },
86 { RotateEvent.ANY, rotateEvent(), true },
87 { RotateEvent.ANY, zoomEvent(), false },
88 { ZoomEvent.ANY, zoomEvent(), true },
89 { ZoomEvent.ANY, rotateEvent(), false },
90 { ScrollEvent.ANY, scrollEvent(), true },
91 { ScrollEvent.ANY, swipeEvent(), false },
92 { SwipeEvent.ANY, swipeEvent(), true },
93 { SwipeEvent.ANY, scrollEvent(), false },
94 { TouchEvent.ANY, touchEvent(), true },
95 { TouchEvent.ANY, rotateEvent(), false },
96 { TransformChangedEvent.ANY, transformChangedEvent(), true },
97 { TransformChangedEvent.ANY, mouseEvent(), false },
98 { WindowEvent.ANY, windowEvent(), true },
99 { WindowEvent.ANY, actionEvent(), false },
100 { GestureEvent.ANY, rotateEvent(), true },
101 { GestureEvent.ANY, mouseEvent(), false },
102 { InputEvent.ANY, mouseEvent(), true },
103 { InputEvent.ANY, actionEvent(), false },
104 });
105 }
106
107 private boolean delivered;
108 private EventType type;
109 private Event event;
110 private boolean matches;
111
112 public EventAnyTest(EventType type, Event event, boolean matches) {
113 this.type = type;
114 this.event = event;
115 this.matches = matches;
116 }
117
118 @Test
119 public void testEventDelivery() {
120 Node n = new Rectangle();
121 delivered = false;
122
123 n.addEventHandler(type, new EventHandler() {
124 @Override public void handle(Event event) {
|
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;
27
28 import com.sun.javafx.FXUnit;
29 import com.sun.javafx.stage.FocusUngrabEvent;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.concurrent.atomic.AtomicReference;
34
35 import javafx.event.ActionEvent;
36 import javafx.event.Event;
37 import javafx.event.EventHandler;
38 import javafx.event.EventType;
39 import javafx.scene.input.ContextMenuEvent;
40 import javafx.scene.input.DragEvent;
41 import javafx.scene.input.GestureEvent;
42 import javafx.scene.input.InputEvent;
43 import javafx.scene.input.InputMethodEvent;
44 import javafx.scene.input.InputMethodTextRun;
45 import javafx.scene.input.KeyCode;
46 import javafx.scene.input.KeyEvent;
47 import javafx.scene.input.MouseButton;
48 import javafx.scene.input.MouseDragEvent;
49 import javafx.scene.input.MouseEvent;
50 import javafx.scene.input.RotateEvent;
51 import javafx.scene.input.ScrollEvent;
52 import javafx.scene.input.SwipeEvent;
53 import javafx.scene.input.TouchEvent;
54 import javafx.scene.input.TouchPoint;
55 import javafx.scene.input.TransferMode;
56 import javafx.scene.input.ZoomEvent;
57 import javafx.scene.shape.Rectangle;
58 import javafx.scene.transform.TransformChangedEvent;
59 import javafx.stage.Stage;
60 import javafx.stage.WindowEvent;
61 import org.junit.Rule;
62 import org.junit.runner.RunWith;
63 import org.junit.runners.Parameterized;
64 import org.junit.runners.Parameterized.Parameters;
65 import static org.junit.Assert.assertTrue;
66 import org.junit.Test;
67
68 @RunWith(Parameterized.class)
69 public class EventAnyTest {
70
71 @Rule
72 public FXUnit fx = new FXUnit();
73
74 @Parameters
75 public static Collection getParams() {
76 AtomicReference<Collection> ref = new AtomicReference<>();
77 new FXUnit().invokeAndWait(() -> ref.set(Arrays.asList(new Object[][] {
78 { ActionEvent.ANY, actionEvent(), true},
79 { ActionEvent.ANY, focusUngrabEvent(), false},
80 { FocusUngrabEvent.ANY, focusUngrabEvent(), true},
81 { FocusUngrabEvent.ANY, actionEvent(), false},
82 { ContextMenuEvent.ANY, contextMenuEvent(), true},
83 { ContextMenuEvent.ANY, actionEvent(), false},
84 { DragEvent.ANY, dragEvent(), true },
85 { DragEvent.ANY, keyEvent(), false },
86 { InputMethodEvent.ANY, inputMethodEvent(), true },
87 { InputMethodEvent.ANY, keyEvent(), false },
88 { KeyEvent.ANY, keyEvent(), true },
89 { KeyEvent.ANY, inputMethodEvent(), false },
90 { MouseDragEvent.ANY, mouseDragEvent(), true },
91 { MouseDragEvent.ANY, mouseEvent(), false },
92 { MouseEvent.ANY, mouseEvent(), true },
93 { MouseEvent.ANY, mouseDragEvent(), true },
94 { MouseEvent.ANY, keyEvent(), false },
95 { RotateEvent.ANY, rotateEvent(), true },
96 { RotateEvent.ANY, zoomEvent(), false },
97 { ZoomEvent.ANY, zoomEvent(), true },
98 { ZoomEvent.ANY, rotateEvent(), false },
99 { ScrollEvent.ANY, scrollEvent(), true },
100 { ScrollEvent.ANY, swipeEvent(), false },
101 { SwipeEvent.ANY, swipeEvent(), true },
102 { SwipeEvent.ANY, scrollEvent(), false },
103 { TouchEvent.ANY, touchEvent(), true },
104 { TouchEvent.ANY, rotateEvent(), false },
105 { TransformChangedEvent.ANY, transformChangedEvent(), true },
106 { TransformChangedEvent.ANY, mouseEvent(), false },
107 { WindowEvent.ANY, windowEvent(), true },
108 { WindowEvent.ANY, actionEvent(), false },
109 { GestureEvent.ANY, rotateEvent(), true },
110 { GestureEvent.ANY, mouseEvent(), false },
111 { InputEvent.ANY, mouseEvent(), true },
112 { InputEvent.ANY, actionEvent(), false },
113 })));
114 return ref.get();
115 }
116
117 private boolean delivered;
118 private EventType type;
119 private Event event;
120 private boolean matches;
121
122 public EventAnyTest(EventType type, Event event, boolean matches) {
123 this.type = type;
124 this.event = event;
125 this.matches = matches;
126 }
127
128 @Test
129 public void testEventDelivery() {
130 Node n = new Rectangle();
131 delivered = false;
132
133 n.addEventHandler(type, new EventHandler() {
134 @Override public void handle(Event event) {
|