changeset 3659:e6bf05485e33

RT-30392 Stage.setScene and sizing
author Martin Sladecek <martin.sladecek@oracle.com>
date Mon, 20 May 2013 14:18:34 +0200
parents ac4ef880fa64
children 9d7dd36b9f4f
files javafx-ui-common/src/javafx/stage/Window.java javafx-ui-common/test/unit/javafx/scene/SceneTest.java javafx-ui-common/test/unit/javafx/stage/StageTest.java test-stub-toolkit/src/com/sun/javafx/pgstub/StubStage.java
diffstat 4 files changed, 75 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/stage/Window.java	Sun May 19 22:12:44 2013 -0700
+++ b/javafx-ui-common/src/javafx/stage/Window.java	Mon May 20 14:18:34 2013 +0200
@@ -217,7 +217,7 @@
 
     private static final float CENTER_ON_SCREEN_X_FRACTION = 1.0f / 2;
     private static final float CENTER_ON_SCREEN_Y_FRACTION = 1.0f / 3;
-    
+
     /**
      * Sets x and y properties on this Window so that it is centered on the screen.
      */
@@ -226,7 +226,7 @@
         yExplicit = false;
         if (impl_peer != null) {
             Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
-            double centerX = 
+            double centerX =
                     bounds.getMinX() + (bounds.getWidth() - getWidth())
                                            * CENTER_ON_SCREEN_X_FRACTION;
             double centerY =
@@ -385,7 +385,7 @@
      */
     @Deprecated
     public final void setFocused(boolean value) { focused.set(value); }
-    
+
     /**
      * Requests that this {@code Window} get the input focus.
      */
@@ -451,9 +451,9 @@
                 // performed in Window.visibleChanging()
                 if (isShowing()) {
                     newScene.getRoot().impl_reapplyCSS();
-                    getScene().impl_preferredSize();
 
                     if (!widthExplicit || !heightExplicit) {
+                        getScene().impl_preferredSize();
                         adjustSize(true);
                     }
                 }
@@ -737,7 +737,7 @@
                         peerBoundsConfigurator.setSize(
                                 getWidth(), getHeight(), -1, -1);
                     }
