1 /*
2 * Copyright (c) 2011, 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 com.sun.javafx.runtime.SystemProperties;
29 import javafx.beans.value.ChangeListener;
30 import javafx.beans.value.ObservableValue;
31 import javafx.concurrent.Task;
32 import javafx.scene.layout.StackPane;
33 import javafx.scene.layout.TilePane;
34 import javafx.scene.layout.VBox;
35 import javafx.scene.shape.Rectangle;
36 import javafx.scene.transform.Scale;
37 import javafx.stage.PopupWindow;
38 import javafx.stage.Stage;
39
40 import test.com.sun.javafx.pgstub.StubScene;
41 import test.com.sun.javafx.pgstub.StubToolkit;
42 import com.sun.javafx.sg.prism.NGCamera;
43 import test.com.sun.javafx.test.MouseEventGenerator;
44 import com.sun.javafx.tk.Toolkit;
45
46 import javafx.application.Platform;
47 import javafx.beans.InvalidationListener;
48 import javafx.beans.Observable;
693 SubScene nestedSubScene = new SubScene(new Group(camera), 100, 100);
694 SubScene subScene = new SubScene(new Group(nestedSubScene), 150, 150);
695 Scene scene = new Scene(new Group(subScene));
696
697 nestedSubScene.setCamera(camera);
698 scene.setCamera(camera);
699 }
700
701 @Test
702 public void testCameraUpdatesPG() {
703 Scene scene = new Scene(new Group(), 300, 200);
704 Camera cam = new ParallelCamera();
705 stage.setScene(scene);
706
707 scene.setCamera(cam);
708 Toolkit.getToolkit().firePulse();
709
710 // verify it has correct owner
711 cam.setNearClip(20);
712 Toolkit.getToolkit().firePulse();
713 NGCamera ngCamera = ((StubScene)scene.impl_getPeer()).getCamera();
714 assertEquals(20, ngCamera.getNearClip(), 0.00001);
715
716 scene.setCamera(null);
717 Toolkit.getToolkit().firePulse();
718 // verify owner was removed
719 cam.setNearClip(30);
720 Toolkit.getToolkit().firePulse();
721 assertEquals(20, ngCamera.getNearClip(), 0.00001);
722
723 scene.setCamera(cam);
724 Toolkit.getToolkit().firePulse();
725 // verify it has correct owner
726 cam.setNearClip(40);
727 Toolkit.getToolkit().firePulse();
728 assertEquals(40, ngCamera.getNearClip(), 0.00001);
729
730 NGCamera oldCam = ngCamera;
731 scene.setCamera(new ParallelCamera());
732 Toolkit.getToolkit().firePulse();
733 // verify owner was removed
734 cam.setNearClip(50);
735 Toolkit.getToolkit().firePulse();
736 ngCamera = scene.getCamera().impl_getPeer();
737 assertEquals(40, oldCam.getNearClip(), 0.00001);
738 assertEquals(0.1, ngCamera.getNearClip(), 0.00001);
739 }
740
741 @Test
742 public void testDefaultCameraUpdatesPG() {
743 Scene scene = new Scene(new Group(), 300, 200);
744 stage.setScene(scene);
745 Toolkit.getToolkit().firePulse();
746 Camera cam = SceneShim.getEffectiveCamera(scene);
747
748 cam.setNearClip(20);
749 Toolkit.getToolkit().firePulse();
750 NGCamera camera = ((StubScene)scene.impl_getPeer()).getCamera();
751 assertEquals(20, camera.getNearClip(), 0.00001);
752 }
753
754 @Test(expected=IllegalArgumentException.class)
755 public void scenesCannotShareCamera() {
756 Scene scene = new Scene(new Group(), 300, 200);
757 Scene scene2 = new Scene(new Group(), 300, 200);
758 Camera cam = new ParallelCamera();
759 scene.setCamera(cam);
760 scene2.setCamera(cam);
761 }
762
763 @Test(expected=IllegalArgumentException.class)
764 public void subSceneAndSceneCannotShareCamera() {
765 SubScene sub = new SubScene(new Group(), 100, 100);
766 Scene scene = new Scene(new Group(sub), 300, 200);
767 Camera cam = new ParallelCamera();
768 sub.setCamera(cam);
769 scene.setCamera(cam);
770 }
785 public void scenePropertyListenerShouldBeCalledForInitializedScene() {
786 final Group root = new Group();
787 final Rectangle rect = new Rectangle();
788 root.getChildren().add(rect);
789
790 root.sceneProperty().addListener(o -> {
791 root.getChildren().remove(rect);
792 });
793
794 Scene scene = new Scene(root, 600, 450);
795 // if there is no exception, the test passed
796 }
797
798 @Test
799 public void testSceneCursorChangePropagatesToScenePeer() {
800 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
801 final MouseEventGenerator generator = new MouseEventGenerator();
802
803 final Scene scene = new Scene(new Group(), 300, 200);
804 stage.setScene(scene);
805 scene.impl_processMouseEvent(
806 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
807 100, 100));
808 toolkit.firePulse();
809
810 scene.setCursor(Cursor.TEXT);
811 assertTrue(toolkit.isPulseRequested());
812 toolkit.firePulse();
813
814 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
815 ((StubScene) scene.impl_getPeer()).getCursor());
816 }
817
818 @Test
819 public void testNodeCursorChangePropagatesToScenePeer() {
820 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
821 final MouseEventGenerator generator = new MouseEventGenerator();
822
823 final Parent root = new Group(new Rectangle(300, 200));
824 final Scene scene = new Scene(root, 300, 200);
825 stage.setScene(scene);
826 scene.impl_processMouseEvent(
827 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
828 100, 100));
829 toolkit.firePulse();
830
831 root.setCursor(Cursor.TEXT);
832 assertTrue(toolkit.isPulseRequested());
833 toolkit.firePulse();
834
835 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
836 ((StubScene) scene.impl_getPeer()).getCursor());
837 }
838
839 @Test public void testProperties() {
840 final Scene scene = new Scene(new Group(), 300, 200);
841
842 javafx.collections.ObservableMap<Object, Object> properties = scene.getProperties();
843
844 /* If we ask for it, we should get it.
845 */
846 assertNotNull(properties);
847
848 /* What we put in, we should get out.
849 */
850 properties.put("MyKey", "MyValue");
851 assertEquals("MyValue", properties.get("MyKey"));
852
853 /* If we ask for it again, we should get the same thing.
854 */
855 javafx.collections.ObservableMap<Object, Object> properties2 = scene.getProperties();
856 assertEquals(properties2, properties);
|
1 /*
2 * Copyright (c) 2011, 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.runtime.SystemProperties;
29 import com.sun.javafx.scene.SceneHelper;
30 import javafx.beans.value.ChangeListener;
31 import javafx.beans.value.ObservableValue;
32 import javafx.concurrent.Task;
33 import javafx.scene.layout.StackPane;
34 import javafx.scene.layout.TilePane;
35 import javafx.scene.layout.VBox;
36 import javafx.scene.shape.Rectangle;
37 import javafx.scene.transform.Scale;
38 import javafx.stage.PopupWindow;
39 import javafx.stage.Stage;
40
41 import test.com.sun.javafx.pgstub.StubScene;
42 import test.com.sun.javafx.pgstub.StubToolkit;
43 import com.sun.javafx.sg.prism.NGCamera;
44 import test.com.sun.javafx.test.MouseEventGenerator;
45 import com.sun.javafx.tk.Toolkit;
46
47 import javafx.application.Platform;
48 import javafx.beans.InvalidationListener;
49 import javafx.beans.Observable;
694 SubScene nestedSubScene = new SubScene(new Group(camera), 100, 100);
695 SubScene subScene = new SubScene(new Group(nestedSubScene), 150, 150);
696 Scene scene = new Scene(new Group(subScene));
697
698 nestedSubScene.setCamera(camera);
699 scene.setCamera(camera);
700 }
701
702 @Test
703 public void testCameraUpdatesPG() {
704 Scene scene = new Scene(new Group(), 300, 200);
705 Camera cam = new ParallelCamera();
706 stage.setScene(scene);
707
708 scene.setCamera(cam);
709 Toolkit.getToolkit().firePulse();
710
711 // verify it has correct owner
712 cam.setNearClip(20);
713 Toolkit.getToolkit().firePulse();
714 NGCamera ngCamera = ((StubScene) SceneHelper.getPeer(scene)).getCamera();
715 assertEquals(20, ngCamera.getNearClip(), 0.00001);
716
717 scene.setCamera(null);
718 Toolkit.getToolkit().firePulse();
719 // verify owner was removed
720 cam.setNearClip(30);
721 Toolkit.getToolkit().firePulse();
722 assertEquals(20, ngCamera.getNearClip(), 0.00001);
723
724 scene.setCamera(cam);
725 Toolkit.getToolkit().firePulse();
726 // verify it has correct owner
727 cam.setNearClip(40);
728 Toolkit.getToolkit().firePulse();
729 assertEquals(40, ngCamera.getNearClip(), 0.00001);
730
731 NGCamera oldCam = ngCamera;
732 scene.setCamera(new ParallelCamera());
733 Toolkit.getToolkit().firePulse();
734 // verify owner was removed
735 cam.setNearClip(50);
736 Toolkit.getToolkit().firePulse();
737 ngCamera = scene.getCamera().impl_getPeer();
738 assertEquals(40, oldCam.getNearClip(), 0.00001);
739 assertEquals(0.1, ngCamera.getNearClip(), 0.00001);
740 }
741
742 @Test
743 public void testDefaultCameraUpdatesPG() {
744 Scene scene = new Scene(new Group(), 300, 200);
745 stage.setScene(scene);
746 Toolkit.getToolkit().firePulse();
747 Camera cam = SceneShim.getEffectiveCamera(scene);
748
749 cam.setNearClip(20);
750 Toolkit.getToolkit().firePulse();
751 NGCamera camera = ((StubScene) SceneHelper.getPeer(scene)).getCamera();
752 assertEquals(20, camera.getNearClip(), 0.00001);
753 }
754
755 @Test(expected=IllegalArgumentException.class)
756 public void scenesCannotShareCamera() {
757 Scene scene = new Scene(new Group(), 300, 200);
758 Scene scene2 = new Scene(new Group(), 300, 200);
759 Camera cam = new ParallelCamera();
760 scene.setCamera(cam);
761 scene2.setCamera(cam);
762 }
763
764 @Test(expected=IllegalArgumentException.class)
765 public void subSceneAndSceneCannotShareCamera() {
766 SubScene sub = new SubScene(new Group(), 100, 100);
767 Scene scene = new Scene(new Group(sub), 300, 200);
768 Camera cam = new ParallelCamera();
769 sub.setCamera(cam);
770 scene.setCamera(cam);
771 }
786 public void scenePropertyListenerShouldBeCalledForInitializedScene() {
787 final Group root = new Group();
788 final Rectangle rect = new Rectangle();
789 root.getChildren().add(rect);
790
791 root.sceneProperty().addListener(o -> {
792 root.getChildren().remove(rect);
793 });
794
795 Scene scene = new Scene(root, 600, 450);
796 // if there is no exception, the test passed
797 }
798
799 @Test
800 public void testSceneCursorChangePropagatesToScenePeer() {
801 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
802 final MouseEventGenerator generator = new MouseEventGenerator();
803
804 final Scene scene = new Scene(new Group(), 300, 200);
805 stage.setScene(scene);
806 SceneHelper.processMouseEvent(scene,
807 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
808 100, 100));
809 toolkit.firePulse();
810
811 scene.setCursor(Cursor.TEXT);
812 assertTrue(toolkit.isPulseRequested());
813 toolkit.firePulse();
814
815 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
816 ((StubScene) SceneHelper.getPeer(scene)).getCursor());
817 }
818
819 @Test
820 public void testNodeCursorChangePropagatesToScenePeer() {
821 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
822 final MouseEventGenerator generator = new MouseEventGenerator();
823
824 final Parent root = new Group(new Rectangle(300, 200));
825 final Scene scene = new Scene(root, 300, 200);
826 stage.setScene(scene);
827 SceneHelper.processMouseEvent(scene,
828 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
829 100, 100));
830 toolkit.firePulse();
831
832 root.setCursor(Cursor.TEXT);
833 assertTrue(toolkit.isPulseRequested());
834 toolkit.firePulse();
835
836 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
837 ((StubScene) SceneHelper.getPeer(scene)).getCursor());
838 }
839
840 @Test public void testProperties() {
841 final Scene scene = new Scene(new Group(), 300, 200);
842
843 javafx.collections.ObservableMap<Object, Object> properties = scene.getProperties();
844
845 /* If we ask for it, we should get it.
846 */
847 assertNotNull(properties);
848
849 /* What we put in, we should get out.
850 */
851 properties.put("MyKey", "MyValue");
852 assertEquals("MyValue", properties.get("MyKey"));
853
854 /* If we ask for it again, we should get the same thing.
855 */
856 javafx.collections.ObservableMap<Object, Object> properties2 = scene.getProperties();
857 assertEquals(properties2, properties);
|