changeset 7607:376fe4bf61aa

RT-37727: [CSS] StyleablePropertyFactoryTest: reintroduce test for StyleableProperty<Insets>
author David Grieve<david.grieve@oracle.com>
date Thu, 31 Jul 2014 14:37:27 -0400
parents 101968b1eef0
children abe50f87067a
files modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java modules/graphics/src/test/java/javafx/css/StyleablePropertyFactoryTest.java modules/graphics/src/test/java/javafx/css/StyleablePropertyFactory_createMethod_Test.java
diffstat 3 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Thu Jul 31 14:37:26 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Thu Jul 31 14:37:27 2014 -0400
@@ -1431,7 +1431,22 @@
                     }
                 }
 
-                if (resolved.getConverter() != null)
+                final StyleConverter cssMetaDataConverter = cssMetaData.getConverter();
+                // RT-37727 - handling of properties that are insets is wonky. If the property is -fx-inset, then
+                // there isn't an issue because the converter assigns the InsetsConverter to the ParsedValueImpl.
+                // But -my-insets will parse as an array of numbers and the parser will assign the Size sequence
+                // converter to it. So, if the CssMetaData says it uses InsetsConverter, use the InsetsConverter
+                // and not the parser assigned converter.
+                if (cssMetaDataConverter == StyleConverter.getInsetsConverter()) {
+                    if (resolved.getValue() instanceof ParsedValue) {
+                        // If you give the parser "-my-insets: 5;" you end up with a ParsedValueImpl<ParsedValue<?,Size>, Number>
+                        // and not a ParsedValueImpl<ParsedValue[], Number[]> so here we wrap the value into an array
+                        // to make the InsetsConverter happy.
+                        resolved = new ParsedValueImpl(new ParsedValue[] {(ParsedValue)resolved.getValue()}, null, false);
+                    }
+                    val = cssMetaDataConverter.convert(resolved, fontForFontRelativeSizes);
+                }
+                else if (resolved.getConverter() != null)
                     val = resolved.convert(fontForFontRelativeSizes);
                 else
                     val = cssMetaData.getConverter().convert(resolved, fontForFontRelativeSizes);
--- a/modules/graphics/src/test/java/javafx/css/StyleablePropertyFactoryTest.java	Thu Jul 31 14:37:26 2014 -0400
+++ b/modules/graphics/src/test/java/javafx/css/StyleablePropertyFactoryTest.java	Thu Jul 31 14:37:27 2014 -0400
@@ -86,8 +86,10 @@
                 },
                 {new Data("myPos", "-my-pos: bottom-right;", Pos.BOTTOM_RIGHT)},
                 {new Data("myFont", "-my-font: 18 system;", Font.font("system", 18))},
-// Pending RT-37727
-//                {new Data("myInsets", "-my-insets: 1 2 3 4;", new Insets(1,2,3,4))},
+                {new Data("myInsets", "-my-insets: 1 2 3 4;", new Insets(1,2,3,4))},
+                {new Data("myInsets", "-my-insets: 5;", new Insets(5,5,5,5))},
+                {new Data("myInsets", "-my-insets: 7 8;", new Insets(7,8,7,8))},
+                {new Data("myInsets", "-my-insets: 9 10 11;", new Insets(9,10,11,10))},
                 {new Data("myPaint", "-my-paint: linear-gradient(from 0% 0% to 100% 100%, red 0%, black 100%);",
                         new LinearGradient(0,0,1,1,true, CycleMethod.NO_CYCLE,new Stop[] { new Stop(0,Color.RED), new Stop(1,Color.BLACK) }))
                 },
--- a/modules/graphics/src/test/java/javafx/css/StyleablePropertyFactory_createMethod_Test.java	Thu Jul 31 14:37:26 2014 -0400
+++ b/modules/graphics/src/test/java/javafx/css/StyleablePropertyFactory_createMethod_Test.java	Thu Jul 31 14:37:27 2014 -0400
@@ -113,7 +113,7 @@
         }
 
         assertEquals(styleable.getProp().getCssMetaData().getInitialValue(null), styleable.getProp().getValue());
-        assertEquals(Boolean.valueOf(inherits), styleable.getProp().getCssMetaData().isInherits());
+        assertEquals(styleable.getProp().getCssMetaData().toString(), Boolean.valueOf(inherits), styleable.getProp().getCssMetaData().isInherits());
 
         List<CssMetaData<? extends Styleable,?>> list = styleable.getCssMetaData();
         assert list != null;
@@ -191,7 +191,7 @@
         final MyStyleable<?> other = new MyStyleable();
         other.setProp(data.createMethodName);
 
-        check(styleable, other, data.converter, false);
+        check(styleable, other, data.converter, data.converter == StyleConverter.getFontConverter());
 
         // one
         final MyStyleable<?> styleable1 = new MyStyleable1();
@@ -200,7 +200,7 @@
         final MyStyleable<?> other1 = new MyStyleable1();
         other1.setProp(data.createMethodName, data.initialValue);
 
-        check(styleable1, other1, data.converter, false);
+        check(styleable1, other1, data.converter, data.converter == StyleConverter.getFontConverter());
 
         assertNotSame(styleable.getProp().getCssMetaData(), styleable1.getProp().getCssMetaData());