changeset 7711:c3a8124d5cd6

RT-38321: [Dialogs] Fix layout issues
author jgiles
date Tue, 19 Aug 2014 12:50:40 +1200
parents 348f681e0717
children 323fe1d9f2b8
files modules/controls/src/main/java/javafx/scene/control/ChoiceDialog.java modules/controls/src/main/java/javafx/scene/control/Dialog.java modules/controls/src/main/java/javafx/scene/control/DialogPane.java modules/controls/src/main/java/javafx/scene/control/TextInputDialog.java modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css
diffstat 5 files changed, 43 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/ChoiceDialog.java	Tue Aug 19 10:46:49 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/ChoiceDialog.java	Tue Aug 19 12:50:40 2014 +1200
@@ -32,6 +32,7 @@
 import javafx.application.Platform;
 import javafx.beans.property.ReadOnlyObjectProperty;
 import javafx.collections.ObservableList;
+import javafx.geometry.Pos;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 import javafx.scene.layout.GridPane;
@@ -114,6 +115,7 @@
         this.grid = new GridPane();
         this.grid.setHgap(10);
         this.grid.setMaxWidth(Double.MAX_VALUE);
+        this.grid.setAlignment(Pos.CENTER_LEFT);
         
         // -- label
         label = DialogPane.createContentLabel(dialogPane.getContentText());
--- a/modules/controls/src/main/java/javafx/scene/control/Dialog.java	Tue Aug 19 10:46:49 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/Dialog.java	Tue Aug 19 12:50:40 2014 +1200
@@ -238,7 +238,6 @@
         this.dialog = new HeavyweightDialog(this);
         setDialogPane(new DialogPane());
         initModality(Modality.APPLICATION_MODAL);
-        setResizable(true);
     }
     
     
--- a/modules/controls/src/main/java/javafx/scene/control/DialogPane.java	Tue Aug 19 10:46:49 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/DialogPane.java	Tue Aug 19 12:50:40 2014 +1200
@@ -58,6 +58,7 @@
 import javafx.scene.image.ImageView;
 import javafx.scene.layout.BorderPane;
 import javafx.scene.layout.Pane;
+import javafx.scene.layout.Region;
 import javafx.scene.layout.StackPane;
 
 import com.sun.javafx.css.StyleManager;
@@ -134,25 +135,18 @@
      * Static fields
      * 
      **************************************************************************/
-    
+
     /**
      * Creates a Label node that works well within a Dialog.
      * @param text The text to display
      */
     static Label createContentLabel(String text) {
         Label label = new Label(text);
-//        label.setAlignment(Pos.TOP_LEFT);
-//        label.setTextAlignment(TextAlignment.LEFT);
         label.setMaxWidth(Double.MAX_VALUE);
         label.setMaxHeight(Double.MAX_VALUE);
         label.getStyleClass().add("content");
         label.setWrapText(true);
-        
-        // FIXME we don't want to restrict the width, but for now this works ok
-        // label.setPrefWidth(MAIN_TEXT_WIDTH);
-//        label.setPrefWidth(360);
-        
-        
+        label.setPrefWidth(360);
         return label;
     }
     
@@ -829,7 +823,7 @@
             y += headerPrefHeight;
         }
         
-        content.resizeRelocate(x, y, w - graphicPrefWidth - rightPadding, contentAreaHeight);
+        content.resizeRelocate(x, y, w - graphicPrefWidth, contentAreaHeight);
         y += contentAreaHeight;
         
         if (expandableContent != null) {
@@ -847,7 +841,7 @@
         double headerPrefWidth = hasHeader() ? getActualHeader().prefWidth(height) : 0;
         double contentPrefWidth = getActualContent().prefWidth(height);
         double buttonBarPrefWidth = buttonBar == null ? 0 : buttonBar.prefWidth(height);
-        double graphicPrefWidth = graphicContainer.prefWidth(height);
+        double graphicPrefWidth = getActualGraphic().prefWidth(height);
         
         double expandableContentPrefWidth = 0;
         final Node expandableContent = getExpandableContent();
@@ -855,18 +849,28 @@
             expandableContentPrefWidth = expandableContent.prefWidth(height);
         }
         
-        return snappedLeftInset() + 
+        double prefWidth = snappedLeftInset() +
                (hasHeader() ? 0 : graphicPrefWidth) +
                Math.max(Math.max(headerPrefWidth, expandableContentPrefWidth), Math.max(contentPrefWidth, buttonBarPrefWidth)) +
                snappedRightInset();
