changeset 4027:4c80b614717f

RT-31161: Scenegraph: error in GridPane layout with "rowConstraint" minWidth/ minHeight constraints weren't taken into account when no prefWidth/prefHeight was set for the column/row and no children was placed in the column/row.
author Eva Krejcirova <eva.krejcirova@oracle.com>
date Fri, 21 Jun 2013 16:33:28 +0100
parents 9c4360ee5f10
children e8ece2a01adb
files javafx-ui-common/src/javafx/scene/layout/GridPane.java javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java
diffstat 2 files changed, 52 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/layout/GridPane.java	Thu Jun 20 20:56:11 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/layout/GridPane.java	Fri Jun 21 16:33:28 2013 +0100
@@ -1378,8 +1378,8 @@
         for (int i = 0; i < rowConstr.size(); ++i) {
             final RowConstraints curConstraint = rowConstr.get(i);
             double prefRowHeight = snapSize(curConstraint.getPrefHeight());
+            final double min = snapSize(curConstraint.getMinHeight());
             if (prefRowHeight != USE_COMPUTED_SIZE) {
-                final double min = snapSize(curConstraint.getMinHeight());
                 final double max = snapSize(curConstraint.getMaxHeight());
                 if (min >= 0 || max >= 0) {
                     result.setPresetSize(i, boundedSize(min < 0 ? 0 : min,
@@ -1388,6 +1388,8 @@
                 } else {
                     result.setPresetSize(i, prefRowHeight);
                 }
+            } else if (min > 0){
+                result.setSize(i, min);
             }
         }
         List<Node> managed = getManagedChildren();
@@ -1516,8 +1518,8 @@
         for (int i = 0; i < columnConstr.size(); ++i) {
             final ColumnConstraints curConstraint = columnConstr.get(i);
             double prefColumnWidth = snapSize(curConstraint.getPrefWidth());
+            final double min = snapSize(curConstraint.getMinWidth());
             if (prefColumnWidth != USE_COMPUTED_SIZE) {
-                final double min = snapSize(curConstraint.getMinWidth());
                 final double max = snapSize(curConstraint.getMaxWidth());
                 if (min >= 0 || max >= 0) {
                     result.setPresetSize(i, boundedSize(min < 0 ? 0 : min,
@@ -1526,6 +1528,8 @@
                 } else {
                     result.setPresetSize(i, prefColumnWidth);
                 }
+            } else if (min > 0){
+                result.setSize(i, min);
             }
         }
         List<Node> managed = getManagedChildren();
--- a/javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java	Thu Jun 20 20:56:11 2013 -0700
+++ b/javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java	Fri Jun 21 16:33:28 2013 +0100
@@ -1398,6 +1398,52 @@
 
     }
 
+    @Test public void testEmptyRowWithRowConstraint() {
+        MockResizable child1 = new MockResizable(10,10, 10,10, 10,10);
+        MockResizable child2 = new MockResizable(10,10, 10,10, 10,10);
+        MockResizable child3 = new MockResizable(10,10, 10,10, 10,10);
+        gridpane.add(child1, 0, 0);
+        gridpane.add(child2, 1, 0);
+        gridpane.add(child3, 2, 0);       
+        GridPane.setConstraints(child3, 2, 0, 2, 2);
+
+        RowConstraints row1 = new RowConstraints();
+        row1.setMinHeight(35);
+        RowConstraints row2 = new RowConstraints();
+        row2.setMinHeight(35);
+        RowConstraints row3 = new RowConstraints();
+        row3.setMinHeight(35);
+
+        gridpane.getRowConstraints().addAll(row1, row2, row3);
+
+        assertEquals(105, gridpane.minHeight(-1), 0);
+        assertEquals(105, gridpane.prefHeight(-1), 0);
+        assertEquals(Double.MAX_VALUE, gridpane.maxHeight(-1), 0);
+    }
+
+    @Test public void testEmptyColumnWithColumnConstraint() {
+        MockResizable child1 = new MockResizable(10,10, 10,10, 10,10);
+        MockResizable child2 = new MockResizable(10,10, 10,10, 10,10);
+        MockResizable child3 = new MockResizable(10,10, 10,10, 10,10);
+        gridpane.add(child1, 0, 0);
+        gridpane.add(child2, 0, 1);
+        gridpane.add(child3, 0, 2);       
+        GridPane.setConstraints(child3, 0, 2, 2, 2);
+
+        ColumnConstraints col1 = new ColumnConstraints();
+        col1.setMinWidth(35);
+        ColumnConstraints col2 = new ColumnConstraints();
+        col2.setMinWidth(35);
+        ColumnConstraints col3 = new ColumnConstraints();
+        col3.setMinWidth(35);
+
+        gridpane.getColumnConstraints().addAll(col1, col2, col3);
+
+        assertEquals(105, gridpane.minWidth(-1), 0);
+        assertEquals(105, gridpane.prefWidth(-1), 0);
+        assertEquals(Double.MAX_VALUE, gridpane.maxWidth(-1), 0);
+    }
+
     @Test public void testMixedColumnSizeTypes() {
         MockResizable child1 = new MockResizable(100,100, 200,200, 500,500);
         MockResizable child2 = new MockResizable(100,100, 200,200, 500,500);