changeset 6544:14580ce9a75e

RT-36371 GridPane ColumnConstraints Java 7 and 8 broken compatibility
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 26 Mar 2014 09:39:16 +0100
parents 85e8ec504bff
children 89ca2db487e3
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, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/layout/GridPane.java	Tue Mar 25 17:40:51 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/layout/GridPane.java	Wed Mar 26 09:39:16 2014 +0100
@@ -2624,7 +2624,7 @@
                 }
             }
             if (totalFixedPercent > 0) {
-                double totalFixed = 0;
+                double totalNotFixed = 0;
                 // First, remove the sizes that are fixed to be 0
                 for (int i = 0; i < fixedPercent.length; ++i) {
                     if (fixedPercent[i] == 0) {
@@ -2633,14 +2633,15 @@
                 }
                 for (int i = 0; i < fixedPercent.length; ++i) {
                     if (fixedPercent[i] > 0) {
-                        totalFixed += singleSizes[i];
                         // Grow the total so that every size at it's value corresponds at least to it's fixedPercent of the total
                         // i.e. total * fixedPercent[i] >= singleSizes[i]
                         total = Math.max(total, singleSizes[i] * (100 / fixedPercent[i]));
+                    } else if (fixedPercent[i] < 0){
+                        totalNotFixed += singleSizes[i];
                     }
                 }
                 if (totalFixedPercent < 100) {
-                    total = Math.max(total, (total - totalFixed) * 100 / (100 - totalFixedPercent));
+                    total = Math.max(total, totalNotFixed * 100 / (100 - totalFixedPercent));
                 }
             }
             return total;
--- a/modules/graphics/src/test/java/javafx/scene/layout/GridPaneTest.java	Tue Mar 25 17:40:51 2014 -0400
+++ b/modules/graphics/src/test/java/javafx/scene/layout/GridPaneTest.java	Wed Mar 26 09:39:16 2014 +0100
@@ -3000,4 +3000,32 @@
         assertEquals(1, GridPane.getColumnIndex(node3), 1e-100);
         assertEquals(1, GridPane.getRowIndex(node3), 1e-100);
     }
+
+    @Test
+    public void testAllColumnsFixedButNotUpTo100() {
+        MockResizable child1 = new MockResizable(10,10, 20, 20, 300, 300);
+        MockResizable child2 = new MockResizable(10,10, 30, 30, 300, 300);
+        MockResizable child3 = new MockResizable(10,10, 40, 40, 300, 300);
+        gridpane.addRow(0, child1,child2,child3);
+
+        final ColumnConstraints cc = new ColumnConstraints();
+        cc.setPercentWidth(25);
+        gridpane.getColumnConstraints().addAll(cc, cc, cc);
+
+        assertEquals(160, gridpane.prefWidth(-1), 1e-100);
+    }
+
+    @Test
+    public void testAllRowsFixedButNotUpTo100() {
+        MockResizable child1 = new MockResizable(10,10, 20, 20, 300, 300);
+        MockResizable child2 = new MockResizable(10,10, 30, 30, 300, 300);
+        MockResizable child3 = new MockResizable(10,10, 40, 40, 300, 300);
+        gridpane.addColumn(0, child1, child2, child3);
+
+        final RowConstraints rc = new RowConstraints();
+        rc.setPercentHeight(25);
+        gridpane.getRowConstraints().addAll(rc, rc, rc);
+
+        assertEquals(160, gridpane.prefHeight(-1), 1e-100);
+    }
 }