changeset 8014:26b2ed1d5d5b

RT-38667 [SpltPane] Cannot set divider position in multiple splitpanes at once under certain conditions Reviewed by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 17 Sep 2014 09:43:52 +0200
parents f73646deab84
children 3cc103a35bee
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/SplitPaneSkin.java modules/controls/src/test/java/javafx/scene/control/SplitPaneTest.java
diffstat 2 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/SplitPaneSkin.java	Wed Sep 17 09:31:50 2014 +0200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/SplitPaneSkin.java	Wed Sep 17 09:43:52 2014 +0200
@@ -136,12 +136,9 @@
         }
         
         @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {  
-            // If we already know the dividers are in the correct position.  We do not
-            // need to recheck their values.
             if (checkDividerPos) {
                 // When checking is enforced, we know that the position was set explicitly
                 divider.posExplicit = true;
-                checkDividerPosition(divider, posToDividerPos(divider, newValue.doubleValue()), posToDividerPos(divider, oldValue.doubleValue()));
             }
             getSkinnable().requestLayout();
         }
@@ -263,9 +260,7 @@
                 delta = e.getSceneY();
             }
             delta -= divider.getPressPos();
-            double newPos = Math.ceil(divider.getInitialPos() + delta);
-            checkDividerPos = true;
-            setAbsoluteDividerPos(divider, newPos);
+            setAndCheckAbsoluteDividerPos(divider, Math.ceil(divider.getInitialPos() + delta));
             e.consume();
         });
     }
@@ -665,23 +660,26 @@
             ContentDivider previousDivider = null;
             ContentDivider divider = null;            
             for (int i = 0; i < contentRegions.size(); i++) {
-                double space = 0;                
+                double space = 0;
                 if (i < contentDividers.size()) {
                     divider = contentDividers.get(i);
+                    if (divider.posExplicit) {
+                        checkDividerPosition(divider, posToDividerPos(divider, divider.d.getPosition()),
+                                divider.getDividerPos());
+                    }
                     if (i == 0) {
                         // First panel
                         space = getAbsoluteDividerPos(divider);
                     } else {
+                        double newPos = getAbsoluteDividerPos(previousDivider) + dividerWidth;
                         // Middle panels
                         if (getAbsoluteDividerPos(divider) <= getAbsoluteDividerPos(previousDivider)) {
                             // The current divider and the previous divider share the same position
                             // or the current divider position is less than the previous position.
                             // We will set the divider next to the previous divider.
-                            double pos = getAbsoluteDividerPos(previousDivider);                                
-                            checkDividerPos = true;
-                            setAbsoluteDividerPos(divider, pos + dividerWidth);
+                            setAndCheckAbsoluteDividerPos(divider, newPos);
                         }
-                        space = getAbsoluteDividerPos(divider) - (getAbsoluteDividerPos(previousDivider) + dividerWidth);
+                        space = getAbsoluteDividerPos(divider) - newPos;
                     }
                 } else if (i == contentDividers.size()) {
                     // Last panel
@@ -835,6 +833,12 @@
         resize = false;        
     }
 
+    private void setAndCheckAbsoluteDividerPos(ContentDivider divider, double value) {
+        double oldPos = divider.getDividerPos();
+        setAbsoluteDividerPos(divider, value);
+        checkDividerPosition(divider, value, oldPos);
+    }
+
     @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
         double minWidth = 0;
         double maxMinWidth = 0;
--- a/modules/controls/src/test/java/javafx/scene/control/SplitPaneTest.java	Wed Sep 17 09:31:50 2014 +0200
+++ b/modules/controls/src/test/java/javafx/scene/control/SplitPaneTest.java	Wed Sep 17 09:43:52 2014 +0200
@@ -1226,8 +1226,9 @@
         assertEquals(10, spCenter.getLayoutBounds().getWidth(), 1e-100);
         assertEquals(30, spRight.getLayoutBounds().getWidth(), 1e-100);       
         
-        splitPane.setDividerPosition(0, 0.20);        
-        
+        splitPane.setDividerPosition(0, 0.20);
+        root.layout();
+
         pos = splitPane.getDividerPositions();
         p0 = convertDividerPostionToAbsolutePostion(pos[0], w);
         p1 = convertDividerPostionToAbsolutePostion(pos[1], w);       
@@ -1235,6 +1236,7 @@
         assertEquals(62, p1, 1e-100);
         
         splitPane.setDividerPosition(1, 0.25);
+        root.layout();
                 
         pos = splitPane.getDividerPositions();
         p0 = convertDividerPostionToAbsolutePostion(pos[0], w);