-                    
+
                     if (!xExplicit && !yExplicit) {
                         centerOnScreen();
                     } else {
@@ -1037,7 +1037,7 @@
     final void applyBounds() {
         peerBoundsConfigurator.apply();
     }
-    
+
     /**
      * Caches all requested bounds settings and applies them at once during
      * the next pulse.
--- a/javafx-ui-common/test/unit/javafx/scene/SceneTest.java	Sun May 19 22:12:44 2013 -0700
+++ b/javafx-ui-common/test/unit/javafx/scene/SceneTest.java	Mon May 20 14:18:34 2013 +0200
@@ -619,10 +619,10 @@
     @Test(expected = IllegalArgumentException.class)
     public void testSetIllegalCameraFromOtherScene() {
         Camera camera = new PerspectiveCamera();
-        
+
         Scene scene1 = new Scene(new Group(camera));
         Scene scene2 = new Scene(new Group());
-        
+
         scene1.setCamera(camera);
         scene2.setCamera(camera);
     }
--- a/javafx-ui-common/test/unit/javafx/stage/StageTest.java	Sun May 19 22:12:44 2013 -0700
+++ b/javafx-ui-common/test/unit/javafx/stage/StageTest.java	Mon May 20 14:18:34 2013 +0200
@@ -25,8 +25,8 @@
 
 package javafx.stage;
 
+import com.sun.javafx.pgstub.StubScene;
 import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
 import static junit.framework.Assert.assertSame;
@@ -43,13 +43,13 @@
 import com.sun.javafx.tk.Toolkit;
 
 public class StageTest {
-    
+
     private StubToolkit toolkit;
     private Stage s;
     private StubStage peer;
 
     private int initialNumTimesSetSizeAndLocation;
-    
+
     @Before
     public void setUp() {
         toolkit = (StubToolkit) Toolkit.getToolkit();
@@ -63,11 +63,11 @@
     public void tearDown() {
         s.hide();
     }
-    
+
     private void pulse() {
         toolkit.fireTestPulse();
     }
-    
+
     /**
      * Simple test which checks whether changing the x/y position of the Stage
      * ends up invoking the appropriate methods on the TKStage interface.
@@ -238,6 +238,31 @@
     }
 
     @Test
+    public void testSwitchSceneWithFixedSize() {
+        Scene scene = new Scene(new Group(), 200, 100);
+        s.setScene(scene);
+
+        s.setWidth(400);
+        s.setHeight(300);
+
+        pulse();
+
+        assertEquals(400, peer.width, 0.0001);
+        assertEquals(300, peer.height, 0.0001);
+        assertEquals(400, scene.getWidth(), 0.0001);
+        assertEquals(300, scene.getHeight(), 0.0001);
+
+        s.setScene(scene = new Scene(new Group(), 220, 110));
+
+        pulse();
+
+        assertEquals(400, peer.width, 0.0001);
+        assertEquals(300, peer.height, 0.0001);
+        assertEquals(400, scene.getWidth(), 0.0001);
+        assertEquals(300, scene.getHeight(), 0.0001);
+    }
+
+    @Test
     public void testSetBoundsNotLostForAsyncNotifications() {
         s.setX(20);
         s.setY(50);
@@ -270,12 +295,12 @@
 
         s.setFullScreen(false);
         assertFalse(s.isFullScreen());
-        
+
         peer.releaseSingleNotification();
         assertTrue(s.isFullScreen());
 
         peer.releaseNotifications();
-        
+
         assertFalse(s.isFullScreen());
     }
 
@@ -312,7 +337,7 @@
         peer.setResizable(true);
         assertTrue(s.isResizable());
     }
-    
+
     @Test
     public void testIconifiedNotLostForAsyncNotifications() {
         peer.holdNotifications();
--- a/test-stub-toolkit/src/com/sun/javafx/pgstub/StubStage.java	Sun May 19 22:12:44 2013 -0700
+++ b/test-stub-toolkit/src/com/sun/javafx/pgstub/StubStage.java	Mon May 20 14:18:34 2013 +0200
@@ -59,6 +59,9 @@
         if (scene != null) {
             StubScene s = (StubScene) scene;
             s.stage = this;
+            notificationSender.setScene(s);
+            if (width != -1 && height != -1)
+                s.getListener().changedSize(width, height);
         }
     }
 
@@ -82,7 +85,7 @@
                           float xGravity, float yGravity)
     {
         numTimesSetSizeAndLocation++;
-        
+
         boolean locationChanged = false;
 
         if (xSet && (this.x != x)) {
@@ -124,7 +127,7 @@
                 sizeChanged = true;
             }
         }
-        
+
         if (sizeChanged) {
             notificationSender.changedSize(width, height);
         }
@@ -197,7 +200,7 @@
     public void requestFocus() {
         notificationSender.changedFocused(true, FocusCause.ACTIVATED);
     }
-    
+
     @Override
     public void requestFocus(FocusCause cause) {
         notificationSender.changedFocused(true, cause);
@@ -231,7 +234,7 @@
     @Override
     public void setMaximumSize(int maxWidth, int maxHeight) {
     }
-    
+
     public void holdNotifications() {
         notificationSender.holdNotifications();
     }
@@ -249,9 +252,9 @@
     }
 
     @Override
-    public void requestInput(String text, int type, double width, double height, 
+    public void requestInput(String text, int type, double width, double height,
                                 double Mxx, double Mxy, double Mxz, double Mxt,
-                                double Myx, double Myy, double Myz, double Myt, 
+                                double Myx, double Myy, double Myz, double Myt,
                                 double Mzx, double Mzy, double Mzz, double Mzt) {
         throw new UnsupportedOperationException("Not supported yet.");
     }
@@ -262,25 +265,25 @@
     }
 
     /**
-     * 
+     *
      * Accessibility glue for native
-     * 
+     *
      */
-    
+
     /**
      * Initialize Accessiblility
-     * 
+     *
      * @param ac    the Glass accessible root object.
      */
     @Override public void setAccessibilityInitIsComplete(Object ac) {
         // TODO: Add code later
-    } 
+    }
 
     /**
      * Create accessible Glass object corresponding to stage
-     * 
+     *
      * @param ac    the FX accessible root/stage node.
-     * 
+     *
      * @return the Glass AccessibleRoot object.
      */
     @Override
@@ -291,8 +294,8 @@
 
     /**
      * Create accessible native object corresponding to controls
-     * 
-     * @param ac 
+     *
+     * @param ac
      * returns native Object
      */
     @Override public Object accessibleCreateBasicProvider(AccessibleProvider ac) {
@@ -302,7 +305,7 @@
 
     /**
      * Delete accessible native object corresponding to controls
-     * 
+     *
      * @param nativeAcc
      * returns native Object
      */
@@ -312,15 +315,15 @@
 
     /**
      * Fire accessible event
-     * 
+     *
      * @param eventID   identifies the event.
      */
     @Override public void accessibleFireEvent(Object nativeAcc, int eventID) {
         // TODO: Add code later
     }
-    
+
     /** Fire accessible property change event
-     * 
+     *
      * @param propertyId    identifies the property
      * @param oldProperty   the old value of the property
      * @param newProperty   the new value of the property
@@ -329,12 +332,12 @@
                                              int newProperty ) {
         // TODO: Add code later
     }
-    
+
     @Override public void accessibleFirePropertyChange(Object nativeAcc, int propertyId, boolean oldProperty,
                                              boolean newProperty ) {
         // TODO: Add code later
-    }        
-    
+    }
+
     private interface Notification {
         void execute(TKStageListener listener);
     }
@@ -345,11 +348,16 @@
 
         private boolean hold;
         private TKStageListener listener;
+        private StubScene scene;
 
         public void setListener(final TKStageListener listener) {
             this.listener = listener;
         }
 
+        public void setScene(final StubScene scene) {
+            this.scene = scene;
+        }
+
         public void holdNotifications() {
             hold = true;
         }
@@ -379,6 +387,9 @@
                         @Override
                         public void execute(final TKStageListener listener) {
                             listener.changedSize(width, height);
+                            if (scene != null && width != -1 && height != -1) {
+                                scene.getListener().changedSize(width, height);
+                            }
                         }
                     });
         }
@@ -495,7 +506,7 @@
         public void initAccessibleTKStageListener() {
             // TODO: Add code later
         }
-                
+
     }
 
     public void setRTL(boolean b) {