changeset 1047:1639f29f5266

RT-21357: set graphic on LabeledImpl if set on Labeled. Plus unit test
author David Grieve<david.grieve@oracle.com>
date Tue, 15 May 2012 13:08:14 -0400
parents 0f8df2a08440
children 533c34fbeefc
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledImpl.java javafx-ui-controls/test/com/sun/javafx/scene/control/skin/LabeledImplTestOther.java
diffstat 2 files changed, 71 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledImpl.java	Tue May 15 18:37:32 2012 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/LabeledImpl.java	Tue May 15 13:08:14 2012 -0400
@@ -50,6 +50,9 @@
         labeledImpl.setText(labeled.getText());
         labeled.textProperty().addListener(shuttler);
         
+        labeledImpl.setGraphic(labeled.getGraphic());
+        labeled.graphicProperty().addListener(shuttler);
+        
         final List<StyleableProperty> styleables = Labeled.impl_CSS_STYLEABLES();
         
         for(int n=0, nMax=styleables.size(); n<nMax; n++) {
@@ -87,8 +90,16 @@
           
             if (valueModel == labeled.textProperty()) {
                 labeledImpl.setText(labeled.getText());
-            } else 
-            if (valueModel instanceof WritableValue) { 
+            } else if (valueModel == labeled.graphicProperty()) {
+                // If the user set the graphic, then mirror that.
+                // Otherwise, the graphic was set via the imageUrlProperty which
+                // will be mirrored onto the labeledImpl by the next block.
+                Stylesheet.Origin origin = StyleableProperty.getOrigin(labeled.graphicProperty());
+                if (origin == null || origin == Stylesheet.Origin.USER) {
+                    labeledImpl.setGraphic(labeled.getGraphic());
+                }
+                
+            } else if (valueModel instanceof WritableValue) { 
                 WritableValue writable = (WritableValue)valueModel;
                 StyleableProperty styleable = 
                         StyleableProperty.getStyleableProperty(writable);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/LabeledImplTestOther.java	Tue May 15 13:08:14 2012 -0400
@@ -0,0 +1,58 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.sun.javafx.scene.control.skin;
+
+import com.sun.javafx.css.StyleConverter;
+import com.sun.javafx.css.StyleableProperty;
+import java.net.URL;
+import java.util.ArrayList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import javafx.beans.value.WritableValue;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.Cursor;
+import javafx.scene.control.ContentDisplay;
+import javafx.scene.control.Label;
+import javafx.scene.control.Labeled;
+import javafx.scene.control.OverrunStyle;
+import javafx.scene.effect.BlendMode;
+import javafx.scene.effect.ColorAdjustBuilder;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.paint.Color;
+import javafx.scene.text.Font;
+import javafx.scene.text.TextAlignment;
+import javax.swing.GroupLayout;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class LabeledImplTestOther {
+    
+    
+    @Test 
+    public void test_RT_21357() {
+        
+        final Labeled labeled = new Label("label");
+        final LabeledImpl labeledImpl = new LabeledImpl(labeled);
+        
+        URL url = SkinBase.class.getResource("caspian/center-btn.png");
+        Image img = new Image(url.toExternalForm());
+        ImageView iView = new ImageView(img);
+        labeled.setGraphic(iView);  
+        
+        assertEquals(labeled.getGraphic(), labeledImpl.getGraphic());
+    }
+
+}