changeset 5596:004595ed0b8f

RT-32009 DataApp client: layout is broken Reviewed-by: ekrejcir
author Martin Sladecek <martin.sladecek@oracle.com>
date Thu, 31 Oct 2013 11:01:57 +0100
parents dba0a7b958a5
children 024eca0e0e8c
files modules/graphics/src/main/java/javafx/scene/layout/GridPane.java modules/graphics/src/test/java/javafx/scene/layout/GridPaneTest.java
diffstat 2 files changed, 69 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/layout/GridPane.java	Thu Oct 31 10:01:29 2013 +0100
+++ b/modules/graphics/src/main/java/javafx/scene/layout/GridPane.java	Thu Oct 31 11:01:57 2013 +0100
@@ -1980,8 +1980,13 @@
             if (portion != 0) {
                 for (Iterator<Integer> i = adjusting.iterator(); i.hasNext();) {
                     final int index = i.next();
-                    final double limit = snapSpace(limitSize.getProportionalSize(index))
+                    double limit = snapSpace(limitSize.getProportionalMinOrMaxSize(index, shrinking))
                             - heights.getSize(index); // negative in shrinking case
+                    if (shrinking && limit > 0
+                            || !shrinking && limit < 0) { // Limit completely if current size
+                                                 // (originally based on preferred) already passed the computed limit
+                        limit = 0;
+                    }
                     final double change = Math.abs(limit) <= Math.abs(portion)? limit : portion;
                     heights.addSize(index, change);
                     available -= change;
@@ -2209,8 +2214,13 @@
             if (portion != 0) {
                 for (Iterator<Integer> i = adjusting.iterator(); i.hasNext();) {
                     final int index = i.next();
-                    final double limit = snapSpace(limitSize.getProportionalSize(index))
+                    double limit = snapSpace(limitSize.getProportionalMinOrMaxSize(index, shrinking))
                             - widths.getSize(index); // negative in shrinking case
+                    if (shrinking && limit > 0
+                            || !shrinking && limit < 0) { // Limit completely if current size
+                                                 // (originally based on preferred) already passed the computed limit
+                        limit = 0;
+                    }
                     final double change = Math.abs(limit) <= Math.abs(portion)? limit : portion;
                     widths.addSize(index, change);
                     available -= change;
@@ -2543,7 +2553,7 @@
             }
         }
 
-        private double getProportionalSize(int position) {
+        private double getProportionalMinOrMaxSize(int position, boolean min) {
             double result = singleSizes[position];
             if (!isPreset(position) && multiSizes != null) {
                 for (Interval i : multiSizes.keySet()) {
@@ -2552,18 +2562,18 @@
                         double propSize = segment;
                         for (int j = i.begin; j < i.end; ++j) {
                             if (j != position) {
-                                if (singleSizes[j] > segment) {
-                                    propSize += singleSizes[j] - segment;
+                                if (min ? singleSizes[j] > segment : singleSizes[j] < segment) {
+                                    propSize += segment - singleSizes[j];
                                 }
                             }
                         }
-                        result = Math.max(result, propSize);
+                        result = min ? Math.max(result, propSize) : Math.min(result, propSize);
                     }
                 }
             }
             return result;
         }
-
+        
         private double computeTotal(final int from, final int to) {
             double total = gap * (to - from - 1);
             for (int i = from; i < to; ++i) {
--- a/modules/graphics/src/test/java/javafx/scene/layout/GridPaneTest.java	Thu Oct 31 10:01:29 2013 +0100
+++ b/modules/graphics/src/test/java/javafx/scene/layout/GridPaneTest.java	Thu Oct 31 11:01:57 2013 +0100
@@ -2844,4 +2844,56 @@
         assertEquals(150, child2.getHeight(), 1e-100);
         assertEquals(150, child2.getWidth(), 1e-100);
     }
+    
+    @Test
+    public void testMultiRowWithOneRowEmpty() {
+        MockResizable childMulti = new MockResizable(100, 500, 100, 500, Double.MAX_VALUE, Double.MAX_VALUE);
+        gridpane.add(childMulti, 0, 0, 1, 3);
+        
+        MockResizable child1 = new MockResizable(100, 300);
+        MockResizable child2 = new MockResizable(100, 300);
+        
+        gridpane.add(child1, 1, 0);
+        gridpane.add(child2, 1, 2);
+        
+        gridpane.resize(500, 500);
+        gridpane.layout();
+        
+        assertEquals(100, child1.getLayoutX(), 1e-100);
+        assertEquals(0, child1.getLayoutY(), 1e-100);
+        assertEquals(250, child1.getHeight(), 1e-100);
+        assertEquals(100, child1.getWidth(), 1e-100);
+        
+        assertEquals(100, child2.getLayoutX(), 1e-100);
+        assertEquals(250, child2.getLayoutY(), 1e-100);
+        assertEquals(250, child2.getHeight(), 1e-100);
+        assertEquals(100, child2.getWidth(), 1e-100);
+        
+    }
+    
+    @Test
+    public void testMultiColumnWithOneColumnEmpty() {
+        MockResizable childMulti = new MockResizable(500, 100, 500, 100, Double.MAX_VALUE, Double.MAX_VALUE);
+        gridpane.add(childMulti, 0, 0, 3, 1);
+        
+        MockResizable child1 = new MockResizable(300, 100);
+        MockResizable child2 = new MockResizable(300, 100);
+        
+        gridpane.add(child1, 0, 1);
+        gridpane.add(child2, 2, 1);
+        
+        gridpane.resize(500, 500);
+        gridpane.layout();
+        
+        assertEquals(0, child1.getLayoutX(), 1e-100);
+        assertEquals(100, child1.getLayoutY(), 1e-100);
+        assertEquals(100, child1.getHeight(), 1e-100);
+        assertEquals(250, child1.getWidth(), 1e-100);
+        
+        assertEquals(250, child2.getLayoutX(), 1e-100);
+        assertEquals(100, child2.getLayoutY(), 1e-100);
+        assertEquals(100, child2.getHeight(), 1e-100);
+        assertEquals(250, child2.getWidth(), 1e-100);
+        
+    }
 }