changeset 317:7603128a3d29

RT-19025: Accordion computed height is incorrect.
author Kinsley Wong
date Tue, 24 Jan 2012 17:17:01 -0800
parents a1590965f8b4
children 9e514329f414 40d15360d669
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/AccordionSkin.java javafx-ui-controls/test/javafx/scene/control/AccordionTest.java
diffstat 2 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/AccordionSkin.java	Tue Jan 24 14:11:46 2012 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/AccordionSkin.java	Tue Jan 24 17:17:01 2012 -0800
@@ -88,8 +88,21 @@
 
     @Override protected double computePrefHeight(double width) {
         double h = 0;
+        // We want the current expanded pane or the currently collapsing one (previousPane).
+        // This is because getExpandedPane() will be null when the expanded pane
+        // is collapsing.
+        TitledPane expandedTitledPane = getSkinnable().getExpandedPane() != null ? getSkinnable().getExpandedPane() : previousPane;
+        if (expandedTitledPane != null) {
+            h = expandedTitledPane.prefHeight(-1);
+        }
         for (Node child: getManagedChildren()) {
-            h += snapSize(child.prefHeight(width));
+            TitledPane pane = (TitledPane)child;
+            if (!pane.equals(expandedTitledPane)) {
+                // The min height is the height of the TitledPane's title bar.
+                // We use the sum of all the TitledPane's title bars
+                // to compute the pref height of the accordion.
+                h += snapSize(pane.minHeight(width));
+            }
         }
         return h + snapSpace(getInsets().getTop()) + snapSpace(getInsets().getBottom());
     }
--- a/javafx-ui-controls/test/javafx/scene/control/AccordionTest.java	Tue Jan 24 14:11:46 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/AccordionTest.java	Tue Jan 24 17:17:01 2012 -0800
@@ -3,6 +3,9 @@
  */
 package javafx.scene.control;
 
+import javafx.scene.Scene;
+import javafx.scene.layout.StackPane;
+import javafx.stage.Stage;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.ObservableValue;
 
@@ -16,9 +19,23 @@
 public class AccordionTest {
 
     private Accordion accordion;
-
+    private Scene scene;
+    private Stage stage;
+    private StackPane root;    
+    
     @Before public void setup() {
         accordion = new Accordion();
+        root = new StackPane();
+        scene = new Scene(root);
+        stage = new Stage();
+        stage.setScene(scene);
+    }
+
+    /*********************************************************************
+     * Helper methods                                                    *
+     ********************************************************************/
+    private void show() {
+        stage.show();
     }
 
     /*********************************************************************
@@ -107,4 +124,34 @@
         accordion.getPanes().removeAll(b, c);
         assertSame(b, accordion.getExpandedPane());
     }
+
+    @Test public void checkComputedHeight_RT19025() {
+        TitledPane a = new TitledPane("A", new javafx.scene.shape.Rectangle(50, 100));
+        TitledPane b = new TitledPane("B", new javafx.scene.shape.Rectangle(50, 100));
+        TitledPane c = new TitledPane("C", new javafx.scene.shape.Rectangle(50, 100));
+
+        a.setAnimated(false);
+        b.setAnimated(false);
+        c.setAnimated(false);
+        
+        accordion.getPanes().addAll(a, b, c);
+        root.setPrefSize(100, 300);
+        root.getChildren().add(accordion);
+        show();
+                
+        root.impl_reapplyCSS();
+        root.autosize();
+        root.layout();
+        
+        assertEquals(54, accordion.prefWidth(-1), 1e-100);
+        assertEquals(66, accordion.prefHeight(-1), 1e-100);
+
+        accordion.setExpandedPane(b);
+        root.impl_reapplyCSS();
+        root.autosize();
+        root.layout();
+
+        assertEquals(54, accordion.prefWidth(-1), 1e-100);
+        assertEquals(170, accordion.prefHeight(-1), 1e-100);
+    }
 }