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.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.Test;
36
37 import com.sun.javafx.pgstub.StubScene;
38 import com.sun.javafx.pgstub.StubToolkit;
39 import com.sun.javafx.tk.Toolkit;
40 import javafx.event.EventTarget;
41 import javafx.event.EventType;
42 import javafx.scene.input.MouseDragEvent;
43 import javafx.scene.input.PickResult;
44 import javafx.scene.paint.Color;
45 import javafx.scene.transform.Rotate;
46
47 public class MouseTest {
48
49 private static final double DONT_TEST = 0.0;
50
51 @Test
52 public void moveShouldBubbleToParent() {
53 SimpleTestScene scene = new SimpleTestScene();
54 MouseEventGenerator generator = new MouseEventGenerator();
55
56 scene.processEvent(generator.generateMouseEvent(
57 MouseEvent.MOUSE_MOVED, 250, 250));
58
59 assertTrue(scene.smallSquareTracker.wasMoved());
60 assertFalse(scene.bigSquareTracker.wasMoved());
61 assertTrue(scene.groupTracker.wasMoved());
62 }
63
64 @Test
65 public void moveOutsideNodesShouldntBeNoticed() {
66 SimpleTestScene scene = new SimpleTestScene();
67 MouseEventGenerator generator = new MouseEventGenerator();
68
69 scene.processEvent(generator.generateMouseEvent(
70 MouseEvent.MOUSE_MOVED, 350, 350));
71
72 assertFalse(scene.smallSquareTracker.wasMoved());
73 assertFalse(scene.bigSquareTracker.wasMoved());
74 assertFalse(scene.groupTracker.wasMoved());
75 }
76
77 @Test
78 public void moveOutsideNodesShouldGoToScene() {
79 SimpleTestScene scene = new SimpleTestScene();
80 MouseEventGenerator generator = new MouseEventGenerator();
81
82 scene.processEvent(generator.generateMouseEvent(
83 MouseEvent.MOUSE_MOVED, 350, 350));
84
85 assertTrue(scene.wasMoused());
86 }
87
88 @Test
89 public void ImpossibleToComputeCoordsShouldResultInNaNs() {
90 final SimpleTestScene scene = new SimpleTestScene();
91
92 scene.smallSquareTracker.node.setOnMouseMoved(new EventHandler<MouseEvent>() {
93 @Override public void handle(MouseEvent event) {
94 scene.smallSquareTracker.node.setScaleX(0);
95 }
96 });
97
98 scene.smallSquareTracker.node.setOnMouseExited(new EventHandler<MouseEvent>() {
99 @Override public void handle(MouseEvent event) {
100 assertTrue(Double.isNaN(event.getX()));
101 assertTrue(Double.isNaN(event.getY()));
102 assertTrue(Double.isNaN(event.getZ()));
103 }
104 });
|
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.pgstub.StubScene;
30 import com.sun.javafx.pgstub.StubToolkit;
31 import com.sun.javafx.test.MouseEventGenerator;
32 import com.sun.javafx.tk.Toolkit;
33 import javafx.event.EventHandler;
34 import javafx.event.EventTarget;
35 import javafx.event.EventType;
36 import javafx.scene.input.MouseEvent;
37 import javafx.scene.input.PickResult;
38 import javafx.scene.paint.Color;
39 import javafx.scene.shape.Rectangle;
40 import javafx.scene.transform.Rotate;
41 import javafx.stage.Stage;
42 import org.junit.Rule;
43 import org.junit.Test;
44
45 import static org.junit.Assert.*;
46
47 public class MouseTest {
48
49 @Rule
50 public FXUnit fx = new FXUnit();
51
52 private static final double DONT_TEST = 0.0;
53
54 @Test
55 public void moveShouldBubbleToParent() {
56 SimpleTestScene scene = new SimpleTestScene();
57 MouseEventGenerator generator = new MouseEventGenerator();
58
59 scene.processEvent(generator.generateMouseEvent(
60 MouseEvent.MOUSE_MOVED, 250, 250));
61
62 assertTrue(scene.smallSquareTracker.wasMoved());
63 assertFalse(scene.bigSquareTracker.wasMoved());
64 assertTrue(scene.groupTracker.wasMoved());
65 }
66
67 @Test
68 public void moveOutsideNodesShouldntBeNoticed() {
69 SimpleTestScene scene = new SimpleTestScene();
70 MouseEventGenerator generator = new MouseEventGenerator();
71
72 scene.processEvent(generator.generateMouseEvent(
73 MouseEvent.MOUSE_MOVED, 350, 350));
74
75 assertFalse(scene.smallSquareTracker.wasMoved());
76 assertFalse(scene.bigSquareTracker.wasMoved());
77 assertFalse(scene.groupTracker.wasMoved());
78 }
79
80 @Test
81 public void moveOutsideNodesShouldGoToScene() {
82 SimpleTestScene scene = new SimpleTestScene();
83 MouseEventGenerator generator = new MouseEventGenerator();
84
85
86 scene.processEvent(generator.generateMouseEvent(
87 MouseEvent.MOUSE_MOVED, 350, 350));
88 assertTrue(scene.wasMoused());
89 }
90
91 @Test
92 public void ImpossibleToComputeCoordsShouldResultInNaNs() {
93 final SimpleTestScene scene = new SimpleTestScene();
94
95 scene.smallSquareTracker.node.setOnMouseMoved(new EventHandler<MouseEvent>() {
96 @Override public void handle(MouseEvent event) {
97 scene.smallSquareTracker.node.setScaleX(0);
98 }
99 });
100
101 scene.smallSquareTracker.node.setOnMouseExited(new EventHandler<MouseEvent>() {
102 @Override public void handle(MouseEvent event) {
103 assertTrue(Double.isNaN(event.getX()));
104 assertTrue(Double.isNaN(event.getY()));
105 assertTrue(Double.isNaN(event.getZ()));
106 }
107 });
|