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;
27
28 import javafx.beans.value.ChangeListener;
29 import javafx.beans.value.ObservableValue;
30 import javafx.concurrent.Task;
31 import javafx.scene.layout.StackPane;
32 import javafx.scene.layout.TilePane;
33 import javafx.scene.layout.VBox;
34 import javafx.scene.shape.Rectangle;
35 import javafx.scene.transform.Scale;
36 import javafx.stage.PopupWindow;
37 import javafx.stage.Stage;
38
39 import com.sun.javafx.pgstub.StubScene;
40 import com.sun.javafx.pgstub.StubToolkit;
41 import com.sun.javafx.sg.prism.NGCamera;
42 import com.sun.javafx.test.MouseEventGenerator;
43 import com.sun.javafx.tk.Toolkit;
44
45 import javafx.application.Platform;
46 import javafx.beans.InvalidationListener;
47 import javafx.beans.Observable;
48 import javafx.scene.input.MouseEvent;
49
50 import org.junit.After;
51 import org.junit.Before;
52 import org.junit.Test;
53
54 import java.util.concurrent.ExecutionException;
55
56 import static junit.framework.Assert.assertEquals;
57 import static junit.framework.Assert.assertNotNull;
58 import static org.junit.Assert.*;
59
60 /**
61 * Tests various aspects of Scene.
62 *
63 */
64 public class SceneTest {
65
66 private Stage stage;
67 private boolean handler1Called = false;
68 private boolean handler2Called = false;
69
70
71 @Before
72 public void setUp() {
73 stage = new Stage();
74 stage.show();
711 cam.setNearClip(40);
712 Toolkit.getToolkit().firePulse();
713 assertEquals(40, ngCamera.getNearClip(), 0.00001);
714
715 NGCamera oldCam = ngCamera;
716 scene.setCamera(new ParallelCamera());
717 Toolkit.getToolkit().firePulse();
718 // verify owner was removed
719 cam.setNearClip(50);
720 Toolkit.getToolkit().firePulse();
721 ngCamera = scene.getCamera().impl_getPeer();
722 assertEquals(40, oldCam.getNearClip(), 0.00001);
723 assertEquals(0.1, ngCamera.getNearClip(), 0.00001);
724 }
725
726 @Test
727 public void testDefaultCameraUpdatesPG() {
728 Scene scene = new Scene(new Group(), 300, 200);
729 stage.setScene(scene);
730 Toolkit.getToolkit().firePulse();
731 Camera cam = scene.getEffectiveCamera();
732
733 cam.setNearClip(20);
734 Toolkit.getToolkit().firePulse();
735 NGCamera camera = ((StubScene)scene.impl_getPeer()).getCamera();
736 assertEquals(20, camera.getNearClip(), 0.00001);
737 }
738
739 @Test(expected=IllegalArgumentException.class)
740 public void scenesCannotShareCamera() {
741 Scene scene = new Scene(new Group(), 300, 200);
742 Scene scene2 = new Scene(new Group(), 300, 200);
743 Camera cam = new ParallelCamera();
744 scene.setCamera(cam);
745 scene2.setCamera(cam);
746 }
747
748 @Test(expected=IllegalArgumentException.class)
749 public void subSceneAndSceneCannotShareCamera() {
750 SubScene sub = new SubScene(new Group(), 100, 100);
751 Scene scene = new Scene(new Group(sub), 300, 200);
779 Scene scene = new Scene(root, 600, 450);
780 // if there is no exception, the test passed
781 }
782
783 @Test
784 public void testSceneCursorChangePropagatesToScenePeer() {
785 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
786 final MouseEventGenerator generator = new MouseEventGenerator();
787
788 final Scene scene = new Scene(new Group(), 300, 200);
789 stage.setScene(scene);
790 scene.impl_processMouseEvent(
791 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
792 100, 100));
793 toolkit.firePulse();
794
795 scene.setCursor(Cursor.TEXT);
796 assertTrue(toolkit.isPulseRequested());
797 toolkit.firePulse();
798
799 assertSame(Cursor.TEXT.getCurrentFrame(),
800 ((StubScene) scene.impl_getPeer()).getCursor());
801 }
802
803 @Test
804 public void testNodeCursorChangePropagatesToScenePeer() {
805 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
806 final MouseEventGenerator generator = new MouseEventGenerator();
807
808 final Parent root = new Group(new Rectangle(300, 200));
809 final Scene scene = new Scene(root, 300, 200);
810 stage.setScene(scene);
811 scene.impl_processMouseEvent(
812 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
813 100, 100));
814 toolkit.firePulse();
815
816 root.setCursor(Cursor.TEXT);
817 assertTrue(toolkit.isPulseRequested());
818 toolkit.firePulse();
819
820 assertSame(Cursor.TEXT.getCurrentFrame(),
821 ((StubScene) scene.impl_getPeer()).getCursor());
822 }
823
824 @Test public void testProperties() {
825 final Scene scene = new Scene(new Group(), 300, 200);
826
827 javafx.collections.ObservableMap<Object, Object> properties = scene.getProperties();
828
829 /* If we ask for it, we should get it.
830 */
831 assertNotNull(properties);
832
833 /* What we put in, we should get out.
834 */
835 properties.put("MyKey", "MyValue");
836 assertEquals("MyValue", properties.get("MyKey"));
837
838 /* If we ask for it again, we should get the same thing.
839 */
840 javafx.collections.ObservableMap<Object, Object> properties2 = scene.getProperties();
|
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 javafx.beans.value.ChangeListener;
29 import javafx.beans.value.ObservableValue;
30 import javafx.concurrent.Task;
31 import javafx.scene.layout.StackPane;
32 import javafx.scene.layout.TilePane;
33 import javafx.scene.layout.VBox;
34 import javafx.scene.shape.Rectangle;
35 import javafx.scene.transform.Scale;
36 import javafx.stage.PopupWindow;
37 import javafx.stage.Stage;
38
39 import test.com.sun.javafx.pgstub.StubScene;
40 import test.com.sun.javafx.pgstub.StubToolkit;
41 import com.sun.javafx.sg.prism.NGCamera;
42 import test.com.sun.javafx.test.MouseEventGenerator;
43 import com.sun.javafx.tk.Toolkit;
44
45 import javafx.application.Platform;
46 import javafx.beans.InvalidationListener;
47 import javafx.beans.Observable;
48 import javafx.scene.input.MouseEvent;
49
50 import org.junit.After;
51 import org.junit.Before;
52 import org.junit.Test;
53
54 import java.util.concurrent.ExecutionException;
55 import javafx.scene.Camera;
56 import javafx.scene.Cursor;
57 import javafx.scene.CursorShim;
58 import javafx.scene.Group;
59 import javafx.scene.Node;
60 import javafx.scene.ParallelCamera;
61 import javafx.scene.Parent;
62 import javafx.scene.PerspectiveCamera;
63 import javafx.scene.Scene;
64 import javafx.scene.SceneShim;
65 import javafx.scene.SubScene;
66
67 import static junit.framework.Assert.assertEquals;
68 import static junit.framework.Assert.assertNotNull;
69 import static org.junit.Assert.*;
70
71 /**
72 * Tests various aspects of Scene.
73 *
74 */
75 public class SceneTest {
76
77 private Stage stage;
78 private boolean handler1Called = false;
79 private boolean handler2Called = false;
80
81
82 @Before
83 public void setUp() {
84 stage = new Stage();
85 stage.show();
722 cam.setNearClip(40);
723 Toolkit.getToolkit().firePulse();
724 assertEquals(40, ngCamera.getNearClip(), 0.00001);
725
726 NGCamera oldCam = ngCamera;
727 scene.setCamera(new ParallelCamera());
728 Toolkit.getToolkit().firePulse();
729 // verify owner was removed
730 cam.setNearClip(50);
731 Toolkit.getToolkit().firePulse();
732 ngCamera = scene.getCamera().impl_getPeer();
733 assertEquals(40, oldCam.getNearClip(), 0.00001);
734 assertEquals(0.1, ngCamera.getNearClip(), 0.00001);
735 }
736
737 @Test
738 public void testDefaultCameraUpdatesPG() {
739 Scene scene = new Scene(new Group(), 300, 200);
740 stage.setScene(scene);
741 Toolkit.getToolkit().firePulse();
742 Camera cam = SceneShim.getEffectiveCamera(scene);
743
744 cam.setNearClip(20);
745 Toolkit.getToolkit().firePulse();
746 NGCamera camera = ((StubScene)scene.impl_getPeer()).getCamera();
747 assertEquals(20, camera.getNearClip(), 0.00001);
748 }
749
750 @Test(expected=IllegalArgumentException.class)
751 public void scenesCannotShareCamera() {
752 Scene scene = new Scene(new Group(), 300, 200);
753 Scene scene2 = new Scene(new Group(), 300, 200);
754 Camera cam = new ParallelCamera();
755 scene.setCamera(cam);
756 scene2.setCamera(cam);
757 }
758
759 @Test(expected=IllegalArgumentException.class)
760 public void subSceneAndSceneCannotShareCamera() {
761 SubScene sub = new SubScene(new Group(), 100, 100);
762 Scene scene = new Scene(new Group(sub), 300, 200);
790 Scene scene = new Scene(root, 600, 450);
791 // if there is no exception, the test passed
792 }
793
794 @Test
795 public void testSceneCursorChangePropagatesToScenePeer() {
796 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
797 final MouseEventGenerator generator = new MouseEventGenerator();
798
799 final Scene scene = new Scene(new Group(), 300, 200);
800 stage.setScene(scene);
801 scene.impl_processMouseEvent(
802 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
803 100, 100));
804 toolkit.firePulse();
805
806 scene.setCursor(Cursor.TEXT);
807 assertTrue(toolkit.isPulseRequested());
808 toolkit.firePulse();
809
810 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
811 ((StubScene) scene.impl_getPeer()).getCursor());
812 }
813
814 @Test
815 public void testNodeCursorChangePropagatesToScenePeer() {
816 final StubToolkit toolkit = (StubToolkit) Toolkit.getToolkit();
817 final MouseEventGenerator generator = new MouseEventGenerator();
818
819 final Parent root = new Group(new Rectangle(300, 200));
820 final Scene scene = new Scene(root, 300, 200);
821 stage.setScene(scene);
822 scene.impl_processMouseEvent(
823 generator.generateMouseEvent(MouseEvent.MOUSE_ENTERED,
824 100, 100));
825 toolkit.firePulse();
826
827 root.setCursor(Cursor.TEXT);
828 assertTrue(toolkit.isPulseRequested());
829 toolkit.firePulse();
830
831 assertSame(CursorShim.getCurrentFrame(Cursor.TEXT),
832 ((StubScene) scene.impl_getPeer()).getCursor());
833 }
834
835 @Test public void testProperties() {
836 final Scene scene = new Scene(new Group(), 300, 200);
837
838 javafx.collections.ObservableMap<Object, Object> properties = scene.getProperties();
839
840 /* If we ask for it, we should get it.
841 */
842 assertNotNull(properties);
843
844 /* What we put in, we should get out.
845 */
846 properties.put("MyKey", "MyValue");
847 assertEquals("MyValue", properties.get("MyKey"));
848
849 /* If we ask for it again, we should get the same thing.
850 */
851 javafx.collections.ObservableMap<Object, Object> properties2 = scene.getProperties();
|