changeset 6153:2abb15915443

RT-27000: ColorPicker renders incorrectly with "button" style
author jgiles
date Tue, 21 Jan 2014 10:24:00 +1300
parents 9a98b0b89f23
children c0c2b5d913ec
files apps/toys/Hello/src/main/java/hello/HelloColorPicker.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxBaseSkin.java
diffstat 3 files changed, 67 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/apps/toys/Hello/src/main/java/hello/HelloColorPicker.java	Tue Jan 21 09:50:22 2014 +1300
+++ b/apps/toys/Hello/src/main/java/hello/HelloColorPicker.java	Tue Jan 21 10:24:00 2014 +1300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,10 +26,14 @@
 package hello;
 
 import javafx.application.Application;
+import javafx.event.ActionEvent;
 import javafx.event.Event;
 import javafx.event.EventHandler;
+import javafx.geometry.Insets;
 import javafx.scene.Scene;
 import javafx.scene.control.ColorPicker;
+import javafx.scene.control.Label;
+import javafx.scene.layout.GridPane;
 import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
 import javafx.stage.Stage;
@@ -40,28 +44,57 @@
         launch(args);
     }
     @Override public void start(Stage stage) {
+//        setUserAgentStylesheet(STYLESHEET_CASPIAN);
+
         stage.setTitle("ColorPicker");
-        
-        Scene scene = new Scene(new VBox(20), 620, 190);
-        VBox box = (VBox)scene.getRoot();
-        
-        final ColorPicker colorPicker = new ColorPicker();
-        // default mode is combobox (above)
-        // uncomment the line below for simple button mode
-//        colorPicker.getStyleClass().add("button");
-        // uncomment the line below for SplitMenuButton mode
-//        colorPicker.getStyleClass().add("split-button");
-        // Uncomment the line below if you do not wish to see the label next the color.
-//        colorPicker.setStyle("-fx-color-label-visible: false;");
-        box.getChildren().addAll(colorPicker);
-        
+
+        EventHandler<ActionEvent> actionEventHandler = new EventHandler<ActionEvent>() {
+            public void handle(ActionEvent t) {
+                ColorPicker cp = (ColorPicker) t.getTarget();
+                Color c = cp.getValue();
+                System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
+            }
+        };
+
+        // default mode combobox
+        final ColorPicker normalColorPicker = new ColorPicker();
+        normalColorPicker.setOnAction(actionEventHandler);
+
+        // simple button mode
+        final ColorPicker buttonColorPicker = new ColorPicker();
+        buttonColorPicker.getStyleClass().add(ColorPicker.STYLE_CLASS_BUTTON);
+        buttonColorPicker.setOnAction(actionEventHandler);
+
+        // SplitMenuButton mode
+        final ColorPicker splitMenuColorPicker = new ColorPicker();
+        splitMenuColorPicker.getStyleClass().add(ColorPicker.STYLE_CLASS_SPLIT_BUTTON);
+        splitMenuColorPicker.setOnAction(actionEventHandler);
+
+        // Hidden label mode
+        final ColorPicker noLabelColorPicker = new ColorPicker();
+        noLabelColorPicker.setStyle("-fx-color-label-visible: false;");
+        noLabelColorPicker.setOnAction(actionEventHandler);
+
+        GridPane grid = new GridPane();
+        grid.setHgap(10);
+        grid.setVgap(10);
+        grid.setPadding(new Insets(10));
+
+        grid.add(new Label("Default ColorPicker: "), 1, 1);
+        grid.add(normalColorPicker, 2, 1);
+
+        grid.add(new Label("'Button' ColorPicker: "), 1, 2);
+        grid.add(buttonColorPicker, 2, 2);
+
+        grid.add(new Label("'SplitButton' ColorPicker: "), 1, 3);
+        grid.add(splitMenuColorPicker, 2, 3);
+
+        grid.add(new Label("'Hidden Label' ColorPicker: "), 1, 4);
+        grid.add(noLabelColorPicker, 2, 4);
+
+        Scene scene = new Scene(grid, 620, 190);
+
         stage.setScene(scene);
         stage.show();
-        colorPicker.setOnAction(new EventHandler() {
-            public void handle(Event t) {
-                Color c = colorPicker.getValue();
-                System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
-            }
-        });
     }
 }
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java	Tue Jan 21 09:50:22 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ColorPickerSkin.java	Tue Jan 21 10:24:00 2014 +1300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -244,10 +244,10 @@
 
 
     private void updateComboBoxMode() {
-        if (getSkinnable().getStyleClass().contains(ColorPicker.STYLE_CLASS_BUTTON)) {
+        List<String> styleClass = getSkinnable().getStyleClass();
+        if (styleClass.contains(ColorPicker.STYLE_CLASS_BUTTON)) {
             setMode(ComboBoxMode.BUTTON);
-        }
-        else if (getSkinnable().getStyleClass().contains(ColorPicker.STYLE_CLASS_SPLIT_BUTTON)) {
+        } else if (styleClass.contains(ColorPicker.STYLE_CLASS_SPLIT_BUTTON)) {
             setMode(ComboBoxMode.SPLITBUTTON);
         }
     }
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxBaseSkin.java	Tue Jan 21 09:50:22 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxBaseSkin.java	Tue Jan 21 10:24:00 2014 +1300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -159,13 +159,13 @@
         if (displayNode != null) {
             displayNode.resizeRelocate(x, y, w - arrowButtonWidth, h);
         }
-        
-        if (isButton()) return;
-        
-        arrowButton.resize(arrowButtonWidth, h);
-        positionInArea(arrowButton, 
-                (x+w) - arrowButtonWidth, y,
-                arrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER);
+
+        arrowButton.setVisible(! isButton());
+        if (! isButton()) {
+            arrowButton.resize(arrowButtonWidth, h);
+            positionInArea(arrowButton, (x + w) - arrowButtonWidth, y,
+                    arrowButtonWidth, h, 0, HPos.CENTER, VPos.CENTER);
+        }
     }
     
     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
@@ -174,7 +174,7 @@
         }
 
         final double arrowWidth = snapSize(arrow.prefWidth(-1));
-        final double arrowButtonWidth = (isButton()) ? 0 : 
+        final double arrowButtonWidth = isButton() ? 0 :
                                         arrowButton.snappedLeftInset() +
                                         arrowWidth + 
                                         arrowButton.snappedRightInset();