changeset 6425:b9b901417181

RT-36088 [Popup] PopupWindow.show(Window): Wrong popup positioning on subsequent calls
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 05 Mar 2014 10:04:40 +0100
parents b6f62f8bd8e6
children a080ea040a9c
files modules/graphics/src/main/java/javafx/stage/PopupWindow.java modules/graphics/src/test/java/javafx/stage/PopupTest.java
diffstat 2 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/stage/PopupWindow.java	Wed Mar 05 12:48:39 2014 +0400
+++ b/modules/graphics/src/main/java/javafx/stage/PopupWindow.java	Wed Mar 05 10:04:40 2014 +0100
@@ -768,11 +768,11 @@
 
         // update popup position
         // don't set Window.xExplicit unnecessarily
-        if (!Double.isNaN(windowScrMinX) || !Double.isNaN(getX())) {
+        if (!Double.isNaN(windowScrMinX)) {
             super.setXInternal(windowScrMinX);
         }
         // don't set Window.yExplicit unnecessarily
-        if (!Double.isNaN(windowScrMinY) || !Double.isNaN(getY())) {
+        if (!Double.isNaN(windowScrMinY)) {
             super.setYInternal(windowScrMinY);
         }
 
--- a/modules/graphics/src/test/java/javafx/stage/PopupTest.java	Wed Mar 05 12:48:39 2014 +0400
+++ b/modules/graphics/src/test/java/javafx/stage/PopupTest.java	Wed Mar 05 10:04:40 2014 +0100
@@ -35,6 +35,7 @@
 import javafx.event.EventHandler;
 import javafx.geometry.BoundingBox;
 import javafx.geometry.Bounds;
+import javafx.geometry.Rectangle2D;
 import javafx.scene.Cursor;
 import javafx.scene.Group;
 import javafx.scene.Parent;
@@ -229,6 +230,31 @@
     }
 
     @Test
+    public void testPopupWithoutAnchorStayInTheCenter() {
+        final Popup popup = new Popup();
+        popup.setWidth(100);
+        popup.setHeight(100);
+        popup.show(stage);
+        Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
+
+        double centerX = Math.ceil((bounds.getMinX() + (bounds.getWidth() - 100))/2);
+        double centerY = Math.ceil((bounds.getMinY() + (bounds.getHeight() - 100))/3);
+
+        StubPopupStage peer = (StubPopupStage) popup.impl_getPeer();
+
+        assertEquals(centerX, Math.ceil(peer.x), 1e-100);
+        assertEquals(centerY, Math.ceil(peer.y), 1e-100);
+
+        popup.hide();
+        popup.show(stage);
+
+        peer = (StubPopupStage) popup.impl_getPeer();
+
+        assertEquals(centerX, Math.ceil(peer.x), 1e-100);
+        assertEquals(centerY, Math.ceil(peer.y), 1e-100);
+    }
+
+    @Test
     public void testHide() {
         Popup p1 = new Popup();
         p1.show(stage);