+
+        return prefWidth;
     }
 
     /** {@inheritDoc} */
     @Override protected double computePrefHeight(double width) {
-        double headerPrefHeight = hasHeader() ? getActualHeader().prefHeight(width) : 0;
-        double contentPrefHeight = getActualContent().prefHeight(width);
+        final boolean hasHeader = hasHeader();
+
+        double headerPrefHeight = hasHeader ? getActualHeader().prefHeight(width) : 0;
         double buttonBarPrefHeight = buttonBar == null ? 0 : buttonBar.prefHeight(width);
-        double graphicPrefHeight = graphicContainer.prefHeight(width);
+
+        Node graphic = getActualGraphic();
+        double graphicPrefWidth = graphic.prefWidth(-1);
+        double graphicPrefHeight = graphic.prefHeight(width);
+
+        double contentAvailableWidth = width == Region.USE_COMPUTED_SIZE ? Region.USE_COMPUTED_SIZE :
+                                       hasHeader ? width : (width - graphicPrefWidth);
+        double contentPrefHeight = getActualContent().prefHeight(contentAvailableWidth);
         
         double expandableContentPrefHeight = 0;
         final Node expandableContent = getExpandableContent();
@@ -874,12 +878,14 @@
             expandableContentPrefHeight = expandableContent.prefHeight(width);
         }
         
-        return snappedTopInset() + 
+        double prefHeight = snappedTopInset() +
                headerPrefHeight + 
                Math.max(graphicPrefHeight, contentPrefHeight) + 
                expandableContentPrefHeight + 
                buttonBarPrefHeight + 
                snappedBottomInset();
+
+        return prefHeight;
     }
     
     
@@ -932,7 +938,7 @@
     }
     
     private Node getActualGraphic() {
-        return graphicContainer;
+        return headerTextPanel;
     }
     
     private void updateHeaderArea() {
@@ -945,7 +951,10 @@
         } else {
             // recreate the headerTextNode and add it to the children list.
             headerTextPanel.setMaxWidth(Double.MAX_VALUE);
-            headerTextPanel.getStyleClass().add("header-panel"); //$NON-NLS-1$
+
+            if (! headerTextPanel.getStyleClass().contains("header-panel")) { //$NON-NLS-1$
+                headerTextPanel.getStyleClass().add("header-panel"); //$NON-NLS-1$
+            }
     
             // on left of header is the text
             Label headerLabel = new Label(getHeaderText());
@@ -957,7 +966,11 @@
     
             // on the right of the header is a graphic, if one is specified
             graphicContainer.getChildren().clear();
-            graphicContainer.getStyleClass().add("graphic-container"); //$NON-NLS-1$
+
+            if (! graphicContainer.getStyleClass().contains("graphic-container")) { //$NON-NLS-1$)
+                graphicContainer.getStyleClass().add("graphic-container"); //$NON-NLS-1$
+            }
+
             final Node graphic = getGraphic();
             if (graphic != null) {
                 graphicContainer.getChildren().add(graphic);
--- a/modules/controls/src/main/java/javafx/scene/control/TextInputDialog.java	Tue Aug 19 10:46:49 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/TextInputDialog.java	Tue Aug 19 12:50:40 2014 +1200
@@ -28,6 +28,7 @@
 import com.sun.javafx.scene.control.skin.resources.ControlResources;
 import javafx.application.Platform;
 import javafx.beans.NamedArg;
+import javafx.geometry.Pos;
 import javafx.scene.control.Label;
 import javafx.scene.control.TextField;
 import javafx.scene.image.Image;
@@ -94,6 +95,7 @@
         this.grid = new GridPane();
         this.grid.setHgap(10);
         this.grid.setMaxWidth(Double.MAX_VALUE);
+        this.grid.setAlignment(Pos.CENTER_LEFT);
         
         dialogPane.contentTextProperty().addListener(o -> updateGrid());
         
--- a/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css	Tue Aug 19 10:46:49 2014 +1200
+++ b/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css	Tue Aug 19 12:50:40 2014 +1200
@@ -3351,12 +3351,16 @@
     -fx-padding: 0.833333em; /* 10px */
 }
 
+.dialog > .dialog-pane > .content.label {
+    -fx-alignment: top-left;
+    -fx-padding: 0.833333em 0.833333em 0 0.833333em; /* 0 10 0 10 */
+}
 .dialog > .dialog-pane > .content {
-    -fx-padding: 0.833333em; /* 10px */
+    -fx-padding: 0.833333em; /* 10 */
 }
 
 .dialog:no-header > .dialog-pane .graphic-container {
-    -fx-padding: 0.833333em 0.833333em 0 0.833333em; /* 10px 10px 0px 10px */
+    -fx-padding: 0.833333em 0 0 0.833333em; /* 10px 0px 0px 10px */
 }
 
 .dialog:header > .dialog-pane .header-panel {
@@ -3371,6 +3375,7 @@
 }
 
 .dialog:header > .dialog-pane .header-panel .graphic-container {
+    /* This prevents the text in the header running directly into the graphic */
     -fx-padding: 0 0 0 0.833333em; /* 0px 0px 0px 10px */
 }