1 /*
2 * Copyright (c) 2000, 2015, 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 test.javafx.scene;
27
28 import test.com.sun.javafx.test.MouseEventGenerator;
29 import static org.junit.Assert.*;
30 import javafx.event.EventHandler;
31 import javafx.scene.input.MouseEvent;
32 import javafx.scene.shape.Rectangle;
33 import javafx.stage.Stage;
34
35 import org.junit.Assert;
36 import org.junit.Test;
37
38 import test.com.sun.javafx.pgstub.StubScene;
39 import test.com.sun.javafx.pgstub.StubToolkit;
40 import com.sun.javafx.tk.Toolkit;
41 import javafx.event.EventTarget;
42 import javafx.event.EventType;
43 import javafx.scene.Cursor;
44 import javafx.scene.CursorShim;
45 import javafx.scene.Group;
46 import javafx.scene.Node;
47 import javafx.scene.ParentShim;
1565 ParentShim.getChildren(group).add(smallSquare);
1566
1567 ParentShim.getChildren(root).add(group);
1568
1569 sceneTracker = new MouseEventTracker(scene);
1570 rootTracker = new MouseEventTracker(root);
1571 groupTracker = new MouseEventTracker(group);
1572 bigSquareTracker = new MouseEventTracker(bigSquare);
1573 smallSquareTracker = new MouseEventTracker(smallSquare);
1574
1575 scene.addEventHandler(MouseEvent.ANY, event -> {
1576 moused = true;
1577 });
1578
1579 Stage stage = new Stage();
1580 stage.setScene(scene);
1581 stage.show();
1582 }
1583
1584 public void processEvent(MouseEvent e) {
1585 scene.impl_processMouseEvent(e);
1586 }
1587
1588 public Object getCursorFrame() {
1589 return ((StubScene) scene.impl_getPeer()).getCursor();
1590 }
1591
1592 public boolean wasMoused() {
1593 return moused;
1594 }
1595
1596 public void clear() {
1597 moused = false;
1598 sceneTracker.clear();
1599 groupTracker.clear();
1600 bigSquareTracker.clear();
1601 smallSquareTracker.clear();
1602 }
1603 }
1604
1605 private static class MouseEventTracker {
1606
1607 private Node node;
1608 private boolean pressed = false;
1609 private boolean released = false;
1774
1775 innerRect2 = new Rectangle(50, 50);
1776 innerRect2.setTranslateX(100);
1777 innerRect2.setTranslateY(10);
1778 subScene2 = new SubScene(new Group(innerRect2), 200, 100);
1779 subScene2.setTranslateX(20);
1780
1781 parent2 = new Group(subScene2);
1782 parent2.setTranslateX(230);
1783 parent2.setTranslateY(10);
1784
1785
1786 ParentShim.getChildren(root).addAll(parent1, parent2);
1787
1788 Stage stage = new Stage();
1789 stage.setScene(scene);
1790 stage.show();
1791 }
1792
1793 public void processEvent(EventType<MouseEvent> type, double x, double y) {
1794 scene.impl_processMouseEvent(
1795 MouseEventGenerator.generateMouseEvent(type, x, y));
1796 }
1797
1798 public Object getCursorFrame() {
1799 return ((StubScene) scene.impl_getPeer()).getCursor();
1800 }
1801
1802 public EventHandler<MouseEvent> handler(final EventTarget target,
1803 final double x, final double y) {
1804
1805 return event -> {
1806 if (target != null) assertSame(target, event.getTarget());
1807 if (x != DONT_TEST) assertEquals(x, event.getX(), 0.00001);
1808 if (y != DONT_TEST) assertEquals(y, event.getY(), 0.00001);
1809 assertEquals(0.0, event.getZ(), 0.00001);
1810 lastPickResult = event.getPickResult();
1811 called = true;
1812 };
1813 }
1814
1815 public void assertCalled() {
1816 assertTrue(called);
1817 }
1818 }
1819
|
1 /*
2 * Copyright (c) 2000, 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 test.javafx.scene;
27
28 import com.sun.javafx.scene.SceneHelper;
29 import test.com.sun.javafx.test.MouseEventGenerator;
30 import static org.junit.Assert.*;
31 import javafx.event.EventHandler;
32 import javafx.scene.input.MouseEvent;
33 import javafx.scene.shape.Rectangle;
34 import javafx.stage.Stage;
35
36 import org.junit.Assert;
37 import org.junit.Test;
38
39 import test.com.sun.javafx.pgstub.StubScene;
40 import test.com.sun.javafx.pgstub.StubToolkit;
41 import com.sun.javafx.tk.Toolkit;
42 import javafx.event.EventTarget;
43 import javafx.event.EventType;
44 import javafx.scene.Cursor;
45 import javafx.scene.CursorShim;
46 import javafx.scene.Group;
47 import javafx.scene.Node;
48 import javafx.scene.ParentShim;
1566 ParentShim.getChildren(group).add(smallSquare);
1567
1568 ParentShim.getChildren(root).add(group);
1569
1570 sceneTracker = new MouseEventTracker(scene);
1571 rootTracker = new MouseEventTracker(root);
1572 groupTracker = new MouseEventTracker(group);
1573 bigSquareTracker = new MouseEventTracker(bigSquare);
1574 smallSquareTracker = new MouseEventTracker(smallSquare);
1575
1576 scene.addEventHandler(MouseEvent.ANY, event -> {
1577 moused = true;
1578 });
1579
1580 Stage stage = new Stage();
1581 stage.setScene(scene);
1582 stage.show();
1583 }
1584
1585 public void processEvent(MouseEvent e) {
1586 SceneHelper.processMouseEvent(scene, e);
1587 }
1588
1589 public Object getCursorFrame() {
1590 return ((StubScene) SceneHelper.getPeer(scene)).getCursor();
1591 }
1592
1593 public boolean wasMoused() {
1594 return moused;
1595 }
1596
1597 public void clear() {
1598 moused = false;
1599 sceneTracker.clear();
1600 groupTracker.clear();
1601 bigSquareTracker.clear();
1602 smallSquareTracker.clear();
1603 }
1604 }
1605
1606 private static class MouseEventTracker {
1607
1608 private Node node;
1609 private boolean pressed = false;
1610 private boolean released = false;
1775
1776 innerRect2 = new Rectangle(50, 50);
1777 innerRect2.setTranslateX(100);
1778 innerRect2.setTranslateY(10);
1779 subScene2 = new SubScene(new Group(innerRect2), 200, 100);
1780 subScene2.setTranslateX(20);
1781
1782 parent2 = new Group(subScene2);
1783 parent2.setTranslateX(230);
1784 parent2.setTranslateY(10);
1785
1786
1787 ParentShim.getChildren(root).addAll(parent1, parent2);
1788
1789 Stage stage = new Stage();
1790 stage.setScene(scene);
1791 stage.show();
1792 }
1793
1794 public void processEvent(EventType<MouseEvent> type, double x, double y) {
1795 SceneHelper.processMouseEvent(scene,
1796 MouseEventGenerator.generateMouseEvent(type, x, y));
1797 }
1798
1799 public Object getCursorFrame() {
1800 return ((StubScene) SceneHelper.getPeer(scene)).getCursor();
1801 }
1802
1803 public EventHandler<MouseEvent> handler(final EventTarget target,
1804 final double x, final double y) {
1805
1806 return event -> {
1807 if (target != null) assertSame(target, event.getTarget());
1808 if (x != DONT_TEST) assertEquals(x, event.getX(), 0.00001);
1809 if (y != DONT_TEST) assertEquals(y, event.getY(), 0.00001);
1810 assertEquals(0.0, event.getZ(), 0.00001);
1811 lastPickResult = event.getPickResult();
1812 called = true;
1813 };
1814 }
1815
1816 public void assertCalled() {
1817 assertTrue(called);
1818 }
1819 }
1820
|