From 33dfa9cc31557c14d826d55be38b49ba2d872b4c Mon Sep 17 00:00:00 2001 From: aalmiray Date: Thu, 9 Aug 2018 12:25:47 +0200 Subject: [PATCH] Replace usages of PropertyEditor with Converter. Relates to #295 --- .../resources-injected-resources.adoc | 6 +- ...doc => resources-property-converters.adoc} | 137 +++++---- .../resources-resource-resolver.adoc | 13 +- .../docs/asciidoc/resources/resources.adoc | 2 +- samples/console-swing-groovy/build.gradle.txt | 5 - .../src/pom/master-pom.xml | 5 - .../griffon/metadata/PropertyEditorFor.java | 34 --- .../editor/PropertyEditorCollector.java | 131 -------- .../editor/PropertyEditorProcessor.java | 182 ----------- .../core/processor/editor/package-info.java | 25 -- .../javax.annotation.processing.Processor | 1 - .../editor/PropertyEditorCollectorTest.java | 166 ---------- .../main/java/griffon/core/Configuration.java | 219 +------------ .../src/main/java/griffon/core/Context.java | 6 +- .../griffon/core/MutableConfiguration.java | 16 +- .../core/configuration/Configured.java | 46 --- .../core/editors/AbstractPropertyEditor.java | 132 -------- .../editors/BigDecimalPropertyEditor.java | 68 ----- .../editors/BigIntegerPropertyEditor.java | 68 ----- .../core/editors/BooleanPropertyEditor.java | 55 ---- .../core/editors/BytePropertyEditor.java | 59 ---- .../core/editors/CalendarPropertyEditor.java | 83 ----- .../core/editors/DatePropertyEditor.java | 76 ----- .../core/editors/DoublePropertyEditor.java | 59 ---- .../core/editors/EnumPropertyEditor.java | 64 ---- .../ExtendedCalendarPropertyEditor.java | 64 ---- .../core/editors/ExtendedPropertyEditor.java | 34 --- .../core/editors/FilePropertyEditor.java | 49 --- .../core/editors/FloatPropertyEditor.java | 59 ---- .../core/editors/IntegerPropertyEditor.java | 59 ---- .../core/editors/LocalDatePropertyEditor.java | 150 --------- .../editors/LocalDateTimePropertyEditor.java | 162 ---------- .../core/editors/LocalTimePropertyEditor.java | 143 --------- .../core/editors/LocalePropertyEditor.java | 47 --- .../core/editors/LongPropertyEditor.java | 59 ---- .../core/editors/PropertyEditorChain.java | 289 ------------------ .../core/editors/PropertyEditorResolver.java | 247 --------------- .../core/editors/ShortPropertyEditor.java | 59 ---- .../core/editors/URIPropertyEditor.java | 62 ---- .../core/editors/URLPropertyEditor.java | 65 ---- .../editors/ValueConversionException.java | 61 ---- .../core/formatters/AbstractFormatter.java | 49 --- .../core/formatters/BigDecimalFormatter.java | 75 ----- .../core/formatters/BigIntegerFormatter.java | 76 ----- .../core/formatters/BooleanFormatter.java | 171 ----------- .../core/formatters/ByteFormatter.java | 69 ----- .../core/formatters/CalendarFormatter.java | 69 ----- .../core/formatters/DateFormatter.java | 67 ---- .../core/formatters/DoubleFormatter.java | 68 ----- .../core/formatters/FloatFormatter.java | 68 ----- .../griffon/core/formatters/Formatter.java | 53 ---- .../core/formatters/IntegerFormatter.java | 69 ----- .../core/formatters/LocalDateFormatter.java | 70 ----- .../formatters/LocalDateTimeFormatter.java | 70 ----- .../core/formatters/LocalTimeFormatter.java | 70 ----- .../core/formatters/LocaleFormatter.java | 52 ---- .../core/formatters/LongFormatter.java | 69 ----- .../core/formatters/ShortFormatter.java | 69 ----- .../core/resources/ResourceResolver.java | 16 +- .../main/java/griffon/inject/MVCMember.java | 7 +- .../src/main/java/griffon/util/TypeUtils.java | 11 +- .../griffon/runtime/core/AbstractContext.java | 15 +- .../core/DefaultApplicationConfigurer.java | 41 --- .../griffon/runtime/core/DefaultContext.java | 9 +- .../runtime/core/DefaultContextFactory.java | 7 +- .../core/DefaultObservableContext.java | 9 +- .../core/DefaultObservableContextFactory.java | 7 +- .../configuration/AbstractConfiguration.java | 55 ++-- .../AbstractConfigurationManager.java | 58 ++-- .../AbstractMapConfiguration.java | 6 +- .../configuration/ConfigurationDecorator.java | 33 +- .../ConfigurationDescriptor.java | 12 +- .../DelegatingMutableConfiguration.java | 13 +- .../FieldConfigurationDescriptor.java | 10 +- .../configuration/FieldInjectionPoint.java | 8 +- .../core/configuration/InjectionPoint.java | 12 +- .../MethodConfigurationDescriptor.java | 10 +- .../configuration/MethodInjectionPoint.java | 8 +- .../ResourceBundleConfiguration.java | 6 +- .../ResourceBundleConfigurationProvider.java | 6 +- .../core/mvc/AbstractMVCGroupManager.java | 10 +- .../core/mvc/DefaultMVCGroupManager.java | 85 +++--- .../editors/java.beans.PropertyEditor | 19 -- .../groovy/griffon/core/ContextSpec.groovy | 24 +- .../griffon/core/ObservableContextSpec.groovy | 18 +- .../BigDecimalPropertyEditorSpec.groovy | 74 ----- .../BigIntegerPropertyEditorSpec.groovy | 74 ----- .../editors/BooleanPropertyEditorSpec.groovy | 77 ----- .../editors/BytePropertyEditorSpec.groovy | 72 ----- .../editors/CalendarPropertyEditorSpec.groovy | 80 ----- .../editors/DatePropertyEditorSpec.groovy | 80 ----- .../editors/DoublePropertyEditorSpec.groovy | 72 ----- .../editors/EnumPropertyEditorSpec.groovy | 77 ----- .../ExtendedCalendarPropertyEditorSpec.groovy | 50 --- .../ExtendedDatePropertyEditorSpec.groovy | 50 --- .../editors/FilePropertyEditorSpec.groovy | 72 ----- .../editors/FloatPropertyEditorSpec.groovy | 72 ----- .../editors/IntegerPropertyEditorSpec.groovy | 72 ----- .../LocalDatePropertyEditorSpec.groovy | 90 ------ .../LocalDateTimePropertyEditorSpec.groovy | 96 ------ .../LocalTimePropertyEditorSpec.groovy | 88 ------ .../editors/LocalePropertyEditorSpec.groovy | 66 ---- .../editors/LongPropertyEditorSpec.groovy | 72 ----- .../editors/PropertyEditorResolverSpec.groovy | 156 ---------- .../editors/PropertyEditorSpecSupport.groovy | 69 ----- .../editors/ShortPropertyEditorSpec.groovy | 72 ----- .../editors/StringPropertyEditorSpec.groovy | 50 --- .../core/editors/URIPropertyEditorSpec.groovy | 75 ----- .../core/editors/URLPropertyEditorSpec.groovy | 75 ----- .../formatters/BigDecimalFormatterSpec.groovy | 93 ------ .../formatters/BigIntegerFormatterSpec.groovy | 93 ------ .../formatters/BooleanFormatterSpec.groovy | 132 -------- .../core/formatters/ByteFormatterSpec.groovy | 93 ------ .../formatters/CalendarFormatterSpec.groovy | 95 ------ .../core/formatters/DateFormatterSpec.groovy | 91 ------ .../formatters/DoubleFormatterSpec.groovy | 93 ------ .../core/formatters/FloatFormatterSpec.groovy | 93 ------ .../formatters/FormatterSpecSupport.groovy | 68 ----- .../formatters/IntegerFormatterSpec.groovy | 93 ------ .../formatters/LocaleFormatterSpec.groovy | 42 --- .../core/formatters/LongFormatterSpec.groovy | 93 ------ .../core/formatters/ShortFormatterSpec.groovy | 93 ------ .../groovy/integration/ChildController.java | 4 +- .../integration/ConfigurableBean.groovy | 5 +- ...or.groovy => CustomStringConverter.groovy} | 18 +- ...PropertyEditor.java => ListConverter.java} | 28 +- .../core/MutableConfigurationSpec.groovy | 57 +--- .../ConfigurationDecoratorSpec.groovy | 7 +- .../configuration/ConfigurationSpec.groovy | 38 +-- .../DefaultConfigurationSpec.groovy | 5 +- .../CustomResourceResolverTests.groovy | 14 +- .../storage/DefaultObjectFactorySpec.groovy | 4 +- .../test/java/griffon/util/TypeUtilsTest.java | 5 +- .../PropertyEditorASTTransformation.java | 156 ---------- ...roovyScriptResourceBundleLoaderSpec.groovy | 2 - .../griffon/util/groovy/application.groovy | 17 ++ .../griffon/util/groovy/application.xml | 19 ++ .../util/groovy/application_jdk8.groovy | 17 ++ .../griffon/util/groovy/bad_application.xml | 19 ++ .../ColorConverter.java} | 81 +++-- .../Dimension2DConverter.java} | 75 ++--- .../GraphicConverter.java} | 48 ++- .../ImageConverter.java} | 59 ++-- .../InsetsConverter.java} | 68 ++--- .../LinearGradientConverter.java} | 53 ++-- .../PaintConverter.java} | 47 ++- .../Point2DConverter.java} | 72 ++--- .../RadialGradientConverter.java} | 53 ++-- .../Rectangle2DConverter.java} | 61 ++-- .../javafx/converters}/package-info.java | 6 +- .../spi/ColorConverterProvider.java} | 25 +- .../spi/Dimension2DConverterProvider.java | 42 +++ .../spi/GraphicConverterProvider.java | 42 +++ .../spi/ImageConverterProvider.java | 42 +++ .../spi/InsetsConverterProvider.java | 42 +++ .../spi/LinearGradientConverterProvider.java | 42 +++ .../spi/PaintConverterProvider.java | 42 +++ .../spi/Point2DConverterProvider.java | 42 +++ .../spi/RadialGradientConverterProvider.java | 42 +++ .../spi/Rectangle2DConverterProvider.java | 42 +++ .../javafx/converters/spi}/package-info.java | 6 +- .../javafx/formatters/ColorFormatter.java | 15 +- .../griffon/javafx/support/JavaFXUtils.java | 10 +- .../JavaFXGriffonControllerAction.java | 14 +- .../ColorConverterSpec.groovy} | 32 +- .../Dimension2DConverterSpec.groovy} | 31 +- .../ImageConverterSpec.groovy} | 25 +- .../InsetsConverterSpec.groovy} | 31 +- .../LinearGradientConverterSpec.groovy} | 21 +- .../PaintConverterSpec.groovy} | 26 +- .../Point2DConverterSpec.groovy} | 31 +- .../RadialGradientConverterSpec.groovy} | 22 +- .../Rectangle2DConverterSpec.groovy} | 31 +- .../spi/ConverterProviderSpec.groovy | 71 +++++ .../formatters/ColorFormatterSpec.groovy | 2 +- .../BoundsConverter.java} | 67 ++-- .../ColorConverter.java} | 82 +++-- .../DimensionsConverter.java} | 79 +++-- .../InsetsConverter.java} | 73 ++--- .../PointConverter.java} | 77 ++--- .../pivot/converters}/package-info.java | 6 +- .../spi/BoundsConverterProvider.java | 42 +++ .../spi/ColorConverterProvider.java} | 25 +- .../spi/DimensionsConverterProvider.java | 42 +++ .../spi/InsetsConverterProvider.java | 42 +++ .../spi/PointConverterProvider.java | 42 +++ .../pivot/converters/spi}/package-info.java | 7 +- .../pivot/formatters/ColorFormatter.java | 19 +- .../BoundsConverterSpec.groovy} | 31 +- .../ColorConverterSpec.groovy} | 32 +- .../DimensionsConverterSpec.groovy} | 30 +- .../InsetsConverterSpec.groovy} | 30 +- .../PointConverterSpec.groovy} | 30 +- .../spi/ConverterProviderSpec.groovy | 56 ++++ .../formatters/ColorFormatterSpec.groovy | 2 +- .../BufferedImageConverter.java} | 67 ++-- .../ColorConverter.java} | 88 +++--- .../DimensionConverter.java} | 79 +++-- .../FontConverter.java} | 74 +++-- .../GradientPaintConverter.java} | 128 ++++---- .../IconConverter.java} | 88 +++--- .../ImageConverter.java} | 74 +++-- .../InsetsConverter.java} | 73 ++--- .../LinearGradientPaintConverter.java} | 105 +++---- .../Point2DConverter.java} | 77 ++--- .../PointConverter.java} | 77 ++--- .../PolygonConverter.java} | 68 ++--- .../RadialGradientPaintConverter.java} | 107 +++---- .../Rectangle2DConverter.java} | 68 ++--- .../RectangleConverter.java} | 67 ++-- .../swing/converters/package-info.java | 24 ++ .../spi/BufferedImageConverterProvider.java} | 33 +- .../spi/ColorConverterProvider.java | 42 +++ .../spi/DimensionConverterProvider.java | 42 +++ .../spi/FontConverterProvider.java} | 27 +- .../spi/GradientPaintConverterProvider.java | 42 +++ .../spi/IconConverterProvider.java} | 33 +- .../spi/ImageConverterProvider.java | 42 +++ .../spi/InsetsConverterProvider.java | 42 +++ .../LineraGradientPaintConverterProvider.java | 42 +++ .../spi/Point2DConverterProvider.java | 42 +++ .../spi/PointConverterProvider.java | 42 +++ .../spi/PolygonConverterProvider.java | 42 +++ .../RadialGradientPaintConverterProvider.java | 42 +++ .../spi/Rectangle2DConverterProvider.java | 42 +++ .../spi/RectangleConverterProvider.java | 42 +++ .../swing/converters/spi/package-info.java | 24 ++ .../swing/formatters/ColorFormatter.java | 23 +- .../SwingGriffonControllerAction.java | 13 +- .../BufferedImageConverterSpec.groovy} | 22 +- .../ColorConverterSpec.groovy} | 34 +-- .../DimensionConverterSpec.groovy} | 30 +- .../FontConverterSpec.groovy} | 30 +- .../GradientPaintConverterSpec.groovy} | 31 +- .../IconConverterSpec.groovy} | 22 +- .../ImageConverterSpec.groovy} | 21 +- .../InsetsConverterSpec.groovy} | 30 +- .../LinearGradientPaintConverterSpec.groovy} | 30 +- .../Point2DConverterSpec.groovy} | 30 +- .../PointConverterSpec.groovy} | 30 +- .../PolygonConverterSpec.groovy} | 30 +- .../RadialGradientPaintConverterSpec.groovy} | 30 +- .../Rectangle2DConverterSpec.groovy} | 30 +- .../RectangleConverterSpec.groovy} | 30 +- .../spi/ConverterProviderSpec.groovy | 86 ++++++ .../formatters/ColorFormatterSpec.groovy | 2 +- .../griffon-javafx-groovy/build.gradle | 5 - .../griffon-javafx-java/build.gradle | 5 - .../griffon-lanterna-groovy/build.gradle | 5 - .../griffon-lanterna-java/build.gradle | 5 - .../griffon-lanterna3-groovy/build.gradle | 5 - .../griffon-lanterna3-java/build.gradle | 5 - .../griffon-pivot-groovy/build.gradle | 5 - .../templates/griffon-pivot-java/build.gradle | 5 - .../griffon-swing-groovy/build.gradle | 5 - .../templates/griffon-swing-java/build.gradle | 5 - tutorials/javafx-app/build.gradle | 5 - 257 files changed, 3245 insertions(+), 9891 deletions(-) rename docs/griffon-guide/src/docs/asciidoc/resources/{resources-property-editors.adoc => resources-property-converters.adoc} (51%) delete mode 100644 subprojects/griffon-core-compile/src/main/java/griffon/metadata/PropertyEditorFor.java delete mode 100644 subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollector.java delete mode 100644 subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorProcessor.java delete mode 100644 subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/package-info.java delete mode 100644 subprojects/griffon-core-compile/src/test/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollectorTest.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/configuration/Configured.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/AbstractPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/BigDecimalPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/BigIntegerPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/BooleanPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/BytePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/CalendarPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/DatePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/DoublePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/EnumPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedCalendarPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/FilePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/FloatPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/IntegerPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDatePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDateTimePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/LocalTimePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/LocalePropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/LongPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorChain.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorResolver.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/ShortPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/URIPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/URLPropertyEditor.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/editors/ValueConversionException.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/AbstractFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/BigDecimalFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/BigIntegerFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/BooleanFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/ByteFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/CalendarFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/DateFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/DoubleFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/FloatFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/Formatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/IntegerFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateTimeFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalTimeFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/LocaleFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/LongFormatter.java delete mode 100644 subprojects/griffon-core/src/main/java/griffon/core/formatters/ShortFormatter.java delete mode 100644 subprojects/griffon-core/src/main/resources/META-INF/editors/java.beans.PropertyEditor delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigDecimalPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigIntegerPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/BooleanPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/BytePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/CalendarPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/DatePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/DoublePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/EnumPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedCalendarPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedDatePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/FilePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/FloatPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/IntegerPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDatePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDateTimePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalTimePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalePropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/LongPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorResolverSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorSpecSupport.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/ShortPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/StringPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/URIPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/editors/URLPropertyEditorSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigDecimalFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigIntegerFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BooleanFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ByteFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/CalendarFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DateFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DoubleFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FloatFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FormatterSpecSupport.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/IntegerFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LocaleFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LongFormatterSpec.groovy delete mode 100644 subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ShortFormatterSpec.groovy rename subprojects/griffon-core/src/test/groovy/integration/{CustomStringPropertyEditor.groovy => CustomStringConverter.groovy} (66%) rename subprojects/griffon-core/src/test/groovy/integration/{ListPropertyEditor.java => ListConverter.java} (61%) delete mode 100644 subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorASTTransformation.java rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/ColorPropertyEditor.java => converters/ColorConverter.java} (64%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/Dimension2DPropertyEditor.java => converters/Dimension2DConverter.java} (64%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/GraphicPropertyEditor.java => converters/GraphicConverter.java} (64%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/ImagePropertyEditor.java => converters/ImageConverter.java} (66%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/InsetsPropertyEditor.java => converters/InsetsConverter.java} (69%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/LinearGradientPropertyEditor.java => converters/LinearGradientConverter.java} (76%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/PaintPropertyEditor.java => converters/PaintConverter.java} (50%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/Point2DPropertyEditor.java => converters/Point2DConverter.java} (66%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/RadialGradientPropertyEditor.java => converters/RadialGradientConverter.java} (76%) rename subprojects/griffon-javafx/src/main/java/griffon/javafx/{editors/Rectangle2DPropertyEditor.java => converters/Rectangle2DConverter.java} (69%) rename subprojects/{griffon-swing/src/main/java/griffon/swing/editors => griffon-javafx/src/main/java/griffon/javafx/converters}/package-info.java (86%) rename subprojects/{griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorPersistence.java => griffon-javafx/src/main/java/griffon/javafx/converters/spi/ColorConverterProvider.java} (54%) create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Dimension2DConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/GraphicConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ImageConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/InsetsConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/LinearGradientConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/PaintConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Point2DConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/RadialGradientConverterProvider.java create mode 100644 subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Rectangle2DConverterProvider.java rename subprojects/{griffon-pivot/src/main/java/griffon/pivot/editors => griffon-javafx/src/main/java/griffon/javafx/converters/spi}/package-info.java (86%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/ColorPropertyEditorSpec.groovy => converters/ColorConverterSpec.groovy} (86%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/Dimension2DPropertyEditorSpec.groovy => converters/Dimension2DConverterSpec.groovy} (81%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/ImagePropertyEditorSpec.groovy => converters/ImageConverterSpec.groovy} (80%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/InsetsPropertyEditorSpec.groovy => converters/InsetsConverterSpec.groovy} (83%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/LinearGradientPropertyEditorSpec.groovy => converters/LinearGradientConverterSpec.groovy} (86%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/PaintPropertyEditorSpec.groovy => converters/PaintConverterSpec.groovy} (90%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/Point2DPropertyEditorSpec.groovy => converters/Point2DConverterSpec.groovy} (80%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/RadialGradientPropertyEditorSpec.groovy => converters/RadialGradientConverterSpec.groovy} (86%) rename subprojects/griffon-javafx/src/test/groovy/griffon/javafx/{editors/Rectangle2DPropertyEditorSpec.groovy => converters/Rectangle2DConverterSpec.groovy} (82%) create mode 100644 subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/spi/ConverterProviderSpec.groovy rename subprojects/griffon-pivot/src/main/java/griffon/pivot/{editors/BoundsPropertyEditor.java => converters/BoundsConverter.java} (68%) rename subprojects/griffon-pivot/src/main/java/griffon/pivot/{editors/ColorPropertyEditor.java => converters/ColorConverter.java} (64%) rename subprojects/griffon-pivot/src/main/java/griffon/pivot/{editors/DimensionsPropertyEditor.java => converters/DimensionsConverter.java} (63%) rename subprojects/griffon-pivot/src/main/java/griffon/pivot/{editors/InsetsPropertyEditor.java => converters/InsetsConverter.java} (68%) rename subprojects/griffon-pivot/src/main/java/griffon/pivot/{editors/PointPropertyEditor.java => converters/PointConverter.java} (65%) rename subprojects/{griffon-javafx/src/main/java/griffon/javafx/editors => griffon-pivot/src/main/java/griffon/pivot/converters}/package-info.java (86%) create mode 100644 subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/BoundsConverterProvider.java rename subprojects/{griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorPersistence.java => griffon-pivot/src/main/java/griffon/pivot/converters/spi/ColorConverterProvider.java} (55%) create mode 100644 subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/DimensionsConverterProvider.java create mode 100644 subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/InsetsConverterProvider.java create mode 100644 subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/PointConverterProvider.java rename subprojects/{griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor => griffon-pivot/src/main/java/griffon/pivot/converters/spi}/package-info.java (80%) rename subprojects/griffon-pivot/src/test/groovy/griffon/pivot/{editors/BoundsPropertyEditorSpec.groovy => converters/BoundsConverterSpec.groovy} (82%) rename subprojects/griffon-pivot/src/test/groovy/griffon/pivot/{editors/ColorPropertyEditorSpec.groovy => converters/ColorConverterSpec.groovy} (86%) rename subprojects/griffon-pivot/src/test/groovy/griffon/pivot/{editors/DimensionsPropertyEditorSpec.groovy => converters/DimensionsConverterSpec.groovy} (81%) rename subprojects/griffon-pivot/src/test/groovy/griffon/pivot/{editors/InsetsPropertyEditorSpec.groovy => converters/InsetsConverterSpec.groovy} (83%) rename subprojects/griffon-pivot/src/test/groovy/griffon/pivot/{editors/PointPropertyEditorSpec.groovy => converters/PointConverterSpec.groovy} (80%) create mode 100644 subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/spi/ConverterProviderSpec.groovy rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/BufferedImagePropertyEditor.java => converters/BufferedImageConverter.java} (55%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/ColorPropertyEditor.java => converters/ColorConverter.java} (63%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/DimensionPropertyEditor.java => converters/DimensionConverter.java} (63%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/FontPropertyEditor.java => converters/FontConverter.java} (72%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/GradientPaintPropertyEditor.java => converters/GradientPaintConverter.java} (69%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/IconPropertyEditor.java => converters/IconConverter.java} (59%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/ImagePropertyEditor.java => converters/ImageConverter.java} (52%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/InsetsPropertyEditor.java => converters/InsetsConverter.java} (68%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/LinearGradientPaintPropertyEditor.java => converters/LinearGradientPaintConverter.java} (79%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/Point2DPropertyEditor.java => converters/Point2DConverter.java} (64%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/PointPropertyEditor.java => converters/PointConverter.java} (65%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/PolygonPropertyEditor.java => converters/PolygonConverter.java} (70%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/RadialGradientPaintPropertyEditor.java => converters/RadialGradientPaintConverter.java} (79%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/Rectangle2DPropertyEditor.java => converters/Rectangle2DConverter.java} (67%) rename subprojects/griffon-swing/src/main/java/griffon/swing/{editors/RectanglePropertyEditor.java => converters/RectangleConverter.java} (67%) create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/package-info.java rename subprojects/{griffon-core/src/main/java/griffon/core/editors/ExtendedDatePropertyEditor.java => griffon-swing/src/main/java/griffon/swing/converters/spi/BufferedImageConverterProvider.java} (52%) create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ColorConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/DimensionConverterProvider.java rename subprojects/{griffon-core/src/main/java/griffon/core/editors/StringPropertyEditor.java => griffon-swing/src/main/java/griffon/swing/converters/spi/FontConverterProvider.java} (55%) create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/GradientPaintConverterProvider.java rename subprojects/{griffon-core/src/main/java/griffon/core/formatters/ParseException.java => griffon-swing/src/main/java/griffon/swing/converters/spi/IconConverterProvider.java} (54%) create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ImageConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/InsetsConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/LineraGradientPaintConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Point2DConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PointConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PolygonConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RadialGradientPaintConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Rectangle2DConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RectangleConverterProvider.java create mode 100644 subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/package-info.java rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/BufferedImagePropertyEditorSpec.groovy => converters/BufferedImageConverterSpec.groovy} (77%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/ColorPropertyEditorSpec.groovy => converters/ColorConverterSpec.groovy} (85%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/DimensionPropertyEditorSpec.groovy => converters/DimensionConverterSpec.groovy} (82%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/FontPropertyEditorSpec.groovy => converters/FontConverterSpec.groovy} (88%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/GradientPaintPropertyEditorSpec.groovy => converters/GradientPaintConverterSpec.groovy} (82%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/IconPropertyEditorSpec.groovy => converters/IconConverterSpec.groovy} (78%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/ImagePropertyEditorSpec.groovy => converters/ImageConverterSpec.groovy} (77%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/InsetsPropertyEditorSpec.groovy => converters/InsetsConverterSpec.groovy} (84%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/LinearGradientPaintPropertyEditorSpec.groovy => converters/LinearGradientPaintConverterSpec.groovy} (87%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/Point2DPropertyEditorSpec.groovy => converters/Point2DConverterSpec.groovy} (82%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/PointPropertyEditorSpec.groovy => converters/PointConverterSpec.groovy} (81%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/PolygonPropertyEditorSpec.groovy => converters/PolygonConverterSpec.groovy} (80%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/RadialGradientPaintPropertyEditorSpec.groovy => converters/RadialGradientPaintConverterSpec.groovy} (87%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/Rectangle2DPropertyEditorSpec.groovy => converters/Rectangle2DConverterSpec.groovy} (84%) rename subprojects/griffon-swing/src/test/groovy/griffon/swing/{editors/RectanglePropertyEditorSpec.groovy => converters/RectangleConverterSpec.groovy} (83%) create mode 100644 subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/spi/ConverterProviderSpec.groovy diff --git a/docs/griffon-guide/src/docs/asciidoc/resources/resources-injected-resources.adoc b/docs/griffon-guide/src/docs/asciidoc/resources/resources-injected-resources.adoc index 2a672123174..ae397eb4ffa 100644 --- a/docs/griffon-guide/src/docs/asciidoc/resources/resources-injected-resources.adoc +++ b/docs/griffon-guide/src/docs/asciidoc/resources/resources-injected-resources.adoc @@ -5,7 +5,7 @@ Resources may be automatically injected into any instance created via the application's `Injector`. Injection points must be annotated with `{link_injected_resource}` which can be set on properties (Groovy), fields (Java and Groovy) and setter methods (Java and Groovy). -@InjectedResource is a perfect companion to <<_models,models>>, as the following example shows: +`@InjectedResource` is a perfect companion to <<_models,models>>, as the following example shows: .griffon-app/resources/resources.properties [source,java,linenums,options="nowrap"] @@ -39,8 +39,8 @@ to use. These are the rules applied by the default by `{link_resources_injector} class name of the field's owner. You may also specify a default value if the resource definition is not found; however, -be aware that this value must be set as a String, thus guaranteeing a type conversion. -An optional `format` value may be specified as a hint to the PropertyEditor used during +be aware that this value must be set as a `String`, thus guaranteeing a type conversion. +An optional `format` value may be specified as a hint to the `Converter` used during value conversion, for example: .griffon-app/models/sample/SampleModel.groovy diff --git a/docs/griffon-guide/src/docs/asciidoc/resources/resources-property-editors.adoc b/docs/griffon-guide/src/docs/asciidoc/resources/resources-property-converters.adoc similarity index 51% rename from docs/griffon-guide/src/docs/asciidoc/resources/resources-property-editors.adoc rename to docs/griffon-guide/src/docs/asciidoc/resources/resources-property-converters.adoc index 99964c0d8bb..2c5252ae474 100644 --- a/docs/griffon-guide/src/docs/asciidoc/resources/resources-property-editors.adoc +++ b/docs/griffon-guide/src/docs/asciidoc/resources/resources-property-converters.adoc @@ -1,26 +1,25 @@ -[[_resources_property_editors]] -= Property Editors +[[_resources_property_converters]] += Converters -Resource injection makes use of the http://docs.oracle.com/javase/6/docs/api/java/beans/PropertyEditor.html[PropertyEditor] -mechanism provided by the `java.beans` package. The default `{link_resources_injector}` queries -`http://docs.oracle.com/javase/6/docs/api/java/beans/PropertyEditorManager.html[PropertyEditorManager]` +Resource injection makes use of the `javax.application.converter.Converter mechanism provided by JSR-377. +The default `{link_resources_injector}` queries the application's `javax.application.converter.ConverterRegistry` whenever a resource value must be transformed to a target type. -PropertyEditorManager provides methods for registering custom PropertyEditors; it also -follows a class naming convention to load PropertyEditors should a custom one not be +ConverterRegistry provides methods for registering custom Converters; it also +follows a class naming convention to load Converters should a custom one may not be programmatically registered. Griffon applications will automatically load and register -PropertyEditors from the following classpath resource: `/META-INF/services/java.beans.PropertyEditor`. +Converters from the following classpath resource: `/META-INF/services/javax.application.converter.spi.ConverterProvider`. Each line follows the format [source] ---- -target.type = full.qualified.classname +fully.qualified.classname ---- -The following table enumerates the default PropertyEditors loaded by Griffon at startup. +The following table enumerates the default Converters loaded by Griffon at startup. -.Core PropertyEditor mappings +.Core Converter mappings [cols="3*", options="header"] |=== @@ -29,79 +28,79 @@ The following table enumerates the default PropertyEditors loaded by Griffon at | Format | java.lang.String -| griffon.core.editors.StringPropertyEditor -|  +| org.kordamp.jsr377.converter.spi.StringConverter +| | java.io.File -| griffon.core.editors.FilePropertyEditor +| org.kordamp.jsr377.converter.spi.FileConverter | | java.net.URL -| griffon.core.editors.URLPropertyEditor +| org.kordamp.jsr377.converter.spi.URLConverter | | java.net.URI -| griffon.core.editors.URIPropertyEditor +| org.kordamp.jsr377.converter.spi.URIConverter | | java.math.BigDecimal -| griffon.core.editors.BigDecimalPropertyEditor +| org.kordamp.jsr377.converter.spi.BigDecimalConverter | 'currency', 'percent' | java.math.BigInteger -| griffon.core.editors.BigIntegerPropertyEditor +| org.kordamp.jsr377.converter.spi.BigIntegerConverter | 'currency', 'percent' | java.lang.Boolean -| griffon.core.editors.BooleanPropertyEditor +| org.kordamp.jsr377.converter.spi.BooleanConverter | 'boolean', 'query', 'switch' | java.lang.Byte -| griffon.core.editors.BytePropertyEditor +| org.kordamp.jsr377.converter.spi.ByteConverter | 'currency', 'percent' | java.lang.Short -| griffon.core.editors.ShortPropertyEditor +| org.kordamp.jsr377.converter.spi.ShortConverter | 'currency', 'percent' | java.lang.Integer -| griffon.core.editors.IntegerPropertyEditor +| org.kordamp.jsr377.converter.spi.IntegerConverter | 'currency', 'percent' | java.lang.Long -| griffon.core.editors.LongPropertyEditor +| org.kordamp.jsr377.converter.spi.LongConverter | 'currency', 'percent' | java.lang.Float -| griffon.core.editors.FloatPropertyEditor +| org.kordamp.jsr377.converter.spi.FloatConverter | 'currency', 'percent' | java.lang.Double -| griffon.core.editors.DoublePropertyEditor +| org.kordamp.jsr377.converter.spi.DoubleConverter | 'currency', 'percent' | java.util.Calendar -| griffon.core.editors.CalendarPropertyEditor +| org.kordamp.jsr377.converter.spi.CalendarConverter | | java.util.Date -| griffon.core.editors.DatePropertyEditor +| org.kordamp.jsr377.converter.spi.DateConverter | | java.util.Locale -| griffon.core.editors.LocalePropertyEditor +| org.kordamp.jsr377.converter.spi.LocaleConverter | [\_[_]] -| java.time.LocalDate -| griffon.core.editors.LocalDatePropertyEditor +| java.time.LocalDate +| org.kordamp.jsr377.converter.spi.LocalDateConverter | -| java.time.LocalDateTime -| griffon.core.editors.LocalDateTimePropertyEditor +| java.time.LocalDateTime +| org.kordamp.jsr377.converter.spi.LocalDateTimeConverter | -| java.time.LocalTime -| griffon.core.editors.LocalTimePropertyEditor +| java.time.LocalTime +| org.kordamp.jsr377.converter.spi.LocalTimeConverter | |=== @@ -114,9 +113,9 @@ Where the following apply: * 'switch' accepts `on` and `off` as values. Core UI Toolkit dependencies, such as `griffon-swing`, `griffon-javafx`, and `griffon-pivot` deliver -additional PropertyEditors. The following tables summarize these additions: +additional Converters. The following tables summarize these additions: -.Swing PropertyEditor mappings +.Swing Converter mappings [cols="3*", options="header"] |=== @@ -125,63 +124,63 @@ additional PropertyEditors. The following tables summarize these additions: | Format | java.awt.Color -| griffon.swing.editors.ColorPropertyEditor +| griffon.swing.converters.ColorConverter | #RGB ; #RGBA ; #RRGGBB; #RRGGBBAA ; Color constant | java.awt.Dimension -| griffon.swing.editors.DimensionPropertyEditor +| griffon.swing.converters.DimensionConverter | width, height | java.awt.Font -| griffon.swing.editors.FontPropertyEditor +| griffon.swing.converters.FontConverter | family-style-size | java.awt.GradientPaint -| griffon.swing.editors.GradientPaintPropertyEditor +| griffon.swing.converters.GradientPaintConverter | x1, y1, #RGB, x2, y2, #RGB, CYCLIC | java.awt.Image -| griffon.swing.editors.ImagePropertyEditor +| griffon.swing.converters.ImageConverter | path/to/image_file | java.awt.Insets -| griffon.swing.editors.InsetsPropertyEditor +| griffon.swing.converters.InsetsConverter | top, left, bottom, right | java.awt.LinearGradientPaint -| griffon.swing.editors.LinearGradientPaintPropertyEditor +| griffon.swing.converters.LinearGradientPaintConverter | xy, y1, x2, x2, [0.0, 1.0], [#RGB, #RGB], REPEAT | java.awt.Point -| griffon.swing.editors.PointPropertyEditor +| griffon.swing.converters.PointConverter | x, y | java.awt.Polygon -| griffon.swing.editors.PolygonPropertyEditor +| griffon.swing.converters.PolygonConverter | x1, y1, x2, y2, ..., xn, yn | java.awt.RadialGradientPaint -| griffon.swing.editors.RadialGradientPaintPropertyEditor +| griffon.swing.converters.RadialGradientPaintConverter | xy, y1, r, fx, fy, [0.0, 1.0], [#RGB, #RGB], REPEAT | java.awt.Rectangle -| griffon.swing.editors.RectanglePropertyEditor +| griffon.swing.converters.RectangleConverter | x, y, width, height | java.awt.geom.Point2D -| griffon.swing.editors.Point2DPropertyEditor +| griffon.swing.converters.Point2DConverter | x, y | java.awt.geom.Rectangle2D -| griffon.swing.editors.Rectangle2DPropertyEditor +| griffon.swing.converters.Rectangle2DConverter | x, y, width, height | java.awt.image.BufferedImage -| griffon.swing.editors.BufferedImagePropertyEditor +| griffon.swing.converters.BufferedImageConverter | path/to/image_file | javax.swing.Icon -| griffon.swing.editors.IconPropertyEditor +| griffon.swing.converters.IconConverter | path/to/image_file |=== @@ -193,16 +192,16 @@ Where the following apply: * REPEAT must be one of `MultipleGradientPaint.CycleMethod`. * GradientPaint supports another format: x1, y1 | x2, y2, | #RGB, #RGB | CYCLIC * Color supports all color constants defined by `griffon.swing.support.Colors`. - * All color formats are supported by gradient editors. + * All color formats are supported by gradient converters. -The following styles are supported by `FontPropertyEditor`: +The following styles are supported by `FontConverter`: * BOLD * ITALIC * BOLDITALIC * PLAIN -.JavaFX PropertyEditor mappings +.JavaFX Converter mappings [cols="3*", options="header"] |=== @@ -211,39 +210,39 @@ The following styles are supported by `FontPropertyEditor`: | Format | javafx.geometry.Dimension2D -| griffon.javafx.editors.Dimension2DPropertyEditor +| griffon.javafx.converters.Dimension2DConverter | width, height | javafx.geometry.Insets -| griffon.javafx.editors.InsetsPropertyEditor +| griffon.javafx.converters.InsetsConverter | top, left, bottom, right | javafx.geometry.Point2D -| griffon.javafx.editors.Point2DPropertyEditor +| griffon.javafx.converters.Point2DConverter | x, y | javafx.geometry.Rectangle2D -| griffon.javafx.editors.Rectangle2DPropertyEditor +| griffon.javafx.converters.Rectangle2DConverter | x, y , width, height | javafx.scene.image.Image -| griffon.javafx.editors.ImagePropertyEditor +| griffon.javafx.converters.ImageConverter | path/to/image_file | javafx.scene.paint.Color -| griffon.javafx.editors.ColorPropertyEditor +| griffon.javafx.converters.ColorConverter | #RGB ; #RGBA ; #RRGGBB; #RRGGBBAA ; Color constant | javafx.scene.paint.LinearGradient -| griffon.javafx.editors.LinearGradientPropertyEditor +| griffon.javafx.converters.LinearGradientConverter | LinearGradient.parse() | javafx.scene.paint.RadialGradient -| griffon.javafx.editors.RadialGradientPropertyEditor +| griffon.javafx.converters.RadialGradientConverter | RadialGradient.parse() | javafx.scene.paint.Paint| -| griffon.javafx.editors.PaintPropertyEditor +| griffon.javafx.converters.PaintConverter | all Color, LinearGradient and RadialGradient formats |=== @@ -252,7 +251,7 @@ Where the following applies: * `R`, `G`, `B` and `A` represent an hexadecimal number. -.Pivot PropertyEditor mappings +.Pivot Converter mappings [cols="3*", options="header"] |=== @@ -261,23 +260,23 @@ Where the following applies: | Format | java.awt.Color -| griffon.pivot.editors.ColorPropertyEditor +| griffon.pivot.converters.ColorConverter | #RGB ; #RGBA ; #RRGGBB; #RRGGBBAA ; Color constant | org.apache.pivot.wtk.Bounds -| griffon.pivot.editors.BoundsPropertyEditor +| griffon.pivot.converters.BoundsConverter | x, y , width, height | org.apache.pivot.wtk.Dimensions -| griffon.pivot.editors.DimensionsPropertyEditor +| griffon.pivot.converters.DimensionsConverter | width, height | org.apache.pivot.wtk.Insets -| griffon.pivot.editors.InsetsPropertyEditor +| griffon.pivot.converters.InsetsConverter | top, left, right, bottom | org.apache.pivot.wtk.Point -| griffon.pivot.editors.PointPropertyEditor +| griffon.pivot.converters.PointConverter | x, y |=== diff --git a/docs/griffon-guide/src/docs/asciidoc/resources/resources-resource-resolver.adoc b/docs/griffon-guide/src/docs/asciidoc/resources/resources-resource-resolver.adoc index c05034137f2..4d078579c80 100644 --- a/docs/griffon-guide/src/docs/asciidoc/resources/resources-resource-resolver.adoc +++ b/docs/griffon-guide/src/docs/asciidoc/resources/resources-resource-resolver.adoc @@ -30,7 +30,7 @@ these methods never throw `NoSuchResourceException` nor return `null` unless the - Object resolveResource(String key, Map args, Object defaultValue) - Object resolveResource(String key, Map args, Locale locale, Object defaultValue) -There is also another set of methods which convert the resource value using ``PropertyEditor``s: +There is also another set of methods which convert the resource value using ``Converter``s: - T resolveResourceConverted(String key, Class type) - T resolveResourceConverted(String key, Locale locale, Class type) @@ -154,7 +154,7 @@ computed.instance = { x, y, w, h -> == Type Conversion Note that the return value of `resolveResource` is marked as `Object`, but you'll get -a `String` from the first two formats. You'll have to rely on <<_resources_property_editors,property editors>> +a `String` from the first two formats. You'll have to rely on <<_resources_property_converters,property converters>> in order to transform the value into the correct type. <<_resources_injected_resources,Injected resources>> are automatically transformed to the expected type. @@ -163,14 +163,13 @@ Here's how it can be done: [source,groovy,options="nowrap"] ---- import javax.swing.Icon -import java.beans.PropertyEditor -import griffon.core.editors.PropertyEditorResolver +import javax.application.converter.Converter +import javax.application.converter.ConverterRegistry ... Object iconValue = getApplication().getResourceResolver() .resolveResource('menu.icon', ['large']) -PropertyEditor propertyEditor = PropertyEditorResolver.findEditor(Icon) -propertyEditor.setAsText(String.valueOf(iconValue)) -Icon icon = propertyEditor.getValue() +Converter converter = ConverterRegistry.findConverter(Icon) +Icon icon = converter.fromObject(String.valueOf(iconValue)) ---- As an alternative you may call `resolveResourceConverted` instead. diff --git a/docs/griffon-guide/src/docs/asciidoc/resources/resources.adoc b/docs/griffon-guide/src/docs/asciidoc/resources/resources.adoc index eceeaa5c785..8638aae4625 100644 --- a/docs/griffon-guide/src/docs/asciidoc/resources/resources.adoc +++ b/docs/griffon-guide/src/docs/asciidoc/resources/resources.adoc @@ -11,5 +11,5 @@ include::resources-resource-resolver.adoc[] include::resources-resource-resolver-configuration.adoc[] include::resources-resource-resolver-transformation.adoc[] include::resources-injected-resources.adoc[] -include::resources-property-editors.adoc[] +include::resources-property-converters.adoc[] :leveloffset: 1 diff --git a/samples/console-swing-groovy/build.gradle.txt b/samples/console-swing-groovy/build.gradle.txt index 10cc6a0d695..2b465777b1c 100644 --- a/samples/console-swing-groovy/build.gradle.txt +++ b/samples/console-swing-groovy/build.gradle.txt @@ -91,11 +91,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/subprojects/application-master-pom/src/pom/master-pom.xml b/subprojects/application-master-pom/src/pom/master-pom.xml index edd5ed60d7e..9d5c3181791 100644 --- a/subprojects/application-master-pom/src/pom/master-pom.xml +++ b/subprojects/application-master-pom/src/pom/master-pom.xml @@ -1002,11 +1002,6 @@ META-INF/types - - - META-INF/editors/java.beans.PropertyEditor - - diff --git a/subprojects/griffon-core-compile/src/main/java/griffon/metadata/PropertyEditorFor.java b/subprojects/griffon-core-compile/src/main/java/griffon/metadata/PropertyEditorFor.java deleted file mode 100644 index 8545cfaa291..00000000000 --- a/subprojects/griffon-core-compile/src/main/java/griffon/metadata/PropertyEditorFor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.metadata; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Andres Almiray - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.SOURCE) -public @interface PropertyEditorFor { - Class[] value(); -} diff --git a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollector.java b/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollector.java deleted file mode 100644 index 0356807eda8..00000000000 --- a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollector.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.codehaus.griffon.compile.core.processor.editor; - -import org.kordamp.jipsy.processor.Initializer; -import org.kordamp.jipsy.processor.LogLocation; -import org.kordamp.jipsy.processor.Logger; - -import java.beans.PropertyEditor; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * @author Andres Almiray - */ -public final class PropertyEditorCollector { - private final Map editors = new TreeMap<>(); - private final Map cached = new TreeMap<>(); - - private final Initializer initializer; - private final Logger logger; - - public PropertyEditorCollector(Initializer initializer, Logger logger) { - this.initializer = initializer; - this.logger = logger; - } - - public String getPropertyEditor(String type, String editorType) { - if (type == null) { - throw new NullPointerException("type"); - } - if (!editors.containsKey(type)) { - editors.put(type, editorType); - } - return editors.get(type); - } - - public boolean isModified() { - if (cached.size() != editors.size()) { - return true; - } - - for (Map.Entry e : cached.entrySet()) { - if (!editors.containsKey(e.getKey())) { - return true; - } - if (!e.getValue().equals(editors.get(e.getKey()))) { - return true; - } - } - - return false; - } - - public void load() { - CharSequence initialData = initializer.initialData(PropertyEditor.class.getName()); - if (initialData != null) { - fromList(initialData.toString()); - } - cached.putAll(editors); - } - - public void removePropertyEditor(String editor) { - if (editor == null) { - throw new NullPointerException("type"); - } - - logger.note(LogLocation.LOG_FILE, "Removing " + editor); - Set keys = new LinkedHashSet<>(); - for (String key : editors.keySet()) { - if (editor.equals(editors.get(key))) { - keys.add(key); - } - } - for (String key : keys) { - editors.remove(key); - } - } - - @Override - public String toString() { - return editors.toString(); - } - - public String toList() { - StringBuilder sb = new StringBuilder(); - for (Map.Entry e : editors.entrySet()) { - sb.append(e.getKey()) - .append("=") - .append(e.getValue()) - .append("\n"); - } - return sb.toString(); - } - - public Map editors() { - return Collections.unmodifiableMap(editors); - } - - public void fromList(String input) { - if (input == null) { - throw new NullPointerException("input"); - } - String[] lines = input.split("\\n"); - for (String line : lines) { - if (line.startsWith("#")) { continue; } - if (line.trim().length() > 0) { - String[] entry = line.trim().split("="); - editors.put(entry[0], entry[1]); - } - } - } -} diff --git a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorProcessor.java b/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorProcessor.java deleted file mode 100644 index 166e6361762..00000000000 --- a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorProcessor.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.codehaus.griffon.compile.core.processor.editor; - -import griffon.metadata.PropertyEditorFor; -import org.kordamp.jipsy.processor.AbstractSpiProcessor; -import org.kordamp.jipsy.processor.CheckResult; -import org.kordamp.jipsy.processor.LogLocation; -import org.kordamp.jipsy.processor.Options; -import org.kordamp.jipsy.processor.Persistence; - -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedOptions; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.beans.PropertyEditor; -import java.io.IOException; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; - -/** - * @author Andres Almiray - */ -@SupportedAnnotationTypes("*") -@SupportedOptions({Options.SPI_DIR_OPTION, Options.SPI_LOG_OPTION, Options.SPI_VERBOSE_OPTION, Options.SPI_DISABLED_OPTION}) -public class PropertyEditorProcessor extends AbstractSpiProcessor { - public static final String NAME = PropertyEditorProcessor.class.getName() - + " (" + PropertyEditorProcessor.class.getPackage().getImplementationVersion() + ")"; - - private static final int MAX_SUPPORTED_VERSION = 8; - - private Persistence persistence; - private PropertyEditorCollector data; - private TypeElement propertyEditorType; - - @Override - public SourceVersion getSupportedSourceVersion() { - SourceVersion[] svs = SourceVersion.values(); - for (int i = svs.length - 1; i >= 0; i--) { - String name = svs[i].name(); - Matcher m = RELEASE_PATTERN.matcher(name); - if (m.matches()) { - int release = Integer.parseInt(m.group(1)); - if (release <= MAX_SUPPORTED_VERSION) return svs[i]; - } - } - - return SourceVersion.RELEASE_6; - } - - @Override - protected Class getAnnotationClass() { - return PropertyEditorFor.class; - } - - @Override - protected void initialize() { - super.initialize(); - - persistence = new PropertyEditorPersistence(NAME, options.dir(), processingEnv.getFiler(), logger); - propertyEditorType = processingEnv.getElementUtils().getTypeElement(PropertyEditor.class.getName()); - data = new PropertyEditorCollector(persistence.getInitializer(), logger); - data.load(); - } - - @Override - protected void handleElement(Element e) { - if (!(e instanceof TypeElement)) { - return; - } - - TypeElement currentClass = (TypeElement) e; - - CheckResult checkResult = checkCurrentClass(currentClass); - if (checkResult.isError()) { - reportError(currentClass, checkResult); - return; - } - - for (TypeElement type : findTypes(currentClass)) { - CheckResult implementationResult = isImplementation(currentClass, propertyEditorType); - if (implementationResult.isError()) { - reportError(currentClass, implementationResult); - } else { - register(createProperQualifiedName(type), currentClass); - } - } - } - - @Override - protected void removeStaleData(RoundEnvironment roundEnv) { - for (Element e : roundEnv.getRootElements()) { - if (e instanceof TypeElement) { - TypeElement currentClass = (TypeElement) e; - data.removePropertyEditor(createProperQualifiedName(currentClass)); - } - } - } - - @Override - protected void writeData() { - if (data.isModified()) { - String content = data.toList(); - if (content.length() > 0) { - logger.note(LogLocation.LOG_FILE, "Writing output"); - try { - persistence.write(PropertyEditor.class.getName(), content); - } catch (IOException ioe) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ioe.getMessage()); - } - persistence.writeLog(); - } else { - logger.note(LogLocation.LOG_FILE, "Writing output"); - try { - persistence.delete(); - } catch (IOException e) { - logger.warning(LogLocation.LOG_FILE, "An error occurred while deleting data file"); - } - } - } - } - - private CheckResult checkCurrentClass(TypeElement currentClass) { - if (currentClass.getKind() != ElementKind.CLASS) { - return CheckResult.valueOf("is not a class"); - } - - if (!currentClass.getModifiers().contains(Modifier.PUBLIC)) { - return CheckResult.valueOf("is not a public class"); - } - - if (isAbstractClass(currentClass)) { - return CheckResult.valueOf("is an abstract class"); - } - - if (!hasPublicNoArgsConstructor(currentClass)) { - return CheckResult.valueOf("has no public no-args constructor"); - } - - return CheckResult.OK; - } - - private List findTypes(TypeElement classElement) { - List types = new ArrayList<>(); - - for (AnnotationMirror annotation : findAnnotationMirrors(classElement, getAnnotationClass().getName())) { - for (AnnotationValue value : findCollectionValueMember(annotation, "value")) { - types.add(toElement(value)); - } - } - - return types; - } - - private void register(String type, TypeElement editorClass) { - data.getPropertyEditor(type, createProperQualifiedName(editorClass)); - } -} diff --git a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/package-info.java b/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/package-info.java deleted file mode 100644 index c1ba8d85bd4..00000000000 --- a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Annotation processor for {@code @PropertyEditorFor} - * - * @since 2.0.0 - * @see griffon.metadata.PropertyEditorFor - */ - -package org.codehaus.griffon.compile.core.processor.editor; diff --git a/subprojects/griffon-core-compile/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/subprojects/griffon-core-compile/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 448eebcaa41..38e4c65a409 100644 --- a/subprojects/griffon-core-compile/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/subprojects/griffon-core-compile/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,3 +1,2 @@ org.codehaus.griffon.compile.core.processor.annotation.AnnotationHandlerProcessor org.codehaus.griffon.compile.core.processor.artifact.ArtifactProviderProcessor -org.codehaus.griffon.compile.core.processor.editor.PropertyEditorProcessor diff --git a/subprojects/griffon-core-compile/src/test/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollectorTest.java b/subprojects/griffon-core-compile/src/test/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollectorTest.java deleted file mode 100644 index 7e43945ee1d..00000000000 --- a/subprojects/griffon-core-compile/src/test/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorCollectorTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.codehaus.griffon.compile.core.processor.editor; - -import org.junit.Before; -import org.junit.Test; -import org.kordamp.jipsy.processor.testutils.NoOutputTestBase; -import org.kordamp.jipsy.processor.testutils.TestInitializer; -import org.kordamp.jipsy.processor.testutils.TestLogger; - -import java.util.HashMap; -import java.util.Map; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; - -public class PropertyEditorCollectorTest extends NoOutputTestBase { - private TestLogger logger; - private PropertyEditorCollector collector; - - @Before - public void loadFrameWork() { - HashMap map = new HashMap(); - map.put("editor1", "type1=provider1\n"); - map.put("editor2", "type1=provider1\ntype2=provider2\n"); - map.put("editor3", "type1=provider1\ntype3=provider3\n"); - TestInitializer initializer = new TestInitializer(map); - logger = new TestLogger(); - collector = new PropertyEditorCollector(initializer, logger); - } - - @Test(expected = NullPointerException.class) - public void testGetPropertyEditorNull() { - collector.getPropertyEditor(null, null); - } - - @Test - public void testGetPropertyEditorExisting() { - assertEquals(0, collector.editors().size()); - collector.getPropertyEditor("editor", "type"); - assertEquals(1, collector.editors().size()); - logger.reset(); - String editor = collector.getPropertyEditor("editor", "type"); - assertTrue(logger.records().isEmpty()); - assertEquals("type", editor); - assertEquals(1, collector.editors().size()); - } - - @Test - public void testGetPropertyEditorNew() { - assertEquals(0, collector.editors().size()); - logger.reset(); - assertEquals("type", collector.getPropertyEditor("editor", "type")); - assertEquals(1, collector.editors().size()); - } - - @Test - public void testPropertyEditorsEmpty() { - Map editors = collector.editors(); - assertEquals(0, editors.size()); - } - - @Test - public void testPropertyEditorsOne() { - collector.getPropertyEditor("editor", "type"); - Map editors = collector.editors(); - assertEquals(1, editors.size()); - assertTrue(editors.containsKey("editor")); - } - - @Test - public void testPropertyEditorsMore() { - collector.getPropertyEditor("editor1", "type1"); - collector.getPropertyEditor("editor2", "type2"); - Map editors = collector.editors(); - assertEquals(2, editors.size()); - assertTrue(editors.containsKey("editor1")); - assertTrue(editors.containsKey("editor2")); - } - - @Test(expected = NullPointerException.class) - public void testRemovePropertyEditorNull() { - collector.removePropertyEditor(null); - } - - @Test - public void testRemovePropertyEditorWhenEmpty() { - collector.removePropertyEditor("provider1"); - assertEquals(1, logger.records().size()); - assertEquals("Removing provider1\n", logger.getFileContent()); - } - - @Test - public void testRemovePropertyEditorWhenInNotOnePropertyEditor() { - collector.getPropertyEditor("editor1", "type1"); - logger.reset(); - collector.removePropertyEditor("provider2"); - assertEquals(1, logger.records().size()); - } - - @Test - public void testRemovePropertyEditorWhenInOnePropertyEditor() { - collector.getPropertyEditor("editor1", "type1"); - logger.reset(); - collector.removePropertyEditor("provider1"); - assertEquals(1, logger.records().size()); - } - - @Test - public void testRemovePropertyEditorWhenInTwoPropertyEditors() { - collector.getPropertyEditor("editor1", "type1"); - collector.getPropertyEditor("editor2", "type2"); - logger.reset(); - collector.removePropertyEditor("provider1"); - assertEquals(1, logger.records().size()); - } - - @Test - public void testRemovePropertyEditorWhenInSomePropertyEditors() { - collector.getPropertyEditor("editor1", "type1"); - collector.getPropertyEditor("editor2", "type2"); - collector.getPropertyEditor("editor3", "type3"); - logger.reset(); - collector.removePropertyEditor("provider2"); - assertEquals(1, logger.records().size()); - } - - @Test - public void testToStringEmpty() { - collector.toString(); - } - - @Test - public void testToStringNonExistingPropertyEditor() { - collector.getPropertyEditor("nonExistingPropertyEditor", null); - collector.toString(); - } - - @Test - public void testToStringExistingPropertyEditor() { - collector.getPropertyEditor("editor1", null); - collector.toString(); - } - - @Test - public void testToStringMoreExistingPropertyEditors() { - collector.getPropertyEditor("editor1", null); - collector.getPropertyEditor("editor2", null); - collector.toString(); - } -} \ No newline at end of file diff --git a/subprojects/griffon-core/src/main/java/griffon/core/Configuration.java b/subprojects/griffon-core/src/main/java/griffon/core/Configuration.java index e97d6966bff..709b89d6c0d 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/Configuration.java +++ b/subprojects/griffon-core/src/main/java/griffon/core/Configuration.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; @@ -27,14 +28,9 @@ * @author Andres Almiray * @since 2.0.0 */ -public interface Configuration { - /** - * Searches for the key in this configuration. - * - * @param key the key to search - * @return true if the context (or its parent) contains the given key, false otherwise - */ - boolean containsKey(@Nonnull String key); +public interface Configuration extends javax.application.configuration.Configuration { + @Nonnull + ConverterRegistry getConverterRegistry(); @Nonnull Map asFlatMap(); @@ -45,35 +41,16 @@ public interface Configuration { @Nonnull Properties asProperties(); - /** - * Returns the value associated with the given key. - * - * @param key the key to search - * @return the value associated with the key or null< if not found. - */ - @Nullable - Object get(@Nonnull String key); - - /** - * Returns the value associated with the given key. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key was not found - * @param the type of the value - * @return returns the value associated with the key, defaultValue if the key was not found - */ - @Nullable - T get(@Nonnull String key, @Nullable T defaultValue); - /** * Returns the value associated with the given key. * Convenience method to use in Groovy aware environments. * * @param key the key to search + * * @return the value associated with the key or null< if not found. */ @Nullable - Object getAt(@Nonnull String key); + T getAt(@Nonnull String key); /** * Returns the value associated with the given key. @@ -81,191 +58,9 @@ public interface Configuration { * @param key the key to search * @param defaultValue the value to be returned if the key was not found * @param the type of the value + * * @return returns the value associated with the key, defaultValue if the key was not found */ @Nullable T getAt(@Nonnull String key, @Nullable T defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to a boolean if found. - * - * @param key the key to search - */ - boolean getAsBoolean(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to a boolean if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - boolean getAsBoolean(@Nonnull String key, boolean defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to an int if found. - * - * @param key the key to search - */ - int getAsInt(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to an int if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - int getAsInt(@Nonnull String key, int defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to a long if found. - * - * @param key the key to search - */ - long getAsLong(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to a long if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - long getAsLong(@Nonnull String key, long defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to a float if found. - * - * @param key the key to search - */ - float getAsFloat(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to a float if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - float getAsFloat(@Nonnull String key, float defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to a double if found. - * - * @param key the key to search - */ - double getAsDouble(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to a double if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - double getAsDouble(@Nonnull String key, double defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to a String if found. - * - * @param key the key to search - */ - @Nullable - String getAsString(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * converted to a String if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - */ - @Nullable - String getAsString(@Nonnull String key, @Nullable String defaultValue); - - /** - * /** - * Finds a value associated with the given key. The value is - * blindly cast to type T if found. - * - * @param key the key to search - * @since 2.5.0 - */ - @Nullable - T getAs(@Nonnull String key); - - /** - * Finds a value associated with the given key. The value is - * blindly cast to type T if found. If not found then the - * supplied defaultValue will be returned. - * - * @param key the key to search - * @param defaultValue the value to be returned if the key is not found - * @since 2.5.0 - */ - @Nullable - T getAs(@Nonnull String key, @Nullable T defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. - * - * @param key the key to search - * @param type the type to be returned - * @since 2.5.0 - */ - @Nullable - T getConverted(@Nonnull String key, @Nonnull Class type); - - /** - * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. - * - * @param key the key to search - * @param type the type to be returned - * @param format format used to convert the value - * @since 2.11.0 - */ - @Nullable - T getConverted(@Nonnull String key, @Nonnull Class type, @Nonnull String format); - - /** - * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. - * If not found then the supplied defaultValue will be returned. - * - * @param key the key to search - * @param type the type to be returned - * @param defaultValue the value to be returned if the key is not found - * @since 2.5.0 - */ - @Nullable - T getConverted(@Nonnull String key, @Nonnull Class type, @Nullable T defaultValue); - - /** - * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. - * If not found then the supplied defaultValue will be returned. - * - * @param key the key to search - * @param type the type to be returned - * @param format format used to convert the value - * @param defaultValue the value to be returned if the key is not found - * @since 2.11.0 - */ - @Nullable - T getConverted(@Nonnull String key, @Nonnull Class type, @Nonnull String format, @Nullable T defaultValue); } diff --git a/subprojects/griffon-core/src/main/java/griffon/core/Context.java b/subprojects/griffon-core/src/main/java/griffon/core/Context.java index 2cf26779f3d..b6c8f802a68 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/Context.java +++ b/subprojects/griffon-core/src/main/java/griffon/core/Context.java @@ -65,7 +65,7 @@ public interface Context { /** * Removes a key from this context. Does not affect the context's hierarchy. The value is - * converted to type T if found using a {@code PropertyEditor}. + * converted to type T if found using a {@code Converter}. * * @param key the key to be removed * @param type the type to be returned @@ -311,7 +311,7 @@ public interface Context { /** * /** * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. + * converted to type T if found using a {@code Converter}. * * @param key the key to search * @param type the type to be returned @@ -322,7 +322,7 @@ public interface Context { /** * Finds a value associated with the given key. The value is - * converted to type T if found using a {@code PropertyEditor}. + * converted to type T if found using a {@code Converter}. * If not found then the supplied defaultValue will be returned. * * @param key the key to search diff --git a/subprojects/griffon-core/src/main/java/griffon/core/MutableConfiguration.java b/subprojects/griffon-core/src/main/java/griffon/core/MutableConfiguration.java index 5ca04b99dbf..961ebca24a2 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/MutableConfiguration.java +++ b/subprojects/griffon-core/src/main/java/griffon/core/MutableConfiguration.java @@ -37,29 +37,21 @@ public interface MutableConfiguration extends Configuration { * Removes a key from this configuration. * * @param key the key to be removed - * @return the value associated with the key or null if there wasn't any value. - */ - @Nullable - Object remove(@Nonnull String key); - - /** - * Removes a key from this configuration. - * Blindly casts the returned value. * - * @param key the key to be removed * @return the value associated with the key or null if there wasn't any value. - * @since 2.5.0 */ @Nullable - T removeAs(@Nonnull String key); + T remove(@Nonnull String key); /** * Removes a key from this configuration. The value is - * converted to type T if found using a {@code PropertyEditor}. + * converted to type T if found using a {@code Converter}. * * @param key the key to be removed * @param type the type to be returned + * * @return the value associated with the key or null if there wasn't any value. + * * @since 2.5.0 */ @Nullable diff --git a/subprojects/griffon-core/src/main/java/griffon/core/configuration/Configured.java b/subprojects/griffon-core/src/main/java/griffon/core/configuration/Configured.java deleted file mode 100644 index e89755b1f6f..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/configuration/Configured.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.configuration; - -import griffon.core.editors.PropertyEditorResolver; - -import java.beans.PropertyEditor; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Andres Almiray - * @since 2.11.0 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.METHOD}) -public @interface Configured { - String NO_VALUE = "!!<<== NO_VALUE ==>>!!"; - - String configuration() default ""; - - String value(); - - String defaultValue() default NO_VALUE; - - String format() default ""; - - Class editor() default PropertyEditorResolver.NoopPropertyEditor.class; -} \ No newline at end of file diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/AbstractPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/AbstractPropertyEditor.java deleted file mode 100644 index 6e405f25372..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/AbstractPropertyEditor.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.ParseException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nullable; -import java.beans.PropertyEditorSupport; - -import static griffon.core.GriffonExceptionHandler.sanitize; -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public abstract class AbstractPropertyEditor extends PropertyEditorSupport implements ExtendedPropertyEditor { - private static final Logger LOG = LoggerFactory.getLogger(AbstractPropertyEditor.class); - - private String format; - - @Nullable - @Override - public String getFormat() { - return format; - } - - @Override - public void setFormat(@Nullable String format) { - this.format = format; - } - - @Override - public String getAsText() { - return isBlank(getFormat()) ? getAsTextInternal() : getFormattedValue(); - } - - @Override - public void setAsText(String str) throws IllegalArgumentException { - if (isBlank(getFormat())) { - setAsTextInternal(str); - } else { - setFormattedValue(str); - } - } - - @Override - public void setValue(Object value) { - if (value instanceof CharSequence) { - setFormattedValue(String.valueOf(value)); - } else { - setValueInternal(value); - } - } - - protected void setValueInternal(Object value) { - super.setValue(value); - } - - protected Object getValueInternal() { - return super.getValue(); - } - - protected void setAsTextInternal(String str) throws IllegalArgumentException { - setValueInternal(str); - } - - protected String getAsTextInternal() { - return super.getAsText(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public String getFormattedValue() { - Object value = getValueInternal(); - Formatter formatter = resolveFormatter(); - if (formatter != null) { - return formatter.format(value); - } - return value != null ? value.toString() : null; - } - - @Override - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") - public void setFormattedValue(String value) { - Formatter formatter = resolveFormatter(); - if (formatter != null) { - try { - setValueInternal(formatter.parse(value)); - } catch (ParseException e) { - e = (ParseException) sanitize(e); - if (LOG.isTraceEnabled()) { - LOG.trace("Cannot parse value " + value, e); - } - - throw new ValueConversionException(value, e); - } - } else { - setValueInternal(value); - } - } - - protected Formatter resolveFormatter() { - return null; - } - - protected ValueConversionException illegalValue(Object value, Class klass) { - throw new ValueConversionException(value, klass); - } - - protected ValueConversionException illegalValue(Object value, Class klass, Exception e) { - throw new ValueConversionException(value, klass, e); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/BigDecimalPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/BigDecimalPropertyEditor.java deleted file mode 100644 index 08144ac7d51..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/BigDecimalPropertyEditor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.BigDecimalFormatter; -import griffon.core.formatters.Formatter; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BigDecimalPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, BigDecimal.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : new BigDecimal(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, BigDecimal.class, e); - } - } - - protected void handleAsNumber(Number number) { - if (number instanceof BigInteger) { - super.setValueInternal(new BigDecimal((BigInteger) number)); - } else if (number instanceof BigDecimal) { - super.setValueInternal(number); - } else { - super.setValueInternal(number.longValue()); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new BigDecimalFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/BigIntegerPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/BigIntegerPropertyEditor.java deleted file mode 100644 index ec0b5cf8879..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/BigIntegerPropertyEditor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.BigIntegerFormatter; -import griffon.core.formatters.Formatter; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BigIntegerPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, BigInteger.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : new BigInteger(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, BigInteger.class, e); - } - } - - protected void handleAsNumber(Number number) { - if (number instanceof BigDecimal) { - super.setValueInternal(((BigDecimal) number).toBigInteger()); - } else if (number instanceof BigInteger) { - super.setValueInternal(number); - } else { - super.setValueInternal(number.longValue()); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new BigIntegerFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/BooleanPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/BooleanPropertyEditor.java deleted file mode 100644 index 7ff1afc43f2..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/BooleanPropertyEditor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.BooleanFormatter; -import griffon.core.formatters.Formatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BooleanPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Boolean) { - handleAsBoolean((Boolean) value); - } else { - throw illegalValue(value, Boolean.class); - } - } - - protected void handleAsString(String str) { - super.setValueInternal(isBlank(str) ? null : Boolean.parseBoolean(str)); - } - - protected void handleAsBoolean(Boolean bool) { - super.setValueInternal(bool); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : BooleanFormatter.getInstance(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/BytePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/BytePropertyEditor.java deleted file mode 100644 index 76c63e5008c..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/BytePropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.ByteFormatter; -import griffon.core.formatters.Formatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BytePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Byte.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Byte.parseByte(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Byte.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.byteValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new ByteFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/CalendarPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/CalendarPropertyEditor.java deleted file mode 100644 index 31e8391b404..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/CalendarPropertyEditor.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.CalendarFormatter; -import griffon.core.formatters.Formatter; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class CalendarPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Calendar) { - super.setValueInternal(value); - } else if (value instanceof Date) { - Calendar c = Calendar.getInstance(); - c.setTime((Date) value); - super.setValueInternal(c); - } else if (value instanceof Number) { - Calendar c = Calendar.getInstance(); - c.setTime(new Date(((Number) value).longValue())); - super.setValueInternal(c); - } else { - throw illegalValue(value, Calendar.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - Calendar c = Calendar.getInstance(); - try { - c.setTime(new Date(Long.parseLong(str))); - super.setValueInternal(c); - return; - } catch (NumberFormatException nfe) { - // ignore, let's try parsing the date in a locale specific format - } - - try { - c.setTime(new SimpleDateFormat().parse(str)); - super.setValueInternal(c); - } catch (ParseException e) { - throw illegalValue(str, Calendar.class, e); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new CalendarFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/DatePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/DatePropertyEditor.java deleted file mode 100644 index d317559f003..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/DatePropertyEditor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.DateFormatter; -import griffon.core.formatters.Formatter; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class DatePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Date) { - super.setValueInternal(value); - } else if (value instanceof Calendar) { - super.setValueInternal(((Calendar) value).getTime()); - } else if (value instanceof Number) { - super.setValueInternal(new Date(((Number) value).longValue())); - } else { - throw illegalValue(value, Date.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(new Date(Long.parseLong(str))); - return; - } catch (NumberFormatException nfe) { - // ignore, let's try parsing the date in a locale specific format - } - - try { - super.setValueInternal(new SimpleDateFormat().parse(str)); - } catch (ParseException e) { - throw illegalValue(str, Date.class, e); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new DateFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/DoublePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/DoublePropertyEditor.java deleted file mode 100644 index ec8429e6c41..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/DoublePropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.DoubleFormatter; -import griffon.core.formatters.Formatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class DoublePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Double.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Double.parseDouble(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Double.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.doubleValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new DoubleFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/EnumPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/EnumPropertyEditor.java deleted file mode 100644 index 1dfc85f340f..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/EnumPropertyEditor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -@SuppressWarnings("rawtypes") -public class EnumPropertyEditor extends AbstractPropertyEditor { - private Class enumType; - - public Class getEnumType() { - return enumType; - } - - public void setEnumType(Class enumType) { - this.enumType = enumType; - } - - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Enum) { - handleAsString(value.toString()); - } else { - throw illegalValue(value, enumType); - } - } - - @SuppressWarnings("unchecked") - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(Enum.valueOf(enumType, str)); - } catch (Exception e) { - throw illegalValue(str, enumType, e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedCalendarPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedCalendarPropertyEditor.java deleted file mode 100644 index aa98e6aa725..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedCalendarPropertyEditor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.Calendar; -import java.util.Date; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class ExtendedCalendarPropertyEditor extends CalendarPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (value instanceof LocalDate) { - handleAsLocalDate((LocalDate) value); - } else if (value instanceof LocalDateTime) { - handleAsLocalDateTime(((LocalDateTime) value)); - } else { - super.setValueInternal(value); - } - } - - protected void handleAsLocalDate(LocalDate value) { - Calendar c = Calendar.getInstance(); - c.setTime(new Date(value.toEpochDay())); - super.setValueInternal(c); - } - - protected void handleAsLocalDateTime(LocalDateTime value) { - LocalDate localDate = value.toLocalDate(); - LocalTime localTime = value.toLocalTime(); - - Calendar c = Calendar.getInstance(); - c.set( - localDate.getYear(), - localDate.getMonthValue() - 1, - localDate.getDayOfMonth(), - localTime.getHour(), - localTime.getMinute(), - localTime.getSecond() - ); - - super.setValueInternal(c); - } -} \ No newline at end of file diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedPropertyEditor.java deleted file mode 100644 index 07c096d8df7..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedPropertyEditor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import java.beans.PropertyEditor; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public interface ExtendedPropertyEditor extends PropertyEditor { - void setFormat(String format); - - String getFormat(); - - String getFormattedValue(); - - void setFormattedValue(String value); -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/FilePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/FilePropertyEditor.java deleted file mode 100644 index 26935f9d003..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/FilePropertyEditor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import java.io.File; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class FilePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof File) { - super.setValueInternal(value); - } else { - throw illegalValue(value, File.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - super.setValueInternal(new File(str)); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/FloatPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/FloatPropertyEditor.java deleted file mode 100644 index 6551667a14f..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/FloatPropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.FloatFormatter; -import griffon.core.formatters.Formatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class FloatPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Float.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Float.parseFloat(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Float.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.floatValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new FloatFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/IntegerPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/IntegerPropertyEditor.java deleted file mode 100644 index 27c1b639186..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/IntegerPropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.IntegerFormatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class IntegerPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Integer.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Integer.parseInt(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Integer.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.intValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new IntegerFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDatePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDatePropertyEditor.java deleted file mode 100644 index 31e1c3802d9..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDatePropertyEditor.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.LocalDateFormatter; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import static griffon.util.GriffonNameUtils.isBlank; -import static java.time.LocalDate.ofEpochDay; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalDatePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof LocalDate) { - super.setValueInternal(value); - } else if (value instanceof LocalDateTime) { - super.setValueInternal(((LocalDateTime) value).toLocalDate()); - } else if (value instanceof Date) { - super.setValueInternal(ofEpochDay(((Date) value).getTime())); - } else if (value instanceof Calendar) { - super.setValueInternal(ofEpochDay(((Calendar) value).getTime().getTime())); - } else if (value instanceof Number) { - super.setValueInternal(ofEpochDay(((Number) value).longValue())); - } else if (value instanceof List) { - handleAsList((List) value); - } else if (value instanceof Map) { - handleAsMap((Map) value); - } else { - throw illegalValue(value, LocalDate.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(LocalDate.parse(str)); - } catch (DateTimeParseException dtpe) { - throw illegalValue(str, LocalDate.class, dtpe); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new LocalDateFormatter(getFormat()); - } - - protected void handleAsList(List list) { - if (list.isEmpty()) { - super.setValueInternal(null); - return; - } - - List values = new ArrayList<>(); - values.addAll(list); - if (values.size() != 3) { - throw illegalValue(list, LocalDate.class); - } - - for (int i = 0, valuesSize = values.size(); i < valuesSize; i++) { - Object val = values.get(i); - if (val instanceof Number) { - values.set(i, parse((Number) val)); - } else if (val instanceof CharSequence) { - values.set(i, parse(String.valueOf(val))); - } else { - throw illegalValue(list, LocalDate.class); - } - } - super.setValueInternal( - LocalDate.of( - (Integer) values.get(0), - (Integer) values.get(1), - (Integer) values.get(2) - ) - ); - } - - protected void handleAsMap(Map map) { - if (map.isEmpty()) { - super.setValueInternal(null); - return; - } - - int y = getMapValue(map, "year", 1970); - int m = getMapValue(map, "month", 1); - int d = getMapValue(map, "day", 1); - super.setValueInternal(LocalDate.of(y, m, d)); - } - - protected int parse(String val) { - try { - return Integer.parseInt(val.trim()); - } catch (NumberFormatException e) { - throw illegalValue(val, LocalDate.class, e); - } - } - - protected int parse(Number val) { - return val.intValue(); - } - - protected int getMapValue(Map map, String key, int defaultValue) { - Object val = map.get(key); - if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } - if (null == val) { - return defaultValue; - } else if (val instanceof CharSequence) { - return parse(String.valueOf(val)); - } else if (val instanceof Number) { - return parse((Number) val); - } - throw illegalValue(map, LocalDate.class); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDateTimePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDateTimePropertyEditor.java deleted file mode 100644 index ab307c8cf6c..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalDateTimePropertyEditor.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.LocalDateTimeFormatter; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalDateTimePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof LocalDateTime) { - super.setValueInternal(value); - } else if (value instanceof LocalDate) { - super.setValueInternal(LocalDateTime.of((LocalDate) value, LocalTime.of(0, 0, 0, 0))); - } else if (value instanceof Date) { - handleAsDate((Date) value); - } else if (value instanceof Calendar) { - handleAsCalendar((Calendar) value); - } else if (value instanceof Number) { - handleAsDate(new Date(((Number) value).longValue())); - } else if (value instanceof List) { - handleAsList((List) value); - } else { - throw illegalValue(value, LocalDateTime.class); - } - } - - protected void handleAsDate(Date date) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - handleAsCalendar(c); - } - - protected void handleAsCalendar(Calendar value) { - int h = value.get(Calendar.HOUR); - int i = value.get(Calendar.MINUTE); - int s = value.get(Calendar.SECOND); - int n = value.get(Calendar.MILLISECOND) * 1000; - super.setValueInternal(LocalDateTime.of(LocalDate.ofEpochDay(value.getTime().getTime()), LocalTime.of(h, i, s, n))); - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(LocalDateTime.parse(str)); - } catch (DateTimeParseException dtpe) { - throw illegalValue(str, LocalDateTime.class, dtpe); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new LocalDateTimeFormatter(getFormat()); - } - - protected void handleAsList(List list) { - if (list.isEmpty()) { - super.setValueInternal(null); - return; - } - - List values = new ArrayList<>(); - values.addAll(list); - switch (list.size()) { - case 7: - // ok - break; - case 6: - values.add(0d); - break; - case 5: - values.add(0d); - values.add(0d); - break; - case 4: - values.add(0d); - values.add(0d); - values.add(0d); - break; - case 3: - values.add(0d); - values.add(0d); - values.add(0d); - values.add(0d); - break; - default: - throw illegalValue(list, LocalDateTime.class); - } - - for (int i = 0, valuesSize = values.size(); i < valuesSize; i++) { - Object val = values.get(i); - if (val instanceof Number) { - values.set(i, parse((Number) val)); - } else if (val instanceof CharSequence) { - values.set(i, parse(String.valueOf(val))); - } else { - throw illegalValue(list, LocalDateTime.class); - } - } - super.setValueInternal( - LocalDateTime.of( - (Integer) values.get(0), - (Integer) values.get(1), - (Integer) values.get(2), - (Integer) values.get(3), - (Integer) values.get(4), - (Integer) values.get(5), - (Integer) values.get(6) - ) - ); - } - - protected int parse(String val) { - try { - return Integer.parseInt(val.trim()); - } catch (NumberFormatException e) { - throw illegalValue(val, LocalDateTime.class, e); - } - } - - protected int parse(Number val) { - return val.intValue(); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalTimePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalTimePropertyEditor.java deleted file mode 100644 index 800bc63c346..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalTimePropertyEditor.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.LocalTimeFormatter; - -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalTimePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof LocalTime) { - super.setValueInternal(value); - } else if (value instanceof LocalDateTime) { - super.setValueInternal(((LocalDateTime) value).toLocalTime()); - } else if (value instanceof Date) { - handleAsDate((Date) value); - } else if (value instanceof Calendar) { - handleAsCalendar((Calendar) value); - } else if (value instanceof Number) { - handleAsDate(new Date(((Number) value).longValue())); - } else if (value instanceof List) { - handleAsList((List) value); - } else { - throw illegalValue(value, LocalTime.class); - } - } - - protected void handleAsDate(Date date) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - handleAsCalendar(c); - } - - protected void handleAsCalendar(Calendar value) { - int h = value.get(Calendar.HOUR); - int i = value.get(Calendar.MINUTE); - int s = value.get(Calendar.SECOND); - int n = value.get(Calendar.MILLISECOND) * 1000; - super.setValueInternal(LocalTime.of(h, i, s, n)); - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(LocalTime.parse(str)); - } catch (DateTimeParseException dtpe) { - throw illegalValue(str, LocalTime.class, dtpe); - } - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new LocalTimeFormatter(getFormat()); - } - - protected void handleAsList(List list) { - if (list.isEmpty()) { - super.setValueInternal(null); - return; - } - - List values = new ArrayList<>(); - values.addAll(list); - switch (values.size()) { - case 4: - // ok - break; - case 3: - values.add(0); - break; - default: - throw illegalValue(list, LocalTime.class); - } - - for (int i = 0, valuesSize = values.size(); i < valuesSize; i++) { - Object val = values.get(i); - if (val instanceof Number) { - values.set(i, parse((Number) val)); - } else if (val instanceof CharSequence) { - values.set(i, parse(String.valueOf(val))); - } else { - throw illegalValue(list, LocalTime.class); - } - } - super.setValueInternal( - LocalTime.of( - (Integer) values.get(0), - (Integer) values.get(1), - (Integer) values.get(2), - (Integer) values.get(3) - ) - ); - } - - protected int parse(String val) { - try { - return Integer.parseInt(val.trim()); - } catch (NumberFormatException e) { - throw illegalValue(val, LocalTime.class, e); - } - } - - protected int parse(Number val) { - return val.intValue(); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalePropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalePropertyEditor.java deleted file mode 100644 index 0a13840b11d..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/LocalePropertyEditor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.LocaleFormatter; - -import java.util.Locale; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class LocalePropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof Locale) { - super.setValueInternal(value); - } else if (value instanceof CharSequence) { - super.setValueInternal(resolveFormatter().parse(String.valueOf(value))); - } else { - throw illegalValue(value, Locale.class); - } - } - - @Override - protected Formatter resolveFormatter() { - return new LocaleFormatter(); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/LongPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/LongPropertyEditor.java deleted file mode 100644 index 2f9dcd33bee..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/LongPropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.LongFormatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class LongPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Long.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Long.parseLong(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Long.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.longValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new LongFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorChain.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorChain.java deleted file mode 100644 index df89722e39e..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorChain.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.GuardedBy; -import java.beans.PropertyEditor; -import java.beans.PropertyEditorSupport; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import static griffon.util.GriffonClassUtils.requireNonEmpty; -import static griffon.util.GriffonNameUtils.isBlank; -import static java.util.Objects.requireNonNull; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class PropertyEditorChain extends PropertyEditorSupport implements ExtendedPropertyEditor { - private final Class targetClass; - private final Object lock = new Object[0]; - private final WeakReference>[] propertyEditorClasses; - @GuardedBy("lock") - private WeakReference[] propertyEditors; - private String format; - - @SuppressWarnings("unchecked") - public PropertyEditorChain(@Nonnull Class targetClass, @Nonnull Class[] propertyEditorClasses) { - this.targetClass = requireNonNull(targetClass, "Argument 'targetClass' must not be null"); - requireNonEmpty(propertyEditorClasses, "Argument 'propertyEditorClasses' must not be null nor empty"); - // let's make sure propertyEditorClasses contains unique elements - Set> classes = new LinkedHashSet<>(); - Collections.addAll(classes, propertyEditorClasses); - - int i = 0; - this.propertyEditorClasses = new WeakReference[classes.size()]; - for (Class klass : classes) { - this.propertyEditorClasses[i++] = new WeakReference>(klass); - } - } - - @Override - @Nullable - public String getFormat() { - return format; - } - - @Override - public void setFormat(@Nullable String format) { - this.format = format; - } - - public int getSize() { - return propertyEditorClasses.length; - } - - @SuppressWarnings("unchecked") - public PropertyEditorChain copyOf() { - List> classes = new ArrayList<>(); - for (WeakReference> reference : propertyEditorClasses) { - if (reference.get() != null) { - classes.add(reference.get()); - } - } - return new PropertyEditorChain(targetClass, classes.toArray(new Class[classes.size()])); - } - - @SuppressWarnings("unchecked") - public PropertyEditorChain copyOf(Class propertyEditorClass) { - requireNonNull(propertyEditorClass, "Argument 'propertyEditorClass' must not be null"); - List> classes = new ArrayList<>(); - for (WeakReference> reference : propertyEditorClasses) { - if (reference.get() != null) { - classes.add(reference.get()); - } - } - if (!classes.contains(propertyEditorClass)) { - classes.add(propertyEditorClass); - } - return new PropertyEditorChain(targetClass, classes.toArray(new Class[classes.size()])); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()); - sb.append("[").append(targetClass.getName()).append(']'); - return sb.toString(); - } - - @Override - public String getAsText() { - return isBlank(getFormat()) ? getAsTextInternal() : getFormattedValue(); - } - - @Override - public void setAsText(String str) throws IllegalArgumentException { - if (isBlank(getFormat())) { - setAsTextInternal(str); - } else { - setFormattedValue(str); - } - } - - @Override - public void setValue(Object value) { - if (value instanceof CharSequence) { - setFormattedValue(String.valueOf(value)); - } else { - setValueInternal(value); - } - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public String getFormattedValue() { - initPropertyEditors(); - - Object value = super.getValue(); - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null && propertyEditor instanceof ExtendedPropertyEditor) { - ExtendedPropertyEditor extendedPropertyEditor = (ExtendedPropertyEditor) propertyEditor; - extendedPropertyEditor.setFormat(format); - extendedPropertyEditor.setValue(value); - return extendedPropertyEditor.getFormattedValue(); - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(value, targetClass); - } - - @Override - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") - public void setFormattedValue(String value) { - initPropertyEditors(); - - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null && propertyEditor instanceof ExtendedPropertyEditor) { - ExtendedPropertyEditor extendedPropertyEditor = (ExtendedPropertyEditor) propertyEditor; - extendedPropertyEditor.setFormat(format); - extendedPropertyEditor.setValue(value); - super.setValue(extendedPropertyEditor.getValue()); - return; - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(value, targetClass); - } - - protected void setValueInternal(Object value) throws IllegalArgumentException { - initPropertyEditors(); - - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null) { - propertyEditor.setValue(value); - super.setValue(propertyEditor.getValue()); - return; - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(value, targetClass); - } - - protected Object getValueInternal() { - initPropertyEditors(); - - Object value = super.getValue(); - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null) { - propertyEditor.setValue(value); - return propertyEditor.getValue(); - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(value, targetClass); - } - - protected String getAsTextInternal() { - initPropertyEditors(); - - Object value = super.getValue(); - - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null) { - propertyEditor.setValue(value); - return propertyEditor.getAsText(); - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(value, targetClass); - } - - protected void setAsTextInternal(String text) throws IllegalArgumentException { - initPropertyEditors(); - - for (WeakReference reference : propertyEditors) { - try { - PropertyEditor propertyEditor = reference.get(); - if (propertyEditor != null) { - propertyEditor.setAsText(text); - super.setValue(propertyEditor.getValue()); - return; - } - } catch (Exception e) { - // ignore. next editor - } - } - - throw illegalValue(text, targetClass); - } - - protected ValueConversionException illegalValue(Object value, Class klass) { - throw new ValueConversionException(value, klass); - } - - protected ValueConversionException illegalValue(Object value, Class klass, Exception e) { - throw new ValueConversionException(value, klass, e); - } - - @SuppressWarnings("unchecked") - private void initPropertyEditors() { - synchronized (lock) { - if (propertyEditors == null) { - List> editors = new ArrayList<>(); - for (WeakReference> propertyEditorClass : propertyEditorClasses) { - try { - Class klass = propertyEditorClass.get(); - if (klass != null) { - editors.add(new WeakReference<>(klass.newInstance())); - } - } catch (InstantiationException | IllegalAccessException e) { - throw new IllegalArgumentException("Can't create instance", e); - } - } - - if (!editors.isEmpty()) { - propertyEditors = editors.toArray(new WeakReference[editors.size()]); - } else { - throw new IllegalStateException("No available PropertyEditors for " + this); - } - } - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorResolver.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorResolver.java deleted file mode 100644 index d37f572f952..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/PropertyEditorResolver.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.GuardedBy; -import java.beans.PropertyEditor; -import java.beans.PropertyEditorManager; -import java.beans.PropertyEditorSupport; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Map; -import java.util.WeakHashMap; -import java.util.concurrent.ConcurrentHashMap; - -import static java.util.Objects.requireNonNull; - -/** - * The PropertyEditorResolver can be used to locate a property editor for - * any given type name. This property editor must support the - * java.beans.PropertyEditor interface for editing a given object. - *

- * - * @author Andres Almiray - * @since 2.0.0 - */ -public final class PropertyEditorResolver { - private static final Logger LOG = LoggerFactory.getLogger(PropertyEditorResolver.class); - private static final Object LOCK = new Object[0]; - @GuardedBy("LOCK") - private static final WeakCache> propertyEditorRegistry = new WeakCache<>(); - @GuardedBy("LOCK") - private static final Map propertyEditorChainRegistry = new ConcurrentHashMap<>(); - private static final String ERROR_TARGET_TYPE_NULL = "Argument 'targetType' must not be null"; - public static final PropertyEditor NOOP_PROPERTY_EDITOR = new NoopPropertyEditor(); - - private PropertyEditorResolver() { - - } - - /** - * Removes all currently registered value editors. - * - * @since 2.4.0 - */ - public static void clear() { - synchronized (LOCK) { - propertyEditorRegistry.clear(); - propertyEditorChainRegistry.clear(); - } - } - - /** - * Locate a value editor for a given target type. - *

- * If the input {@code type} is an Enum then an instance of {@code EnumPropertyEditor} - * is returned with the {@code type} set as {@code enumType}. - * - * @param type The Class object for the type to be edited - * - * @return An editor object for the given target class. - * The result is null if no suitable editor can be found. - * - * @see griffon.core.editors.EnumPropertyEditor - */ - @Nonnull - @SuppressWarnings("unchecked") - public static PropertyEditor findEditor(@Nonnull Class type) { - requireNonNull(type, ERROR_TARGET_TYPE_NULL); - LOG.trace("Searching PropertyEditor for {}", type.getName()); - - PropertyEditor editor; - if (Enum.class.isAssignableFrom(type)) { - editor = new EnumPropertyEditor(); - ((EnumPropertyEditor) editor).setEnumType((Class>) type); - } else { - editor = doFindEditor(type); - } - - if (editor == null) { - // fallback - editor = PropertyEditorManager.findEditor(type); - } - - if (editor == null) { - editor = new NoopPropertyEditor(); - } - - LOG.trace("PropertyEditor for {} is {}", type.getName(), editor.getClass().getName()); - return editor; - } - - /** - * Unregisters an editor class to edit values of the given target class. - * - * @param targetType the class object of the type to be edited - * - * @since 2.4.0 - */ - public static void unregisterEditor(@Nonnull Class targetType) { - requireNonNull(targetType, ERROR_TARGET_TYPE_NULL); - synchronized (LOCK) { - String targetTypeName = targetType.getName(); - propertyEditorChainRegistry.remove(targetTypeName); - propertyEditorRegistry.remove(targetTypeName); - } - } - - /** - * Registers an editor class to edit values of the given target class. - * If the editor class is {@code null}, - * then any existing definition will be removed. - * Thus this method can be used to cancel the registration. - * The registration is canceled automatically - * if either the target or editor class is unloaded. - *

- * - * @param targetType the class object of the type to be edited - * @param editorClass the class object of the editor class - * - * @since 2.4.0 - */ - @SuppressWarnings("unchecked") - public static void registerEditor(@Nonnull Class targetType, @Nullable Class editorClass) { - requireNonNull(targetType, ERROR_TARGET_TYPE_NULL); - synchronized (LOCK) { - String targetTypeName = targetType.getName(); - if (editorClass == null) { - propertyEditorChainRegistry.remove(targetTypeName); - propertyEditorRegistry.remove(targetTypeName); - return; - } - - // is targetType handled by a chain? - PropertyEditorChain chain = propertyEditorChainRegistry.get(targetTypeName); - if (chain != null) { - PropertyEditorChain propertyEditorChain = chain.copyOf(editorClass); - if (propertyEditorChain.getSize() > 1) { - propertyEditorChainRegistry.put(targetTypeName, propertyEditorChain); - } else { - // standard registration - propertyEditorChainRegistry.remove(targetTypeName); - propertyEditorRegistry.put(targetTypeName, editorClass); - } - } else { - // is targetType handled by an editor ? - Class propertyEditorType = propertyEditorRegistry.get(targetTypeName); - if (propertyEditorType != null) { - propertyEditorRegistry.remove(targetTypeName); - Class[] propertyEditorClasses = new Class[2]; - propertyEditorClasses[0] = propertyEditorType; - propertyEditorClasses[1] = editorClass; - PropertyEditorChain propertyEditorChain = new PropertyEditorChain(targetType, propertyEditorClasses); - if (propertyEditorChain.getSize() > 1) { - propertyEditorChainRegistry.put(targetTypeName, propertyEditorChain); - } else { - // standard registration - propertyEditorChainRegistry.remove(targetTypeName); - propertyEditorRegistry.put(targetTypeName, editorClass); - } - } else { - // standard registration - propertyEditorChainRegistry.remove(targetTypeName); - propertyEditorRegistry.put(targetTypeName, editorClass); - } - } - } - } - - @Nullable - private static PropertyEditor doFindEditor(@Nonnull Class targetType) { - synchronized (LOCK) { - String targetTypeName = targetType.getName(); - if (propertyEditorChainRegistry.containsKey(targetTypeName)) { - PropertyEditorChain chain = propertyEditorChainRegistry.get(targetTypeName); - return chain.copyOf(); - } else { - Class propertyEditorType = propertyEditorRegistry.get(targetTypeName); - if (propertyEditorType != null) { - try { - return (PropertyEditor) propertyEditorType.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new IllegalStateException("Can't instantiate " + propertyEditorType, e); - } - } - } - } - return null; - } - - public static final class NoopPropertyEditor extends PropertyEditorSupport { - - } - - private static final class WeakCache { - private final Map> map = new WeakHashMap<>(); - - private V get(K key) { - Reference reference = this.map.get(key); - if (reference == null) { - return null; - } else { - V value = reference.get(); - if (value == null) { - this.map.remove(key); - } - - return value; - } - } - - private void put(K key, V value) { - if (value != null) { - this.map.put(key, new WeakReference<>(value)); - } else { - this.map.remove(key); - } - } - - private void remove(K key) { - this.map.remove(key); - } - - private void clear() { - this.map.clear(); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/ShortPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/ShortPropertyEditor.java deleted file mode 100644 index c648b4de92d..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/ShortPropertyEditor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import griffon.core.formatters.Formatter; -import griffon.core.formatters.ShortFormatter; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class ShortPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof Number) { - handleAsNumber((Number) value); - } else { - throw illegalValue(value, Short.class); - } - } - - protected void handleAsString(String str) { - try { - super.setValueInternal(isBlank(str) ? null : Short.parseShort(str)); - } catch (NumberFormatException e) { - throw illegalValue(str, Short.class, e); - } - } - - protected void handleAsNumber(Number number) { - super.setValueInternal(number.shortValue()); - } - - @Override - protected Formatter resolveFormatter() { - return isBlank(getFormat()) ? null : new ShortFormatter(getFormat()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/URIPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/URIPropertyEditor.java deleted file mode 100644 index 060e3770c7b..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/URIPropertyEditor.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class URIPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof File) { - handleAsFile((File) value); - } else if (value instanceof URI) { - super.setValueInternal(value); - } else { - throw illegalValue(value, URI.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - - try { - super.setValueInternal(new URI(str)); - } catch (URISyntaxException e) { - throw illegalValue(str, URI.class, e); - } - } - - protected void handleAsFile(File file) { - super.setValueInternal(file.toURI()); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/URLPropertyEditor.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/URLPropertyEditor.java deleted file mode 100644 index 533168ed37a..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/URLPropertyEditor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class URLPropertyEditor extends AbstractPropertyEditor { - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof File) { - handleAsFile((File) value); - } else if (value instanceof URL) { - super.setValueInternal(value); - } else { - throw illegalValue(value, URL.class); - } - } - - protected void handleAsString(String str) { - if (isBlank(str)) { - super.setValueInternal(null); - return; - } - try { - super.setValueInternal(new URL(str)); - } catch (MalformedURLException e) { - throw illegalValue(str, URL.class, e); - } - } - - protected void handleAsFile(File file) { - try { - super.setValueInternal(file.toURI().toURL()); - } catch (MalformedURLException e) { - throw illegalValue(file, URL.class, e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/ValueConversionException.java b/subprojects/griffon-core/src/main/java/griffon/core/editors/ValueConversionException.java deleted file mode 100644 index d0bd4267f55..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/ValueConversionException.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class ValueConversionException extends IllegalArgumentException { - private static final long serialVersionUID = 6344566641106178891L; - - private final transient Object value; - private Class type; - - public ValueConversionException(Object value) { - this(value, (Exception) null); - } - - public ValueConversionException(Object value, Class type) { - this(value, type, null); - } - - public ValueConversionException(Object value, Class type, Exception cause) { - super("Can't convert '" + value + "' into " + type.getName(), cause); - this.value = value; - this.type = type; - } - - public ValueConversionException(Object value, Exception cause) { - super("Can't convert '" + value + "'", cause); - this.value = value; - } - - @Nonnull - public Object getValue() { - return value; - } - - @Nullable - public Class getType() { - return type; - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/AbstractFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/AbstractFormatter.java deleted file mode 100644 index 52083aa5ab9..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/AbstractFormatter.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static java.util.Objects.requireNonNull; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public abstract class AbstractFormatter implements Formatter { - protected static int parseHexInt(@Nonnull String val, @Nonnull Class klass) throws ParseException { - try { - return Integer.parseInt(String.valueOf(requireNonNull(val)).trim(), 16) & 0xFF; - } catch (NumberFormatException e) { - throw parseError(val, klass, e); - } - } - - protected static int parseHexInt(@Nonnull Number val) { - return requireNonNull(val).intValue() & 0xFF; - } - - protected static ParseException parseError(@Nullable Object value, @Nonnull Class klass) throws ParseException { - throw new ParseException("Can't convert '" + value + "' into " + requireNonNull(klass).getName()); - } - - protected static ParseException parseError(@Nullable Object value, @Nonnull Class klass, @Nonnull Exception e) throws ParseException { - throw new ParseException("Can't convert '" + value + "' into " + requireNonNull(klass).getName(), requireNonNull(e)); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigDecimalFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigDecimalFormatter.java deleted file mode 100644 index a6dbd537911..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigDecimalFormatter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BigDecimalFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public BigDecimalFormatter() { - this(null); - } - - public BigDecimalFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = new DecimalFormat(); - ((DecimalFormat) numberFormat).setParseBigDecimal(true); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - ((DecimalFormat) numberFormat).setParseBigDecimal(true); - } - } - - @Nullable - @Override - public String format(@Nullable BigDecimal number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public BigDecimal parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - Number number = numberFormat.parse(str); - if (number instanceof BigDecimal) { - return (BigDecimal) number; - } - return new BigDecimal(number.longValue()); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigIntegerFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigIntegerFormatter.java deleted file mode 100644 index 75c3def2afe..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BigIntegerFormatter.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BigIntegerFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public BigIntegerFormatter() { - this(null); - } - - public BigIntegerFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = NumberFormat.getIntegerInstance(); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - numberFormat.setParseIntegerOnly(true); - ((DecimalFormat) numberFormat).setParseBigDecimal(true); - } - } - - @Nullable - @Override - public String format(@Nullable BigInteger number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public BigInteger parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - Number number = numberFormat.parse(str); - if (number instanceof BigDecimal) { - return ((BigDecimal) number).toBigInteger(); - } - return BigInteger.valueOf(number.longValue()); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BooleanFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/BooleanFormatter.java deleted file mode 100644 index d8618a8f79d..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/BooleanFormatter.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Arrays; - -import static griffon.util.GriffonNameUtils.isBlank; -import static java.util.Objects.requireNonNull; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class BooleanFormatter extends AbstractFormatter { - public static final String PATTERN_BOOL = "boolean"; - public static final String PATTERN_QUERY = "query"; - public static final String PATTERN_SWITCH = "switch"; - public static final String DEFAULT_PATTERN = PATTERN_BOOL; - - private static final String[] PATTERNS = new String[]{ - PATTERN_BOOL, - PATTERN_QUERY, - PATTERN_SWITCH - }; - - public static final BooleanFormatter BOOL = new BooleanFormatter(PATTERN_BOOL); - public static final BooleanFormatter QUERY = new BooleanFormatter(PATTERN_QUERY); - public static final BooleanFormatter SWITCH = new BooleanFormatter(PATTERN_SWITCH); - - private static final BooleanFormatter[] FORMATTERS = new BooleanFormatter[]{ - BOOL, - QUERY, - SWITCH - }; - - @Nonnull - public static BooleanFormatter getInstance(@Nullable String pattern) { - return new BooleanFormatter(pattern); - } - - private final BooleanFormatterDelegate delegate; - - public BooleanFormatter() { - this(DEFAULT_PATTERN); - } - - protected BooleanFormatter(@Nullable String pattern) { - if (PATTERN_BOOL.equals(pattern)) { - delegate = new BoolBooleanFormatterDelegate(); - } else if (PATTERN_QUERY.equals(pattern)) { - delegate = new QueryBooleanFormatterDelegate(); - } else if (PATTERN_SWITCH.equals(pattern)) { - delegate = new SwitchBooleanFormatterDelegate(); - } else if (isBlank(pattern)) { - delegate = new BoolBooleanFormatterDelegate(); - } else { - throw new IllegalArgumentException("Invalid pattern '" + pattern + "'. Valid patterns are " + Arrays.toString(PATTERNS)); - } - } - - @Nonnull - public String getPattern() { - return delegate.getPattern(); - } - - @Nullable - public static Boolean parseBoolean(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - for (BooleanFormatter formatter : FORMATTERS) { - try { - return formatter.parse(str); - } catch (ParseException e) { - // ignore - } - } - throw parseError(str, Boolean.class); - } - - @Nullable - @Override - public String format(@Nullable Boolean value) { - return value == null ? null : delegate.format(value); - } - - @Nullable - @Override - @SuppressWarnings("ConstantConditions") - public Boolean parse(@Nullable String str) throws ParseException { - return isBlank(str) ? null : delegate.parse(str); - } - - private interface BooleanFormatterDelegate { - @Nonnull - String getPattern(); - - @Nonnull - String format(@Nonnull Boolean value); - - @Nonnull - Boolean parse(@Nonnull String str) throws ParseException; - } - - private abstract static class AbstractBooleanFormatterDelegate implements BooleanFormatterDelegate { - private final String pattern; - private final String[] tokens; - - private AbstractBooleanFormatterDelegate(String pattern, String[] tokens) { - this.pattern = pattern; - this.tokens = tokens; - } - - @Nonnull - @Override - public String getPattern() { - return pattern; - } - - @Nonnull - @Override - public String format(@Nonnull Boolean bool) { - requireNonNull(bool, "Can't format given Boolean because it's null"); - return bool ? tokens[1] : tokens[0]; - } - - @Nonnull - @Override - public Boolean parse(@Nonnull String str) throws ParseException { - if (tokens[0].equalsIgnoreCase(str)) { - return Boolean.FALSE; - } else if (tokens[1].equalsIgnoreCase(str)) { - return Boolean.TRUE; - } - throw parseError(str, Boolean.class); - } - } - - private static class BoolBooleanFormatterDelegate extends AbstractBooleanFormatterDelegate { - private BoolBooleanFormatterDelegate() { - super(PATTERN_BOOL, new String[]{"false", "true"}); - } - } - - private static class QueryBooleanFormatterDelegate extends AbstractBooleanFormatterDelegate { - private QueryBooleanFormatterDelegate() { - super(PATTERN_QUERY, new String[]{"no", "yes"}); - } - } - - private static class SwitchBooleanFormatterDelegate extends AbstractBooleanFormatterDelegate { - private SwitchBooleanFormatterDelegate() { - super(PATTERN_SWITCH, new String[]{"off", "on"}); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ByteFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/ByteFormatter.java deleted file mode 100644 index c91f26683dc..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ByteFormatter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class ByteFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public ByteFormatter() { - this(null); - } - - public ByteFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = NumberFormat.getIntegerInstance(); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - numberFormat.setParseIntegerOnly(true); - } - } - - @Nullable - @Override - public String format(@Nullable Byte number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Byte parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).byteValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/CalendarFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/CalendarFormatter.java deleted file mode 100644 index 42fc2fca656..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/CalendarFormatter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.text.SimpleDateFormat; -import java.util.Calendar; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class CalendarFormatter extends AbstractFormatter { - private final SimpleDateFormat dateFormat; - - public CalendarFormatter() { - this(null); - } - - public CalendarFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - dateFormat = new SimpleDateFormat(); - } else { - dateFormat = new SimpleDateFormat(pattern); - } - } - - @Nonnull - public String getPattern() { - return dateFormat.toPattern(); - } - - @Nullable - @Override - public String format(@Nullable Calendar date) { - return date == null ? null : dateFormat.format(date.getTime()); - } - - @Nullable - @Override - public Calendar parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - Calendar c = Calendar.getInstance(); - c.setTime(dateFormat.parse(str)); - return c; - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/DateFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/DateFormatter.java deleted file mode 100644 index 00ce810ba64..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/DateFormatter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class DateFormatter extends AbstractFormatter { - private final SimpleDateFormat dateFormat; - - public DateFormatter() { - this(null); - } - - public DateFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - dateFormat = new SimpleDateFormat(); - } else { - dateFormat = new SimpleDateFormat(pattern); - } - } - - @Nonnull - public String getPattern() { - return dateFormat.toPattern(); - } - - @Nullable - @Override - public String format(@Nullable Date date) { - return date == null ? null : dateFormat.format(date); - } - - @Nullable - @Override - public Date parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return dateFormat.parse(str); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/DoubleFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/DoubleFormatter.java deleted file mode 100644 index 8b1c54686f6..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/DoubleFormatter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class DoubleFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public DoubleFormatter() { - this(null); - } - - public DoubleFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = new DecimalFormat("#.0"); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - } - } - - @Nullable - @Override - public String format(@Nullable Double number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Double parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).doubleValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/FloatFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/FloatFormatter.java deleted file mode 100644 index e3671d59bdc..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/FloatFormatter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class FloatFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public FloatFormatter() { - this(null); - } - - public FloatFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = new DecimalFormat("#.0"); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - } - } - - @Nullable - @Override - public String format(@Nullable Float number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Float parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).floatValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/Formatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/Formatter.java deleted file mode 100644 index 535d47ba5e6..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/Formatter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; - -/** - *

Strategy for parsing and formatting instances from and to their literal representation

- * - * @param the type of instances this {@code Formatter} can handle. - * @author Andres Almiray - * @since 2.0.0 - */ -public interface Formatter { - /** - *

Formats an instance into its literal representation.

- *

The resulting {@code String} may be set as an argument to {@link Formatter#parse} - * resulting in a similar instance as the input.

- * - * @param obj the instance to be formatted - * @return A {@code String} representing the instance's state. - */ - @Nullable - String format(@Nullable T obj); - - /** - *

Parses a literal representation into an instance of type {@code T}.

- *

The resulting instance {@code T} may be set as an argument to {@link Formatter#format} - * resulting in an equal {@code String} as the input.

- * - * @param str the {@code String} to be parsed - * @return an instance of type {@code T} whose state is initialized given the - * parameters of the input {@code String}. - * @throws ParseException if the {@code String} cannot be parsed. - */ - @Nullable - T parse(@Nullable String str) throws ParseException; -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/IntegerFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/IntegerFormatter.java deleted file mode 100644 index 278769d7ca4..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/IntegerFormatter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class IntegerFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public IntegerFormatter() { - this(null); - } - - public IntegerFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = NumberFormat.getIntegerInstance(); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - numberFormat.setParseIntegerOnly(true); - } - } - - @Nullable - @Override - public String format(@Nullable Integer number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Integer parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).intValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateFormatter.java deleted file mode 100644 index 5adae65901f..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateFormatter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalDateFormatter extends AbstractFormatter { - private final DateTimeFormatter formatter; - private final String pattern; - - public LocalDateFormatter() { - this(null); - } - - public LocalDateFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - formatter = DateTimeFormatter.ISO_LOCAL_DATE; - this.pattern = "yyyy-MM-dd"; - } else { - formatter = DateTimeFormatter.ofPattern(pattern); - this.pattern = pattern; - } - } - - @Nonnull - public String getPattern() { - return pattern; - } - - @Nullable - public String format(@Nullable LocalDate date) { - return date == null ? null : formatter.format(date); - } - - @Nullable - @Override - public LocalDate parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return LocalDate.parse(str, formatter); - } catch (DateTimeParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateTimeFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateTimeFormatter.java deleted file mode 100644 index 484fc4988ec..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalDateTimeFormatter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalDateTimeFormatter extends AbstractFormatter { - private final DateTimeFormatter formatter; - private final String pattern; - - public LocalDateTimeFormatter() { - this(null); - } - - public LocalDateTimeFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; - this.pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS"; - } else { - formatter = DateTimeFormatter.ofPattern(pattern); - this.pattern = pattern; - } - } - - @Nonnull - public String getPattern() { - return pattern; - } - - @Nullable - public String format(@Nullable LocalDateTime time) { - return time == null ? null : formatter.format(time); - } - - @Nullable - @Override - public LocalDateTime parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return LocalDateTime.parse(str, formatter); - } catch (DateTimeParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalTimeFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalTimeFormatter.java deleted file mode 100644 index 64d9cc97549..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocalTimeFormatter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.4.0 - */ -public class LocalTimeFormatter extends AbstractFormatter { - private final DateTimeFormatter formatter; - private final String pattern; - - public LocalTimeFormatter() { - this(null); - } - - public LocalTimeFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - formatter = DateTimeFormatter.ISO_LOCAL_TIME; - this.pattern = "HH:mm:ss.SSS"; - } else { - formatter = DateTimeFormatter.ofPattern(pattern); - this.pattern = pattern; - } - } - - @Nonnull - public String getPattern() { - return pattern; - } - - @Nullable - public String format(@Nullable LocalTime time) { - return time == null ? null : formatter.format(time); - } - - @Nullable - @Override - public LocalTime parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return LocalTime.parse(str, formatter); - } catch (DateTimeParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocaleFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocaleFormatter.java deleted file mode 100644 index 9d7b8cc4c77..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LocaleFormatter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.util.Locale; - -import static griffon.util.GriffonApplicationUtils.parseLocale; -import static griffon.util.GriffonNameUtils.isNotBlank; - -/** - * @author Andres Almiray - * @since 2.5.0 - */ -public class LocaleFormatter extends AbstractFormatter { - @Nullable - @Override - public String format(@Nullable Locale locale) { - if (locale == null) { return null; } - StringBuilder b = new StringBuilder(); - b.append(locale.getLanguage()); - if (isNotBlank(locale.getCountry())) { - b.append("_").append(locale.getCountry()); - if (isNotBlank(locale.getVariant())) { - b.append("_").append(locale.getVariant()); - } - } - - return b.toString(); - } - - @Nullable - @Override - public Locale parse(@Nullable String str) throws ParseException { - return parseLocale(str); - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LongFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/LongFormatter.java deleted file mode 100644 index 03278645788..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/LongFormatter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class LongFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public LongFormatter() { - this(null); - } - - public LongFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = NumberFormat.getIntegerInstance(); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - numberFormat.setParseIntegerOnly(true); - } - } - - @Nullable - @Override - public String format(@Nullable Long number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Long parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).longValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ShortFormatter.java b/subprojects/griffon-core/src/main/java/griffon/core/formatters/ShortFormatter.java deleted file mode 100644 index 220035fc2e8..00000000000 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ShortFormatter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters; - -import javax.annotation.Nullable; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import static griffon.util.GriffonNameUtils.isBlank; - -/** - * @author Andres Almiray - * @since 2.0.0 - */ -public class ShortFormatter extends AbstractFormatter { - public static final String PATTERN_CURRENCY = "currency"; - public static final String PATTERN_PERCENT = "percent"; - - private final NumberFormat numberFormat; - - public ShortFormatter() { - this(null); - } - - public ShortFormatter(@Nullable String pattern) { - if (isBlank(pattern)) { - numberFormat = NumberFormat.getIntegerInstance(); - } else if (PATTERN_CURRENCY.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getCurrencyInstance(); - } else if (PATTERN_PERCENT.equalsIgnoreCase(pattern)) { - numberFormat = NumberFormat.getPercentInstance(); - } else { - numberFormat = new DecimalFormat(pattern); - numberFormat.setParseIntegerOnly(true); - } - } - - @Nullable - @Override - public String format(@Nullable Short number) { - return number == null ? null : numberFormat.format(number); - } - - @Nullable - @Override - public Short parse(@Nullable String str) throws ParseException { - if (isBlank(str)) return null; - try { - return numberFormat.parse(str).shortValue(); - } catch (java.text.ParseException e) { - throw new ParseException(e); - } - } -} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/resources/ResourceResolver.java b/subprojects/griffon-core/src/main/java/griffon/core/resources/ResourceResolver.java index 77388074220..434296492a1 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/resources/ResourceResolver.java +++ b/subprojects/griffon-core/src/main/java/griffon/core/resources/ResourceResolver.java @@ -202,7 +202,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe T resolveResourceConverted(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale, @Nonnull Class type) throws NoSuchResourceException; /** - * Try to resolve the resource. The value is converted to type T if found using a {@code PropertyEditor}. + * Try to resolve the resource. The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a @@ -218,7 +218,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe T resolveResourceConverted(@Nonnull String key, @Nonnull List args, @Nonnull Class type) throws NoSuchResourceException; /** - * Try to resolve the resource. The value is converted to type T if found using a {@code PropertyEditor}. + * Try to resolve the resource. The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{0}" within a @@ -252,7 +252,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe /** * Try to resolve the resource. Returns default value if no resource was found. - * The value is converted to type T if found using a {@code PropertyEditor}. + * The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{0}" @@ -269,7 +269,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe /** * Try to resolve the resource. Returns default value if no resource was found. - * The value is converted to type T if found using a {@code PropertyEditor}. + * The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{0}" @@ -286,7 +286,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe T resolveResourceConverted(@Nonnull String key, @Nonnull List args, @Nonnull Locale locale, @Nullable T defaultValue, @Nonnull Class type); /** - * Try to resolve the resource. The value is converted to type T if found using a {@code PropertyEditor}. + * Try to resolve the resource. The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{:key}" @@ -302,7 +302,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe T resolveResourceConverted(@Nonnull String key, @Nonnull Map args, @Nonnull Class type) throws NoSuchResourceException; /** - * Try to resolve the resource. The value is converted to type T if found using a {@code PropertyEditor}. + * Try to resolve the resource. The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{:key}" @@ -320,7 +320,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe /** * Try to resolve the resource. Returns default value if no resource was found. - * The value is converted to type T if found using a {@code PropertyEditor}. + * The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{:key}" @@ -337,7 +337,7 @@ public interface ResourceResolver extends javax.application.resources.ResourceRe /** * Try to resolve the resource. Returns default value if no resource was found. - * The value is converted to type T if found using a {@code PropertyEditor}. + * The value is converted to type T if found using a {@code Converter}. * * @param key Key to lookup, such as 'sample.SampleModel.icon' * @param args Arguments that will be filled in for params within the resource (params look like "{:key}" diff --git a/subprojects/griffon-core/src/main/java/griffon/inject/MVCMember.java b/subprojects/griffon-core/src/main/java/griffon/inject/MVCMember.java index 60b08437abd..061abd99d1b 100644 --- a/subprojects/griffon-core/src/main/java/griffon/inject/MVCMember.java +++ b/subprojects/griffon-core/src/main/java/griffon/inject/MVCMember.java @@ -17,10 +17,9 @@ */ package griffon.inject; -import griffon.core.editors.PropertyEditorResolver; - +import javax.application.converter.Converter; +import javax.application.converter.NoopConverter; import javax.inject.Qualifier; -import java.beans.PropertyEditor; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -38,5 +37,5 @@ public @interface MVCMember { String format() default ""; - Class editor() default PropertyEditorResolver.NoopPropertyEditor.class; + Class converter() default NoopConverter.class; } diff --git a/subprojects/griffon-core/src/main/java/griffon/util/TypeUtils.java b/subprojects/griffon-core/src/main/java/griffon/util/TypeUtils.java index bcc7e738d70..87fbc6d6496 100644 --- a/subprojects/griffon-core/src/main/java/griffon/util/TypeUtils.java +++ b/subprojects/griffon-core/src/main/java/griffon/util/TypeUtils.java @@ -17,14 +17,11 @@ */ package griffon.util; -import griffon.core.editors.ExtendedPropertyEditor; -import griffon.core.editors.PropertyEditorResolver; import griffon.exceptions.GriffonException; import griffon.exceptions.TypeConversionException; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; @@ -36,7 +33,6 @@ import java.util.Map; import java.util.Set; -import static griffon.util.GriffonNameUtils.isNotBlank; import static java.util.Objects.requireNonNull; /** @@ -46,7 +42,6 @@ * @since 2.0.0 */ public final class TypeUtils { - private static final String ERROR_VALUE_NULL = "Argument 'value' must not be null"; private TypeUtils() { @@ -229,15 +224,20 @@ public static T convertValue(@Nonnull Class targetType, @Nonnull Object v } } + /* PropertyEditor targetEditor = resolveTargetPropertyEditor(targetType, format); if (targetEditor != null) { targetEditor.setValue(value); return (T) targetEditor.getValue(); } + */ throw new TypeConversionException(value, targetType); } + // TODO: FIX ME! + + /* @Nullable private static PropertyEditor resolveTargetPropertyEditor(@Nonnull Class targetType, @Nullable String format) { PropertyEditor editor = doResolveTargetPropertyEditor(targetType); @@ -251,6 +251,7 @@ private static PropertyEditor resolveTargetPropertyEditor(@Nonnull Class private static PropertyEditor doResolveTargetPropertyEditor(@Nonnull Class targetType) { return PropertyEditorResolver.findEditor(targetType); } + */ public static boolean isBoolean(@Nonnull Class type) { return Boolean.class == type || Boolean.TYPE == type; diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/AbstractContext.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/AbstractContext.java index 791f731be39..f791922cdd4 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/AbstractContext.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/AbstractContext.java @@ -23,13 +23,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; import java.beans.PropertyDescriptor; -import java.beans.PropertyEditor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import static griffon.core.editors.PropertyEditorResolver.findEditor; import static griffon.util.AnnotationUtils.annotationsOfMethodParameter; import static griffon.util.AnnotationUtils.findAnnotation; import static griffon.util.AnnotationUtils.nameFor; @@ -48,9 +48,11 @@ * @since 2.2.0 */ public abstract class AbstractContext implements Context { + protected final ConverterRegistry converterRegistry; protected Context parentContext; - public AbstractContext(@Nullable Context parentContext) { + public AbstractContext(@Nonnull ConverterRegistry converterRegistry, @Nullable Context parentContext) { + this.converterRegistry = requireNonNull(converterRegistry, "Argument 'converterRegistry' must not be null"); this.parentContext = parentContext; } @@ -207,9 +209,10 @@ protected T convertValue(@Nullable Object value, @Nonnull Class type) { if (type.isAssignableFrom(value.getClass())) { return (T) value; } else { - PropertyEditor editor = findEditor(type); - editor.setValue(value); - return (T) editor.getValue(); + Converter converter = converterRegistry.findConverter(type); + if (null != converter) { + return converter.fromObject(value); + } } } return null; diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultApplicationConfigurer.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultApplicationConfigurer.java index 06a963c7816..6051fc5a34f 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultApplicationConfigurer.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultApplicationConfigurer.java @@ -27,13 +27,11 @@ import griffon.core.artifact.ArtifactManager; import griffon.core.artifact.GriffonController; import griffon.core.controller.ActionHandler; -import griffon.core.editors.PropertyEditorResolver; import griffon.core.env.Lifecycle; import griffon.core.event.EventHandler; import griffon.core.injection.Injector; import griffon.core.mvc.MVCGroupConfiguration; import griffon.core.resources.ResourceInjector; -import griffon.util.ServiceLoaderUtils; import org.codehaus.griffon.runtime.core.controller.NoopActionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,14 +40,12 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; import javax.inject.Inject; -import java.beans.PropertyEditor; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import static griffon.core.GriffonExceptionHandler.sanitize; import static griffon.util.AnnotationUtils.named; import static griffon.util.AnnotationUtils.sortByDependencies; import static java.util.Collections.singletonList; @@ -115,7 +111,6 @@ protected void doInitialize() { event(ApplicationEvent.BOOTSTRAP_START, singletonList(application)); - initializePropertyEditors(); initializeResourcesInjector(); initializeConfigurationManager(); runLifecycleHandler(Lifecycle.INITIALIZE); @@ -140,42 +135,6 @@ protected void event(@Nonnull ApplicationEvent event, @Nullable List args) { application.getEventRouter().publishEvent(event.getName(), args); } - protected void initializePropertyEditors() { - ServiceLoaderUtils.load(applicationClassLoader().get(), "META-INF/editors/", PropertyEditor.class, (classLoader, type, line) -> { - try { - String[] parts = line.trim().split("="); - Class targetType = loadClass(parts[0].trim(), classLoader); - Class editorClass = (Class) loadClass(parts[1].trim(), classLoader); - - // Editor must have a no-args constructor - // CCE means the class can not be used - editorClass.newInstance(); - PropertyEditorResolver.registerEditor(targetType, editorClass); - LOG.debug("Registering {} as editor for {}", editorClass.getName(), targetType.getName()); - } catch (Exception e) { - if (LOG.isWarnEnabled()) { - LOG.warn("Could not load " + type.getName() + " with " + line, sanitize(e)); - } - } - }); - - Class[][] pairs = new Class[][]{ - new Class[]{Boolean.class, Boolean.TYPE}, - new Class[]{Byte.class, Byte.TYPE}, - new Class[]{Short.class, Short.TYPE}, - new Class[]{Integer.class, Integer.TYPE}, - new Class[]{Long.class, Long.TYPE}, - new Class[]{Float.class, Float.TYPE}, - new Class[]{Double.class, Double.TYPE} - }; - - for (Class[] pair : pairs) { - PropertyEditor editor = PropertyEditorResolver.findEditor(pair[0]); - LOG.debug("Registering {} as editor for {}", editor.getClass().getName(), pair[1].getName()); - PropertyEditorResolver.registerEditor(pair[1], editor.getClass()); - } - } - protected void initializeResourcesInjector() { final ResourceInjector injector = application.getResourceInjector(); application.getEventRouter().addEventListener(ApplicationEvent.NEW_INSTANCE.getName(), args -> injector.injectResources(args[1])); diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContext.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContext.java index cfdaee5f1ca..abe6124aef9 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContext.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContext.java @@ -21,6 +21,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -36,12 +37,12 @@ public class DefaultContext extends AbstractContext { protected static final String ERROR_KEY_BLANK = "Argument 'key' must not be blank"; private final Map attributes = new ConcurrentHashMap<>(); - public DefaultContext() { - this(null); + public DefaultContext(@Nonnull ConverterRegistry converterRegistry) { + this(converterRegistry,null); } - public DefaultContext(@Nullable Context parentContext) { - super(parentContext); + public DefaultContext(@Nonnull ConverterRegistry converterRegistry, @Nullable Context parentContext) { + super(converterRegistry, parentContext); } @Nullable diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContextFactory.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContextFactory.java index 6210668c052..0d20098854e 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContextFactory.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultContextFactory.java @@ -22,15 +22,20 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; +import javax.inject.Inject; /** * @author Andres Almiray * @since 2.4.0 */ public class DefaultContextFactory implements ContextFactory { + @Inject + private ConverterRegistry converterRegistry; + @Nonnull @Override public Context create(@Nullable Context parentContext) { - return new DefaultContext(parentContext); + return new DefaultContext(converterRegistry, parentContext); } } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContext.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContext.java index e7f7efde3e4..6f14b6ee41c 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContext.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContext.java @@ -23,6 +23,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -43,12 +44,12 @@ public class DefaultObservableContext extends DefaultContext implements Observab } }; - public DefaultObservableContext() { - super(); + public DefaultObservableContext(@Nonnull ConverterRegistry converterRegistry) { + super(converterRegistry); } - public DefaultObservableContext(@Nullable Context parentContext) { - super(parentContext); + public DefaultObservableContext(@Nonnull ConverterRegistry converterRegistry, @Nullable Context parentContext) { + super(converterRegistry, parentContext); if (parentContext instanceof ObservableContext) { ObservableContext observableParent = (ObservableContext) parentContext; observableParent.addContextEventListener(parentListener); diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContextFactory.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContextFactory.java index 64521f41d51..932ff428c1f 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContextFactory.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/DefaultObservableContextFactory.java @@ -22,15 +22,20 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; +import javax.inject.Inject; /** * @author Andres Almiray * @since 2.5.0 */ public class DefaultObservableContextFactory implements ContextFactory { + @Inject + private ConverterRegistry converterRegistry; + @Nonnull @Override public Context create(@Nullable Context parentContext) { - return new DefaultObservableContext(parentContext); + return new DefaultObservableContext(converterRegistry, parentContext); } } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfiguration.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfiguration.java index 9059c1c9e75..cb137bd417b 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfiguration.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfiguration.java @@ -18,16 +18,15 @@ package org.codehaus.griffon.runtime.core.configuration; import griffon.core.Configuration; -import griffon.core.editors.ExtendedPropertyEditor; +import org.kordamp.jsr377.converter.FormattingConverter; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; import java.util.Properties; -import static griffon.core.editors.PropertyEditorResolver.findEditor; import static griffon.util.CollectionUtils.toProperties; -import static griffon.util.GriffonNameUtils.requireNonBlank; import static griffon.util.TypeUtils.castToBoolean; import static griffon.util.TypeUtils.castToDouble; import static griffon.util.TypeUtils.castToFloat; @@ -43,6 +42,18 @@ public abstract class AbstractConfiguration implements Configuration { private static final String ERROR_TYPE_NULL = "Argument 'type' must not be null"; private static final String ERROR_FORMAT_BLANK = "Argument 'format' must not be blank"; + protected ConverterRegistry converterRegistry; + + public AbstractConfiguration(@Nonnull ConverterRegistry converterRegistry) { + this.converterRegistry = requireNonNull(converterRegistry, "Argument 'converterRegistry' must not be null"); + } + + @Nonnull + @Override + public ConverterRegistry getConverterRegistry() { + return converterRegistry; + } + @Nullable @Override @SuppressWarnings("unchecked") @@ -53,7 +64,7 @@ public T get(@Nonnull String key, @Nullable T defaultValue) { @Nullable @Override - public Object getAt(@Nonnull String key) { + public T getAt(@Nonnull String key) { return get(key); } @@ -119,21 +130,6 @@ public String getAsString(@Nonnull String key) { return getAsString(key, null); } - @Nullable - @Override - @SuppressWarnings("unchecked") - public T getAs(@Nonnull String key) { - return (T) get(key); - } - - @Nullable - @Override - @SuppressWarnings("unchecked") - public T getAs(@Nonnull String key, @Nullable T defaultValue) { - Object value = get(key); - return (T) (value != null ? value : defaultValue); - } - @Nullable @Override public T getConverted(@Nonnull String key, @Nonnull Class type) { @@ -168,9 +164,10 @@ protected T convertValue(@Nullable Object value, @Nonnull Class type) { if (type.isAssignableFrom(value.getClass())) { return (T) value; } else { - PropertyEditor editor = findEditor(type); - editor.setValue(value); - return (T) editor.getValue(); + Converter converter = converterRegistry.findConverter(type); + if (null != converter) { + return converter.fromObject(value); + } } } return null; @@ -182,13 +179,13 @@ protected T convertValue(@Nullable Object value, @Nonnull Class type, @No if (type.isAssignableFrom(value.getClass())) { return (T) value; } else { - PropertyEditor editor = findEditor(type); - if (editor instanceof ExtendedPropertyEditor) { - requireNonBlank(format, ERROR_FORMAT_BLANK); - ((ExtendedPropertyEditor) editor).setFormat(format); + Converter converter = converterRegistry.findConverter(type); + if (null != converter) { + if (converter instanceof FormattingConverter) { + ((FormattingConverter) converter).setFormat(format); + } + return converter.fromObject(value); } - editor.setValue(value); - return (T) editor.getValue(); } } return null; diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfigurationManager.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfigurationManager.java index 63f29bc149d..29884d78e60 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfigurationManager.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractConfigurationManager.java @@ -21,26 +21,26 @@ import griffon.core.Configuration; import griffon.core.GriffonApplication; import griffon.core.configuration.ConfigurationManager; -import griffon.core.configuration.Configured; -import griffon.core.editors.ExtendedPropertyEditor; -import griffon.core.editors.PropertyEditorResolver; import griffon.exceptions.GriffonException; import griffon.util.GriffonClassUtils; +import org.kordamp.jsr377.converter.FormattingConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.PostConstruct; +import javax.application.configuration.Configured; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; +import javax.application.converter.NoopConverter; import javax.inject.Inject; import java.beans.PropertyDescriptor; -import java.beans.PropertyEditor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.LinkedHashMap; import java.util.Map; -import static griffon.core.editors.PropertyEditorResolver.findEditor; import static griffon.util.GriffonNameUtils.isNotBlank; import static java.lang.reflect.Modifier.isStatic; import static java.util.Objects.requireNonNull; @@ -59,6 +59,9 @@ public abstract class AbstractConfigurationManager implements ConfigurationManag @Inject protected GriffonApplication application; + @Inject + protected ConverterRegistry converterRegistry; + @PostConstruct private void initialize() { requireNonNull(application, "Argument 'application' cannot ne null"); @@ -98,7 +101,7 @@ protected void harvestDescriptors(@Nonnull Class instanceClass, @Nonnull Clas String defaultValue = annotation.defaultValue(); defaultValue = Configured.NO_VALUE.equals(defaultValue) ? null : defaultValue; String format = annotation.format(); - Class editor = annotation.editor(); + Class converter = annotation.converter(); if (LOG.isDebugEnabled()) { LOG.debug("Property " + propertyName + @@ -109,7 +112,7 @@ protected void harvestDescriptors(@Nonnull Class instanceClass, @Nonnull Clas "', format='" + format + "'] is marked for configuration injection."); } - descriptors.put(propertyName, new MethodConfigurationDescriptor(writeMethod, configuration, key, defaultValue, format, editor)); + descriptors.put(propertyName, new MethodConfigurationDescriptor(writeMethod, configuration, key, defaultValue, format, converter)); } for (Field field : currentClass.getDeclaredFields()) { @@ -126,7 +129,7 @@ protected void harvestDescriptors(@Nonnull Class instanceClass, @Nonnull Clas String defaultValue = annotation.defaultValue(); defaultValue = Configured.NO_VALUE.equals(defaultValue) ? null : defaultValue; String format = annotation.format(); - Class editor = annotation.editor(); + Class converter = annotation.converter(); if (LOG.isDebugEnabled()) { LOG.debug("Field " + fqFieldName + @@ -138,7 +141,7 @@ protected void harvestDescriptors(@Nonnull Class instanceClass, @Nonnull Clas "'] is marked for configuration injection."); } - descriptors.put(field.getName(), new FieldConfigurationDescriptor(field, configuration, key, defaultValue, format, editor)); + descriptors.put(field.getName(), new FieldConfigurationDescriptor(field, configuration, key, defaultValue, format, converter)); } } @@ -148,8 +151,8 @@ protected void doConfigurationInjection(@Nonnull Object instance, @Nonnull Map type, @Nonnull Object value, @Nullable String format, @Nonnull Class editor) { + protected Object convertValue(@Nonnull Class type, @Nonnull Object value, @Nullable String format, @Nonnull Class converter) { requireNonNull(type, ERROR_TYPE_NULL); requireNonNull(value, ERROR_VALUE_NULL); - PropertyEditor propertyEditor = resolvePropertyEditor(type, format, editor); - if (isNoopPropertyEditor(propertyEditor.getClass())) { return value; } + Converter resolvedConverter = resolveConverter(type, format, converter); + if (isNoopConverter(resolvedConverter.getClass())) { return value; } if (value instanceof CharSequence) { - propertyEditor.setAsText(String.valueOf(value)); + return resolvedConverter.fromObject(String.valueOf(value)); } else { - propertyEditor.setValue(value); + return resolvedConverter.fromObject(value); } - return propertyEditor.getValue(); } @Nonnull - protected PropertyEditor resolvePropertyEditor(@Nonnull Class type, @Nullable String format, @Nonnull Class editor) { + protected Converter resolveConverter(@Nonnull Class type, @Nullable String format, @Nonnull Class converter) { requireNonNull(type, ERROR_TYPE_NULL); - PropertyEditor propertyEditor = null; - if (isNoopPropertyEditor(editor)) { - propertyEditor = findEditor(type); + Converter resolvedConverter = null; + if (isNoopConverter(converter)) { + resolvedConverter = converterRegistry.findConverter(type); } else { try { - propertyEditor = editor.newInstance(); + resolvedConverter = converter.newInstance(); } catch (InstantiationException | IllegalAccessException e) { - throw new GriffonException("Could not instantiate editor with " + editor, e); + throw new GriffonException("Could not instantiate converter with " + converter, e); } } - if (propertyEditor instanceof ExtendedPropertyEditor) { - ((ExtendedPropertyEditor) propertyEditor).setFormat(format); + if (resolvedConverter instanceof FormattingConverter) { + ((FormattingConverter) resolvedConverter).setFormat(format); } - return propertyEditor; + return resolvedConverter; } - protected boolean isNoopPropertyEditor(@Nonnull Class editor) { - return PropertyEditorResolver.NoopPropertyEditor.class.isAssignableFrom(editor); + protected boolean isNoopConverter(@Nonnull Class converter) { + return NoopConverter.class.isAssignableFrom(converter); } } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractMapConfiguration.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractMapConfiguration.java index ef7886c1c12..a6625901728 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractMapConfiguration.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/AbstractMapConfiguration.java @@ -21,6 +21,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; import java.util.Collections; import java.util.Map; import java.util.MissingResourceException; @@ -39,7 +40,8 @@ public abstract class AbstractMapConfiguration extends AbstractConfiguration { private static final String ERROR_MAP_NULL = "Argument 'map' must not be null"; private final Map map; - protected AbstractMapConfiguration(@Nonnull Map map) { + protected AbstractMapConfiguration(@Nonnull ConverterRegistry converterRegistry, @Nonnull Map map) { + super(converterRegistry); this.map = requireNonNull(map, ERROR_MAP_NULL); } @@ -67,7 +69,7 @@ protected void initialize(@Nonnull Map entries) { @Nullable @Override - public Object get(@Nonnull String key) { + public T get(@Nonnull String key) { try { return getConfigValue(map, key); } catch (MissingResourceException mre) { diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecorator.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecorator.java index 297e193aec4..ad0c2337bd1 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecorator.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecorator.java @@ -21,12 +21,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; -import static griffon.core.editors.PropertyEditorResolver.findEditor; import static griffon.util.CollectionUtils.toProperties; import static griffon.util.TypeUtils.castToBoolean; import static griffon.util.TypeUtils.castToDouble; @@ -46,9 +46,15 @@ public ConfigurationDecorator(@Nonnull Configuration delegate) { this.delegate = requireNonNull(delegate, "Argument 'delegate' must not be null."); } + @Nonnull + @Override + public ConverterRegistry getConverterRegistry() { + return delegate.getConverterRegistry(); + } + @Override @Nullable - public Object get(@Nonnull String key) { + public T get(@Nonnull String key) { return delegate.get(key); } @@ -61,7 +67,7 @@ public T get(@Nonnull String key, @Nullable T defaultValue) { @Nullable @Override - public Object getAt(@Nonnull String key) { + public T getAt(@Nonnull String key) { return get(key); } @@ -133,18 +139,6 @@ public String getAsString(@Nonnull String key, @Nullable String defaultValue) { return delegate.getAsString(key, defaultValue); } - @Nullable - @Override - public T getAs(@Nonnull String key) { - return delegate.getAs(key); - } - - @Nullable - @Override - public T getAs(@Nonnull String key, @Nullable T defaultValue) { - return delegate.getAs(key, defaultValue); - } - @Nullable @Override public T getConverted(@Nonnull String key, @Nonnull Class type) { @@ -198,9 +192,10 @@ protected T convertValue(@Nullable Object value, @Nonnull Class type) { if (type.isAssignableFrom(value.getClass())) { return (T) value; } else { - PropertyEditor editor = findEditor(type); - editor.setValue(value); - return (T) editor.getValue(); + Converter converter = getConverterRegistry().findConverter(type); + if (null != converter) { + return converter.fromObject(value); + } } } return null; diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDescriptor.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDescriptor.java index c8f46e3655b..340778f4d59 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDescriptor.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ConfigurationDescriptor.java @@ -19,7 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import static griffon.util.GriffonNameUtils.requireNonBlank; @@ -32,14 +32,14 @@ public abstract class ConfigurationDescriptor { private final String key; private final String defaultValue; private final String format; - private final Class editor; + private final Class converter; - public ConfigurationDescriptor(@Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class editor) { + public ConfigurationDescriptor(@Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class converter) { this.configuration = configuration; this.key = requireNonBlank(key, "Argument 'key' must not be blank"); this.defaultValue = defaultValue; this.format = format; - this.editor = editor; + this.converter = converter; } @Nonnull @@ -63,8 +63,8 @@ public String getFormat() { } @Nonnull - public Class getEditor() { - return editor; + public Class getConverter() { + return converter; } @Nonnull diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/DelegatingMutableConfiguration.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/DelegatingMutableConfiguration.java index ce5684c4d13..3a02ccf7c8f 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/DelegatingMutableConfiguration.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/DelegatingMutableConfiguration.java @@ -62,11 +62,11 @@ public void set(@Nonnull String key, @Nonnull Object value) { @Nullable @Override - public Object remove(@Nonnull String key) { + public T remove(@Nonnull String key) { requireNonBlank(key, ERROR_KEY_BLANK); if (mutableKeyValues.containsKey(key)) { removedKeys.add(key); - return mutableKeyValues.remove(key); + return (T) mutableKeyValues.remove(key); } else if (!removedKeys.contains(key) && delegate.containsKey(key)) { removedKeys.add(key); return delegate.get(key); @@ -74,13 +74,6 @@ public Object remove(@Nonnull String key) { return null; } - @Nullable - @Override - @SuppressWarnings("unchecked") - public T removeAs(@Nonnull String key) { - return (T) remove(key); - } - @Nullable @Override @SuppressWarnings("unchecked") @@ -107,7 +100,7 @@ public ResourceBundle asResourceBundle() { @Nullable @Override - public Object get(@Nonnull String key) { + public T get(@Nonnull String key) { requireNonBlank(key, ERROR_KEY_BLANK); try { return getConfigValue(mutableKeyValues, key); diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldConfigurationDescriptor.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldConfigurationDescriptor.java index 815218afa57..e43148e1357 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldConfigurationDescriptor.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldConfigurationDescriptor.java @@ -19,7 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import java.lang.reflect.Field; import static java.util.Objects.requireNonNull; @@ -31,8 +31,8 @@ public class FieldConfigurationDescriptor extends ConfigurationDescriptor { private final Field field; - public FieldConfigurationDescriptor(@Nonnull Field field, @Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class editor) { - super(configuration, key, defaultValue, format, editor); + public FieldConfigurationDescriptor(@Nonnull Field field, @Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class converter) { + super(configuration, key, defaultValue, format, converter); this.field = requireNonNull(field, "Argument 'field' must not be null"); } @@ -43,7 +43,7 @@ public Field getField() { @Nonnull public InjectionPoint asInjectionPoint() { - return new FieldInjectionPoint(field, getConfiguration(), getKey(), getFormat(), getEditor()); + return new FieldInjectionPoint(field, getConfiguration(), getKey(), getFormat(), getConverter()); } @Override @@ -54,7 +54,7 @@ public String toString() { sb.append(", key='").append(getKey()).append('\''); sb.append(", defaultValue='").append(getDefaultValue()).append('\''); sb.append(", format='").append(getFormat()).append('\''); - sb.append(", editor='").append(getEditor()).append('\''); + sb.append(", converter='").append(getConverter()).append('\''); sb.append('}'); return sb.toString(); } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldInjectionPoint.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldInjectionPoint.java index 2052d899043..dd04fadcc49 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldInjectionPoint.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/FieldInjectionPoint.java @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import java.lang.reflect.Field; import static griffon.core.GriffonExceptionHandler.sanitize; @@ -39,8 +39,8 @@ public class FieldInjectionPoint extends InjectionPoint { private final Field field; - public FieldInjectionPoint(@Nonnull Field field, @Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class editor) { - super(configuration, key, format, editor); + public FieldInjectionPoint(@Nonnull Field field, @Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class converter) { + super(configuration, key, format, converter); this.field = requireNonNull(field, "Argument 'field' must not be null"); } @@ -76,7 +76,7 @@ public String toString() { sb.append(", configuration='").append(getConfiguration()).append('\''); sb.append(", key='").append(getKey()).append('\''); sb.append(", format='").append(getFormat()).append('\''); - sb.append(", editor='").append(getEditor()).append('\''); + sb.append(", converter='").append(getConverter()).append('\''); sb.append('}'); return sb.toString(); } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/InjectionPoint.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/InjectionPoint.java index 2c48387bda9..269046ce1a0 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/InjectionPoint.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/InjectionPoint.java @@ -18,7 +18,7 @@ package org.codehaus.griffon.runtime.core.configuration; import javax.annotation.Nonnull; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import static griffon.util.GriffonNameUtils.requireNonBlank; @@ -30,13 +30,13 @@ public abstract class InjectionPoint { private final String configuration; private final String key; private final String format; - private final Class editor; + private final Class converter; - public InjectionPoint(@Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class editor) { + public InjectionPoint(@Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class converter) { this.configuration = configuration; this.key = requireNonBlank(key, "Argument 'key' must not be blank"); this.format = format; - this.editor = editor; + this.converter = converter; } @Nonnull @@ -55,8 +55,8 @@ public String getFormat() { } @Nonnull - public Class getEditor() { - return editor; + public Class getConverter() { + return converter; } public abstract void setValue(@Nonnull Object instance, Object value); diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodConfigurationDescriptor.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodConfigurationDescriptor.java index d32b6185cca..e63ed563010 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodConfigurationDescriptor.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodConfigurationDescriptor.java @@ -19,7 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import java.lang.reflect.Method; import static java.util.Objects.requireNonNull; @@ -31,8 +31,8 @@ public class MethodConfigurationDescriptor extends ConfigurationDescriptor { private final Method writeMethod; - public MethodConfigurationDescriptor(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class editor) { - super(configuration, key, defaultValue, format, editor); + public MethodConfigurationDescriptor(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nullable String defaultValue, @Nonnull String format, @Nonnull Class converter) { + super(configuration, key, defaultValue, format, converter); this.writeMethod = requireNonNull(writeMethod, "Argument 'writeMethod' must not be null"); } @@ -43,7 +43,7 @@ public Method getWriteMethod() { @Nonnull public InjectionPoint asInjectionPoint() { - return new MethodInjectionPoint(writeMethod, getConfiguration(), getKey(), getFormat(), getEditor()); + return new MethodInjectionPoint(writeMethod, getConfiguration(), getKey(), getFormat(), getConverter()); } @Override @@ -54,7 +54,7 @@ public String toString() { sb.append(", key='").append(getKey()).append('\''); sb.append(", defaultValue='").append(getDefaultValue()).append('\''); sb.append(", format='").append(getFormat()).append('\''); - sb.append(", editor='").append(getEditor()).append('\''); + sb.append(", converter='").append(getConverter()).append('\''); sb.append('}'); return sb.toString(); } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodInjectionPoint.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodInjectionPoint.java index 318e720bfe0..55e10507bcb 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodInjectionPoint.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/MethodInjectionPoint.java @@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -38,8 +38,8 @@ public class MethodInjectionPoint extends InjectionPoint { private final Method writeMethod; private final Class type; - public MethodInjectionPoint(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class editor) { - super(configuration, key, format, editor); + public MethodInjectionPoint(@Nonnull Method writeMethod, @Nonnull String configuration, @Nonnull String key, @Nonnull String format, @Nonnull Class converter) { + super(configuration, key, format, converter); this.writeMethod = requireNonNull(writeMethod, "Argument 'writeMethod' must not be null"); this.type = writeMethod.getParameterTypes()[0]; } @@ -73,7 +73,7 @@ public String toString() { sb.append(", configuration='").append(getConfiguration()).append('\''); sb.append(", key='").append(getKey()).append('\''); sb.append(", format='").append(getFormat()).append('\''); - sb.append(", editor='").append(getEditor()).append('\''); + sb.append(", converter='").append(getConverter()).append('\''); sb.append('}'); return sb.toString(); } diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfiguration.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfiguration.java index 765b83af901..b6062ca2515 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfiguration.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfiguration.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConverterRegistry; import javax.inject.Inject; import java.util.Enumeration; import java.util.LinkedHashMap; @@ -41,7 +42,8 @@ public class ResourceBundleConfiguration extends AbstractConfiguration { private final Map flatMap = new LinkedHashMap<>(); @Inject - public ResourceBundleConfiguration(@Nonnull ResourceBundle resourceBundle) { + public ResourceBundleConfiguration(@Nonnull ConverterRegistry converterRegistry, @Nonnull ResourceBundle resourceBundle) { + super(converterRegistry); this.resourceBundle = requireNonNull(resourceBundle, "Argument 'resourceBundle' must not be null"); Enumeration keys = resourceBundle.getKeys(); while (keys.hasMoreElements()) { @@ -68,7 +70,7 @@ public ResourceBundle asResourceBundle() { @Nullable @Override - public Object get(@Nonnull String key) { + public T get(@Nonnull String key) { try { return getConfigValue(resourceBundle, key); } catch (MissingResourceException mre) { diff --git a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfigurationProvider.java b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfigurationProvider.java index 96a07b05771..6d38be3c851 100644 --- a/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfigurationProvider.java +++ b/subprojects/griffon-core/src/main/java/org/codehaus/griffon/runtime/core/configuration/ResourceBundleConfigurationProvider.java @@ -19,6 +19,7 @@ import griffon.core.Configuration; +import javax.application.converter.ConverterRegistry; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; @@ -37,11 +38,14 @@ public class ResourceBundleConfigurationProvider implements Provider type; protected final String format; - protected final Class editor; + protected final Class converter; - protected InjectionPoint(String name, boolean nullable, Kind kind, Class type, String format, Class editor) { + protected InjectionPoint(ConverterRegistry converterRegistry, String name, boolean nullable, Kind kind, Class type, String format, Class converter) { + this.converterRegistry = converterRegistry; this.name = name; this.nullable = nullable; this.kind = kind; this.type = type; this.format = format; - this.editor = editor; + this.converter = converter; } protected enum Kind { @@ -342,51 +346,50 @@ protected enum Kind { protected abstract void apply(@Nonnull MVCGroup group, @Nonnull String memberType, @Nonnull Object instance, @Nonnull Map args); @Nonnull - protected Object convertValue(@Nonnull Class type, @Nonnull Object value, @Nullable String format, @Nonnull Class editor) { + protected Object convertValue(@Nonnull Class type, @Nonnull Object value, @Nullable String format, @Nonnull Class converter) { requireNonNull(type, ERROR_TYPE_NULL); requireNonNull(value, ERROR_VALUE_NULL); - PropertyEditor propertyEditor = resolvePropertyEditor(type, format, editor); - if (isNoopPropertyEditor(propertyEditor.getClass())) { return value; } + Converter resolvedConverter = resolveConverter(type, format, converter); + if (isNoopConverter(resolvedConverter.getClass())) { return value; } if (value instanceof CharSequence) { - propertyEditor.setAsText(String.valueOf(value)); + return resolvedConverter.fromObject(String.valueOf(value)); } else { - propertyEditor.setValue(value); + return resolvedConverter.fromObject(value); } - return propertyEditor.getValue(); } @Nonnull - protected PropertyEditor resolvePropertyEditor(@Nonnull Class type, @Nullable String format, @Nonnull Class editor) { + protected Converter resolveConverter(@Nonnull Class type, @Nullable String format, @Nonnull Class converter) { requireNonNull(type, ERROR_TYPE_NULL); - PropertyEditor propertyEditor = null; - if (isNoopPropertyEditor(editor)) { - propertyEditor = findEditor(type); + Converter resolvedConverter = null; + if (isNoopConverter(converter)) { + resolvedConverter = converterRegistry.findConverter(type); } else { try { - propertyEditor = editor.newInstance(); + resolvedConverter = converter.newInstance(); } catch (InstantiationException | IllegalAccessException e) { - throw new GriffonException("Could not instantiate editor with " + editor, e); + throw new GriffonException("Could not instantiate converter with " + converter, e); } } - if (propertyEditor instanceof ExtendedPropertyEditor) { - ((ExtendedPropertyEditor) propertyEditor).setFormat(format); + if (resolvedConverter instanceof FormattingConverter) { + ((FormattingConverter) resolvedConverter).setFormat(format); } - return propertyEditor; + return resolvedConverter; } - protected boolean isNoopPropertyEditor(@Nonnull Class editor) { - return PropertyEditorResolver.NoopPropertyEditor.class.isAssignableFrom(editor); + protected boolean isNoopConverter(@Nonnull Class converter) { + return NoopConverter.class.isAssignableFrom(converter); } } protected static class FieldInjectionPoint extends InjectionPoint { protected final Field field; - protected FieldInjectionPoint(String name, boolean nullable, Kind kind, Class type, Field field, String format, Class editor) { - super(name, nullable, kind, type, format, editor); + protected FieldInjectionPoint(ConverterRegistry converterRegistry, String name, boolean nullable, Kind kind, Class type, Field field, String format, Class converter) { + super(converterRegistry, name, nullable, kind, type, format, converter); this.field = field; } @@ -420,8 +423,8 @@ protected void apply(@Nonnull MVCGroup group, @Nonnull String memberType, @Nonnu } } return; - } else if (kind == Kind.MEMBER && (!isNoopPropertyEditor(editor) || !type.isAssignableFrom(argValue.getClass()))) { - argValue = convertValue(type, argValue, format, editor); + } else if (kind == Kind.MEMBER && (!isNoopConverter(converter) || !type.isAssignableFrom(argValue.getClass()))) { + argValue = convertValue(type, argValue, format, converter); } setFieldValue(instance, name, argValue); @@ -438,8 +441,8 @@ protected void apply(@Nonnull MVCGroup group, @Nonnull String memberType, @Nonnu protected static class MethodInjectionPoint extends InjectionPoint { protected final Method method; - protected MethodInjectionPoint(String name, boolean nullable, Kind kind, Class type, Method method, String format, Class editor) { - super(name, nullable, kind, type, format, editor); + protected MethodInjectionPoint(ConverterRegistry converterRegistry, String name, boolean nullable, Kind kind, Class type, Method method, String format, Class converter) { + super(converterRegistry, name, nullable, kind, type, format, converter); this.method = method; } @@ -481,8 +484,8 @@ protected void apply(@Nonnull MVCGroup group, @Nonnull String memberType, @Nonnu } } return; - } else if (kind == Kind.MEMBER && (!isNoopPropertyEditor(editor) || !type.isAssignableFrom(argValue.getClass()))) { - argValue = convertValue(type, argValue, format, editor); + } else if (kind == Kind.MEMBER && (!isNoopConverter(converter) || !type.isAssignableFrom(argValue.getClass()))) { + argValue = convertValue(type, argValue, format, converter); } method.invoke(instance, argValue); @@ -516,16 +519,16 @@ protected void fillReferencedProperties(@Nonnull MVCGroup group, @Nonnull Map editor = resolveEditor(method); + Class converter = resolveEditor(method); Field field = fields.get(descriptor.getName()); if (field != null && kind == InjectionPoint.Kind.OTHER) { kind = resolveKind(field); nullable = field.getAnnotation(Nonnull.class) == null; type = field.getType(); format = resolveFormat(field); - editor = resolveEditor(field); + converter = resolveEditor(field); } - injectionPoints.put(descriptor.getName(), new MethodInjectionPoint(descriptor.getName(), nullable, kind, type, method, format, editor)); + injectionPoints.put(descriptor.getName(), new MethodInjectionPoint(converterRegistry, descriptor.getName(), nullable, kind, type, method, format, converter)); } for (Field field : getAllDeclaredFields(resolveMemberClass(member))) { @@ -535,8 +538,8 @@ protected void fillReferencedProperties(@Nonnull MVCGroup group, @Nonnull Map type = field.getType(); String format = resolveFormat(field); - Class editor = resolveEditor(field); - injectionPoints.put(field.getName(), new FieldInjectionPoint(field.getName(), nullable, kind, type, field, format, editor)); + Class converter = resolveEditor(field); + injectionPoints.put(field.getName(), new FieldInjectionPoint(converterRegistry, field.getName(), nullable, kind, type, field, format, converter)); } } @@ -579,11 +582,11 @@ protected String resolveFormat(@Nonnull AnnotatedElement element) { } @Nonnull - protected Class resolveEditor(@Nonnull AnnotatedElement element) { + protected Class resolveEditor(@Nonnull AnnotatedElement element) { if (isMvcMember(element)) { - return element.getAnnotation(MVCMember.class).editor(); + return element.getAnnotation(MVCMember.class).converter(); } - return PropertyEditorResolver.NoopPropertyEditor.class; + return NoopConverter.class; } protected boolean isContextual(AnnotatedElement element) { diff --git a/subprojects/griffon-core/src/main/resources/META-INF/editors/java.beans.PropertyEditor b/subprojects/griffon-core/src/main/resources/META-INF/editors/java.beans.PropertyEditor deleted file mode 100644 index 6a391aa91ac..00000000000 --- a/subprojects/griffon-core/src/main/resources/META-INF/editors/java.beans.PropertyEditor +++ /dev/null @@ -1,19 +0,0 @@ -java.io.File=griffon.core.editors.FilePropertyEditor -java.lang.String=griffon.core.editors.StringPropertyEditor -java.lang.Boolean=griffon.core.editors.BooleanPropertyEditor -java.lang.Byte=griffon.core.editors.BytePropertyEditor -java.lang.Short=griffon.core.editors.ShortPropertyEditor -java.lang.Integer=griffon.core.editors.IntegerPropertyEditor -java.lang.Long=griffon.core.editors.LongPropertyEditor -java.lang.Float=griffon.core.editors.FloatPropertyEditor -java.lang.Double=griffon.core.editors.DoublePropertyEditor -java.math.BigDecimal=griffon.core.editors.BigDecimalPropertyEditor -java.math.BigInteger=griffon.core.editors.BigIntegerPropertyEditor -java.net.URL=griffon.core.editors.URLPropertyEditor -java.net.URI=griffon.core.editors.URIPropertyEditor -java.time.LocalDate=griffon.core.editors.LocalDatePropertyEditor -java.time.LocalDateTime=griffon.core.editors.LocalDateTimePropertyEditor -java.time.LocalTime=griffon.core.editors.LocalTimePropertyEditor -java.util.Calendar=griffon.core.editors.CalendarPropertyEditor -java.util.Date=griffon.core.editors.DatePropertyEditor -java.util.Locale=griffon.core.editors.LocalePropertyEditor \ No newline at end of file diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/ContextSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/ContextSpec.groovy index 0302eb59daf..e1301b00012 100644 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/ContextSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/griffon/core/ContextSpec.groovy @@ -17,21 +17,23 @@ */ package griffon.core -import griffon.core.editors.IntegerPropertyEditor -import griffon.core.editors.PropertyEditorResolver import griffon.inject.Contextual import org.codehaus.griffon.runtime.core.DefaultContext +import org.kordamp.jsr377.converter.DefaultConverterRegistry +import org.kordamp.jsr377.converter.IntegerConverter import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConverterRegistry import javax.inject.Named @Unroll class ContextSpec extends Specification { - @Shared private Context ctx1 = new DefaultContext() - @Shared private Context ctx2 = new DefaultContext(ctx1) - @Shared private Context ctx3 = new DefaultContext(ctx1) + @Shared private ConverterRegistry converterRegistry = new DefaultConverterRegistry() + @Shared private Context ctx1 = new DefaultContext(converterRegistry) + @Shared private Context ctx2 = new DefaultContext(converterRegistry, ctx1) + @Shared private Context ctx3 = new DefaultContext(converterRegistry, ctx1) def setup() { ctx1['foo'] = 'foo' @@ -122,8 +124,8 @@ class ContextSpec extends Specification { def "Find values on context 1 using converted value"() { given: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) when: Integer val = ctx1.getConverted(key, type) @@ -132,7 +134,7 @@ class ContextSpec extends Specification { value == val cleanup: - PropertyEditorResolver.clear() + converterRegistry.clear() where: key | type || value @@ -156,8 +158,8 @@ class ContextSpec extends Specification { def "Remove values on context 1 using converted value"() { given: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) when: Integer val = ctx1.removeConverted(key, type) @@ -167,7 +169,7 @@ class ContextSpec extends Specification { value == val cleanup: - PropertyEditorResolver.clear() + converterRegistry.clear() where: key | type || value diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/ObservableContextSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/ObservableContextSpec.groovy index 53f5ab7b5fe..b3646a862a5 100644 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/ObservableContextSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/griffon/core/ObservableContextSpec.groovy @@ -17,20 +17,22 @@ */ package griffon.core -import griffon.core.editors.IntegerPropertyEditor -import griffon.core.editors.PropertyEditorResolver import org.codehaus.griffon.runtime.core.DefaultObservableContext +import org.kordamp.jsr377.converter.DefaultConverterRegistry +import org.kordamp.jsr377.converter.IntegerConverter import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll import javax.annotation.Nonnull +import javax.application.converter.ConverterRegistry @Unroll class ObservableContextSpec extends Specification { - @Shared private ObservableContext ctx1 = new DefaultObservableContext() - @Shared private ObservableContext ctx2 = new DefaultObservableContext(ctx1) - @Shared private ObservableContext ctx3 = new DefaultObservableContext(ctx1) + @Shared private ConverterRegistry converterRegistry = new DefaultConverterRegistry() + @Shared private ObservableContext ctx1 = new DefaultObservableContext(converterRegistry) + @Shared private ObservableContext ctx2 = new DefaultObservableContext(converterRegistry,ctx1) + @Shared private ObservableContext ctx3 = new DefaultObservableContext(converterRegistry, ctx1) def setup() { ctx1['foo'] = 'foo' @@ -195,8 +197,8 @@ class ObservableContextSpec extends Specification { when: ctx1.put('key', '1') - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) Integer converted = ctx1.removeConverted('key', Integer) then: @@ -207,7 +209,7 @@ class ObservableContextSpec extends Specification { listener.contextEvent.newValue == null cleanup: - PropertyEditorResolver.clear() + converterRegistry.clear() } void "listen to lateral context events"() { diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigDecimalPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigDecimalPropertyEditorSpec.groovy deleted file mode 100644 index 10ad5e9fcda..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigDecimalPropertyEditorSpec.groovy +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class BigDecimalPropertyEditorSpec extends PropertyEditorSpecSupport { - void "BigDecimal literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new BigDecimalPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | BigDecimal.ONE - '100%' | 'percent' | BigDecimal.ONE - '$1.00' | 'currency' | BigDecimal.ONE - BigDecimal.ONE | null | BigDecimal.ONE - BigInteger.ONE | null | BigDecimal.ONE - 1L | null | BigDecimal.ONE - } - - void "Invalid bigdecimal literal '#literal'"() { - setup: - - PropertyEditor editor = new BigDecimalPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigIntegerPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigIntegerPropertyEditorSpec.groovy deleted file mode 100644 index 2629e701748..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BigIntegerPropertyEditorSpec.groovy +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class BigIntegerPropertyEditorSpec extends PropertyEditorSpecSupport { - void "BigInteger literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new BigIntegerPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | BigInteger.ONE - '100%' | 'percent' | BigInteger.ONE - '$1.00' | 'currency' | BigInteger.ONE - BigInteger.ONE | null | BigInteger.ONE - BigDecimal.ONE | null | BigInteger.ONE - 1L | null | BigInteger.ONE - } - - void "Invalid biginteger literal '#literal'"() { - setup: - - PropertyEditor editor = new BigIntegerPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BooleanPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BooleanPropertyEditorSpec.groovy deleted file mode 100644 index cef64d6c738..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BooleanPropertyEditorSpec.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class BooleanPropertyEditorSpec extends Specification { - void "Boolean literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new BooleanPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - 'true' | null | true - 'false' | null | false - true | null | true - false | null | false - 'true' | 'boolean' | true - 'false' | 'boolean' | false - 'yes' | 'query' | true - 'no' | 'query' | false - 'on' | 'switch' | true - 'off' | 'switch' | false - } - - void "Invalid boolean literal '#literal'"() { - setup: - - PropertyEditor editor = new BooleanPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BytePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BytePropertyEditorSpec.groovy deleted file mode 100644 index a2a0a3606ac..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/BytePropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class BytePropertyEditorSpec extends PropertyEditorSpecSupport { - void "Byte literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new BytePropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | 1 - '100%' | 'percent' | 1 - '$1.00' | 'currency' | 1 - 1 | null | 1 - } - - void "Invalid byte literal '#literal'"() { - setup: - - PropertyEditor editor = new BytePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/CalendarPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/CalendarPropertyEditorSpec.groovy deleted file mode 100644 index 915eb9c3d83..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/CalendarPropertyEditorSpec.groovy +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class CalendarPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Calendar literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new CalendarPropertyEditor() - - when: - editor.format = format - editor.value = literal - - Calendar v1 = value ? clearTime(value) : value - Calendar v2 = editor.value ? clearTime(editor.value) : editor.value - - then: - - v1?.time == v2?.time - - where: - literal | format | value - null | null | null - '' | null | null - '1/1/70 12:00 AM' | null | epochAsCalendar() - '0' | null | epochAsCalendar() - 0 | null | epochAsCalendar() - epochAsDate() | null | epochAsCalendar() - epochAsCalendar() | null | epochAsCalendar() - '' | 'yyyy-MM-dd HH:mm:ss' | null - '1970-01-01 00:00:00' | 'yyyy-MM-dd HH:mm:ss' | epochAsCalendar() - 0 | 'yyyy-MM-dd HH:mm:ss' | epochAsCalendar() - epochAsDate() | 'yyyy-MM-dd HH:mm:ss' | epochAsCalendar() - epochAsCalendar() | 'yyyy-MM-dd HH:mm:ss' | epochAsCalendar() - } - - void "Invalid calendar literal '#literal'"() { - setup: - - PropertyEditor editor = new CalendarPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DatePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DatePropertyEditorSpec.groovy deleted file mode 100644 index 9badc730f09..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DatePropertyEditorSpec.groovy +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class DatePropertyEditorSpec extends PropertyEditorSpecSupport { - void "Date literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new DatePropertyEditor() - - when: - editor.format = format - editor.value = literal - - Date v1 = value ? clearTime(value) : value - Date v2 = editor.value ? clearTime(editor.value) : editor.value - - then: - - v1?.time == v2?.time - - where: - literal | format | value - null | null | null - '' | null | null - '1/1/70 12:00 AM' | null | epochAsDate() - '0' | null | epochAsDate() - 0 | null | epochAsDate() - epochAsDate() | null | epochAsDate() - epochAsCalendar() | null | epochAsDate() - '' | 'yyyy-MM-dd HH:mm:ss' | null - '1970-01-01 00:00:00' | 'yyyy-MM-dd HH:mm:ss' | epochAsDate() - 0 | 'yyyy-MM-dd HH:mm:ss' | epochAsDate() - epochAsDate() | 'yyyy-MM-dd HH:mm:ss' | epochAsDate() - epochAsCalendar() | 'yyyy-MM-dd HH:mm:ss' | epochAsDate() - } - - void "Invalid date literal '#literal'"() { - setup: - - PropertyEditor editor = new DatePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DoublePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DoublePropertyEditorSpec.groovy deleted file mode 100644 index 58f2233aafb..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/DoublePropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class DoublePropertyEditorSpec extends PropertyEditorSpecSupport { - void "Double literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new DoublePropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '0.1' | null | 0.1d - '10%' | 'percent' | 0.1d - '$0.10' | 'currency' | 0.1d - 0.1d | null | 0.1d - } - - void "Invalid double literal '#literal'"() { - setup: - - PropertyEditor editor = new DoublePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/EnumPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/EnumPropertyEditorSpec.groovy deleted file mode 100644 index 2c97a27bcdd..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/EnumPropertyEditorSpec.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class EnumPropertyEditorSpec extends Specification { - void "Enum literal '#literal' should be equal to #value"() { - setup: - - PropertyEditor editor = new EnumPropertyEditor() - - when: - editor.enumType = Numbers - editor.value = literal - - then: - - editor.enumType == Numbers - value == editor.value - - where: - literal | value - null | null - '' | null - ' ' | null - 'ZERO' | Numbers.ZERO - Numbers.ONE | Numbers.ONE - } - - void "Invalid enum literal '#literal'"() { - setup: - - PropertyEditor editor = new EnumPropertyEditor() - - when: - editor.enumType = Numbers - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} - -enum Numbers { - ZERO, ONE, TWO -} \ No newline at end of file diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedCalendarPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedCalendarPropertyEditorSpec.groovy deleted file mode 100644 index c022863d4b3..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedCalendarPropertyEditorSpec.groovy +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor -import java.time.LocalDate -import java.time.LocalDateTime - -@Unroll -class ExtendedCalendarPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Date literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new ExtendedCalendarPropertyEditor() - - when: - editor.format = format - editor.value = literal - - Calendar v1 = value ? clearTime(value) : value - Calendar v2 = editor.value ? clearTime(editor.value) : editor.value - - then: - - v1?.time == v2?.time - - where: - literal | format | value - null | null | null - LocalDate.of(1970, 1, 1) | null | epochAsCalendar() - LocalDateTime.of(1970, 1, 1, 0, 0, 0) | null | epochAsCalendar() - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedDatePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedDatePropertyEditorSpec.groovy deleted file mode 100644 index 900126452b2..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ExtendedDatePropertyEditorSpec.groovy +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor -import java.time.LocalDate -import java.time.LocalDateTime - -@Unroll -class ExtendedDatePropertyEditorSpec extends PropertyEditorSpecSupport { - void "Date literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new ExtendedDatePropertyEditor() - - when: - editor.format = format - editor.value = literal - - Date v1 = value ? clearTime(value) : value - Date v2 = editor.value ? clearTime(editor.value) : editor.value - - then: - - v1?.time == v2?.time - - where: - literal | format | value - null | null | null - LocalDate.of(1970, 1, 1) | null | epochAsDate() - LocalDateTime.of(1970, 1, 1, 12, 13, 14) | null | epochAsDate() - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FilePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FilePropertyEditorSpec.groovy deleted file mode 100644 index 97dc492229b..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FilePropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Shared -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class FilePropertyEditorSpec extends Specification { - @Shared - private File sharedFile = new File('.') - - void "File literal '#literal' should be equal to #value"() { - setup: - - PropertyEditor editor = new FilePropertyEditor() - - when: - editor.value = literal - - then: - value == editor.value - - - where: - literal | value - null | null - '' | null - ' ' | null - sharedFile | sharedFile - } - - void "Invalid file literal '#literal'"() { - setup: - - PropertyEditor editor = new FilePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FloatPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FloatPropertyEditorSpec.groovy deleted file mode 100644 index acd58e9ea81..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/FloatPropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class FloatPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Float literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new FloatPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '0.1' | null | 0.1f - '10%' | 'percent' | 0.1f - '$0.10' | 'currency' | 0.1f - 0.1f | null | 0.1f - } - - void "Invalid float literal '#literal'"() { - setup: - - PropertyEditor editor = new FloatPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/IntegerPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/IntegerPropertyEditorSpec.groovy deleted file mode 100644 index d3567bb7096..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/IntegerPropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class IntegerPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Integer literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new IntegerPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | 1 - '100%' | 'percent' | 1 - '$1.00' | 'currency' | 1 - 1 | null | 1 - } - - void "Invalid integer literal '#literal'"() { - setup: - - PropertyEditor editor = new IntegerPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDatePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDatePropertyEditorSpec.groovy deleted file mode 100644 index 3940013bf72..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDatePropertyEditorSpec.groovy +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor -import java.time.LocalDate -import java.time.LocalDateTime - -@Unroll -class LocalDatePropertyEditorSpec extends PropertyEditorSpecSupport { - void "LocalDate literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new LocalDatePropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1970-01-01' | null | LocalDate.of(1970, 1, 1) - 0 | null | LocalDate.of(1970, 1, 1) - epochAsDate() | null | LocalDate.of(1970, 1, 1) - epochAsCalendar() | null | LocalDate.of(1970, 1, 1) - [1970, 1, 1] | null | LocalDate.of(1970, 1, 1) - ['1970', '1', '1'] | null | LocalDate.of(1970, 1, 1) - [y: 1970, m: 1, d: 1] | null | LocalDate.of(1970, 1, 1) - [y: '1970', m: '1', d: 1] | null | LocalDate.of(1970, 1, 1) - LocalDate.of(1970, 1, 1) | null | LocalDate.of(1970, 1, 1) - LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) | null | LocalDate.of(1970, 1, 1) - '' | 'yyyy-MM-dd' | null - '1970-01-01' | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - 0 | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - epochAsDate() | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - epochAsCalendar() | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - [1970, 1, 1] | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - ['1970', '1', '1'] | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - [y: 1970, m: 1, d: 1] | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - [y: '1970', m: '1', d: 1] | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - LocalDate.of(1970, 1, 1) | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) | 'yyyy-MM-dd' | LocalDate.of(1970, 1, 1) - [] | null | null - [:] | null | null - } - - void "Invalid date literal '#literal'"() { - setup: - - PropertyEditor editor = new LocalDatePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [1, 2], - [1, 2, 3, 4], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDateTimePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDateTimePropertyEditorSpec.groovy deleted file mode 100644 index 583a86b5dac..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalDateTimePropertyEditorSpec.groovy +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor -import java.time.LocalDate -import java.time.LocalDateTime - -@Unroll -class LocalDateTimePropertyEditorSpec extends PropertyEditorSpecSupport { - void "LocalDateTime literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new LocalDateTimePropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - [] | null | null - '' | null | null - "1970-01-01T12:13:14" | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - 0 | null | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - epochAsDate() | null | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - epochAsCalendar() | null | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - [1970, 1, 1,] | null | LocalDateTime.of(1970, 1, 1, 0, 0, 0) - LocalDate.of(1970, 1, 1) | null | LocalDateTime.of(1970, 1, 1, 0, 0, 0) - [1970, 1, 1, 12,] | null | LocalDateTime.of(1970, 1, 1, 12, 0, 0) - [1970, 1, 1, 12, 13] | null | LocalDateTime.of(1970, 1, 1, 12, 13, 0) - [1970, 1, 1, 12, 13, 14] | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - [1970, 1, 1, 12, 13, 14, 0] | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14, 0) - ['1970', '1', '1', '12', '13', '14'] | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - LocalDateTime.of(1970, 1, 1, 12, 13, 14) | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - LocalDateTime.of(1970, 1, 1, 12, 13, 14) | null | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - '' | 'yyyy-MM-dd HH:mm:ss' | null - '1970-01-01 12:13:14' | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - 0 | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - epochAsDate() | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - epochAsCalendar() | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0) - LocalDate.of(1970, 1, 1) | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 0, 0, 0) - [1970, 1, 1,] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 0, 0, 0) - [1970, 1, 1, 12,] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 0, 0) - [1970, 1, 1, 12, 13] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 0) - [1970, 1, 1, 12, 13, 14] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - [1970, 1, 1, 12, 13, 14, 0] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14, 0) - ['1970', '1', '1', '12', '13', '14'] | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - LocalDateTime.of(1970, 1, 1, 12, 13, 14) | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - LocalDateTime.of(1970, 1, 1, 12, 13, 14) | 'yyyy-MM-dd HH:mm:ss' | LocalDateTime.of(1970, 1, 1, 12, 13, 14) - } - - void "Invalid date literal '#literal'"() { - setup: - - PropertyEditor editor = new LocalDateTimePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [1, 2], - [1, 2, 3, 4, 5, 6, 7, 8], - [:], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalTimePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalTimePropertyEditorSpec.groovy deleted file mode 100644 index 83090271ec6..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalTimePropertyEditorSpec.groovy +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor -import java.time.LocalDateTime -import java.time.LocalTime - -@Unroll -class LocalTimePropertyEditorSpec extends PropertyEditorSpecSupport { - void "LocalTime literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new LocalTimePropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - [] | null | null - '01:02:03.400' | null | LocalTime.of(1, 2, 3, 400000000) - 0 | null | LocalTime.of(0, 0, 0, 0) - epochAsDate() | null | LocalTime.of(0, 0, 0, 0) - epochAsCalendar() | null | LocalTime.of(0, 0, 0, 0) - [1, 2, 3] | null | LocalTime.of(1, 2, 3) - [1, 2, 3, 400000000] | null | LocalTime.of(1, 2, 3, 400000000) - ['1', '2', '3', '400000000'] | null | LocalTime.of(1, 2, 3, 400000000) - LocalTime.of(1, 2, 3, 400000000) | null | LocalTime.of(1, 2, 3, 400000000) - LocalDateTime.of(1970, 1, 1, 1, 2, 3, 400000000) | null | LocalTime.of(1, 2, 3, 400000000) - '' | 'HH:mm:ss.SSS' | null - '01:02:03.400' | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 400000000) - 0 | 'HH:mm:ss.SSS' | LocalTime.of(0, 0, 0, 0) - epochAsDate() | 'HH:mm:ss.SSS' | LocalTime.of(0, 0, 0, 0) - epochAsCalendar() | 'HH:mm:ss.SSS' | LocalTime.of(0, 0, 0, 0) - [1, 2, 3] | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 0) - [1, 2, 3, 400000000] | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 400000000) - ['1', '2', '3', '400000000'] | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 400000000) - LocalTime.of(1, 2, 3, 400000000) | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 400000000) - LocalDateTime.of(1970, 1, 1, 1, 2, 3, 400000000) | 'HH:mm:ss.SSS' | LocalTime.of(1, 2, 3, 400000000) - } - - void "Invalid date literal '#literal'"() { - setup: - - PropertyEditor editor = new LocalTimePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [:], - [1, 2], - [1, 2, 3, 4, 5], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalePropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalePropertyEditorSpec.groovy deleted file mode 100644 index 28c8177527d..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LocalePropertyEditorSpec.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class LocalePropertyEditorSpec extends PropertyEditorSpecSupport { - void "Locale literal '#literal' should be equal to #value"() { - setup: - PropertyEditor editor = new LocalePropertyEditor() - - when: - editor.value = literal - - then: - value == editor.value - - where: - literal | value - null | null - '' | Locale.US // force Locale due to base class. See https://github.com/griffon/griffon/issues/111 - 'de' | Locale.GERMAN - 'de_CH' | new Locale('de', 'CH') - 'de_CH_Basel' | new Locale('de', 'CH', 'Basel') - Locale.US | Locale.US - } - - void "Invalid biginteger literal '#literal'"() { - setup: - - PropertyEditor editor = new LocalePropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 1, - [], - [:], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LongPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LongPropertyEditorSpec.groovy deleted file mode 100644 index 359222150f5..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/LongPropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class LongPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Long literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new LongPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | 1L - '100%' | 'percent' | 1L - '$1.00' | 'currency' | 1L - 1L | null | 1L - } - - void "Invalid long literal '#literal'"() { - setup: - - PropertyEditor editor = new LongPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorResolverSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorResolverSpec.groovy deleted file mode 100644 index ae46fd2fb12..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorResolverSpec.groovy +++ /dev/null @@ -1,156 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class PropertyEditorResolverSpec extends Specification { - void "PropertyEditor for type #type should be #editorClass"() { - setup: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(String, StringPropertyEditor) - - expect: - PropertyEditorResolver.findEditor(type)?.class == editorClass - - where: - type | editorClass - Numbers | EnumPropertyEditor - String | StringPropertyEditor - } - - void "PropertyEditor at index 0 is called (value)"() { - setup: - APropertyEditor.called = 0 - BPropertyEditor.called = 0 - PropertyEditorResolver.registerEditor(Object, APropertyEditor) - PropertyEditorResolver.registerEditor(Object, BPropertyEditor) - - when: - PropertyEditor editor = PropertyEditorResolver.findEditor(Object) - editor.value = 'Groovy' - - then: - editor.value == 'Groovy' - APropertyEditor.called == 1 - BPropertyEditor.called == 0 - } - - void "PropertyEditor at index 1 is called (value)"() { - setup: - APropertyEditor.called = 0 - BPropertyEditor.called = 0 - PropertyEditorResolver.registerEditor(Object, APropertyEditor) - PropertyEditorResolver.registerEditor(Object, BPropertyEditor) - - when: - PropertyEditor editor = PropertyEditorResolver.findEditor(Object) - editor.value = 1 - - then: - editor.value == 1 - APropertyEditor.called == 0 - BPropertyEditor.called == 1 - } - - void "PropertyEditor at index 0 is called (text)"() { - setup: - APropertyEditor.called = 0 - BPropertyEditor.called = 0 - PropertyEditorResolver.registerEditor(Object, APropertyEditor) - PropertyEditorResolver.registerEditor(Object, BPropertyEditor) - - when: - PropertyEditor editor = PropertyEditorResolver.findEditor(Object) - editor.asText = 'Groovy' - - then: - editor.asText == 'Groovy' - APropertyEditor.called == 1 - BPropertyEditor.called == 0 - } - - void "Register and unregister an editor class"() { - given: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Object, APropertyEditor) - - when: - PropertyEditor editor = PropertyEditorResolver.findEditor(Object) - - then: - editor instanceof APropertyEditor - - when: - editor = PropertyEditorResolver.unregisterEditor(Object) - - then: 'editor is a NoopPropertyEditor' - !(editor instanceof APropertyEditor) - } - - void "Register non-null and null editor for the same target class"() { - given: - PropertyEditorResolver.clear() - - when: - PropertyEditorResolver.registerEditor(Object, APropertyEditor) - PropertyEditor editor = PropertyEditorResolver.findEditor(Object) - - then: - editor instanceof APropertyEditor - - when: - PropertyEditorResolver.registerEditor(Object, null) - editor = PropertyEditorResolver.unregisterEditor(Object) - - then: 'editor is a NoopPropertyEditor' - !(editor instanceof APropertyEditor) - } - - static class APropertyEditor extends AbstractPropertyEditor { - static int called = 0 - - @Override - void setValue(Object value) { - if (value instanceof String) { - super.setValue(value) - called++ - } else { - throw illegalValue(value, Object) - } - } - } - - static class BPropertyEditor extends AbstractPropertyEditor { - static int called = 0 - - @Override - void setValue(Object value) { - if (value instanceof Number) { - super.setValue(value) - called++ - } else { - throw illegalValue(value, Object) - } - } - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorSpecSupport.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorSpecSupport.groovy deleted file mode 100644 index 6c106074c82..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/PropertyEditorSpecSupport.groovy +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Shared -import spock.lang.Specification - -abstract class PropertyEditorSpecSupport extends Specification { - @Shared - private Locale defaultLocale = Locale.default - - def setup() { - Locale.default = Locale.US - } - - def cleanup() { - Locale.default = defaultLocale - } - - static Date epochAsDate() { - // Thu Jan 01 00:00:00 1970 - TimeZone.setDefault(TimeZone.getTimeZone('Etc/GMT')) - clearTime(new Date(0)) - } - - static Calendar epochAsCalendar() { - // Thu Jan 01 00:00:00 1970 - TimeZone.setDefault(TimeZone.getTimeZone('Etc/GMT')) - Calendar c = Calendar.getInstance() - c.time = epochAsDate() - c - } - - private static void clearTimeCommon(final Calendar self) { - self.set(Calendar.HOUR_OF_DAY, 0) - self.clear(Calendar.MINUTE) - self.clear(Calendar.SECOND) - self.clear(Calendar.MILLISECOND) - self.setTimeZone(TimeZone.getTimeZone('GMT')) - } - - static Date clearTime(final Date self) { - Calendar calendar = Calendar.getInstance() - calendar.setTime(self) - clearTimeCommon(calendar) - self.setTime(calendar.getTime().getTime()) - return self - } - - static Calendar clearTime(final Calendar self) { - clearTimeCommon(self) - return self - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ShortPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ShortPropertyEditorSpec.groovy deleted file mode 100644 index 01d63233cc1..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/ShortPropertyEditorSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class ShortPropertyEditorSpec extends PropertyEditorSpecSupport { - void "Short literal '#literal' with format '#format' should be equal to #value"() { - setup: - - PropertyEditor editor = new ShortPropertyEditor() - - when: - editor.format = format - editor.value = literal - - then: - - value == editor.value - - where: - literal | format | value - null | null | null - '' | null | null - '1' | null | 1 - '100%' | 'percent' | 1 - '$1.00' | 'currency' | 1 - 1 | null | 1 - } - - void "Invalid short literal '#literal'"() { - setup: - - PropertyEditor editor = new ShortPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - '1, 2, 3', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/StringPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/StringPropertyEditorSpec.groovy deleted file mode 100644 index 3d3762c2582..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/StringPropertyEditorSpec.groovy +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Shared -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class StringPropertyEditorSpec extends Specification { - @Shared - private Object object = new Object() - - void "String literal '#literal' should be equal to #value"() { - setup: - - PropertyEditor editor = new StringPropertyEditor() - - when: - editor.value = literal - - then: - - value == editor.value - - where: - literal | value - null | null - '' | '' - 'string' | 'string' - object | object.toString() - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URIPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URIPropertyEditorSpec.groovy deleted file mode 100644 index 10611ba05fd..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URIPropertyEditorSpec.groovy +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Shared -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class URIPropertyEditorSpec extends Specification { - @Shared - private URI uri = 'http://localhost'.toURI() - - void "URI literal '#literal' should be equal to #value"() { - setup: - - PropertyEditor editor = new URIPropertyEditor() - - when: - editor.value = literal - - then: - - value == editor.value - - where: - literal | value - null | null - '' | null - ' ' | null - 'http://localhost' | 'http://localhost'.toURI() - new File('/').absoluteFile | new File('/').absoluteFile.toURI() - uri | uri - } - - void "Invalid uri literal '#literal'"() { - setup: - - PropertyEditor editor = new URIPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'http://localhost/&?_<>', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URLPropertyEditorSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URLPropertyEditorSpec.groovy deleted file mode 100644 index 754d7cfce41..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/editors/URLPropertyEditorSpec.groovy +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.editors - -import spock.lang.Shared -import spock.lang.Specification -import spock.lang.Unroll - -import java.beans.PropertyEditor - -@Unroll -class URLPropertyEditorSpec extends Specification { - @Shared - private URL url = 'http://localhost'.toURL() - - void "URL literal '#literal' should be equal to #value"() { - setup: - - PropertyEditor editor = new URLPropertyEditor() - - when: - editor.value = literal - - then: - - value == editor.value - - where: - literal | value - null | null - '' | null - ' ' | null - 'http://localhost' | 'http://localhost'.toURL() - new File('/').absoluteFile | new File('/').absoluteFile.toURI().toURL() - url | url - } - - void "Invalid url literal '#literal'"() { - setup: - - PropertyEditor editor = new URLPropertyEditor() - - when: - editor.value = literal - - then: - - thrown(IllegalArgumentException) - - where: - literal << [ - 'garbage', - [], - [1, 2, 3], - [:], - [key: 'value'], - new Object() - ] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigDecimalFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigDecimalFormatterSpec.groovy deleted file mode 100644 index 8d991c6bd37..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigDecimalFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.BigDecimalFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.BigDecimalFormatter.PATTERN_PERCENT - -@Unroll -class BigDecimalFormatterSpec extends FormatterSpecSupport { - void "BigDecimal '#value' produces literal '#literal'"() { - given: - BigDecimalFormatter formatter = new BigDecimalFormatter() - - when: - String str = formatter.format(value) - BigDecimal val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - BigDecimal.valueOf(100L) | '100' - } - - void "BigDecimal '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - BigDecimalFormatter formatter = new BigDecimalFormatter(pattern) - - when: - String str = formatter.format(value) - BigDecimal val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | BigDecimal.valueOf(100L) | '$100.00' - PATTERN_PERCENT | BigDecimal.ONE | '100%' - null | BigDecimal.valueOf(100L) | '100' - '' | BigDecimal.valueOf(100L) | '100' - '##.0' | BigDecimal.valueOf(20) | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - BigDecimalFormatter formatter = new BigDecimalFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new BigDecimalFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigIntegerFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigIntegerFormatterSpec.groovy deleted file mode 100644 index ea63840c858..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BigIntegerFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.BigIntegerFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.BigIntegerFormatter.PATTERN_PERCENT - -@Unroll -class BigIntegerFormatterSpec extends FormatterSpecSupport { - void "BigInteger '#value' produces literal '#literal'"() { - given: - BigIntegerFormatter formatter = new BigIntegerFormatter() - - when: - String str = formatter.format(value) - BigInteger val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - BigInteger.valueOf(100L) | '100' - } - - void "BigInteger '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - BigIntegerFormatter formatter = new BigIntegerFormatter(pattern) - - when: - String str = formatter.format(value) - BigInteger val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | BigInteger.valueOf(100L) | '$100.00' - PATTERN_PERCENT | BigInteger.ONE | '100%' - null | BigInteger.valueOf(100L) | '100' - '' | BigInteger.valueOf(100L) | '100' - '##.0' | BigInteger.valueOf(20) | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - BigIntegerFormatter formatter = new BigIntegerFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new BigIntegerFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BooleanFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BooleanFormatterSpec.groovy deleted file mode 100644 index 8b95b95e862..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/BooleanFormatterSpec.groovy +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Specification -import spock.lang.Unroll - -import static griffon.core.formatters.BooleanFormatter.PATTERN_BOOL -import static griffon.core.formatters.BooleanFormatter.PATTERN_QUERY -import static griffon.core.formatters.BooleanFormatter.PATTERN_SWITCH -import static griffon.core.formatters.BooleanFormatter.getInstance -import static griffon.core.formatters.BooleanFormatter.parseBoolean - -@Unroll -class BooleanFormatterSpec extends Specification { - void "Boolean '#value' produces literal '#literal'"() { - given: - BooleanFormatter formatter = new BooleanFormatter() - - when: - String str = formatter.format(value) - Boolean val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - false | 'false' - true | 'true' - } - - void "Boolean '#value' produces '#literal'"() { - expect: - value == parseBoolean(literal) - - where: - value | literal - null | null - null | '' - false | 'false' - true | 'true' - false | 'no' - true | 'yes' - false | 'off' - true | 'on' - } - - void "Boolean '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - BooleanFormatter formatter = getInstance(pattern) - - when: - String str = formatter.format(value) - Boolean val = formatter.parse(str) - - then: - str == literal - val == value - pattern ? pattern == formatter.pattern : true - - where: - pattern | value | literal - null | null | null - null | false | 'false' - null | true | 'true' - PATTERN_BOOL | null | null - PATTERN_BOOL | false | 'false' - PATTERN_BOOL | true | 'true' - PATTERN_QUERY | null | null - PATTERN_QUERY | false | 'no' - PATTERN_QUERY | true | 'yes' - PATTERN_SWITCH | null | null - PATTERN_SWITCH | false | 'off' - PATTERN_SWITCH | true | 'on' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - BooleanFormatter formatter = new BooleanFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_BOOL | 'abc' - PATTERN_QUERY | 'abc' - PATTERN_SWITCH | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new BooleanFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << ['garbage'] - } - - void "Illegal literal '#literal'"() { - when: - parseBoolean(literal) - - then: - thrown(ParseException) - - where: - literal << ['garbage'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ByteFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ByteFormatterSpec.groovy deleted file mode 100644 index 96405fa517a..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ByteFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.ByteFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.ByteFormatter.PATTERN_PERCENT - -@Unroll -class ByteFormatterSpec extends FormatterSpecSupport { - void "Byte '#value' produces literal '#literal'"() { - given: - ByteFormatter formatter = new ByteFormatter() - - when: - String str = formatter.format(value) - Byte val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as byte | '100' - } - - void "Byte '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - ByteFormatter formatter = new ByteFormatter(pattern) - - when: - String str = formatter.format(value) - Byte val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as byte | '$100.00' - PATTERN_PERCENT | 1 as byte | '100%' - null | 100 as byte | '100' - '' | 100 as byte | '100' - '##.0' | 20 as byte | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - ByteFormatter formatter = new ByteFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new ByteFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/CalendarFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/CalendarFormatterSpec.groovy deleted file mode 100644 index ab70e3019ff..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/CalendarFormatterSpec.groovy +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -@Unroll -class CalendarFormatterSpec extends FormatterSpecSupport { - void "Calendar '#value' produces literal '#literal'"() { - given: - CalendarFormatter formatter = new CalendarFormatter() - - when: - String str = formatter.format(value) - Calendar val = formatter.parse(str) - - Calendar v1 = value ? clearTime(value) : value - Calendar v2 = val ? clearTime(val) : val - - then: - - v1?.time == v2?.time - - then: - str == literal - v1 == v2 - - where: - value | literal - epochAsCalendar() | '1/1/70 12:00 AM' - } - - void "Calendar '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - CalendarFormatter formatter = new CalendarFormatter(pattern) - - when: - String str = formatter.format(value) - Calendar val = formatter.parse(str) - - Calendar v1 = value ? clearTime(value) : value - Calendar v2 = val ? clearTime(val) : val - - then: - pattern == formatter.pattern - str == literal - v1?.time?.time == v2?.time?.time - - where: - pattern | value | literal - 'yyyy-MM-dd' | null | null - 'yyyy-MM-dd' | epochAsCalendar() | '1970-01-01' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - CalendarFormatter formatter = new CalendarFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - 'yyyy-MM-dd' | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new CalendarFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DateFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DateFormatterSpec.groovy deleted file mode 100644 index 1df044750a4..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DateFormatterSpec.groovy +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -@Unroll -class DateFormatterSpec extends FormatterSpecSupport { - void "Date '#value' produces literal '#literal'"() { - given: - DateFormatter formatter = new DateFormatter() - - when: - String str = formatter.format(value) - Date val = formatter.parse(str) - - Date v1 = value ? clearTime(value) : value - Date v2 = val ? clearTime(val) : val - - then: - str == literal - v1 == v2 - - where: - value | literal - epochAsDate() | '1/1/70 12:00 AM' - } - - void "Date '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - DateFormatter formatter = new DateFormatter(pattern) - - when: - String str = formatter.format(value) - Date val = formatter.parse(str) - - Date v1 = value ? clearTime(value) : value - Date v2 = val ? clearTime(val) : val - - then: - pattern == formatter.pattern - str == literal - v1?.time == v2?.time - - where: - pattern | value | literal - 'yyyy-MM-dd' | null | null - 'yyyy-MM-dd' | epochAsDate() | '1970-01-01' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - DateFormatter formatter = new DateFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - 'yyyy-MM-dd' | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new DateFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DoubleFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DoubleFormatterSpec.groovy deleted file mode 100644 index 93196bcd867..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/DoubleFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.DoubleFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.DoubleFormatter.PATTERN_PERCENT - -@Unroll -class DoubleFormatterSpec extends FormatterSpecSupport { - void "Double '#value' produces literal '#literal'"() { - given: - DoubleFormatter formatter = new DoubleFormatter() - - when: - String str = formatter.format(value) - Double val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as double | '100.0' - } - - void "Double '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - DoubleFormatter formatter = new DoubleFormatter(pattern) - - when: - String str = formatter.format(value) - Double val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as double | '$100.00' - PATTERN_PERCENT | 1 as double | '100%' - null | 100 as double | '100.0' - '' | 100 as double | '100.0' - '##.0' | 20 as double | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - DoubleFormatter formatter = new DoubleFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new DoubleFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FloatFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FloatFormatterSpec.groovy deleted file mode 100644 index 836f57ebb99..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FloatFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.FloatFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.FloatFormatter.PATTERN_PERCENT - -@Unroll -class FloatFormatterSpec extends FormatterSpecSupport { - void "Float '#value' produces literal '#literal'"() { - given: - FloatFormatter formatter = new FloatFormatter() - - when: - String str = formatter.format(value) - Float val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as float | '100.0' - } - - void "Float '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - FloatFormatter formatter = new FloatFormatter(pattern) - - when: - String str = formatter.format(value) - Float val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as float | '$100.00' - PATTERN_PERCENT | 1 as float | '100%' - null | 100 as float | '100.0' - '' | 100 as float | '100.0' - '##.0' | 20 as float | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - FloatFormatter formatter = new FloatFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new FloatFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FormatterSpecSupport.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FormatterSpecSupport.groovy deleted file mode 100644 index 28b18706235..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/FormatterSpecSupport.groovy +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Shared -import spock.lang.Specification - -abstract class FormatterSpecSupport extends Specification { - @Shared - private Locale defaultLocale = Locale.default - - def setup() { - Locale.default = Locale.US - } - - def cleanup() { - Locale.default = defaultLocale - } - - static Date epochAsDate() { - // Thu Jan 01 00:00:00 1970 - TimeZone.setDefault(TimeZone.getTimeZone('Etc/GMT')) - clearTime(new Date(0)) - } - - static Calendar epochAsCalendar() { - // Thu Jan 01 00:00:00 1970 - TimeZone.setDefault(TimeZone.getTimeZone('Etc/GMT')) - Calendar c = Calendar.getInstance() - c.time = epochAsDate() - c - } - - private static void clearTimeCommon(final Calendar self) { - self.set(Calendar.HOUR_OF_DAY, 0) - self.clear(Calendar.MINUTE) - self.clear(Calendar.SECOND) - self.clear(Calendar.MILLISECOND) - } - - static Date clearTime(final Date self) { - Calendar calendar = Calendar.getInstance() - calendar.setTime(self) - clearTimeCommon(calendar) - self.setTime(calendar.getTime().getTime()) - return self - } - - static Calendar clearTime(final Calendar self) { - clearTimeCommon(self) - return self - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/IntegerFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/IntegerFormatterSpec.groovy deleted file mode 100644 index 948d12bd10a..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/IntegerFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.IntegerFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.IntegerFormatter.PATTERN_PERCENT - -@Unroll -class IntegerFormatterSpec extends FormatterSpecSupport { - void "Integer '#value' produces literal '#literal'"() { - given: - IntegerFormatter formatter = new IntegerFormatter() - - when: - String str = formatter.format(value) - Integer val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as int | '100' - } - - void "Integer '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - IntegerFormatter formatter = new IntegerFormatter(pattern) - - when: - String str = formatter.format(value) - Integer val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as int | '$100.00' - PATTERN_PERCENT | 1 as int | '100%' - null | 100 as int | '100' - '' | 100 as int | '100' - '##.0' | 20 as int | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - IntegerFormatter formatter = new IntegerFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new IntegerFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LocaleFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LocaleFormatterSpec.groovy deleted file mode 100644 index 57b26676db6..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LocaleFormatterSpec.groovy +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -@Unroll -class LocaleFormatterSpec extends FormatterSpecSupport { - void "Locale '#value' produces literal '#literal'"() { - given: - LocaleFormatter formatter = new LocaleFormatter() - - when: - String str = formatter.format(value) - Locale val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - Locale.US | 'en_US' - Locale.UK | 'en_GB' - new Locale('de', 'CH', 'Basel') | 'de_CH_Basel' - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LongFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LongFormatterSpec.groovy deleted file mode 100644 index 84b16af86b3..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/LongFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.LongFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.LongFormatter.PATTERN_PERCENT - -@Unroll -class LongFormatterSpec extends FormatterSpecSupport { - void "Long '#value' produces literal '#literal'"() { - given: - LongFormatter formatter = new LongFormatter() - - when: - String str = formatter.format(value) - Long val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as long | '100' - } - - void "Long '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - LongFormatter formatter = new LongFormatter(pattern) - - when: - String str = formatter.format(value) - Long val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as long | '$100.00' - PATTERN_PERCENT | 1 as long | '100%' - null | 100 as long | '100' - '' | 100 as long | '100' - '##.0' | 20 as long | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - LongFormatter formatter = new LongFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new LongFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ShortFormatterSpec.groovy b/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ShortFormatterSpec.groovy deleted file mode 100644 index a0d0c1057f4..00000000000 --- a/subprojects/griffon-core/src/test/groovy/griffon/core/formatters/ShortFormatterSpec.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package griffon.core.formatters - -import spock.lang.Unroll - -import static griffon.core.formatters.ShortFormatter.PATTERN_CURRENCY -import static griffon.core.formatters.ShortFormatter.PATTERN_PERCENT - -@Unroll -class ShortFormatterSpec extends FormatterSpecSupport { - void "Short '#value' produces literal '#literal'"() { - given: - ShortFormatter formatter = new ShortFormatter() - - when: - String str = formatter.format(value) - Short val = formatter.parse(str) - - then: - str == literal - val == value - - where: - value | literal - 100 as short | '100' - } - - void "Short '#value' with pattern '#pattern' produces literal '#literal'"() { - given: - ShortFormatter formatter = new ShortFormatter(pattern) - - when: - String str = formatter.format(value) - Short val = formatter.parse(str) - - then: - str == literal - val == value - - where: - pattern | value | literal - PATTERN_CURRENCY | null | null - PATTERN_PERCENT | null | null - PATTERN_CURRENCY | 100 as short | '$100.00' - PATTERN_PERCENT | 1 as short | '100%' - null | 100 as short | '100' - '' | 100 as short | '100' - '##.0' | 20 as short | '20.0' - } - - void "Parse error for pattern '#pattern' with literal '#literal'"() { - given: - ShortFormatter formatter = new ShortFormatter(pattern) - - when: - formatter.parse(literal) - - then: - thrown(ParseException) - - where: - pattern | literal - PATTERN_CURRENCY | 'abc' - PATTERN_PERCENT | 'abc' - } - - void "Illegal pattern '#pattern'"() { - when: - new ShortFormatter(pattern) - - then: - thrown(IllegalArgumentException) - - where: - pattern << [';garbage*@%&'] - } -} diff --git a/subprojects/griffon-core/src/test/groovy/integration/ChildController.java b/subprojects/griffon-core/src/test/groovy/integration/ChildController.java index 6f8905a6074..8f263b8c444 100644 --- a/subprojects/griffon-core/src/test/groovy/integration/ChildController.java +++ b/subprojects/griffon-core/src/test/groovy/integration/ChildController.java @@ -33,7 +33,7 @@ public class ChildController extends AbstractGriffonController { private MVCGroup parentGroup; private RootController parentController; - @MVCMember(editor = ListPropertyEditor.class) + @MVCMember(converter = ListConverter.class) private List list1 = new ArrayList<>(); private List list2 = new ArrayList<>(); private List list3 = new ArrayList<>(); @@ -94,7 +94,7 @@ public List getList1() { return list1; } - @MVCMember(editor = ListPropertyEditor.class) + @MVCMember(converter = ListConverter.class) public void setList2(List list) { this.list2.addAll(list); } diff --git a/subprojects/griffon-core/src/test/groovy/integration/ConfigurableBean.groovy b/subprojects/griffon-core/src/test/groovy/integration/ConfigurableBean.groovy index faeb1a2549c..db357ca42e9 100644 --- a/subprojects/griffon-core/src/test/groovy/integration/ConfigurableBean.groovy +++ b/subprojects/griffon-core/src/test/groovy/integration/ConfigurableBean.groovy @@ -17,9 +17,8 @@ */ package integration -import griffon.core.configuration.Configured - import javax.annotation.Nonnull +import javax.application.configuration.Configured class ConfigurableBean { private String pstring @@ -40,6 +39,6 @@ class ConfigurableBean { this.pstring = pstring } - @Configured(value='keys.key4', defaultValue = '*custom*', editor = CustomStringPropertyEditor) + @Configured(value = 'keys.key4', defaultValue = '*custom*', converter = CustomStringConverter) String customString } diff --git a/subprojects/griffon-core/src/test/groovy/integration/CustomStringPropertyEditor.groovy b/subprojects/griffon-core/src/test/groovy/integration/CustomStringConverter.groovy similarity index 66% rename from subprojects/griffon-core/src/test/groovy/integration/CustomStringPropertyEditor.groovy rename to subprojects/griffon-core/src/test/groovy/integration/CustomStringConverter.groovy index 39cfffdbe11..50902a3dee4 100644 --- a/subprojects/griffon-core/src/test/groovy/integration/CustomStringPropertyEditor.groovy +++ b/subprojects/griffon-core/src/test/groovy/integration/CustomStringConverter.groovy @@ -17,19 +17,19 @@ */ package integration -import java.beans.PropertyEditorSupport +import org.kordamp.jsr377.converter.AbstractConverter + +import javax.application.converter.ConversionException /** * @author Andres Almiray */ -class CustomStringPropertyEditor extends PropertyEditorSupport { - @Override - String getAsText() { - return '*' + super.getAsText() + '*' - } - +class CustomStringConverter extends AbstractConverter { @Override - void setAsText(String text) throws IllegalArgumentException { - setValue(text[1..-2].toString()) + String fromObject(Object o) throws ConversionException { + if(o instanceof CharSequence) { + return o.toString()[1..-2] + } + return '*' + String.valueOf(o) + '*' } } diff --git a/subprojects/griffon-core/src/test/groovy/integration/ListPropertyEditor.java b/subprojects/griffon-core/src/test/groovy/integration/ListConverter.java similarity index 61% rename from subprojects/griffon-core/src/test/groovy/integration/ListPropertyEditor.java rename to subprojects/griffon-core/src/test/groovy/integration/ListConverter.java index ff3c1b674e0..bcdbd47ed27 100644 --- a/subprojects/griffon-core/src/test/groovy/integration/ListPropertyEditor.java +++ b/subprojects/griffon-core/src/test/groovy/integration/ListConverter.java @@ -17,29 +17,25 @@ */ package integration; -import java.beans.PropertyEditorSupport; +import org.kordamp.jsr377.converter.AbstractConverter; + +import javax.application.converter.ConversionException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import static griffon.util.GriffonNameUtils.isBlank; - -public class ListPropertyEditor extends PropertyEditorSupport { - @Override - public String getAsText() { - Object value = getValue(); - return value != null ? value.toString() : ""; - } - +public class ListConverter extends AbstractConverter> { @Override - public void setAsText(String text) throws IllegalArgumentException { - if (isBlank(text)) { - setValue(new ArrayList<>()); - } else { + public List fromObject(Object o) throws ConversionException { + if (o instanceof Collection) { + return new ArrayList<>((Collection) o); + } else if (o instanceof CharSequence) { List value = new ArrayList(); - for (String s : text.trim().split(",")) { + for (String s : String.valueOf(o).trim().split(",")) { value.add(s.trim()); } - setValue(value); + return value; } + throw illegalValue(o, List.class); } } \ No newline at end of file diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/MutableConfigurationSpec.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/MutableConfigurationSpec.groovy index 4c9f13b2c00..e3d5fe9895a 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/MutableConfigurationSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/MutableConfigurationSpec.groovy @@ -20,18 +20,20 @@ package org.codehaus.griffon.runtime.core import com.google.guiceberry.GuiceBerryModule import com.google.guiceberry.junit4.GuiceBerryRule import com.google.inject.AbstractModule -import com.google.inject.Inject import griffon.core.Configuration import griffon.core.MutableConfiguration -import griffon.core.editors.IntegerPropertyEditor -import griffon.core.editors.PropertyEditorResolver import org.codehaus.griffon.runtime.core.configuration.ConfigurationDecoratorFactory import org.codehaus.griffon.runtime.core.configuration.MutableConfigurationDecoratorFactory import org.codehaus.griffon.runtime.core.configuration.ResourceBundleConfigurationProvider import org.junit.Rule +import org.kordamp.jsr377.converter.DefaultConverterRegistry +import org.kordamp.jsr377.converter.IntegerConverter import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConverterRegistry +import javax.inject.Inject + import static com.google.inject.util.Providers.guicify import static griffon.util.AnnotationUtils.named @@ -43,6 +45,9 @@ class MutableConfigurationSpec extends Specification { @Inject private Configuration configuration + @Inject + private ConverterRegistry converterRegistry + def 'Calling configuration.get(#key, #defaultValue) returns #expectedValue'() { expect: expectedValue == configuration.get(key, defaultValue) @@ -188,50 +193,12 @@ class MutableConfigurationSpec extends Specification { 'key.foo' || _ } - def 'Calling configuration.removeAs(#key) removes the key'() { - given: - assert configuration instanceof MutableConfiguration - configuration.set('key.foo', 'foo') - - expect: - configuration.containsKey(key) - null != configuration.get(key) - - when: - String val = configuration.removeAs(key) - - then: - !configuration.containsKey(key) - - when: - def value = configuration.get(key) - - then: - null == value - - when: - value = configuration.remove(key) - - then: - null == value - - where: - key || _ - 'key.string' || _ - 'key.boolean.string' || _ - 'key.int.string' || _ - 'key.long.string' || _ - 'key.float.string' || _ - 'key.double.string' || _ - 'key.foo' || _ - } - def 'Calling configuration.removeConverted(#key) removes the key'() { given: assert configuration instanceof MutableConfiguration configuration.set('key.foo', 2) - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) expect: configuration.containsKey(key) @@ -256,7 +223,7 @@ class MutableConfigurationSpec extends Specification { null == value cleanup: - PropertyEditorResolver.clear() + converterRegistry.clear() where: key || _ @@ -364,6 +331,8 @@ class MutableConfigurationSpec extends Specification { .to(MutableConfigurationDecoratorFactory) bind(Configuration) .toProvider(guicify(new ResourceBundleConfigurationProvider())) + bind(ConverterRegistry) + .to(DefaultConverterRegistry) } } } diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecoratorSpec.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecoratorSpec.groovy index 09a00fe1fcb..329cb28f956 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecoratorSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationDecoratorSpec.groovy @@ -20,6 +20,7 @@ package org.codehaus.griffon.runtime.core.configuration import griffon.core.Configuration import griffon.util.AbstractMapResourceBundle import org.codehaus.griffon.runtime.core.MapResourceBundle +import org.kordamp.jsr377.converter.DefaultConverterRegistry import spock.lang.Specification import spock.lang.Unroll @@ -30,7 +31,7 @@ class ConfigurationDecoratorSpec extends Specification { def 'Calling configuration.#method(#key, #defaultValue) gives #value as result'() { given: ResourceBundle bundle = new MapResourceBundle() - Configuration configuration = new ResourceBundleConfiguration(bundle) + Configuration configuration = new ResourceBundleConfiguration(new DefaultConverterRegistry(), bundle) configuration = new ConfigurationDecorator(configuration) expect: @@ -68,7 +69,7 @@ class ConfigurationDecoratorSpec extends Specification { def 'Can resolve nested keys from sample application configuration (Properties)'() { given: ResourceBundle bundle = new AppResourceBundle() - Configuration configuration = new ResourceBundleConfiguration(bundle) + Configuration configuration = new ResourceBundleConfiguration(new DefaultConverterRegistry(), bundle) configuration = new ConfigurationDecorator(configuration) Properties props = configuration.asProperties() @@ -82,7 +83,7 @@ class ConfigurationDecoratorSpec extends Specification { def 'Can resolve nested keys from sample application configuration (ResourceBundle)'() { given: ResourceBundle bundle = new AppResourceBundle() - Configuration configuration = new ResourceBundleConfiguration(bundle) + Configuration configuration = new ResourceBundleConfiguration(new DefaultConverterRegistry(), bundle) configuration = new ConfigurationDecorator(configuration) ResourceBundle asBundle = configuration.asResourceBundle() diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationSpec.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationSpec.groovy index d85e42c30d2..de8a4176a78 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/ConfigurationSpec.groovy @@ -20,16 +20,18 @@ package org.codehaus.griffon.runtime.core.configuration import com.google.guiceberry.GuiceBerryModule import com.google.guiceberry.junit4.GuiceBerryRule import com.google.inject.AbstractModule -import com.google.inject.Inject import griffon.core.Configuration -import griffon.core.editors.DatePropertyEditor -import griffon.core.editors.IntegerPropertyEditor -import griffon.core.editors.PropertyEditorResolver import org.codehaus.griffon.runtime.core.MapResourceBundle import org.junit.Rule +import org.kordamp.jsr377.converter.DateConverter +import org.kordamp.jsr377.converter.DefaultConverterRegistry +import org.kordamp.jsr377.converter.IntegerConverter import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConverterRegistry +import javax.inject.Inject + import static com.google.inject.util.Providers.guicify import static griffon.util.AnnotationUtils.named @@ -41,8 +43,11 @@ class ConfigurationSpec extends Specification { @Inject private Configuration configuration + @Inject + private ConverterRegistry converterRegistry + def cleanup() { - PropertyEditorResolver.clear() + converterRegistry.clear() } def 'Calling configuration.get(#key, #defaultValue) returns #expectedValue'() { @@ -59,23 +64,10 @@ class ConfigurationSpec extends Specification { 'key.foo' | 'foo' || 'foo' } - - def 'Calling configuration.getAs(#key) returns blindly casted #expectedValue'() { - when: - Integer value = configuration.getAs(key) - - then: - value == expectedValue - - where: - key || expectedValue - 'key.int.type' || 42 - } - def 'Calling configuration.getConverted(#key) returns converted #expectedValue'() { given: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) when: Integer value = configuration.getConverted(key, Integer) @@ -92,8 +84,8 @@ class ConfigurationSpec extends Specification { def 'Calling configuration.getConverted(#key) with format returns converted #expectedValue'() { given: - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Date, DatePropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Date, DateConverter) when: Date value = configuration.getConverted(key, Date, 'YYYY-MM-dd') @@ -131,6 +123,8 @@ class ConfigurationSpec extends Specification { .to(DefaultConfigurationDecoratorFactory) bind(Configuration) .toProvider(guicify(new ResourceBundleConfigurationProvider())) + bind(ConverterRegistry) + .to(DefaultConverterRegistry) } } } diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/DefaultConfigurationSpec.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/DefaultConfigurationSpec.groovy index c6de6be0f80..92fcc3d5e9b 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/DefaultConfigurationSpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/configuration/DefaultConfigurationSpec.groovy @@ -20,6 +20,7 @@ package org.codehaus.griffon.runtime.core.configuration import griffon.core.Configuration import griffon.util.AbstractMapResourceBundle import org.codehaus.griffon.runtime.core.MapResourceBundle +import org.kordamp.jsr377.converter.DefaultConverterRegistry import spock.lang.Specification import spock.lang.Unroll @@ -30,7 +31,7 @@ class DefaultConfigurationSpec extends Specification { def 'Calling configuration.#method(#key, #defaultValue) gives #value as result'() { given: ResourceBundle bundle = new MapResourceBundle() - Configuration configuration = new ResourceBundleConfiguration(bundle) + Configuration configuration = new ResourceBundleConfiguration(new DefaultConverterRegistry(), bundle) expect: value == (defaultValue != null ? configuration."$method"(key, defaultValue) : configuration."$method"(key)) @@ -67,7 +68,7 @@ class DefaultConfigurationSpec extends Specification { def 'Can resolve nested keys from sample application configuration'() { given: ResourceBundle bundle = new AppResourceBundle() - Configuration configuration = new ResourceBundleConfiguration(bundle) + Configuration configuration = new ResourceBundleConfiguration(new DefaultConverterRegistry(), bundle) Properties props = configuration.asProperties() expect: diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/resources/CustomResourceResolverTests.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/resources/CustomResourceResolverTests.groovy index d20b1c268c0..9eb53dd1bac 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/resources/CustomResourceResolverTests.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/resources/CustomResourceResolverTests.groovy @@ -20,18 +20,17 @@ package org.codehaus.griffon.runtime.core.resources import com.google.guiceberry.GuiceBerryModule import com.google.guiceberry.junit4.GuiceBerryRule import com.google.inject.AbstractModule -import com.google.inject.Inject -import griffon.core.editors.IntegerPropertyEditor -import griffon.core.editors.PropertyEditorResolver import griffon.core.resources.NoSuchResourceException import griffon.core.resources.ResourceResolver import griffon.util.AbstractMapResourceBundle import org.junit.Rule import org.junit.Test import org.kordamp.jsr377.converter.DefaultConverterRegistry +import org.kordamp.jsr377.converter.IntegerConverter import javax.annotation.Nonnull import javax.application.converter.ConverterRegistry +import javax.inject.Inject import javax.inject.Singleton class CustomResourceResolverTests { @@ -41,6 +40,9 @@ class CustomResourceResolverTests { @Inject private ResourceResolver resourceResolver + @Inject + private ConverterRegistry converterRegistry + @Test void getAllDefinedMessages() { assert resourceResolver.resolveResource('key.string') == 'string' @@ -156,8 +158,8 @@ class CustomResourceResolverTests { @Test void exerciseAllMethodsWithConverter() { - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Integer, IntegerPropertyEditor) + converterRegistry.clear() + converterRegistry.registerConverter(Integer, IntegerConverter) try { Integer defaultValue = 21 @@ -179,7 +181,7 @@ class CustomResourceResolverTests { assert 42 == resourceResolver.resolveResourceConverted('integer', [:], Locale.default, Integer) assert 42 == resourceResolver.resolveResourceConverted('integer', [] as Object[], Locale.default, Integer) } finally { - PropertyEditorResolver.clear() + converterRegistry.clear() } } diff --git a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/storage/DefaultObjectFactorySpec.groovy b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/storage/DefaultObjectFactorySpec.groovy index 28a96b93aed..bc1edae1051 100644 --- a/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/storage/DefaultObjectFactorySpec.groovy +++ b/subprojects/griffon-core/src/test/groovy/org/codehaus/griffon/runtime/core/storage/DefaultObjectFactorySpec.groovy @@ -26,6 +26,7 @@ import griffon.util.ExpandableResourceBundle import integration.TestGriffonApplication import org.codehaus.griffon.runtime.core.configuration.AbstractConfiguration import org.codehaus.griffon.runtime.core.event.DefaultEventRouter +import org.kordamp.jsr377.converter.DefaultConverterRegistry import spock.lang.Specification import spock.lang.Unroll @@ -79,6 +80,7 @@ class TestConfiguration extends AbstractConfiguration { private ResourceBundle resourceBundle TestConfiguration() { + super(new DefaultConverterRegistry()) resourceBundle = ExpandableResourceBundle.wrapResourceBundle(new AbstractMapResourceBundle() { @Override protected void initialize(@Nonnull Map entries) { @@ -115,7 +117,7 @@ class TestConfiguration extends AbstractConfiguration { } @Override - Object get(@Nonnull String key) { + T get(@Nonnull String key) { return resourceBundle.getObject(key) } } diff --git a/subprojects/griffon-core/src/test/java/griffon/util/TypeUtilsTest.java b/subprojects/griffon-core/src/test/java/griffon/util/TypeUtilsTest.java index 237c99823b0..15aea142e05 100644 --- a/subprojects/griffon-core/src/test/java/griffon/util/TypeUtilsTest.java +++ b/subprojects/griffon-core/src/test/java/griffon/util/TypeUtilsTest.java @@ -17,8 +17,6 @@ */ package griffon.util; -import griffon.core.editors.PropertyEditorResolver; -import griffon.core.editors.URIPropertyEditor; import org.junit.Test; import java.math.BigDecimal; @@ -181,6 +179,8 @@ public void castToNumberWithDefaultCantHandleNonNumberValues() { TypeUtils.castToNumber(new Object(), 1); } + /* + @Test public void convertValue() throws URISyntaxException { URI expected = new URI("http://localhost"); assertEquals(expected, TypeUtils.convertValue(URI.class, expected)); @@ -189,6 +189,7 @@ public void convertValue() throws URISyntaxException { assertEquals(expected, TypeUtils.convertValue(URI.class, "http://localhost", "format")); TypeUtils.convertValue(TypeUtils.class, expected); } + */ @Test public void convertBooleans() { diff --git a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorASTTransformation.java b/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorASTTransformation.java deleted file mode 100644 index 02f93b4630a..00000000000 --- a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorASTTransformation.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.codehaus.griffon.compile.core.ast.editor; - -import griffon.metadata.PropertyEditorFor; -import org.codehaus.griffon.compile.core.processor.editor.PropertyEditorCollector; -import org.codehaus.groovy.ast.AnnotationNode; -import org.codehaus.groovy.ast.ClassNode; -import org.codehaus.groovy.ast.ModuleNode; -import org.codehaus.groovy.ast.expr.ClassExpression; -import org.codehaus.groovy.ast.expr.Expression; -import org.codehaus.groovy.control.CompilePhase; -import org.codehaus.groovy.transform.ASTTransformation; -import org.codehaus.groovy.transform.GroovyASTTransformation; -import org.kordamp.gipsy.transform.GipsyASTTransformation; -import org.kordamp.jipsy.ServiceProviderFor; -import org.kordamp.jipsy.processor.CheckResult; -import org.kordamp.jipsy.processor.LogLocation; -import org.kordamp.jipsy.processor.Persistence; - -import java.beans.PropertyEditor; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static java.lang.reflect.Modifier.isAbstract; -import static java.lang.reflect.Modifier.isPublic; - -/** - * @author Andres Almiray - */ -@ServiceProviderFor(ASTTransformation.class) -@GroovyASTTransformation(phase = CompilePhase.CLASS_GENERATION) -public class PropertyEditorASTTransformation extends GipsyASTTransformation { - public static final String NAME = PropertyEditorASTTransformation.class.getName() - + " (" + PropertyEditorASTTransformation.class.getPackage().getImplementationVersion() + ")"; - - private static final ClassNode PROPERTY_EDITOR_FOR_TYPE = makeClassSafe(PropertyEditorFor.class); - private static final ClassNode PROPERTY_EDITOR_TYPE = makeClassSafe(PropertyEditor.class); - - private Persistence persistence; - private PropertyEditorCollector data; - - @Override - protected ClassNode getAnnotationClassNode() { - return PROPERTY_EDITOR_FOR_TYPE; - } - - @Override - protected void initialize(ModuleNode moduleNode) { - super.initialize(moduleNode); - - File outputDir = moduleNode.getContext().getConfiguration().getTargetDirectory(); - persistence = new PropertyEditorPersistence(NAME, options.dir(), outputDir, logger); - data = new PropertyEditorCollector(persistence.getInitializer(), logger); - data.load(); - } - - @Override - protected void removeStaleData(ClassNode classNode, ModuleNode moduleNode) { - data.removePropertyEditor(classNode.getName()); - } - - protected void handleAnnotations(ClassNode classNode, List annotations, ModuleNode moduleNode) { - CheckResult checkResult = checkCurrentClass(classNode); - if (checkResult.isError()) { - addError(checkResult.getMessage(), classNode, moduleNode.getContext()); - return; - } - - for (ClassNode type : findTypes(annotations)) { - CheckResult implementationResult = isImplementation(classNode, PROPERTY_EDITOR_TYPE); - if (implementationResult.isError()) { - addError(implementationResult.getMessage(), classNode, moduleNode.getContext()); - } else { - register(type.getName(), classNode); - } - } - } - - @Override - protected void writeData() { - // if (data.isModified()) { - String content = data.toList(); - if (content.length() > 0) { - logger.note(LogLocation.LOG_FILE, "Writing output"); - try { - persistence.write(PropertyEditor.class.getName(), content); - } catch (IOException ioe) { - // TODO print out error - } - persistence.writeLog(); - } else { - logger.note(LogLocation.LOG_FILE, "Writing output"); - try { - persistence.delete(); - } catch (IOException e) { - logger.warning(LogLocation.LOG_FILE, "An error occurred while deleting data file"); - } - } - // } - } - - private CheckResult checkCurrentClass(ClassNode currentClass) { - if (currentClass.isInterface()) { - return CheckResult.valueOf("is not a class"); - } - if (!isPublic(currentClass.getModifiers())) { - return CheckResult.valueOf("is not a public class"); - } - - if (isAbstract(currentClass.getModifiers())) { - return CheckResult.valueOf("is an abstract class"); - } - - if (!hasNoArgsConstructor(currentClass)) { - return CheckResult.valueOf("has no public no-args constructor"); - } - - return CheckResult.OK; - } - - private List findTypes(List annotations) { - List types = new ArrayList<>(); - - for (AnnotationNode annotation : annotations) { - for (Expression expr : findCollectionValueMember(annotation, "value")) { - if (expr instanceof ClassExpression) { - types.add(((ClassExpression) expr).getType()); - } - } - } - - return types; - } - - private void register(String type, ClassNode editor) { - data.getPropertyEditor(type, editor.getName()); - } -} \ No newline at end of file diff --git a/subprojects/griffon-groovy/src/test/groovy/org/codehaus/griffon/runtime/groovy/util/GroovyScriptResourceBundleLoaderSpec.groovy b/subprojects/griffon-groovy/src/test/groovy/org/codehaus/griffon/runtime/groovy/util/GroovyScriptResourceBundleLoaderSpec.groovy index a097104a766..523e59a825c 100644 --- a/subprojects/griffon-groovy/src/test/groovy/org/codehaus/griffon/runtime/groovy/util/GroovyScriptResourceBundleLoaderSpec.groovy +++ b/subprojects/griffon-groovy/src/test/groovy/org/codehaus/griffon/runtime/groovy/util/GroovyScriptResourceBundleLoaderSpec.groovy @@ -53,10 +53,8 @@ class GroovyScriptResourceBundleLoaderSpec extends Specification { def 'Load bundle #name and check #key = #value'() { when: Collection bundles = resourceBundleLoader.load(name) - println bundles then: - println bundles[0].keySet() bundles.size() == 1 bundles[0].getObject(key) == value diff --git a/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.groovy b/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.groovy index 6c737651b58..1854bee3fda 100644 --- a/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.groovy +++ b/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.groovy @@ -1,3 +1,20 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ application(title: app.config.application.title, pack: true) { actions { action(id: 'clickAction', name: 'Click', closure: { controller.click(it) }) diff --git a/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.xml b/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.xml index c956bf3aa38..c1411a7e441 100644 --- a/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.xml +++ b/subprojects/griffon-groovy/src/test/resources/griffon/util/groovy/application.xml @@ -1,3 +1,22 @@ + { public static String format(Color color) { return ColorFormatter.LONG.format(color); } - @Override - public String getAsText() { - if (null == getValue()) { return null; } - return isBlank(getFormat()) ? format((Color) getValueInternal()) : getFormattedValue(); + public String toString(Color value) throws ConversionException { + if (null == value) { + return null; + } else { + return null == getFormat() ? format(value) : this.getFormatted(value, this.getFormat()); + } } @Override - protected void setValueInternal(Object value) { + protected Color convertFromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value).trim()); + return handleAsString(String.valueOf(value).trim()); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Color) { - super.setValueInternal(value); + return (Color) value; } else { throw illegalValue(value, Color.class); } } @Override - protected Formatter resolveFormatter() { - return isNotBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; + protected Formatter resolveFormatter(String s) { + return !isBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; } - protected void handleAsString(String str) { + protected Color handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } try { - super.setValueInternal(ColorFormatter.parseColor(str)); + return ColorFormatter.parseColor(str); } catch (ParseException e) { throw illegalValue(str, Color.class, e); } } - protected void handleAsList(List list) { + protected Color handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } List values = new ArrayList<>(list); @@ -109,27 +106,25 @@ protected void handleAsList(List list) { throw illegalValue(list, Color.class); } } - super.setValueInternal( - new Color( - (Double) values.get(0), - (Double) values.get(1), - (Double) values.get(2), - (Double) values.get(3) - ) + + return new Color( + (Double) values.get(0), + (Double) values.get(1), + (Double) values.get(2), + (Double) values.get(3) ); } - protected void handleAsMap(Map map) { + protected Color handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double r = getMapValue(map, "red", 0d); double g = getMapValue(map, "green", 0d); double b = getMapValue(map, "blue", 0d); double a = getMapValue(map, "alpha", 1d); - super.setValueInternal(new Color(r, g, b, a)); + return new Color(r, g, b, a); } protected double parse(String val) { @@ -157,8 +152,8 @@ protected double getMapValue(Map map, String key, double defaultValue) { throw illegalValue(map, Color.class); } - protected void handleAsNumber(Number value) { + protected Color handleAsNumber(Number value) { double c = parse(value); - super.setValueInternal(new Color(c, c, c, 1d)); + return new Color(c, c, c, 1d); } } \ No newline at end of file diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Dimension2DPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Dimension2DConverter.java similarity index 64% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Dimension2DPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Dimension2DConverter.java index d1ddd6f1024..533c327aede 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Dimension2DPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Dimension2DConverter.java @@ -15,100 +15,91 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.geometry.Dimension2D; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray + * @since 3.0.0 */ -@PropertyEditorFor(Dimension2D.class) -public class Dimension2DPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Dimension2D dimension = (Dimension2D) getValue(); - return dimension.getWidth() + ", " + dimension.getHeight(); - } - +public class Dimension2DConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Dimension2D fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Dimension2D) { - super.setValueInternal(value); + return (Dimension2D) value; } else { throw illegalValue(value, Dimension2D.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Dimension2D value) throws ConversionException { + if (null == value) { return null; } + return value.getWidth() + ", " + value.getHeight(); + } + + + protected Dimension2D handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: double s = parseValue(parts[0]); - super.setValueInternal(new Dimension2D(s, s)); - break; + return new Dimension2D(s, s); case 2: double w = parseValue(parts[0]); double h = parseValue(parts[1]); - super.setValueInternal(new Dimension2D(w, h)); - break; + return new Dimension2D(w, h); default: throw illegalValue(str, Dimension2D.class); } } - protected void handleAsList(List list) { + protected Dimension2D handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } switch (list.size()) { case 1: double s = parseValue(list.get(0)); - super.setValueInternal(new Dimension2D(s, s)); - break; + return new Dimension2D(s, s); case 2: double w = parseValue(list.get(0)); double h = parseValue(list.get(1)); - super.setValueInternal(new Dimension2D(w, h)); - break; + return new Dimension2D(w, h); default: throw illegalValue(list, Dimension2D.class); } } - protected void handleAsMap(Map map) { + protected Dimension2D handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double w = getMapValue(map, "width", 0); double h = getMapValue(map, "height", 0); - super.setValueInternal(new Dimension2D(w, h)); + return new Dimension2D(w, h); } protected double parseValue(Object value) { @@ -134,7 +125,7 @@ protected double parse(Number val) { protected double getMapValue(Map map, String key, double defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -145,8 +136,8 @@ protected double getMapValue(Map map, String key, double defaultValue) { throw illegalValue(map, Dimension2D.class); } - protected void handleAsNumber(Number value) { + protected Dimension2D handleAsNumber(Number value) { double s = parse(value); - super.setValueInternal(new Dimension2D(s, s)); + return new Dimension2D(s, s); } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/GraphicPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/GraphicConverter.java similarity index 64% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/GraphicPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/GraphicConverter.java index 5887f7c48a8..6f47f12a9b2 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/GraphicPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/GraphicConverter.java @@ -15,68 +15,64 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.scene.Node; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.3.0 + * @since 3.0.0 */ -@PropertyEditorFor(Node.class) -public class GraphicPropertyEditor extends AbstractPropertyEditor { - protected final ImagePropertyEditor imagePropertyEditor = new ImagePropertyEditor(); +public class GraphicConverter extends AbstractConverter { + protected final ImageConverter imageConverter = new ImageConverter(); @Override - protected void setValueInternal(Object value) { + public Node fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else { - handleWithImagePropertyEditor(value); + return handleWithImageConverter(value); } } - protected void handleAsString(String str) { + protected Node handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); + return null; } else if (str.contains("|")) { - handleAsClassWithArg(str); + return handleAsClassWithArg(str); } else { - handleWithImagePropertyEditor(str); + return handleWithImageConverter(str); } } - protected void handleWithImagePropertyEditor(Object value) { + protected Node handleWithImageConverter(Object value) { try { - imagePropertyEditor.setValueInternal(value); - Image image = (Image) imagePropertyEditor.getValue(); + Image image = imageConverter.fromObject(value); if (image != null) { - super.setValueInternal(new ImageView(image)); + return new ImageView(image); } else { - super.setValueInternal(null); + return null; } } catch (IllegalArgumentException iae) { throw illegalValue(value, Node.class, iae); } } - protected void handleAsClassWithArg(String str) { + protected Node handleAsClassWithArg(String str) { String[] args = str.split("\\|"); if (args.length == 2) { Class iconClass = null; try { - iconClass = GraphicPropertyEditor.class.getClassLoader().loadClass(args[0]); + iconClass = GraphicConverter.class.getClassLoader().loadClass(args[0]); } catch (ClassNotFoundException e) { throw illegalValue(str, Node.class, e); } @@ -91,9 +87,9 @@ protected void handleAsClassWithArg(String str) { try { Object o = constructor.newInstance(args[1]); if (o instanceof Node) { - super.setValueInternal(o); + return (Node) o; } else if (o instanceof Image) { - super.setValueInternal(new ImageView((Image) o)); + return new ImageView((Image) o); } else { throw illegalValue(str, Node.class); } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/ImagePropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/ImageConverter.java similarity index 66% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/ImagePropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/ImageConverter.java index 3980675d2a7..ae5ef1084dc 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/ImagePropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/ImageConverter.java @@ -15,13 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.io.File; import java.io.InputStream; import java.lang.reflect.Constructor; @@ -30,82 +30,79 @@ import java.net.URI; import java.net.URL; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray */ -@PropertyEditorFor(Image.class) -public class ImagePropertyEditor extends AbstractPropertyEditor { +public class ImageConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Image fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof File) { - handleAsFile((File) value); + return handleAsFile((File) value); } else if (value instanceof URL) { - handleAsURL((URL) value); + return handleAsURL((URL) value); } else if (value instanceof URI) { - handleAsURI((URI) value); + return handleAsURI((URI) value); } else if (value instanceof InputStream) { - handleAsInputStream((InputStream) value); + return handleAsInputStream((InputStream) value); } else if (value instanceof Image) { - super.setValueInternal(value); + return (Image) value; } else { throw illegalValue(value, Image.class); } } - protected void handleAsString(String str) { + protected Image handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); + return null; } else if (str.contains("|")) { - handleAsClassWithArg(str); + return handleAsClassWithArg(str); } else { - handleAsURL(getClass().getClassLoader().getResource(str)); + return handleAsURL(getClass().getClassLoader().getResource(str)); } } - protected void handleAsFile(File file) { + protected Image handleAsFile(File file) { try { - handleAsURL(file.toURI().toURL()); + return handleAsURL(file.toURI().toURL()); } catch (MalformedURLException e) { throw illegalValue(file, URL.class, e); } } - protected void handleAsURL(URL url) { + protected Image handleAsURL(URL url) { try { - super.setValueInternal(new Image(url.toString())); + return new Image(url.toString()); } catch (Exception e) { throw illegalValue(url, URL.class, e); } } - protected void handleAsURI(URI uri) { + protected Image handleAsURI(URI uri) { try { - handleAsURL(uri.toURL()); + return handleAsURL(uri.toURL()); } catch (MalformedURLException e) { throw illegalValue(uri, URL.class, e); } } - protected void handleAsInputStream(InputStream stream) { + protected Image handleAsInputStream(InputStream stream) { try { - super.setValueInternal(new Image(stream)); + return new Image(stream); } catch (Exception e) { throw illegalValue(stream, URL.class, e); } } - protected void handleAsClassWithArg(String str) { + protected Image handleAsClassWithArg(String str) { String[] args = str.split("\\|"); if (args.length == 2) { Class iconClass = null; try { - iconClass = ImagePropertyEditor.class.getClassLoader().loadClass(args[0]); + iconClass = ImageConverter.class.getClassLoader().loadClass(args[0]); } catch (ClassNotFoundException e) { throw illegalValue(str, Image.class, e); } @@ -120,9 +117,9 @@ protected void handleAsClassWithArg(String str) { try { Object o = constructor.newInstance(args[1]); if (o instanceof Image) { - super.setValueInternal(o); + return (Image) o; } else if (o instanceof ImageView) { - super.setValueInternal(((ImageView) o).getImage()); + return ((ImageView) o).getImage(); } else { throw illegalValue(str, Image.class); } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/InsetsPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/InsetsConverter.java similarity index 69% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/InsetsPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/InsetsConverter.java index 55622da1317..c8b91d882d5 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/InsetsPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/InsetsConverter.java @@ -15,52 +15,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.geometry.Insets; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray + * @since 3.0.0 */ -@PropertyEditorFor(Insets.class) -public class InsetsPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Insets i = (Insets) getValue(); - return i.getTop() + ", " + i.getRight() + ", " + i.getBottom() + ", " + i.getLeft(); - } - +public class InsetsConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Insets fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Insets) { - super.setValueInternal(value); + return (Insets) value; } else { throw illegalValue(value, Insets.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Insets value) throws ConversionException { + if (null == value) { return null; } + return value.getTop() + ", " + value.getRight() + ", " + value.getBottom() + ", " + value.getLeft(); + } + + protected Insets handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } double t = 0; @@ -77,17 +73,15 @@ protected void handleAsString(String str) { r = parseValue(parts[1]); case 1: t = parseValue(parts[0]); - super.setValueInternal(new Insets(t, r, b, l)); - break; + return new Insets(t, r, b, l); default: throw illegalValue(str, Insets.class); } } - protected void handleAsList(List list) { + protected Insets handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double t = 0; @@ -103,24 +97,22 @@ protected void handleAsList(List list) { r = parseValue(list.get(1)); case 1: t = parseValue(list.get(0)); - super.setValueInternal(new Insets(t, r, b, l)); - break; + return new Insets(t, r, b, l); default: throw illegalValue(list, Insets.class); } } - protected void handleAsMap(Map map) { + protected Insets handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double t = getMapValue(map, "top", 0); double l = getMapValue(map, "left", 0); double r = getMapValue(map, "right", 0); double b = getMapValue(map, "bottom", 0); - super.setValueInternal(new Insets(t, r, b, l)); + return new Insets(t, r, b, l); } protected double parseValue(Object value) { @@ -146,7 +138,7 @@ protected double parse(Number val) { protected double getMapValue(Map map, String key, double defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -157,8 +149,8 @@ protected double getMapValue(Map map, String key, double defaultValue) { throw illegalValue(map, Insets.class); } - protected void handleAsNumber(Number value) { + protected Insets handleAsNumber(Number value) { double c = parse(value); - super.setValueInternal(new Insets(c, c, c, c)); + return new Insets(c, c, c, c); } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/LinearGradientPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/LinearGradientConverter.java similarity index 76% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/LinearGradientPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/LinearGradientConverter.java index 314446a99de..aa4837422b3 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/LinearGradientPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/LinearGradientConverter.java @@ -15,66 +15,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.4.0 + * @since 3.0.0 */ -@PropertyEditorFor(LinearGradient.class) -public class LinearGradientPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - return getValueInternal().toString(); - } - +public class LinearGradientConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public LinearGradient fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value).trim()); + return handleAsString(String.valueOf(value).trim()); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof LinearGradient) { - super.setValueInternal(value); + return (LinearGradient) value; } else { throw illegalValue(value, LinearGradient.class); } } - protected void handleAsString(String str) { + protected LinearGradient handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } try { - super.setValueInternal(LinearGradient.valueOf(str)); + return LinearGradient.valueOf(str); } catch (Exception e) { throw illegalValue(str, LinearGradient.class, e); } } - protected void handleAsList(List list) { + protected LinearGradient handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double sx = 0; @@ -95,17 +84,15 @@ protected void handleAsList(List list) { ey = parseValue(list.get(3)); proportional = (Boolean) list.get(4); stops = (List) list.get(5); - super.setValueInternal(new LinearGradient(sx, sy, ex, ey, proportional, cyclicMethod, stops)); - break; + return new LinearGradient(sx, sy, ex, ey, proportional, cyclicMethod, stops); default: throw illegalValue(list, LinearGradient.class); } } - protected void handleAsMap(Map map) { + protected LinearGradient handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double sx = (Double) getMapValue(map, "sx", 0d); @@ -124,7 +111,7 @@ protected void handleAsMap(Map map) { cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue)); } - super.setValueInternal(new LinearGradient(sx, sy, ex, ey, proportional, cyclicMethod, stops)); + return new LinearGradient(sx, sy, ex, ey, proportional, cyclicMethod, stops); } protected CycleMethod parseCyclicMethod(Object source, String str) { diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/PaintPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/PaintConverter.java similarity index 50% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/PaintPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/PaintConverter.java index 7443c4e8bbb..28904b51d5e 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/PaintPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/PaintConverter.java @@ -15,55 +15,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; -import javafx.scene.paint.Color; -import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Paint; -import javafx.scene.paint.RadialGradient; +import org.kordamp.jsr377.converter.AbstractConverter; -import java.beans.PropertyEditor; +import javax.application.converter.ConversionException; +import javax.application.converter.Converter; import java.util.List; import java.util.Map; -import static griffon.core.editors.PropertyEditorResolver.findEditor; - /** * @author Andres Almiray - * @since 2.4.0 + * @since 3.0.0 */ -@PropertyEditorFor(Paint.class) -public class PaintPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - return getValueInternal().toString(); - } +public class PaintConverter extends AbstractConverter { + private static final Converter[] CONVERTERS = new Converter[]{ + new ColorConverter(), + new RadialGradientConverter(), + new LinearGradientConverter() + }; @Override - protected void setValueInternal(Object value) { + public Paint fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleInternal(String.valueOf(value).trim()); + return handleInternal(String.valueOf(value).trim()); } else if (value instanceof List || value instanceof Map) { - handleInternal(value); + return handleInternal(value); } else if (value instanceof Paint) { - super.setValueInternal(value); + return (Paint) value; } else { throw illegalValue(value, Paint.class); } } - private void handleInternal(Object value) { - for (Class type : new Class[]{Color.class, RadialGradient.class, LinearGradient.class}) { + private Paint handleInternal(Object value) { + for (Converter converter : CONVERTERS) { try { - PropertyEditor propertyEditor = findEditor(type); - propertyEditor.setValue(value); - super.setValueInternal(propertyEditor.getValue()); - return; + return (Paint) converter.fromObject(value); } catch (Exception e) { // ignore } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Point2DPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Point2DConverter.java similarity index 66% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Point2DPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Point2DConverter.java index c9ccd138eb8..2d510c5e08d 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Point2DPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Point2DConverter.java @@ -15,100 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.geometry.Point2D; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray + * @since 3.0.0 */ -@PropertyEditorFor(Point2D.class) -public class Point2DPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Point2D p = (Point2D) getValue(); - return p.getX() + ", " + p.getY(); - } - +public class Point2DConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Point2D fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Point2D) { - super.setValueInternal(value); + return (Point2D) value; } else { throw illegalValue(value, Point2D.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Point2D value) throws ConversionException { + if (null == value) { return null; } + return value.getX() + ", " + value.getY(); + } + + protected Point2D handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: double s = parseValue(parts[0]); - super.setValueInternal(new Point2D(s, s)); - break; + return new Point2D(s, s); case 2: double x = parseValue(parts[0]); double y = parseValue(parts[1]); - super.setValueInternal(new Point2D(x, y)); - break; + return new Point2D(x, y); default: throw illegalValue(str, Point2D.class); } } - protected void handleAsList(List list) { + protected Point2D handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } switch (list.size()) { case 1: double s = parseValue(list.get(0)); - super.setValueInternal(new Point2D(s, s)); - break; + return new Point2D(s, s); case 2: double x = parseValue(list.get(0)); double y = parseValue(list.get(1)); - super.setValueInternal(new Point2D(x, y)); - break; + return new Point2D(x, y); default: throw illegalValue(list, Point2D.class); } } - protected void handleAsMap(Map map) { + protected Point2D handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double x = getMapValue(map, "x", 0); double y = getMapValue(map, "y", 0); - super.setValueInternal(new Point2D(x, y)); + return new Point2D(x, y); } protected double parseValue(Object value) { @@ -144,8 +134,8 @@ protected double getMapValue(Map map, String key, double defaultValue) { throw illegalValue(map, Point2D.class); } - protected void handleAsNumber(Number value) { + protected Point2D handleAsNumber(Number value) { double s = parse(value); - super.setValueInternal(new Point2D(s, s)); + return new Point2D(s, s); } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/RadialGradientPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/RadialGradientConverter.java similarity index 76% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/RadialGradientPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/RadialGradientConverter.java index c0a8bc4a855..6ab5f3fb65e 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/RadialGradientPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/RadialGradientConverter.java @@ -15,66 +15,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.RadialGradient; import javafx.scene.paint.Stop; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.4.0 + * @since 3.0.0 */ -@PropertyEditorFor(RadialGradient.class) -public class RadialGradientPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - return getValueInternal().toString(); - } - +public class RadialGradientConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public RadialGradient fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value).trim()); + return handleAsString(String.valueOf(value).trim()); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof RadialGradient) { - super.setValueInternal(value); + return (RadialGradient) value; } else { throw illegalValue(value, RadialGradient.class); } } - protected void handleAsString(String str) { + protected RadialGradient handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } try { - super.setValueInternal(RadialGradient.valueOf(str)); + return RadialGradient.valueOf(str); } catch (Exception e) { throw illegalValue(str, RadialGradient.class, e); } } - protected void handleAsList(List list) { + protected RadialGradient handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double fa = 0; @@ -97,17 +86,15 @@ protected void handleAsList(List list) { r = parseValue(list.get(4)); proportional = (Boolean) list.get(5); stops = (List) list.get(6); - super.setValueInternal(new RadialGradient(fa, fd, cx, cy, r, proportional, cyclicMethod, stops)); - break; + return new RadialGradient(fa, fd, cx, cy, r, proportional, cyclicMethod, stops); default: throw illegalValue(list, RadialGradient.class); } } - protected void handleAsMap(Map map) { + protected RadialGradient handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double fa = (Double) getMapValue(map, "fa", 0d); @@ -127,7 +114,7 @@ protected void handleAsMap(Map map) { cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue)); } - super.setValueInternal(new RadialGradient(fa, fd, cx, cy, r, proportional, cyclicMethod, stops)); + return new RadialGradient(fa, fd, cx, cy, r, proportional, cyclicMethod, stops); } protected CycleMethod parseCyclicMethod(Object source, String str) { diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Rectangle2DPropertyEditor.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Rectangle2DConverter.java similarity index 69% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Rectangle2DPropertyEditor.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Rectangle2DConverter.java index 4a7b6c621fc..ab8af309b14 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/Rectangle2DPropertyEditor.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/Rectangle2DConverter.java @@ -15,50 +15,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors; +package griffon.javafx.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import javafx.geometry.Rectangle2D; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray + * @since 3.0.0 */ -@PropertyEditorFor(Rectangle2D.class) -public class Rectangle2DPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Rectangle2D r = (Rectangle2D) getValue(); - return r.getMinX() + ", " + r.getMinY() + ", " + r.getWidth() + ", " + r.getHeight(); - } +public class Rectangle2DConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Rectangle2D fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Rectangle2D) { - super.setValueInternal(value); + return (Rectangle2D) value; } else { throw illegalValue(value, Rectangle2D.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Rectangle2D value) throws ConversionException { + if (null == value) { return null; } + return value.getMinX() + ", " + value.getMinY() + ", " + value.getWidth() + ", " + value.getHeight(); + } + + protected Rectangle2D handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); @@ -68,17 +65,15 @@ protected void handleAsString(String str) { double y = parseValue(parts[1]); double w = parseValue(parts[2]); double h = parseValue(parts[3]); - super.setValueInternal(new Rectangle2D(x, y, w, h)); - break; + return new Rectangle2D(x, y, w, h); default: throw illegalValue(str, Rectangle2D.class); } } - protected void handleAsList(List list) { + protected Rectangle2D handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } switch (list.size()) { @@ -87,24 +82,22 @@ protected void handleAsList(List list) { double y = parseValue(list.get(1)); double w = parseValue(list.get(2)); double h = parseValue(list.get(3)); - super.setValueInternal(new Rectangle2D(x, y, w, h)); - break; + return new Rectangle2D(x, y, w, h); default: throw illegalValue(list, Rectangle2D.class); } } - protected void handleAsMap(Map map) { + protected Rectangle2D handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } double x = getMapValue(map, "x", 0); double y = getMapValue(map, "y", 0); double w = getMapValue(map, "width", 0); double h = getMapValue(map, "height", 0); - super.setValueInternal(new Rectangle2D(x, y, w, h)); + return new Rectangle2D(x, y, w, h); } protected double parseValue(Object value) { @@ -130,7 +123,7 @@ protected double parse(Number val) { protected double getMapValue(Map map, String key, double defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/package-info.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/package-info.java similarity index 86% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/package-info.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/package-info.java index 9710dd41e26..2785dc96aae 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/package-info.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/package-info.java @@ -16,9 +16,9 @@ * limitations under the License. */ /** - * Swing specific Java Beans compliant property editors. + * JavaFX specific type converters. * - * @since 2.0.0 + * @since 3.0.0 */ -package griffon.swing.editors; +package griffon.javafx.converters; diff --git a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorPersistence.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ColorConverterProvider.java similarity index 54% rename from subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorPersistence.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ColorConverterProvider.java index d2763fc41fd..01511ef1361 100644 --- a/subprojects/griffon-core-compile/src/main/java/org/codehaus/griffon/compile/core/processor/editor/PropertyEditorPersistence.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ColorConverterProvider.java @@ -15,25 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.codehaus.griffon.compile.core.processor.editor; +package griffon.javafx.converters.spi; -import org.kordamp.jipsy.processor.AbstractResourcePersistence; -import org.kordamp.jipsy.processor.Logger; -import org.kordamp.jipsy.processor.SimpleFileFilter; +import griffon.javafx.converters.ColorConverter; +import javafx.scene.paint.Color; +import org.kordamp.jipsy.ServiceProviderFor; -import javax.annotation.processing.Filer; -import java.io.FileFilter; +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; /** * @author Andres Almiray + * @since 3.0.0 */ -public class PropertyEditorPersistence extends AbstractResourcePersistence { - public PropertyEditorPersistence(String name, String root, Filer filer, Logger logger) { - super(filer, name, logger, root + "META-INF/editors/"); +@ServiceProviderFor(ConverterProvider.class) +public class ColorConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Color.class; } @Override - protected FileFilter getFileFilter() { - return SimpleFileFilter.INSTANCE; + public Class> getConverterType() { + return ColorConverter.class; } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Dimension2DConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Dimension2DConverterProvider.java new file mode 100644 index 00000000000..130bc00ac85 --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Dimension2DConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.Dimension2DConverter; +import javafx.geometry.Dimension2D; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class Dimension2DConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Dimension2D.class; + } + + @Override + public Class> getConverterType() { + return Dimension2DConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/GraphicConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/GraphicConverterProvider.java new file mode 100644 index 00000000000..82d1775b6b1 --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/GraphicConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.GraphicConverter; +import javafx.scene.Node; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class GraphicConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public Class> getConverterType() { + return GraphicConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ImageConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ImageConverterProvider.java new file mode 100644 index 00000000000..9d4d672564a --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/ImageConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.ImageConverter; +import javafx.scene.image.Image; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class ImageConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Image.class; + } + + @Override + public Class> getConverterType() { + return ImageConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/InsetsConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/InsetsConverterProvider.java new file mode 100644 index 00000000000..78a28f3f42f --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/InsetsConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.InsetsConverter; +import javafx.geometry.Insets; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class InsetsConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Insets.class; + } + + @Override + public Class> getConverterType() { + return InsetsConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/LinearGradientConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/LinearGradientConverterProvider.java new file mode 100644 index 00000000000..ec26e72d9d5 --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/LinearGradientConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.LinearGradientConverter; +import javafx.scene.paint.LinearGradient; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class LinearGradientConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return LinearGradient.class; + } + + @Override + public Class> getConverterType() { + return LinearGradientConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/PaintConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/PaintConverterProvider.java new file mode 100644 index 00000000000..09381999ea7 --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/PaintConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.PaintConverter; +import javafx.scene.paint.Paint; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class PaintConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Paint.class; + } + + @Override + public Class> getConverterType() { + return PaintConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Point2DConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Point2DConverterProvider.java new file mode 100644 index 00000000000..2f6536f59a6 --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Point2DConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.Point2DConverter; +import javafx.geometry.Point2D; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class Point2DConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Point2D.class; + } + + @Override + public Class> getConverterType() { + return Point2DConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/RadialGradientConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/RadialGradientConverterProvider.java new file mode 100644 index 00000000000..1431c2623cc --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/RadialGradientConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.RadialGradientConverter; +import javafx.scene.paint.RadialGradient; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class RadialGradientConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return RadialGradient.class; + } + + @Override + public Class> getConverterType() { + return RadialGradientConverter.class; + } +} diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Rectangle2DConverterProvider.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Rectangle2DConverterProvider.java new file mode 100644 index 00000000000..38fb5bf351b --- /dev/null +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/Rectangle2DConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi; + +import griffon.javafx.converters.Rectangle2DConverter; +import javafx.geometry.Rectangle2D; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class Rectangle2DConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Rectangle2D.class; + } + + @Override + public Class> getConverterType() { + return Rectangle2DConverter.class; + } +} diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/package-info.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/package-info.java similarity index 86% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/package-info.java rename to subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/package-info.java index 3de90be82f4..eaea918953c 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/package-info.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/converters/spi/package-info.java @@ -16,9 +16,9 @@ * limitations under the License. */ /** - * Pivot specific Java Beans compliant property editors. + * JavaFX specific type converter providers. * - * @since 2.0.0 + * @since 3.0.0 */ -package griffon.pivot.editors; +package griffon.javafx.converters.spi; diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/formatters/ColorFormatter.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/formatters/ColorFormatter.java index d0a0fa4b597..694bfcddf10 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/formatters/ColorFormatter.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/formatters/ColorFormatter.java @@ -17,16 +17,15 @@ */ package griffon.javafx.formatters; -import griffon.core.formatters.AbstractFormatter; -import griffon.core.formatters.ParseException; import javafx.scene.paint.Color; +import org.kordamp.jsr377.formatter.AbstractFormatter; +import org.kordamp.jsr377.formatter.ParseException; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.lang.reflect.Field; import java.util.Arrays; -import static griffon.util.GriffonNameUtils.isBlank; import static java.lang.Integer.toHexString; import static java.util.Objects.requireNonNull; @@ -52,7 +51,7 @@ *

* * @author Andres Almiray - * @see griffon.core.formatters.Formatter + * @see org.kordamp.jsr377.formatter.Formatter * @since 2.0.0 */ public class ColorFormatter extends AbstractFormatter { @@ -436,4 +435,12 @@ public Color parse(@Nonnull String str) throws ParseException { private static String padLeft(String self, String padding) { return 2 <= self.length() ? self : padding + self; } + + private static int parseHexInt(@Nonnull String val, @Nonnull Class klass) throws ParseException { + try { + return Integer.parseInt(String.valueOf(requireNonNull(val)).trim(), 16) & 0xFF; + } catch (NumberFormatException e) { + throw parseError(val, klass, e); + } + } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/support/JavaFXUtils.java b/subprojects/griffon-javafx/src/main/java/griffon/javafx/support/JavaFXUtils.java index bffb776ebc8..0c3b6723af6 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/support/JavaFXUtils.java +++ b/subprojects/griffon-javafx/src/main/java/griffon/javafx/support/JavaFXUtils.java @@ -21,7 +21,6 @@ import griffon.core.artifact.GriffonController; import griffon.core.controller.Action; import griffon.core.controller.ActionManager; -import griffon.core.editors.ValueConversionException; import griffon.core.i18n.MessageSource; import griffon.exceptions.InstanceMethodInvocationException; import javafx.application.Platform; @@ -62,6 +61,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.ConversionException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.net.URL; @@ -1624,11 +1624,11 @@ public static Window getWindowAncestor(@Nonnull Object node) { return null; } - private static ValueConversionException illegalValue(Object value, Class klass) { - throw new ValueConversionException(value, klass); + private static ConversionException illegalValue(Object value, Class klass) { + throw new ConversionException(value, klass); } - private static ValueConversionException illegalValue(Object value, Class klass, Exception e) { - throw new ValueConversionException(value, klass, e); + private static ConversionException illegalValue(Object value, Class klass, Exception e) { + throw new ConversionException(value, klass, e); } } diff --git a/subprojects/griffon-javafx/src/main/java/org/codehaus/griffon/runtime/javafx/controller/JavaFXGriffonControllerAction.java b/subprojects/griffon-javafx/src/main/java/org/codehaus/griffon/runtime/javafx/controller/JavaFXGriffonControllerAction.java index 7e3f218f0b8..d6a3f08fbcd 100644 --- a/subprojects/griffon-javafx/src/main/java/org/codehaus/griffon/runtime/javafx/controller/JavaFXGriffonControllerAction.java +++ b/subprojects/griffon-javafx/src/main/java/org/codehaus/griffon/runtime/javafx/controller/JavaFXGriffonControllerAction.java @@ -30,9 +30,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.beans.PropertyEditor; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; -import static griffon.core.editors.PropertyEditorResolver.findEditor; import static griffon.util.GriffonNameUtils.isNotBlank; import static griffon.util.TypeUtils.castToBoolean; import static java.util.Objects.requireNonNull; @@ -199,9 +199,13 @@ public void setIcon(@Nullable String icon) { @Nullable public Image getImage() { - PropertyEditor editor = findEditor(Image.class); - editor.setValue(image); - return (Image) editor.getValue(); + ConverterRegistry converterRegistry = getController().getApplication() + .getInjector().getInstance(ConverterRegistry.class); + Converter converter = converterRegistry.findConverter(Image.class); + if (converter != null) { + return converter.fromObject(image); + } + return null; } public void setImage(@Nullable String image) { diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ColorPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ColorConverterSpec.groovy similarity index 86% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ColorPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ColorConverterSpec.groovy index 46a12bfb292..ac16e0f4251 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ColorPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ColorConverterSpec.groovy @@ -15,28 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.scene.paint.Color import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class ColorPropertyEditorSpec extends Specification { +class ColorConverterSpec extends Specification { void "Color format '#format' should be equal to #color"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - - editor.value = format - def parsedColor = editor.value + Color parsedColor = converter.fromObject(format) then: - // use string comparison to avoid inequality on double values color?.toString() == parsedColor?.toString() @@ -76,15 +72,13 @@ class ColorPropertyEditorSpec extends Specification { void "Invalid color format '#format'"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -105,17 +99,13 @@ class ColorPropertyEditorSpec extends Specification { void "Formatted color '#expected' with format #format"() { given: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - - editor.format = format - editor.value = value - String actual = editor.asText + converter.format = format + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Dimension2DPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Dimension2DConverterSpec.groovy similarity index 81% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Dimension2DPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Dimension2DConverterSpec.groovy index b7487fda86d..6d348ba3891 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Dimension2DPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Dimension2DConverterSpec.groovy @@ -15,32 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.geometry.Dimension2D import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class Dimension2DPropertyEditorSpec extends Specification { +class Dimension2DConverterSpec extends Specification { @Shared private Dimension2D dimension = new Dimension2D(10, 20) void "Dimension2D format '#format' should be equal to #dimension"() { setup: - - PropertyEditor editor = new Dimension2DPropertyEditor() + Dimension2DConverter converter = new Dimension2DConverter() when: - - editor.value = format + Dimension2D parsedDimension = converter.fromObject(format) then: - - value == editor.value + value == parsedDimension where: value | format @@ -69,15 +66,13 @@ class Dimension2DPropertyEditorSpec extends Specification { void "Invalid dimension format '#format'"() { setup: - - PropertyEditor editor = new Dimension2DPropertyEditor() + Dimension2DConverter converter = new Dimension2DConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -95,16 +90,12 @@ class Dimension2DPropertyEditorSpec extends Specification { void "Formatted dimension '#expected'"() { given: - - PropertyEditor editor = new Dimension2DPropertyEditor() + Dimension2DConverter converter = new Dimension2DConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ImagePropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ImageConverterSpec.groovy similarity index 80% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ImagePropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ImageConverterSpec.groovy index 3785656b1c9..3dfd7588de2 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/ImagePropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/ImageConverterSpec.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.embed.swing.JFXPanel import javafx.scene.image.Image @@ -23,10 +23,10 @@ import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class ImagePropertyEditorSpec extends Specification { +class ImageConverterSpec extends Specification { @Shared private Image sharedImage = new Image(getClass().getClassLoader().getResourceAsStream('griffon-icon-16x16.png')) @@ -40,14 +40,13 @@ class ImagePropertyEditorSpec extends Specification { void "Image format '#format' should be equal to #image"() { setup: - PropertyEditor editor = new ImagePropertyEditor() + ImageConverter converter = new ImageConverter() when: - - editor.value = format + Image result = converter.fromObject(format) then: - image == editor.value + image == result where: image | format @@ -59,13 +58,13 @@ class ImagePropertyEditorSpec extends Specification { void "Valid image format '#format'"() { setup: - PropertyEditor editor = new ImagePropertyEditor() + ImageConverter converter = new ImageConverter() when: - editor.value = format + Image image = converter.fromObject(format) then: - editor.value + image where: format << [ @@ -79,14 +78,14 @@ class ImagePropertyEditorSpec extends Specification { void "Invalid image format '#format'"() { setup: - PropertyEditor editor = new ImagePropertyEditor() + ImageConverter converter = new ImageConverter() when: - editor.value = format + converter.fromObject(format) then: - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/InsetsPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/InsetsConverterSpec.groovy similarity index 83% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/InsetsPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/InsetsConverterSpec.groovy index aab8019dfb1..190b588a8b8 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/InsetsPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/InsetsConverterSpec.groovy @@ -15,32 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.geometry.Insets import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class InsetsPropertyEditorSpec extends Specification { +class InsetsConverterSpec extends Specification { @Shared private Insets insets = new Insets(1, 2, 3, 4) void "Insets format '#format' should be equal to #insets"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - - editor.value = format + Insets parsedInsets = converter.fromObject(format) then: - - value == editor.value + value == parsedInsets where: value | format @@ -71,15 +68,13 @@ class InsetsPropertyEditorSpec extends Specification { void "Invalid insets format '#format'"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -97,16 +92,12 @@ class InsetsPropertyEditorSpec extends Specification { void "Formatted insets '#expected'"() { given: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/LinearGradientPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/LinearGradientConverterSpec.groovy similarity index 86% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/LinearGradientPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/LinearGradientConverterSpec.groovy index 24b6e073076..62d8e861226 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/LinearGradientPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/LinearGradientConverterSpec.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.scene.paint.CycleMethod import javafx.scene.paint.LinearGradient @@ -24,13 +24,13 @@ import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException import static javafx.scene.paint.Color.BLACK import static javafx.scene.paint.Color.WHITE @Unroll -class LinearGradientPropertyEditorSpec extends Specification { +class LinearGradientConverterSpec extends Specification { @Shared private LinearGradient sharedPaint = new LinearGradient(1, 2, 3, 4, false, CycleMethod.NO_CYCLE, [new Stop(0d, BLACK), new Stop(1d, WHITE)]) @@ -39,14 +39,13 @@ class LinearGradientPropertyEditorSpec extends Specification { void "LinearGradient format '#format' is supported"() { setup: - PropertyEditor editor = new LinearGradientPropertyEditor() + LinearGradientConverter converter = new LinearGradientConverter() when: - editor.value = format + LinearGradient parsedLinearGradient = converter.fromObject(format) then: - - paintsAreEqual value, editor.value + paintsAreEqual value, parsedLinearGradient where: value | format @@ -80,15 +79,13 @@ class LinearGradientPropertyEditorSpec extends Specification { void "Invalid gradient format '#format'"() { setup: - - PropertyEditor editor = new LinearGradientPropertyEditor() + LinearGradientConverter converter = new LinearGradientConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/PaintPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/PaintConverterSpec.groovy similarity index 90% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/PaintPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/PaintConverterSpec.groovy index 8ec86f6f90c..49ac1fee509 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/PaintPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/PaintConverterSpec.groovy @@ -15,25 +15,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters -import griffon.core.editors.PropertyEditorResolver import javafx.scene.paint.Color import javafx.scene.paint.CycleMethod import javafx.scene.paint.LinearGradient +import javafx.scene.paint.Paint import javafx.scene.paint.RadialGradient import javafx.scene.paint.Stop import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor - import static javafx.scene.paint.Color.BLACK import static javafx.scene.paint.Color.WHITE @Unroll -class PaintPropertyEditorSpec extends Specification { +class PaintConverterSpec extends Specification { @Shared private RadialGradient sharedLinerPaint = new RadialGradient(1, 2, 3, 4, 5, false, CycleMethod.NO_CYCLE, [new Stop(0d, BLACK), new Stop(1d, WHITE)]) @@ -46,27 +44,15 @@ class PaintPropertyEditorSpec extends Specification { @Shared private RadialGradient sharedRadialPaintC = new RadialGradient(1, 2, 3, 4, 5, false, CycleMethod.REPEAT, [new Stop(0d, BLACK), new Stop(1d, WHITE)]) - void setup() { - PropertyEditorResolver.clear() - PropertyEditorResolver.registerEditor(Color, ColorPropertyEditor) - PropertyEditorResolver.registerEditor(LinearGradient, LinearGradientPropertyEditor) - PropertyEditorResolver.registerEditor(RadialGradient, RadialGradientPropertyEditor) - } - - void cleanup() { - PropertyEditorResolver.clear() - } - void "Paint format '#format' is supported"() { setup: - - PropertyEditor editor = new PaintPropertyEditor() + PaintConverter converter = new PaintConverter() when: - editor.value = format + Paint parsedPaint = converter.fromObject(format) then: - paintsAreEqual value, editor.value + paintsAreEqual value, parsedPaint where: value | format diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Point2DPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Point2DConverterSpec.groovy similarity index 80% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Point2DPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Point2DConverterSpec.groovy index f8fcaed3759..d60793b77c1 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Point2DPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Point2DConverterSpec.groovy @@ -15,32 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.geometry.Point2D import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class Point2DPropertyEditorSpec extends Specification { +class Point2DConverterSpec extends Specification { @Shared private Point2D point = new Point2D(10, 20) void "Point2D format '#format' should be equal to #point"() { setup: - - PropertyEditor editor = new Point2DPropertyEditor() + Point2DConverter converter = new Point2DConverter() when: - - editor.value = format + Point2D parsedPoint = converter.fromObject(format) then: - - value == editor.value + value == parsedPoint where: value | format @@ -67,15 +64,13 @@ class Point2DPropertyEditorSpec extends Specification { void "Invalid point format '#format'"() { setup: - - PropertyEditor editor = new Point2DPropertyEditor() + Point2DConverter converter = new Point2DConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +87,12 @@ class Point2DPropertyEditorSpec extends Specification { void "Formatted point '#expected'"() { given: - - PropertyEditor editor = new Point2DPropertyEditor() + Point2DConverter converter = new Point2DConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/RadialGradientPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/RadialGradientConverterSpec.groovy similarity index 86% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/RadialGradientPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/RadialGradientConverterSpec.groovy index 57291289c84..7e98bc83299 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/RadialGradientPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/RadialGradientConverterSpec.groovy @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.scene.paint.CycleMethod import javafx.scene.paint.RadialGradient @@ -24,13 +24,13 @@ import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException import static javafx.scene.paint.Color.BLACK import static javafx.scene.paint.Color.WHITE @Unroll -class RadialGradientPropertyEditorSpec extends Specification { +class RadialGradientConverterSpec extends Specification { @Shared private RadialGradient sharedPaint = new RadialGradient(1, 2, 3, 4, 5, false, CycleMethod.NO_CYCLE, [new Stop(0d, BLACK), new Stop(1d, WHITE)]) @@ -39,15 +39,13 @@ class RadialGradientPropertyEditorSpec extends Specification { void "RadialGradient format '#format' is supported"() { setup: - - PropertyEditor editor = new RadialGradientPropertyEditor() + RadialGradientConverter converter = new RadialGradientConverter() when: - editor.value = format + RadialGradient parsedRadialGradient = converter.fromObject(format) then: - - paintsAreEqual value, editor.value + paintsAreEqual value, parsedRadialGradient where: value | format @@ -82,15 +80,13 @@ class RadialGradientPropertyEditorSpec extends Specification { void "Invalid gradient format '#format'"() { setup: - - PropertyEditor editor = new RadialGradientPropertyEditor() + RadialGradientConverter converter = new RadialGradientConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Rectangle2DPropertyEditorSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Rectangle2DConverterSpec.groovy similarity index 82% rename from subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Rectangle2DPropertyEditorSpec.groovy rename to subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Rectangle2DConverterSpec.groovy index 899e8c69cb0..a10dd3d90d2 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/editors/Rectangle2DPropertyEditorSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/Rectangle2DConverterSpec.groovy @@ -15,32 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.javafx.editors +package griffon.javafx.converters import javafx.geometry.Rectangle2D import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class Rectangle2DPropertyEditorSpec extends Specification { +class Rectangle2DConverterSpec extends Specification { @Shared private Rectangle2D rectangle = new Rectangle2D(10, 20, 30, 40) void "Rectangle2D format '#format' should be equal to #rectangle"() { setup: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + Rectangle2DConverter converter = new Rectangle2DConverter() when: - - editor.value = format + Rectangle2D parsedRectangle = converter.fromObject(format) then: - - value == editor.value + value == parsedRectangle where: value | format @@ -65,15 +62,13 @@ class Rectangle2DPropertyEditorSpec extends Specification { void "Invalid rectangle format '#format'"() { setup: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + Rectangle2DConverter converter = new Rectangle2DConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -94,16 +89,12 @@ class Rectangle2DPropertyEditorSpec extends Specification { void "Formatted rectangle '#expected'"() { given: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + Rectangle2DConverter converter = new Rectangle2DConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/spi/ConverterProviderSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/spi/ConverterProviderSpec.groovy new file mode 100644 index 00000000000..425fe03b222 --- /dev/null +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/converters/spi/ConverterProviderSpec.groovy @@ -0,0 +1,71 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.javafx.converters.spi + +import griffon.javafx.converters.ColorConverter +import griffon.javafx.converters.Dimension2DConverter +import griffon.javafx.converters.GraphicConverter +import griffon.javafx.converters.ImageConverter +import griffon.javafx.converters.InsetsConverter +import griffon.javafx.converters.LinearGradientConverter +import griffon.javafx.converters.PaintConverter +import griffon.javafx.converters.Point2DConverter +import griffon.javafx.converters.RadialGradientConverter +import griffon.javafx.converters.Rectangle2DConverter +import javafx.geometry.Dimension2D +import javafx.geometry.Insets +import javafx.geometry.Point2D +import javafx.geometry.Rectangle2D +import javafx.scene.Node +import javafx.scene.image.Image +import javafx.scene.paint.Color +import javafx.scene.paint.LinearGradient +import javafx.scene.paint.Paint +import javafx.scene.paint.RadialGradient +import spock.lang.Specification +import spock.lang.Unroll + +import javax.application.converter.Converter +import javax.application.converter.spi.ConverterProvider + +@Unroll +class ConverterProviderSpec extends Specification { + public void "Provider for #targetType is related to #converterType"(Class targetType, Class> converterType) { + given: + ServiceLoader providers = ServiceLoader.load(ConverterProvider) + + when: + ConverterProvider converterProvider = providers.iterator().find { it.targetType == targetType } + + then: + converterProvider.converterType == converterType + + where: + targetType | converterType + Color | ColorConverter + Dimension2D | Dimension2DConverter + Node | GraphicConverter + Image | ImageConverter + Insets | InsetsConverter + LinearGradient | LinearGradientConverter + Paint | PaintConverter + Point2D | Point2DConverter + RadialGradient | RadialGradientConverter + Rectangle2D | Rectangle2DConverter + } +} diff --git a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/formatters/ColorFormatterSpec.groovy b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/formatters/ColorFormatterSpec.groovy index 94c8dc46899..7394fe0ec8f 100644 --- a/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/formatters/ColorFormatterSpec.groovy +++ b/subprojects/griffon-javafx/src/test/groovy/griffon/javafx/formatters/ColorFormatterSpec.groovy @@ -17,8 +17,8 @@ */ package griffon.javafx.formatters -import griffon.core.formatters.ParseException import javafx.scene.paint.Color +import org.kordamp.jsr377.formatter.ParseException import spock.lang.Specification import spock.lang.Unroll diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/BoundsPropertyEditor.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/BoundsConverter.java similarity index 68% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/BoundsPropertyEditor.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/BoundsConverter.java index 95e71e849b6..f102e45daa3 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/BoundsPropertyEditor.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/BoundsConverter.java @@ -15,51 +15,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors; +package griffon.pivot.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import org.apache.pivot.wtk.Bounds; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Bounds.class) -public class BoundsPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Bounds r = (Bounds) getValue(); - return r.x + ", " + r.y + ", " + r.width + ", " + r.height; - } - +public class BoundsConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Bounds fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Bounds) { - super.setValueInternal(value); + return (Bounds) value; } else { throw illegalValue(value, Bounds.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Bounds value) throws ConversionException { + if (null == value) { return null; } + return value.x + ", " + value.y + ", " + value.width + ", " + value.height; + } + + protected Bounds handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); @@ -69,17 +64,15 @@ protected void handleAsString(String str) { int y = parseValue(parts[1]); int w = parseValue(parts[2]); int h = parseValue(parts[3]); - super.setValueInternal(new Bounds(x, y, w, h)); - break; + return new Bounds(x, y, w, h); default: throw illegalValue(str, Bounds.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Bounds handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { @@ -88,24 +81,22 @@ protected void handleAsList(List list) { int y = parseValue(list.get(1)); int w = parseValue(list.get(2)); int h = parseValue(list.get(3)); - super.setValueInternal(new Bounds(x, y, w, h)); - break; + return new Bounds(x, y, w, h); default: throw illegalValue(list, Bounds.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Bounds handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int x = getMapValue(map, "x", 0); int y = getMapValue(map, "y", 0); int w = getMapValue(map, "width", 0); int h = getMapValue(map, "height", 0); - super.setValueInternal(new Bounds(x, y, w, h)); + return new Bounds(x, y, w, h); } protected int parseValue(Object value) { @@ -131,7 +122,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/ColorPropertyEditor.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/ColorConverter.java similarity index 64% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/ColorPropertyEditor.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/ColorConverter.java index fd2da2f651e..0f64cf2bfde 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/ColorPropertyEditor.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/ColorConverter.java @@ -15,79 +15,75 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors; +package griffon.pivot.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.core.formatters.Formatter; -import griffon.core.formatters.ParseException; -import griffon.metadata.PropertyEditorFor; import griffon.pivot.formatters.ColorFormatter; +import org.kordamp.jsr377.converter.AbstractFormattingConverter; +import org.kordamp.jsr377.formatter.Formatter; +import org.kordamp.jsr377.formatter.ParseException; +import javax.application.converter.ConversionException; import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; -import static griffon.util.GriffonNameUtils.isNotBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Color.class) -public class ColorPropertyEditor extends AbstractPropertyEditor { +public class ColorConverter extends AbstractFormattingConverter { public static String format(Color color) { return ColorFormatter.LONG.format(color); } - @Override - public String getAsText() { - if (null == getValue()) { return null; } - return isBlank(getFormat()) ? format((Color) getValueInternal()) : getFormattedValue(); + public String toString(Color value) throws ConversionException { + if (null == value) { + return null; + } else { + return null == getFormat() ? format(value) : this.getFormatted(value, this.getFormat()); + } } @Override - protected void setValueInternal(Object value) { + protected Color convertFromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value).trim()); + return handleAsString(String.valueOf(value).trim()); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Color) { - super.setValueInternal(value); + return (Color) value; } else { throw illegalValue(value, Color.class); } } @Override - protected Formatter resolveFormatter() { - return isNotBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; + protected Formatter resolveFormatter(String s) { + return !isBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; } - protected void handleAsString(String str) { + protected Color handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } try { - super.setValueInternal(ColorFormatter.parseColor(str)); + return ColorFormatter.parseColor(str); } catch (ParseException e) { throw illegalValue(str, Color.class, e); } } - protected void handleAsList(List list) { + protected Color handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } List values = new ArrayList<>(list); @@ -111,27 +107,25 @@ protected void handleAsList(List list) { throw illegalValue(list, Color.class); } } - super.setValueInternal( - new Color( - (Integer) values.get(0), - (Integer) values.get(1), - (Integer) values.get(2), - (Integer) values.get(3) - ) + + return new Color( + (Integer) values.get(0), + (Integer) values.get(1), + (Integer) values.get(2), + (Integer) values.get(3) ); } - protected void handleAsMap(Map map) { + protected Color handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } int r = getMapValue(map, "red", 0); int g = getMapValue(map, "green", 0); int b = getMapValue(map, "blue", 0); int a = getMapValue(map, "alpha", 255); - super.setValueInternal(new Color(r, g, b, a)); + return new Color(r, g, b, a); } protected int parse(String val) { @@ -159,8 +153,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Color.class); } - protected void handleAsNumber(Number value) { + protected Color handleAsNumber(Number value) { int c = parse(value); - super.setValueInternal(new Color(c, c, c, 255)); + return new Color(c, c, c, 255); } } diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/DimensionsPropertyEditor.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/DimensionsConverter.java similarity index 63% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/DimensionsPropertyEditor.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/DimensionsConverter.java index 807594788b4..4a278f15b06 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/DimensionsPropertyEditor.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/DimensionsConverter.java @@ -15,101 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors; +package griffon.pivot.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import org.apache.pivot.wtk.Dimensions; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Dimensions.class) -public class DimensionsPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Dimensions dimension = (Dimensions) getValue(); - return dimension.width + ", " + dimension.height; - } - +public class DimensionsConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Dimensions fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Dimensions) { - super.setValueInternal(value); + return (Dimensions) value; } else { throw illegalValue(value, Dimensions.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Dimensions value) throws ConversionException { + if (null == value) { return null; } + return value.width + ", " + value.height; + } + + protected Dimensions handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: int s = parseValue(parts[0]); - super.setValueInternal(new Dimensions(s, s)); - break; + return new Dimensions(s, s); case 2: int w = parseValue(parts[0]); int h = parseValue(parts[1]); - super.setValueInternal(new Dimensions(w, h)); - break; + return new Dimensions(w, h); default: throw illegalValue(str, Dimensions.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Dimensions handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { case 1: int s = parseValue(list.get(0)); - super.setValueInternal(new Dimensions(s, s)); - break; + return new Dimensions(s, s); case 2: int w = parseValue(list.get(0)); int h = parseValue(list.get(1)); - super.setValueInternal(new Dimensions(w, h)); - break; + return new Dimensions(w, h); default: throw illegalValue(list, Dimensions.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Dimensions handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int w = getMapValue(map, "width", 0); int h = getMapValue(map, "height", 0); - super.setValueInternal(new Dimensions(w, h)); + return new Dimensions(w, h); } protected int parseValue(Object value) { @@ -135,7 +124,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -146,8 +135,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Dimensions.class); } - protected void handleAsNumber(Number value) { + protected Dimensions handleAsNumber(Number value) { int s = parse(value); - super.setValueInternal(new Dimensions(s, s)); + return new Dimensions(s, s); } } diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/InsetsPropertyEditor.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/InsetsConverter.java similarity index 68% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/InsetsPropertyEditor.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/InsetsConverter.java index 0e649105d5b..fc9b7d88cda 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/InsetsPropertyEditor.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/InsetsConverter.java @@ -15,53 +15,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors; +package griffon.pivot.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import org.apache.pivot.wtk.Insets; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Insets.class) -public class InsetsPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Insets i = (Insets) getValue(); - return i.top + ", " + i.left + ", " + i.bottom + ", " + i.right; - } - +public class InsetsConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Insets fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Insets) { - super.setValueInternal(value); + return (Insets) value; } else { throw illegalValue(value, Insets.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Insets value) throws ConversionException { + if (null == value) { return null; } + return value.top + ", " + value.left + ", " + value.bottom + ", " + value.right; + } + + protected Insets handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } int t = 0; @@ -78,17 +73,15 @@ protected void handleAsString(String str) { l = parseValue(parts[1]); case 1: t = parseValue(parts[0]); - super.setValueInternal(new Insets(t, l, r, b)); - break; + return new Insets(t, l, r, b); default: throw illegalValue(str, Insets.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Insets handleAsList(List list) { + if (list.isEmpty()) { + return null; } int t = 0; @@ -104,24 +97,22 @@ protected void handleAsList(List list) { l = parseValue(list.get(1)); case 1: t = parseValue(list.get(0)); - super.setValueInternal(new Insets(t, l, r, b)); - break; + return new Insets(t, l, r, b); default: throw illegalValue(list, Insets.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Insets handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int t = getMapValue(map, "top", 0); int l = getMapValue(map, "left", 0); int r = getMapValue(map, "right", 0); int b = getMapValue(map, "bottom", 0); - super.setValueInternal(new Insets(t, l, r, b)); + return new Insets(t, l, r, b); } protected int parseValue(Object value) { @@ -147,7 +138,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -158,8 +149,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Insets.class); } - protected void handleAsNumber(Number value) { + protected Insets handleAsNumber(Number value) { int c = parse(value); - super.setValueInternal(new Insets(c, c, c, c)); + return new Insets(c, c, c, c); } } diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/PointPropertyEditor.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/PointConverter.java similarity index 65% rename from subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/PointPropertyEditor.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/PointConverter.java index 1e67e797021..00624c7c7d8 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/editors/PointPropertyEditor.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/PointConverter.java @@ -15,101 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors; +package griffon.pivot.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; import org.apache.pivot.wtk.Point; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Point.class) -public class PointPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Point p = (Point) getValue(); - return p.x + ", " + p.y; - } - +public class PointConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Point fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Point) { - super.setValueInternal(value); + return (Point) value; } else { throw illegalValue(value, Point.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Point value) throws ConversionException { + if (null == value) { return null; } + return value.x + ", " + value.y; + } + + protected Point handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: int s = parseValue(parts[0]); - super.setValueInternal(new Point(s, s)); - break; + return new Point(s, s); case 2: int x = parseValue(parts[0]); int y = parseValue(parts[1]); - super.setValueInternal(new Point(x, y)); - break; + return new Point(x, y); default: throw illegalValue(str, Point.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Point handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { case 1: int s = parseValue(list.get(0)); - super.setValueInternal(new Point(s, s)); - break; + return new Point(s, s); case 2: int x = parseValue(list.get(0)); int y = parseValue(list.get(1)); - super.setValueInternal(new Point(x, y)); - break; + return new Point(x, y); default: throw illegalValue(list, Point.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Point handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int x = getMapValue(map, "x", 0); int y = getMapValue(map, "y", 0); - super.setValueInternal(new Point(x, y)); + return new Point(x, y); } protected int parseValue(Object value) { @@ -145,8 +134,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Point.class); } - protected void handleAsNumber(Number value) { + protected Point handleAsNumber(Number value) { int s = parse(value); - super.setValueInternal(new Point(s, s)); + return new Point(s, s); } } diff --git a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/package-info.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/package-info.java similarity index 86% rename from subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/package-info.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/package-info.java index 6f92de814c3..d37f0f7820b 100644 --- a/subprojects/griffon-javafx/src/main/java/griffon/javafx/editors/package-info.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/package-info.java @@ -16,9 +16,9 @@ * limitations under the License. */ /** - * JavaFX specific Java Beans compliant property editors. + * Pivot specific type converters. * - * @since 2.0.0 + * @since 3.0.0 */ -package griffon.javafx.editors; +package griffon.pivot.converters; diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/BoundsConverterProvider.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/BoundsConverterProvider.java new file mode 100644 index 00000000000..25470283786 --- /dev/null +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/BoundsConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.pivot.converters.spi; + +import griffon.pivot.converters.BoundsConverter; +import org.apache.pivot.wtk.Bounds; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class BoundsConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Bounds.class; + } + + @Override + public Class> getConverterType() { + return BoundsConverter.class; + } +} diff --git a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorPersistence.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/ColorConverterProvider.java similarity index 55% rename from subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorPersistence.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/ColorConverterProvider.java index 398664aa462..95387f1381f 100644 --- a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/PropertyEditorPersistence.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/ColorConverterProvider.java @@ -15,25 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.codehaus.griffon.compile.core.ast.editor; +package griffon.pivot.converters.spi; -import org.kordamp.gipsy.transform.AbstractFilePersistence; -import org.kordamp.jipsy.processor.Logger; -import org.kordamp.jipsy.processor.SimpleFileFilter; +import griffon.pivot.converters.ColorConverter; +import org.kordamp.jipsy.ServiceProviderFor; -import java.io.File; -import java.io.FileFilter; +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Color; /** * @author Andres Almiray + * @since 3.0.0 */ -public class PropertyEditorPersistence extends AbstractFilePersistence { - public PropertyEditorPersistence(String name, String root, File outputDir, Logger logger) { - super(outputDir, name, logger, root + "/META-INF/editors/"); +@ServiceProviderFor(ConverterProvider.class) +public class ColorConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Color.class; } @Override - protected FileFilter getFileFilter() { - return SimpleFileFilter.INSTANCE; + public Class> getConverterType() { + return ColorConverter.class; } } diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/DimensionsConverterProvider.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/DimensionsConverterProvider.java new file mode 100644 index 00000000000..ec8df624f8b --- /dev/null +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/DimensionsConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.pivot.converters.spi; + +import griffon.pivot.converters.DimensionsConverter; +import org.apache.pivot.wtk.Dimensions; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class DimensionsConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Dimensions.class; + } + + @Override + public Class> getConverterType() { + return DimensionsConverter.class; + } +} diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/InsetsConverterProvider.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/InsetsConverterProvider.java new file mode 100644 index 00000000000..c49e7e8454f --- /dev/null +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/InsetsConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.pivot.converters.spi; + +import griffon.pivot.converters.InsetsConverter; +import org.apache.pivot.wtk.Insets; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class InsetsConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Insets.class; + } + + @Override + public Class> getConverterType() { + return InsetsConverter.class; + } +} diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/PointConverterProvider.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/PointConverterProvider.java new file mode 100644 index 00000000000..b3a0907ab02 --- /dev/null +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/PointConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.pivot.converters.spi; + +import griffon.pivot.converters.PointConverter; +import org.apache.pivot.wtk.Point; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class PointConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Point.class; + } + + @Override + public Class> getConverterType() { + return PointConverter.class; + } +} diff --git a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/package-info.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/package-info.java similarity index 80% rename from subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/package-info.java rename to subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/package-info.java index c94661017a5..51778598e87 100644 --- a/subprojects/griffon-groovy-compile/src/main/java/org/codehaus/griffon/compile/core/ast/editor/package-info.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/converters/spi/package-info.java @@ -16,10 +16,9 @@ * limitations under the License. */ /** - * AST Transformation for {@code @PropertyEditorFor} + * Pivot specific type converter providers. * - * @since 2.0.0 - * @see griffon.metadata.PropertyEditorFor + * @since 3.0.0 */ -package org.codehaus.griffon.compile.core.ast.editor; +package griffon.pivot.converters.spi; diff --git a/subprojects/griffon-pivot/src/main/java/griffon/pivot/formatters/ColorFormatter.java b/subprojects/griffon-pivot/src/main/java/griffon/pivot/formatters/ColorFormatter.java index 458d7f8ca8e..7ae20f1b4b0 100644 --- a/subprojects/griffon-pivot/src/main/java/griffon/pivot/formatters/ColorFormatter.java +++ b/subprojects/griffon-pivot/src/main/java/griffon/pivot/formatters/ColorFormatter.java @@ -17,16 +17,15 @@ */ package griffon.pivot.formatters; -import griffon.core.formatters.AbstractFormatter; -import griffon.core.formatters.ParseException; import griffon.pivot.support.Colors; +import org.kordamp.jsr377.formatter.AbstractFormatter; +import org.kordamp.jsr377.formatter.ParseException; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.awt.Color; import java.util.Arrays; -import static griffon.util.GriffonNameUtils.isBlank; import static griffon.util.GriffonNameUtils.requireNonBlank; import static java.lang.Integer.toHexString; import static java.util.Objects.requireNonNull; @@ -53,7 +52,7 @@ *

* * @author Andres Almiray - * @see griffon.core.formatters.Formatter + * @see org.kordamp.jsr377.formatter.Formatter * @since 2.0.0 */ public class ColorFormatter extends AbstractFormatter { @@ -113,7 +112,9 @@ public class ColorFormatter extends AbstractFormatter { *

Returns a {@code ColorFormatter} given a color pattern.

* * @param pattern the input pattern. Must be one of the 4 supported color patterns. + * * @return a {@code ColorPattern} instance + * * @throws IllegalArgumentException if the supplied {@code pattern} is not supported */ @Nonnull @@ -175,7 +176,9 @@ public String getPattern() { * {@code griffon.pivot.support.Colors}. * * @param str the string representation of a {@code java.awt.Color} + * * @return a {@code java.awt.Color} instance matching the supplied RGBA color components + * * @throws ParseException if the string cannot be parsed by the chosen pattern * @see griffon.pivot.support.Colors */ @@ -407,4 +410,12 @@ public Color parse(@Nonnull String str) throws ParseException { private static String padLeft(String self, String padding) { return 2 <= self.length() ? self : padding + self; } + + private static int parseHexInt(@Nonnull String val, @Nonnull Class klass) throws ParseException { + try { + return Integer.parseInt(String.valueOf(requireNonNull(val)).trim(), 16) & 0xFF; + } catch (NumberFormatException e) { + throw parseError(val, klass, e); + } + } } diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/BoundsPropertyEditorSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/BoundsConverterSpec.groovy similarity index 82% rename from subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/BoundsPropertyEditorSpec.groovy rename to subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/BoundsConverterSpec.groovy index 6aff0dd705e..4af37c4453a 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/BoundsPropertyEditorSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/BoundsConverterSpec.groovy @@ -15,31 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors +package griffon.pivot.converters import org.apache.pivot.wtk.Bounds import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class BoundsPropertyEditorSpec extends Specification { +class BoundsConverterSpec extends Specification { @Shared private Bounds bounds = new Bounds(10, 20, 30, 40) void "Bounds format '#format' should be equal to #bounds"() { setup: - - PropertyEditor editor = new BoundsPropertyEditor() - + BoundsConverter converter = new BoundsConverter() when: - editor.value = format + Bounds parsedBounds = converter.fromObject(format) then: - - value == editor.value + value == parsedBounds where: value | format @@ -64,15 +61,13 @@ class BoundsPropertyEditorSpec extends Specification { void "Invalid bounds format '#format'"() { setup: - - PropertyEditor editor = new BoundsPropertyEditor() + BoundsConverter converter = new BoundsConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +87,12 @@ class BoundsPropertyEditorSpec extends Specification { void "Formatted bounds '#expected'"() { given: - - PropertyEditor editor = new BoundsPropertyEditor() + BoundsConverter converter = new BoundsConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/ColorPropertyEditorSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/ColorConverterSpec.groovy similarity index 86% rename from subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/ColorPropertyEditorSpec.groovy rename to subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/ColorConverterSpec.groovy index f6a19c2a197..3ab5163577d 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/ColorPropertyEditorSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/ColorConverterSpec.groovy @@ -15,28 +15,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors +package griffon.pivot.converters import griffon.pivot.support.Colors import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Color -import java.beans.PropertyEditor @Unroll -class ColorPropertyEditorSpec extends Specification { +class ColorConverterSpec extends Specification { void "Color format '#format' should be equal to #color"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - editor.value = format + Color parsedColor = converter.fromObject(format) then: - - color == editor.value + color == parsedColor where: color | format @@ -76,15 +74,13 @@ class ColorPropertyEditorSpec extends Specification { void "Invalid color format '#format'"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -105,17 +101,13 @@ class ColorPropertyEditorSpec extends Specification { void "Formatted color '#expected' with format #format"() { given: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - - editor.format = format - editor.value = value - String actual = editor.asText + converter.format = format + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/DimensionsPropertyEditorSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/DimensionsConverterSpec.groovy similarity index 81% rename from subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/DimensionsPropertyEditorSpec.groovy rename to subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/DimensionsConverterSpec.groovy index 522896c9443..d8932c45f6c 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/DimensionsPropertyEditorSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/DimensionsConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors +package griffon.pivot.converters import org.apache.pivot.wtk.Dimensions import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class DimensionsPropertyEditorSpec extends Specification { +class DimensionsConverterSpec extends Specification { @Shared private Dimensions dimensions = new Dimensions(10, 20) void "Dimensions format '#format' should be equal to #dimensions"() { setup: - - PropertyEditor editor = new DimensionsPropertyEditor() + DimensionsConverter converter = new DimensionsConverter() when: - editor.value = format + Dimensions parsedDimensions = converter.fromObject(format) then: - - value == editor.value + value == parsedDimensions where: value | format @@ -68,15 +66,13 @@ class DimensionsPropertyEditorSpec extends Specification { void "Invalid dimensions format '#format'"() { setup: - - PropertyEditor editor = new DimensionsPropertyEditor() + DimensionsConverter converter = new DimensionsConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -93,16 +89,12 @@ class DimensionsPropertyEditorSpec extends Specification { void "Formatted dimensions '#expected'"() { given: - - PropertyEditor editor = new DimensionsPropertyEditor() + DimensionsConverter converter = new DimensionsConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/InsetsPropertyEditorSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/InsetsConverterSpec.groovy similarity index 83% rename from subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/InsetsPropertyEditorSpec.groovy rename to subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/InsetsConverterSpec.groovy index 1466ea03632..ccefa1e15e9 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/InsetsPropertyEditorSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/InsetsConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors +package griffon.pivot.converters import org.apache.pivot.wtk.Insets import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class InsetsPropertyEditorSpec extends Specification { +class InsetsConverterSpec extends Specification { @Shared private Insets sharedInsets = new Insets(1, 2, 3, 4) void "Insets format '#format' should be equal to #insets"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - editor.value = format + Insets parsedInsets = converter.fromObject(format) then: - - insets == editor.value + insets == parsedInsets where: insets | format @@ -70,15 +68,13 @@ class InsetsPropertyEditorSpec extends Specification { void "Invalid insets format '#format'"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -96,16 +92,12 @@ class InsetsPropertyEditorSpec extends Specification { void "Formatted insets '#expected'"() { given: - - PropertyEditor editor = new InsetsPropertyEditor() + InsetsConverter converter = new InsetsConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/PointPropertyEditorSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/PointConverterSpec.groovy similarity index 80% rename from subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/PointPropertyEditorSpec.groovy rename to subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/PointConverterSpec.groovy index 43655ec0a26..7c3075dbdf1 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/editors/PointPropertyEditorSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/PointConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.pivot.editors +package griffon.pivot.converters import org.apache.pivot.wtk.Point import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class PointPropertyEditorSpec extends Specification { +class PointConverterSpec extends Specification { @Shared private Point point = new Point(10, 20) void "Point format '#format' should be equal to #point"() { setup: - - PropertyEditor editor = new PointPropertyEditor() + PointConverter converter = new PointConverter() when: - editor.value = format + Point parsedPoint = converter.fromObject(format) then: - - value == editor.value + value == parsedPoint where: value | format @@ -66,15 +64,13 @@ class PointPropertyEditorSpec extends Specification { void "Invalid point format '#format'"() { setup: - - PropertyEditor editor = new PointPropertyEditor() + PointConverter converter = new PointConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -91,16 +87,12 @@ class PointPropertyEditorSpec extends Specification { void "Formatted point '#expected'"() { given: - - PropertyEditor editor = new PointPropertyEditor() + PointConverter converter = new PointConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/spi/ConverterProviderSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/spi/ConverterProviderSpec.groovy new file mode 100644 index 00000000000..68f7e94211a --- /dev/null +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/converters/spi/ConverterProviderSpec.groovy @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.pivot.converters.spi + +import griffon.pivot.converters.BoundsConverter +import griffon.pivot.converters.ColorConverter +import griffon.pivot.converters.DimensionsConverter +import griffon.pivot.converters.InsetsConverter +import griffon.pivot.converters.PointConverter +import org.apache.pivot.wtk.Bounds +import org.apache.pivot.wtk.Dimensions +import org.apache.pivot.wtk.Insets +import org.apache.pivot.wtk.Point +import spock.lang.Specification +import spock.lang.Unroll + +import javax.application.converter.Converter +import javax.application.converter.spi.ConverterProvider +import java.awt.Color + +@Unroll +class ConverterProviderSpec extends Specification { + public void "Provider for #targetType is related to #converterType"(Class targetType, Class> converterType) { + given: + ServiceLoader providers = ServiceLoader.load(ConverterProvider) + + when: + ConverterProvider converterProvider = providers.iterator().find { it.targetType == targetType } + + then: + converterProvider.converterType == converterType + + where: + targetType | converterType + Bounds | BoundsConverter + Color | ColorConverter + Dimensions | DimensionsConverter + Insets | InsetsConverter + Point | PointConverter + } +} diff --git a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/formatters/ColorFormatterSpec.groovy b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/formatters/ColorFormatterSpec.groovy index 443c0656235..3edc5a431a0 100644 --- a/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/formatters/ColorFormatterSpec.groovy +++ b/subprojects/griffon-pivot/src/test/groovy/griffon/pivot/formatters/ColorFormatterSpec.groovy @@ -17,7 +17,7 @@ */ package griffon.pivot.formatters -import griffon.core.formatters.ParseException +import org.kordamp.jsr377.formatter.ParseException import spock.lang.Specification import spock.lang.Unroll diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/BufferedImagePropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/BufferedImageConverter.java similarity index 55% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/BufferedImagePropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/BufferedImageConverter.java index 62ec8955ffc..b682dc21ae6 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/BufferedImagePropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/BufferedImageConverter.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import java.awt.image.BufferedImage; @@ -30,81 +30,78 @@ import java.net.URI; import java.net.URL; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(BufferedImage.class) -public class BufferedImagePropertyEditor extends AbstractPropertyEditor { +public class BufferedImageConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public BufferedImage fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof File) { - handleAsFile((File) value); + return handleAsFile((File) value); } else if (value instanceof URL) { - handleAsURL((URL) value); + return handleAsURL((URL) value); } else if (value instanceof URI) { - handleAsURI((URI) value); + return handleAsURI((URI) value); } else if (value instanceof InputStream) { - handleAsInputStream((InputStream) value); + return handleAsInputStream((InputStream) value); } else if (value instanceof ImageInputStream) { - handleAsImageInputStream((ImageInputStream) value); + return handleAsImageInputStream((ImageInputStream) value); } else if (value instanceof BufferedImage) { - super.setValueInternal(value); + return (BufferedImage) value; } else { throw illegalValue(value, BufferedImage.class); } } - protected void handleAsString(String str) { + protected BufferedImage handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); + return null; } else { - handleAsURL(getClass().getClassLoader().getResource(str)); + return handleAsURL(getClass().getClassLoader().getResource(str)); } } - protected void handleAsFile(File file) { + protected BufferedImage handleAsFile(File file) { try { - super.setValueInternal(ImageIO.read(file)); - } catch (IOException e) { + return ImageIO.read(file); + } catch (Exception e) { throw illegalValue(file, BufferedImage.class, e); } } - protected void handleAsURL(URL url) { + protected BufferedImage handleAsURL(URL url) { try { - super.setValueInternal(ImageIO.read(url)); - } catch (IOException e) { + return ImageIO.read(url); + } catch (Exception e) { throw illegalValue(url, BufferedImage.class, e); } } - protected void handleAsURI(URI uri) { + protected BufferedImage handleAsURI(URI uri) { try { - handleAsURL(uri.toURL()); - } catch (MalformedURLException e) { + return handleAsURL(uri.toURL()); + } catch (Exception e) { throw illegalValue(uri, BufferedImage.class, e); } } - protected void handleAsInputStream(InputStream stream) { + protected BufferedImage handleAsInputStream(InputStream stream) { try { - super.setValueInternal(ImageIO.read(stream)); - } catch (IOException e) { + return ImageIO.read(stream); + } catch (Exception e) { throw illegalValue(stream, BufferedImage.class, e); } } - protected void handleAsImageInputStream(ImageInputStream stream) { + protected BufferedImage handleAsImageInputStream(ImageInputStream stream) { try { - super.setValueInternal(ImageIO.read(stream)); - } catch (IOException e) { + return ImageIO.read(stream); + } catch (Exception e) { throw illegalValue(stream, BufferedImage.class, e); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/ColorPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/ColorConverter.java similarity index 63% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/ColorPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/ColorConverter.java index 442fd480f8a..5e0a5945f57 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/ColorPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/ColorConverter.java @@ -15,80 +15,76 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.core.formatters.Formatter; -import griffon.core.formatters.ParseException; -import griffon.metadata.PropertyEditorFor; import griffon.swing.formatters.ColorFormatter; +import org.kordamp.jsr377.converter.AbstractFormattingConverter; +import org.kordamp.jsr377.formatter.Formatter; +import org.kordamp.jsr377.formatter.ParseException; +import javax.application.converter.ConversionException; import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; -import static griffon.util.GriffonNameUtils.isNotBlank; - - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Color.class) -public class ColorPropertyEditor extends AbstractPropertyEditor { +public class ColorConverter extends AbstractFormattingConverter { public static String format(Color color) { return ColorFormatter.LONG.format(color); } - @Override - public String getAsText() { - if (null == getValue()) { return null; } - return isBlank(getFormat()) ? format((Color) getValueInternal()) : getFormattedValue(); + public String toString(Color value) throws ConversionException { + if (null == value) { + return null; + } else { + return null == getFormat() ? format(value) : this.getFormatted(value, this.getFormat()); + } } @Override - protected void setValueInternal(Object value) { + protected Color convertFromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value).trim()); + return handleAsString(String.valueOf(value).trim()); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Color) { - super.setValueInternal(value); + return (Color) value; } else { throw illegalValue(value, Color.class); } } @Override - protected Formatter resolveFormatter() { - return isNotBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; + protected Formatter resolveFormatter(String s) { + return !isBlank(getFormat()) ? ColorFormatter.getInstance(getFormat()) : null; } - protected void handleAsString(String str) { + protected Color handleAsString(String str) { + if (isBlank(str)) { + return null; + } + try { - if (isBlank(str)) { - super.setValueInternal(null); - } else { - super.setValueInternal(ColorFormatter.parseColor(str)); - } + return ColorFormatter.parseColor(str); } catch (ParseException e) { throw illegalValue(str, Color.class, e); } } - protected void handleAsList(List list) { + protected Color handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } List values = new ArrayList<>(list); @@ -112,27 +108,25 @@ protected void handleAsList(List list) { throw illegalValue(list, Color.class); } } - super.setValueInternal( - new Color( - (Integer) values.get(0), - (Integer) values.get(1), - (Integer) values.get(2), - (Integer) values.get(3) - ) + + return new Color( + (Integer) values.get(0), + (Integer) values.get(1), + (Integer) values.get(2), + (Integer) values.get(3) ); } - protected void handleAsMap(Map map) { + protected Color handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } int r = getMapValue(map, "red", 0); int g = getMapValue(map, "green", 0); int b = getMapValue(map, "blue", 0); int a = getMapValue(map, "alpha", 255); - super.setValueInternal(new Color(r, g, b, a)); + return new Color(r, g, b, a); } protected int parse(String val) { @@ -160,8 +154,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Color.class); } - protected void handleAsNumber(Number value) { + protected Color handleAsNumber(Number value) { int c = parse(value); - super.setValueInternal(new Color(c, c, c, 255)); + return new Color(c, c, c, 255); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/DimensionPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/DimensionConverter.java similarity index 63% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/DimensionPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/DimensionConverter.java index e04115b6afc..58257a5354c 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/DimensionPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/DimensionConverter.java @@ -15,101 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Dimension; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Dimension.class) -public class DimensionPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Dimension dimension = (Dimension) getValue(); - return dimension.getWidth() + ", " + dimension.getHeight(); - } - +public class DimensionConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Dimension fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Dimension) { - super.setValueInternal(value); + return (Dimension) value; } else { throw illegalValue(value, Dimension.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Dimension value) throws ConversionException { + if (null == value) { return null; } + return value.getWidth() + ", " + value.getHeight(); + } + + protected Dimension handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: int s = parseValue(parts[0]); - super.setValueInternal(new Dimension(s, s)); - break; + return new Dimension(s, s); case 2: int w = parseValue(parts[0]); int h = parseValue(parts[1]); - super.setValueInternal(new Dimension(w, h)); - break; + return new Dimension(w, h); default: throw illegalValue(str, Dimension.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Dimension handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { case 1: int s = parseValue(list.get(0)); - super.setValueInternal(new Dimension(s, s)); - break; + return new Dimension(s, s); case 2: int w = parseValue(list.get(0)); int h = parseValue(list.get(1)); - super.setValueInternal(new Dimension(w, h)); - break; + return new Dimension(w, h); default: throw illegalValue(list, Dimension.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Dimension handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int w = getMapValue(map, "width", 0); int h = getMapValue(map, "height", 0); - super.setValueInternal(new Dimension(w, h)); + return new Dimension(w, h); } protected int parseValue(Object value) { @@ -135,7 +124,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -146,8 +135,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Dimension.class); } - protected void handleAsNumber(Number value) { + protected Dimension handleAsNumber(Number value) { int s = parse(value); - super.setValueInternal(new Dimension(s, s)); + return new Dimension(s, s); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/FontPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/FontConverter.java similarity index 72% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/FontPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/FontConverter.java index ccd43025759..ff9fc40ea77 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/FontPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/FontConverter.java @@ -15,27 +15,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Font; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray + * @since 3.0.0 */ -@PropertyEditorFor(Font.class) -public class FontPropertyEditor extends AbstractPropertyEditor { +public class FontConverter extends AbstractConverter { + @Override + public Font fromObject(Object value) throws ConversionException { + if (null == value) { + return null; + } else if (value instanceof CharSequence) { + return handleAsString(String.valueOf(value)); + } else if (value instanceof List) { + return handleAsList((List) value); + } else if (value instanceof Map) { + return handleAsMap((Map) value); + } else if (value instanceof Font) { + return (Font) value; + } else { + throw illegalValue(value, Font.class); + } + } + @Override - public String getAsText() { - if (null == getValue()) { return null; } - Font font = (Font) getValue(); - return font.getFamily() + "-" + formatStyle(font) + "-" + font.getSize(); + public String toString(Font value) throws ConversionException { + if (null == value) { return null; } + return value.getFamily() + "-" + formatStyle(value) + "-" + value.getSize(); } protected String formatStyle(Font font) { @@ -49,27 +63,9 @@ protected String formatStyle(Font font) { return "PLAIN"; } - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof List) { - handleAsList((List) value); - } else if (value instanceof Map) { - handleAsMap((Map) value); - } else if (value instanceof Font) { - super.setValueInternal(value); - } else { - throw illegalValue(value, Font.class); - } - } - - protected void handleAsString(String str) { + protected Font handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split("-"); if (parts.length != 3) { @@ -80,13 +76,12 @@ protected void handleAsString(String str) { int style = resolveStyle(str, parts[1]); int size = parseSize(str, parts[2]); - super.setValueInternal(new Font(family, style, size)); + return new Font(family, style, size); } - protected void handleAsList(List list) { + protected Font handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } if (list.size() != 3) { @@ -97,19 +92,18 @@ protected void handleAsList(List list) { int style = resolveStyle(list, String.valueOf(list.get(1))); int size = parseSize(list, String.valueOf(list.get(2))); - super.setValueInternal(new Font(family, style, size)); + return new Font(family, style, size); } - protected void handleAsMap(Map map) { + protected Font handleAsMap(Map map) { if (map.isEmpty()) { - super.setValueInternal(null); - return; + return null; } String family = getMapValue(map, "family", ""); String style = getMapValue(map, "style", ""); String size = getMapValue(map, "size", ""); - super.setValueInternal(new Font(family, resolveStyle(map, style), parseSize(map, size))); + return new Font(family, resolveStyle(map, style), parseSize(map, size)); } protected String getMapValue(Map map, String key, String defaultValue) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/GradientPaintPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/GradientPaintConverter.java similarity index 69% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/GradientPaintPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/GradientPaintConverter.java index 9b71e124c21..708aabde584 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/GradientPaintPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/GradientPaintConverter.java @@ -15,67 +15,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Color; import java.awt.GradientPaint; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(GradientPaint.class) -public class GradientPaintPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - GradientPaint p = (GradientPaint) getValue(); - return new StringBuilder() - .append(p.getPoint1().getX()) - .append(", ") - .append(p.getPoint1().getY()) - .append(", ") - .append(ColorPropertyEditor.format(p.getColor1())) - .append(", ") - .append(p.getPoint2().getX()) - .append(", ") - .append(p.getPoint2().getY()) - .append(", ") - .append(ColorPropertyEditor.format(p.getColor2())) - .append(", ") - .append(p.isCyclic()) - .toString(); - } - +public class GradientPaintConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public GradientPaint fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof GradientPaint) { - super.setValueInternal(value); + return (GradientPaint) value; } else { throw illegalValue(value, GradientPaint.class); } } - protected void handleAsString(String str) { + @Override + public String toString(GradientPaint value) throws ConversionException { + if (null == value) { return null; } + return new StringBuilder() + .append(value.getPoint1().getX()) + .append(", ") + .append(value.getPoint1().getY()) + .append(", ") + .append(ColorConverter.format(value.getColor1())) + .append(", ") + .append(value.getPoint2().getX()) + .append(", ") + .append(value.getPoint2().getY()) + .append(", ") + .append(ColorConverter.format(value.getColor2())) + .append(", ") + .append(value.isCyclic()) + .toString(); + } + + protected GradientPaint handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } float x1 = 0; @@ -92,7 +87,7 @@ protected void handleAsString(String str) { case 4: cyclic = parseBoolean(parts[3]); case 3: - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); // point1 String[] p1 = parts[0].split(","); if (p1.length != 2) { @@ -111,20 +106,17 @@ protected void handleAsString(String str) { String[] colors = parts[2].split(","); try { - colorEditor.setAsText(colors[0]); - c1 = (Color) colorEditor.getValue(); + c1 = colorConverter.fromObject(colors[0]); } catch (Exception e) { throw illegalValue(colors[0], GradientPaint.class); } try { - colorEditor.setAsText(colors[1]); - c2 = (Color) colorEditor.getValue(); + c2 = colorConverter.fromObject(colors[1]); } catch (Exception e) { throw illegalValue(colors[1], GradientPaint.class); } - super.setValueInternal(new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic)); - break; + return new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic); default: throw illegalValue(str, GradientPaint.class); } @@ -134,25 +126,22 @@ protected void handleAsString(String str) { case 7: cyclic = parseBoolean(parts[6]); case 6: - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); x1 = parseValue(parts[0]); y1 = parseValue(parts[1]); x2 = parseValue(parts[3]); y2 = parseValue(parts[4]); try { - colorEditor.setAsText(parts[2]); - c1 = (Color) colorEditor.getValue(); + c1 = colorConverter.fromObject(parts[2]); } catch (Exception e) { throw illegalValue(parts[2], GradientPaint.class); } try { - colorEditor.setAsText(parts[5]); - c2 = (Color) colorEditor.getValue(); + c2 = colorConverter.fromObject(parts[5]); } catch (Exception e) { throw illegalValue(parts[5], GradientPaint.class); } - super.setValueInternal(new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic)); - break; + return new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic); default: throw illegalValue(str, GradientPaint.class); } @@ -160,10 +149,9 @@ protected void handleAsString(String str) { } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected GradientPaint handleAsList(List list) { + if (list.isEmpty()) { + return null; } float x1 = 0; @@ -177,34 +165,30 @@ protected void handleAsList(List list) { case 7: cyclic = parseBoolean(String.valueOf(list.get(6))); case 6: - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); x1 = parseValue(list.get(0)); y1 = parseValue(list.get(1)); x2 = parseValue(list.get(3)); y2 = parseValue(list.get(4)); try { - colorEditor.setValueInternal(list.get(2)); - c1 = (Color) colorEditor.getValue(); + c1 = colorConverter.fromObject(list.get(2)); } catch (Exception e) { throw illegalValue(list.get(2), GradientPaint.class); } try { - colorEditor.setValueInternal(list.get(5)); - c2 = (Color) colorEditor.getValue(); + c2 = colorConverter.fromObject(list.get(5)); } catch (Exception e) { throw illegalValue(list.get(5), GradientPaint.class); } - super.setValueInternal(new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic)); - break; + return new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic); default: throw illegalValue(list, GradientPaint.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected GradientPaint handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } float x1 = (Float) getMapValue(map, "x1", 0f); @@ -215,12 +199,11 @@ protected void handleAsMap(Map map) { Color c2 = Color.BLACK; boolean cyclic = false; - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); Object colorValue = map.get("c1"); try { if (null != colorValue) { - colorEditor.setValueInternal(colorValue); - c1 = (Color) colorEditor.getValue(); + c1 = colorConverter.fromObject(colorValue); } else { c1 = Color.WHITE; } @@ -230,8 +213,7 @@ protected void handleAsMap(Map map) { colorValue = map.get("c2"); try { if (null != colorValue) { - colorEditor.setValueInternal(colorValue); - c2 = (Color) colorEditor.getValue(); + c2 = colorConverter.fromObject(colorValue); } else { c2 = Color.BLACK; } @@ -243,7 +225,7 @@ protected void handleAsMap(Map map) { cyclic = parseBoolean(String.valueOf(cyclicValue)); } - super.setValueInternal(new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic)); + return new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic); } protected float parse(String val) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/IconPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/IconConverter.java similarity index 59% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/IconPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/IconConverter.java index 2834e9a8e81..05e0fefc331 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/IconPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/IconConverter.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import javax.swing.Icon; @@ -34,61 +34,57 @@ import java.net.URI; import java.net.URL; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Icon.class) -public class IconPropertyEditor extends AbstractPropertyEditor { +public class IconConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Icon fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof File) { - handleAsFile((File) value); + return handleAsFile((File) value); } else if (value instanceof URL) { - handleAsURL((URL) value); + return handleAsURL((URL) value); } else if (value instanceof URI) { - handleAsURI((URI) value); + return handleAsURI((URI) value); } else if (value instanceof InputStream) { - handleAsInputStream((InputStream) value); + return handleAsInputStream((InputStream) value); } else if (value instanceof ImageInputStream) { - handleAsImageInputStream((ImageInputStream) value); + return handleAsImageInputStream((ImageInputStream) value); } else if (value instanceof byte[]) { - handleAsByteArray((byte[]) value); + return handleAsByteArray((byte[]) value); } else if (value instanceof Image) { - handleAsImage((Image) value); + return handleAsImage((Image) value); } else if (value instanceof Icon) { - super.setValueInternal(value); + return (Icon) value; } else { throw illegalValue(value, Icon.class); } } - protected void handleAsString(String str) { + protected Icon handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } if (str.contains("|")) { // assume classname|arg format - handleAsClassWithArg(str); + return handleAsClassWithArg(str); } else { - handleAsURL(getClass().getClassLoader().getResource(str)); + return handleAsURL(getClass().getClassLoader().getResource(str)); } } @SuppressWarnings("unchecked") - protected void handleAsClassWithArg(String str) { + protected Icon handleAsClassWithArg(String str) { String[] args = str.split("\\|"); if (args.length == 2) { Class iconClass = null; try { - iconClass = (Class) IconPropertyEditor.class.getClassLoader().loadClass(args[0]); + iconClass = (Class) IconConverter.class.getClassLoader().loadClass(args[0]); } catch (ClassNotFoundException e) { throw illegalValue(str, Icon.class, e); } @@ -101,7 +97,7 @@ protected void handleAsClassWithArg(String str) { } try { - super.setValueInternal(constructor.newInstance(args[1])); + return constructor.newInstance(args[1]); } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { throw illegalValue(str, Icon.class, e); } @@ -110,51 +106,51 @@ protected void handleAsClassWithArg(String str) { } } - protected void handleAsFile(File file) { + protected Icon handleAsFile(File file) { try { - handleAsImage(ImageIO.read(file)); - } catch (IOException e) { + return handleAsImage(ImageIO.read(file)); + } catch (Exception e) { throw illegalValue(file, Icon.class, e); } } - protected void handleAsURL(URL url) { + protected Icon handleAsURL(URL url) { try { - handleAsImage(ImageIO.read(url)); - } catch (IOException e) { + return handleAsImage(ImageIO.read(url)); + } catch (Exception e) { throw illegalValue(url, Icon.class, e); } } - protected void handleAsURI(URI uri) { + protected Icon handleAsURI(URI uri) { try { - handleAsURL(uri.toURL()); - } catch (MalformedURLException e) { + return handleAsURL(uri.toURL()); + } catch (Exception e) { throw illegalValue(uri, Icon.class, e); } } - protected void handleAsInputStream(InputStream stream) { + protected Icon handleAsInputStream(InputStream stream) { try { - handleAsImage(ImageIO.read(stream)); - } catch (IOException e) { + return handleAsImage(ImageIO.read(stream)); + } catch (Exception e) { throw illegalValue(stream, Icon.class, e); } } - protected void handleAsImageInputStream(ImageInputStream stream) { + protected Icon handleAsImageInputStream(ImageInputStream stream) { try { - handleAsImage(ImageIO.read(stream)); - } catch (IOException e) { + return handleAsImage(ImageIO.read(stream)); + } catch (Exception e) { throw illegalValue(stream, Icon.class, e); } } - protected void handleAsByteArray(byte[] bytes) { - super.setValueInternal(new ImageIcon(bytes)); + protected Icon handleAsByteArray(byte[] bytes) { + return new ImageIcon(bytes); } - protected void handleAsImage(Image img) { - super.setValueInternal(new ImageIcon(img)); + protected Icon handleAsImage(Image img) { + return new ImageIcon(img); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/ImagePropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/ImageConverter.java similarity index 52% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/ImagePropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/ImageConverter.java index 8d9c1a21288..8feb250eb2b 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/ImagePropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/ImageConverter.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import javax.imageio.ImageIO; import javax.imageio.stream.ImageInputStream; import java.awt.Image; @@ -31,88 +31,84 @@ import java.net.URI; import java.net.URL; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Image.class) -public class ImagePropertyEditor extends AbstractPropertyEditor { +public class ImageConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Image fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof File) { - handleAsFile((File) value); + return handleAsFile((File) value); } else if (value instanceof URL) { - handleAsURL((URL) value); + return handleAsURL((URL) value); } else if (value instanceof URI) { - handleAsURI((URI) value); + return handleAsURI((URI) value); } else if (value instanceof InputStream) { - handleAsInputStream((InputStream) value); + return handleAsInputStream((InputStream) value); } else if (value instanceof ImageInputStream) { - handleAsImageInputStream((ImageInputStream) value); + return handleAsImageInputStream((ImageInputStream) value); } else if (value instanceof byte[]) { - handleAsByteArray((byte[]) value); + return handleAsByteArray((byte[]) value); } else if (value instanceof Image) { - super.setValueInternal(value); + return (Image) value; } else { throw illegalValue(value, Image.class); } } - protected void handleAsString(String str) { + protected Image handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } - handleAsURL(getClass().getClassLoader().getResource(str)); + return handleAsURL(getClass().getClassLoader().getResource(str)); } - protected void handleAsFile(File file) { + protected Image handleAsFile(File file) { try { - super.setValueInternal(ImageIO.read(file)); - } catch (IOException e) { + return ImageIO.read(file); + } catch (Exception e) { throw illegalValue(file, Image.class, e); } } - protected void handleAsURL(URL url) { + protected Image handleAsURL(URL url) { try { - super.setValueInternal(ImageIO.read(url)); - } catch (IOException e) { + return ImageIO.read(url); + } catch (Exception e) { throw illegalValue(url, Image.class, e); } } - protected void handleAsURI(URI uri) { + protected Image handleAsURI(URI uri) { try { - handleAsURL(uri.toURL()); - } catch (MalformedURLException e) { + return handleAsURL(uri.toURL()); + } catch (Exception e) { throw illegalValue(uri, Image.class, e); } } - protected void handleAsInputStream(InputStream stream) { + protected Image handleAsInputStream(InputStream stream) { try { - super.setValueInternal(ImageIO.read(stream)); - } catch (IOException e) { + return ImageIO.read(stream); + } catch (Exception e) { throw illegalValue(stream, Image.class, e); } } - protected void handleAsImageInputStream(ImageInputStream stream) { + protected Image handleAsImageInputStream(ImageInputStream stream) { try { - super.setValueInternal(ImageIO.read(stream)); - } catch (IOException e) { + return ImageIO.read(stream); + } catch (Exception e) { throw illegalValue(stream, Image.class, e); } } - protected void handleAsByteArray(byte[] bytes) { - super.setValueInternal(Toolkit.getDefaultToolkit().createImage(bytes)); + protected Image handleAsByteArray(byte[] bytes) { + return Toolkit.getDefaultToolkit().createImage(bytes); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/InsetsPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/InsetsConverter.java similarity index 68% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/InsetsPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/InsetsConverter.java index 2aa5bf55ef5..20f201f8958 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/InsetsPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/InsetsConverter.java @@ -15,54 +15,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Insets; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Insets.class) -public class InsetsPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Insets i = (Insets) getValue(); - return i.top + ", " + i.left + ", " + i.bottom + ", " + i.right; - } - +public class InsetsConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Insets fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Insets) { - super.setValueInternal(value); + return (Insets) value; } else { throw illegalValue(value, Insets.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Insets value) throws ConversionException { + if (null == value) { return null; } + return value.top + ", " + value.left + ", " + value.bottom + ", " + value.right; + } + + protected Insets handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } int t = 0; @@ -79,17 +74,15 @@ protected void handleAsString(String str) { l = parseValue(parts[1]); case 1: t = parseValue(parts[0]); - super.setValueInternal(new Insets(t, l, r, b)); - break; + return new Insets(t, l, r, b); default: throw illegalValue(str, Insets.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Insets handleAsList(List list) { + if (list.isEmpty()) { + return null; } int t = 0; @@ -105,24 +98,22 @@ protected void handleAsList(List list) { l = parseValue(list.get(1)); case 1: t = parseValue(list.get(0)); - super.setValueInternal(new Insets(t, l, r, b)); - break; + return new Insets(t, l, r, b); default: throw illegalValue(list, Insets.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Insets handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int t = getMapValue(map, "top", 0); int l = getMapValue(map, "left", 0); int r = getMapValue(map, "right", 0); int b = getMapValue(map, "bottom", 0); - super.setValueInternal(new Insets(t, l, r, b)); + return new Insets(t, l, r, b); } protected int parseValue(Object value) { @@ -148,7 +139,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { @@ -159,8 +150,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Insets.class); } - protected void handleAsNumber(Number value) { + protected Insets handleAsNumber(Number value) { int c = parse(value); - super.setValueInternal(new Insets(c, c, c, c)); + return new Insets(c, c, c, c); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/LinearGradientPaintPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/LinearGradientPaintConverter.java similarity index 79% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/LinearGradientPaintPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/LinearGradientPaintConverter.java index 479d53270cb..ea604580f7f 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/LinearGradientPaintPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/LinearGradientPaintConverter.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Color; import java.awt.LinearGradientPaint; import java.awt.MultipleGradientPaint; @@ -27,32 +27,45 @@ import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(LinearGradientPaint.class) -public class LinearGradientPaintPropertyEditor extends AbstractPropertyEditor { +public class LinearGradientPaintConverter extends AbstractConverter { + @Override + public LinearGradientPaint fromObject(Object value) throws ConversionException { + if (null == value) { + return null; + } else if (value instanceof CharSequence) { + return handleAsString(String.valueOf(value)); + } else if (value instanceof List) { + return handleAsList((List) value); + } else if (value instanceof Map) { + return handleAsMap((Map) value); + } else if (value instanceof LinearGradientPaint) { + return (LinearGradientPaint) value; + } else { + throw illegalValue(value, LinearGradientPaint.class); + } + } + @Override - public String getAsText() { - if (null == getValue()) return null; - LinearGradientPaint p = (LinearGradientPaint) getValue(); + public String toString(LinearGradientPaint value) throws ConversionException { + if (null == value) { return null; } return new StringBuilder() - .append(p.getStartPoint().getX()) + .append(value.getStartPoint().getX()) .append(", ") - .append(p.getStartPoint().getY()) + .append(value.getStartPoint().getY()) .append(", ") - .append(p.getEndPoint().getX()) + .append(value.getEndPoint().getX()) .append(", ") - .append(p.getEndPoint().getY()) + .append(value.getEndPoint().getY()) .append(", ") - .append(formatFractions(p.getFractions())) + .append(formatFractions(value.getFractions())) .append(", ") - .append(formatColors(p.getColors())) + .append(formatColors(value.getColors())) .append(", ") - .append(p.getCycleMethod().name()) + .append(value.getCycleMethod().name()) .toString(); } @@ -81,32 +94,14 @@ protected String formatColors(Color[] colors) { } else { b.append(":"); } - b.append(ColorPropertyEditor.format(c)); + b.append(ColorConverter.format(c)); } return b.append("]").toString(); } - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof List) { - handleAsList((List) value); - } else if (value instanceof Map) { - handleAsMap((Map) value); - } else if (value instanceof LinearGradientPaint) { - super.setValueInternal(value); - } else { - throw illegalValue(value, LinearGradientPaint.class); - } - } - - protected void handleAsString(String str) { + protected LinearGradientPaint handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } float x1 = 0; @@ -130,17 +125,15 @@ protected void handleAsString(String str) { if (fractions.length != colors.length) { throw illegalValue(str, LinearGradientPaint.class); } - super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod)); - break; + return new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod); default: throw illegalValue(str, LinearGradientPaint.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected LinearGradientPaint handleAsList(List list) { + if (list.isEmpty()) { + return null; } float x1 = 0; @@ -163,17 +156,15 @@ protected void handleAsList(List list) { if (fractions.length != colors.length) { throw illegalValue(list, LinearGradientPaint.class); } - super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod)); - break; + return new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod); default: throw illegalValue(list, LinearGradientPaint.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected LinearGradientPaint handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } float x1 = (Float) getMapValue(map, "x1", 0f); @@ -192,7 +183,7 @@ protected void handleAsMap(Map map) { cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue)); } - super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod)); + return new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod); } protected float[] parseFractions(Object source, Object obj) { @@ -243,11 +234,10 @@ protected Color[] parseColors(Object source, String str) { String[] strs = str.substring(1, str.length() - 1).split(":"); Color[] colors = new Color[strs.length]; - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); for (int i = 0; i < strs.length; i++) { try { - colorEditor.setValueInternal(strs[i]); - colors[i] = (Color) colorEditor.getValue(); + colors[i] = colorConverter.fromObject(strs[i]); } catch (Exception e) { throw illegalValue(strs[i], LinearGradientPaint.class); } @@ -258,11 +248,10 @@ protected Color[] parseColors(Object source, String str) { protected Color[] parseColors(Object source, List list) { Color[] colors = new Color[list.size()]; - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); for (int i = 0; i < list.size(); i++) { try { - colorEditor.setValueInternal(list.get(i)); - colors[i] = (Color) colorEditor.getValue(); + colors[i] = colorConverter.fromObject(list.get(i)); } catch (Exception e) { throw illegalValue(list.get(i), LinearGradientPaint.class, e); } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/Point2DPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/Point2DConverter.java similarity index 64% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/Point2DPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/Point2DConverter.java index 215e65ceb2d..e0798ab3789 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/Point2DPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/Point2DConverter.java @@ -15,101 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.geom.Point2D; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Point2D.class) -public class Point2DPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Point2D p = (Point2D) getValue(); - return p.getX() + ", " + p.getY(); - } - +public class Point2DConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Point2D fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Point2D) { - super.setValueInternal(value); + return (Point2D) value; } else { throw illegalValue(value, Point2D.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Point2D value) throws ConversionException { + if (null == value) { return null; } + return value.getX() + ", " + value.getY(); + } + + protected Point2D handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: double s = parseValue(parts[0]); - super.setValueInternal(new Point2D.Double(s, s)); - break; + return new Point2D.Double(s, s); case 2: double x = parseValue(parts[0]); double y = parseValue(parts[1]); - super.setValueInternal(new Point2D.Double(x, y)); - break; + return new Point2D.Double(x, y); default: throw illegalValue(str, Point2D.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Point2D handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { case 1: double s = parseValue(list.get(0)); - super.setValueInternal(new Point2D.Double(s, s)); - break; + return new Point2D.Double(s, s); case 2: double x = parseValue(list.get(0)); double y = parseValue(list.get(1)); - super.setValueInternal(new Point2D.Double(x, y)); - break; + return new Point2D.Double(x, y); default: throw illegalValue(list, Point2D.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Point2D handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } double x = getMapValue(map, "x", 0); double y = getMapValue(map, "y", 0); - super.setValueInternal(new Point2D.Double(x, y)); + return new Point2D.Double(x, y); } protected double parseValue(Object value) { @@ -145,8 +134,8 @@ protected double getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Point2D.class); } - protected void handleAsNumber(Number value) { + protected Point2D handleAsNumber(Number value) { double s = parse(value); - super.setValueInternal(new Point2D.Double(s, s)); + return new Point2D.Double(s, s); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/PointPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/PointConverter.java similarity index 65% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/PointPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/PointConverter.java index b8aa6a8aca1..7e89e608c33 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/PointPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/PointConverter.java @@ -15,102 +15,91 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Point; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Point.class) -public class PointPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Point p = (Point) getValue(); - return p.getX() + ", " + p.getY(); - } - +public class PointConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Point fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Number) { - handleAsNumber((Number) value); + return handleAsNumber((Number) value); } else if (value instanceof Point) { - super.setValueInternal(value); + return (Point) value; } else { throw illegalValue(value, Point.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Point value) throws ConversionException { + if (null == value) { return null; } + return value.getX() + ", " + value.getY(); + } + + protected Point handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); switch (parts.length) { case 1: int s = parseValue(parts[0]); - super.setValueInternal(new Point(s, s)); - break; + return new Point(s, s); case 2: int x = parseValue(parts[0]); int y = parseValue(parts[1]); - super.setValueInternal(new Point(x, y)); - break; + return new Point(x, y); default: throw illegalValue(str, Point.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Point handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { case 1: int s = parseValue(list.get(0)); - super.setValueInternal(new Point(s, s)); - break; + return new Point(s, s); case 2: int x = parseValue(list.get(0)); int y = parseValue(list.get(1)); - super.setValueInternal(new Point(x, y)); - break; + return new Point(x, y); default: throw illegalValue(list, Point.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Point handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int x = getMapValue(map, "x", 0); int y = getMapValue(map, "y", 0); - super.setValueInternal(new Point(x, y)); + return new Point(x, y); } protected int parseValue(Object value) { @@ -146,8 +135,8 @@ protected int getMapValue(Map map, String key, int defaultValue) { throw illegalValue(map, Point.class); } - protected void handleAsNumber(Number value) { + protected Point handleAsNumber(Number value) { int s = parse(value); - super.setValueInternal(new Point(s, s)); + return new Point(s, s); } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/PolygonPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/PolygonConverter.java similarity index 70% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/PolygonPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/PolygonConverter.java index 2ee72cddb8c..d6f2e684ca9 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/PolygonPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/PolygonConverter.java @@ -15,57 +15,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Polygon; import java.util.List; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Polygon.class) -public class PolygonPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Polygon p = (Polygon) getValue(); - StringBuilder b = new StringBuilder(); - for (int i = 0; i < p.npoints; i++) { - if (i != 0) { - b.append(", "); - } - b.append(p.xpoints[i]) - .append(", ") - .append(p.ypoints[i]); - } - return b.toString(); - } - +public class PolygonConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Polygon fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Polygon) { - super.setValueInternal(value); + return (Polygon) value; } else { throw illegalValue(value, Polygon.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Polygon value) throws ConversionException { + if (null == value) { return null; } + StringBuilder b = new StringBuilder(); + for (int i = 0; i < value.npoints; i++) { + if (i != 0) { + b.append(", "); + } + b.append(value.xpoints[i]) + .append(", ") + .append(value.ypoints[i]); + } + return b.toString(); + } + + protected Polygon handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); @@ -81,13 +76,12 @@ protected void handleAsString(String str) { xpoints[i] = parse(parts[2 * i]); ypoints[i] = parse(parts[(2 * i) + 1]); } - super.setValueInternal(new Polygon(xpoints, ypoints, npoints)); + return new Polygon(xpoints, ypoints, npoints); } - protected void handleAsList(List list) { + protected Polygon handleAsList(List list) { if (list.isEmpty()) { - super.setValueInternal(null); - return; + return null; } if (list.size() % 2 == 1) { @@ -102,7 +96,7 @@ protected void handleAsList(List list) { xpoints[i] = parseValue(list.get(2 * i)); ypoints[i] = parseValue(list.get((2 * i) + 1)); } - super.setValueInternal(new Polygon(xpoints, ypoints, npoints)); + return new Polygon(xpoints, ypoints, npoints); } protected int parseValue(Object value) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/RadialGradientPaintPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/RadialGradientPaintConverter.java similarity index 79% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/RadialGradientPaintPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/RadialGradientPaintConverter.java index 5c191a6beec..554422b4f89 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/RadialGradientPaintPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/RadialGradientPaintConverter.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Color; import java.awt.MultipleGradientPaint; import java.awt.RadialGradientPaint; @@ -27,34 +27,47 @@ import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(RadialGradientPaint.class) -public class RadialGradientPaintPropertyEditor extends AbstractPropertyEditor { +public class RadialGradientPaintConverter extends AbstractConverter { + @Override + public RadialGradientPaint fromObject(Object value) throws ConversionException { + if (null == value) { + return null; + } else if (value instanceof CharSequence) { + return handleAsString(String.valueOf(value)); + } else if (value instanceof List) { + return handleAsList((List) value); + } else if (value instanceof Map) { + return handleAsMap((Map) value); + } else if (value instanceof RadialGradientPaint) { + return (RadialGradientPaint) value; + } else { + throw illegalValue(value, RadialGradientPaint.class); + } + } + @Override - public String getAsText() { - if (null == getValue()) return null; - RadialGradientPaint p = (RadialGradientPaint) getValue(); + public String toString(RadialGradientPaint value) throws ConversionException { + if (null == value) { return null; } return new StringBuilder() - .append(p.getCenterPoint().getX()) + .append(value.getCenterPoint().getX()) .append(", ") - .append(p.getCenterPoint().getY()) + .append(value.getCenterPoint().getY()) .append(", ") - .append(p.getRadius()) + .append(value.getRadius()) .append(", ") - .append(p.getFocusPoint().getX()) + .append(value.getFocusPoint().getX()) .append(", ") - .append(p.getFocusPoint().getY()) + .append(value.getFocusPoint().getY()) .append(", ") - .append(formatFractions(p.getFractions())) + .append(formatFractions(value.getFractions())) .append(", ") - .append(formatColors(p.getColors())) + .append(formatColors(value.getColors())) .append(", ") - .append(p.getCycleMethod().name()) + .append(value.getCycleMethod().name()) .toString(); } @@ -83,32 +96,14 @@ protected String formatColors(Color[] colors) { } else { b.append(":"); } - b.append(ColorPropertyEditor.format(c)); + b.append(ColorConverter.format(c)); } return b.append("]").toString(); } - @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); - } else if (value instanceof List) { - handleAsList((List) value); - } else if (value instanceof Map) { - handleAsMap((Map) value); - } else if (value instanceof RadialGradientPaint) { - super.setValueInternal(value); - } else { - throw illegalValue(value, RadialGradientPaint.class); - } - } - - protected void handleAsString(String str) { + protected RadialGradientPaint handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } float cx = 0; @@ -134,17 +129,15 @@ protected void handleAsString(String str) { if (fractions.length != colors.length) { throw illegalValue(str, RadialGradientPaint.class); } - super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod)); - break; + return new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod); default: throw illegalValue(str, RadialGradientPaint.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected RadialGradientPaint handleAsList(List list) { + if (list.isEmpty()) { + return null; } float cx = 0; @@ -169,17 +162,15 @@ protected void handleAsList(List list) { if (fractions.length != colors.length) { throw illegalValue(list, RadialGradientPaint.class); } - super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod)); - break; + return new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod); default: throw illegalValue(list, RadialGradientPaint.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected RadialGradientPaint handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } float cx = (Float) getMapValue(map, "cx", 0f); @@ -199,7 +190,7 @@ protected void handleAsMap(Map map) { cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue)); } - super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod)); + return new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod); } protected float[] parseFractions(Object source, Object obj) { @@ -250,11 +241,10 @@ protected Color[] parseColors(Object source, String str) { String[] strs = str.substring(1, str.length() - 1).split(":"); Color[] colors = new Color[strs.length]; - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); for (int i = 0; i < strs.length; i++) { try { - colorEditor.setValueInternal(strs[i]); - colors[i] = (Color) colorEditor.getValue(); + colors[i] = colorConverter.fromObject(strs[i]); } catch (Exception e) { throw illegalValue(strs[i], RadialGradientPaint.class); } @@ -265,11 +255,10 @@ protected Color[] parseColors(Object source, String str) { protected Color[] parseColors(Object source, List list) { Color[] colors = new Color[list.size()]; - ColorPropertyEditor colorEditor = new ColorPropertyEditor(); + ColorConverter colorConverter = new ColorConverter(); for (int i = 0; i < list.size(); i++) { try { - colorEditor.setValueInternal(list.get(i)); - colors[i] = (Color) colorEditor.getValue(); + colors[i] = colorConverter.fromObject(list.get(i)); } catch (Exception e) { throw illegalValue(list.get(i), RadialGradientPaint.class, e); } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/Rectangle2DPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/Rectangle2DConverter.java similarity index 67% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/Rectangle2DPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/Rectangle2DConverter.java index fdf11f6b8c0..3682edad49d 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/Rectangle2DPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/Rectangle2DConverter.java @@ -15,51 +15,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.geom.Rectangle2D; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Rectangle2D.class) -public class Rectangle2DPropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Rectangle2D r = (Rectangle2D) getValue(); - return r.getX() + ", " + r.getY() + ", " + r.getWidth() + ", " + r.getHeight(); - } - +public class Rectangle2DConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Rectangle2D fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Rectangle2D) { - super.setValueInternal(value); + return (Rectangle2D) value; } else { throw illegalValue(value, Rectangle2D.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Rectangle2D value) throws ConversionException { + if (null == value) { return null; } + return value.getX() + ", " + value.getY() + ", " + value.getWidth() + ", " + value.getHeight(); + } + + + protected Rectangle2D handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); @@ -69,17 +65,15 @@ protected void handleAsString(String str) { double y = parseValue(parts[1]); double w = parseValue(parts[2]); double h = parseValue(parts[3]); - super.setValueInternal(new Rectangle2D.Double(x, y, w, h)); - break; + return new Rectangle2D.Double(x, y, w, h); default: throw illegalValue(str, Rectangle2D.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Rectangle2D handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { @@ -88,24 +82,22 @@ protected void handleAsList(List list) { double y = parseValue(list.get(1)); double w = parseValue(list.get(2)); double h = parseValue(list.get(3)); - super.setValueInternal(new Rectangle2D.Double(x, y, w, h)); - break; + return new Rectangle2D.Double(x, y, w, h); default: throw illegalValue(list, Rectangle2D.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Rectangle2D handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } double x = getMapValue(map, "x", 0); double y = getMapValue(map, "y", 0); double w = getMapValue(map, "width", 0); double h = getMapValue(map, "height", 0); - super.setValueInternal(new Rectangle2D.Double(x, y, w, h)); + return new Rectangle2D.Double(x, y, w, h); } protected double parseValue(Object value) { @@ -131,7 +123,7 @@ protected double parse(Number val) { protected double getMapValue(Map map, String key, double defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/RectanglePropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/RectangleConverter.java similarity index 67% rename from subprojects/griffon-swing/src/main/java/griffon/swing/editors/RectanglePropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/RectangleConverter.java index 976c68e0b4d..1fa4df83c09 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/editors/RectanglePropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/RectangleConverter.java @@ -15,52 +15,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors; +package griffon.swing.converters; -import griffon.core.editors.AbstractPropertyEditor; -import griffon.metadata.PropertyEditorFor; +import org.kordamp.jsr377.converter.AbstractConverter; +import javax.application.converter.ConversionException; import java.awt.Rectangle; import java.util.List; import java.util.Map; -import static griffon.util.GriffonNameUtils.isBlank; - /** * @author Andres Almiray * @author Alexander Klein - * @since 2.0.0 + * @since 3.0.0 */ -@PropertyEditorFor(Rectangle.class) -public class RectanglePropertyEditor extends AbstractPropertyEditor { - @Override - public String getAsText() { - if (null == getValue()) return null; - Rectangle r = (Rectangle) getValue(); - return r.getX() + ", " + r.getY() + ", " + r.getWidth() + ", " + r.getHeight(); - } - +public class RectangleConverter extends AbstractConverter { @Override - protected void setValueInternal(Object value) { + public Rectangle fromObject(Object value) throws ConversionException { if (null == value) { - super.setValueInternal(null); + return null; } else if (value instanceof CharSequence) { - handleAsString(String.valueOf(value)); + return handleAsString(String.valueOf(value)); } else if (value instanceof List) { - handleAsList((List) value); + return handleAsList((List) value); } else if (value instanceof Map) { - handleAsMap((Map) value); + return handleAsMap((Map) value); } else if (value instanceof Rectangle) { - super.setValueInternal(value); + return (Rectangle) value; } else { throw illegalValue(value, Rectangle.class); } } - protected void handleAsString(String str) { + @Override + public String toString(Rectangle value) throws ConversionException { + if (null == value) { return null; } + return value.getX() + ", " + value.getY() + ", " + value.getWidth() + ", " + value.getHeight(); + } + + protected Rectangle handleAsString(String str) { if (isBlank(str)) { - super.setValueInternal(null); - return; + return null; } String[] parts = str.split(","); @@ -70,17 +65,15 @@ protected void handleAsString(String str) { int y = parseValue(parts[1]); int w = parseValue(parts[2]); int h = parseValue(parts[3]); - super.setValueInternal(new Rectangle(x, y, w, h)); - break; + return new Rectangle(x, y, w, h); default: throw illegalValue(str, Rectangle.class); } } - protected void handleAsList(List list) { - if(list.isEmpty()) { - super.setValueInternal(null); - return; + protected Rectangle handleAsList(List list) { + if (list.isEmpty()) { + return null; } switch (list.size()) { @@ -89,24 +82,22 @@ protected void handleAsList(List list) { int y = parseValue(list.get(1)); int w = parseValue(list.get(2)); int h = parseValue(list.get(3)); - super.setValueInternal(new Rectangle(x, y, w, h)); - break; + return new Rectangle(x, y, w, h); default: throw illegalValue(list, Rectangle.class); } } - protected void handleAsMap(Map map) { - if(map.isEmpty()) { - super.setValueInternal(null); - return; + protected Rectangle handleAsMap(Map map) { + if (map.isEmpty()) { + return null; } int x = getMapValue(map, "x", 0); int y = getMapValue(map, "y", 0); int w = getMapValue(map, "width", 0); int h = getMapValue(map, "height", 0); - super.setValueInternal(new Rectangle(x, y, w, h)); + return new Rectangle(x, y, w, h); } protected int parseValue(Object value) { @@ -132,7 +123,7 @@ protected int parse(Number val) { protected int getMapValue(Map map, String key, int defaultValue) { Object val = map.get(key); - if (null == val) val = map.get(String.valueOf(key.charAt(0))); + if (null == val) { val = map.get(String.valueOf(key.charAt(0))); } if (null == val) { return defaultValue; } else if (val instanceof CharSequence) { diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/package-info.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/package-info.java new file mode 100644 index 00000000000..83db6a9bb13 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/package-info.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Swing specific type converters. + * + * @since 3.0.0 + */ + +package griffon.swing.converters; diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedDatePropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/BufferedImageConverterProvider.java similarity index 52% rename from subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedDatePropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/BufferedImageConverterProvider.java index d56a543e94b..91281f08f42 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/ExtendedDatePropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/BufferedImageConverterProvider.java @@ -15,29 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.core.editors; +package griffon.swing.converters.spi; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Date; +import griffon.swing.converters.BufferedImageConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.image.BufferedImage; /** * @author Andres Almiray - * @since 2.4.0 + * @since 3.0.0 */ -public class ExtendedDatePropertyEditor extends DatePropertyEditor { +@ServiceProviderFor(ConverterProvider.class) +public class BufferedImageConverterProvider implements ConverterProvider { @Override - protected void setValueInternal(Object value) { - if (value instanceof LocalDate) { - handleAsLocalDate((LocalDate) value); - } else if (value instanceof LocalDateTime) { - handleAsLocalDate(((LocalDateTime) value).toLocalDate()); - } else { - super.setValueInternal(value); - } + public Class getTargetType() { + return BufferedImage.class; } - protected void handleAsLocalDate(LocalDate value) { - super.setValueInternal(new Date(value.toEpochDay())); + @Override + public Class> getConverterType() { + return BufferedImageConverter.class; } -} \ No newline at end of file +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ColorConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ColorConverterProvider.java new file mode 100644 index 00000000000..29851431eb2 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ColorConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.ColorConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Color; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class ColorConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Color.class; + } + + @Override + public Class> getConverterType() { + return ColorConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/DimensionConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/DimensionConverterProvider.java new file mode 100644 index 00000000000..d92fc8a09c9 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/DimensionConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.DimensionConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Dimension; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class DimensionConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Dimension.class; + } + + @Override + public Class> getConverterType() { + return DimensionConverter.class; + } +} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/editors/StringPropertyEditor.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/FontConverterProvider.java similarity index 55% rename from subprojects/griffon-core/src/main/java/griffon/core/editors/StringPropertyEditor.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/FontConverterProvider.java index 90a135579fa..a65dd6c2843 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/editors/StringPropertyEditor.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/FontConverterProvider.java @@ -15,19 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.core.editors; +package griffon.swing.converters.spi; + +import griffon.swing.converters.FontConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Font; /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -public class StringPropertyEditor extends AbstractPropertyEditor { +@ServiceProviderFor(ConverterProvider.class) +public class FontConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Font.class; + } + @Override - protected void setValueInternal(Object value) { - if (null == value) { - super.setValueInternal(null); - } else { - super.setValueInternal(value.toString()); - } + public Class> getConverterType() { + return FontConverter.class; } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/GradientPaintConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/GradientPaintConverterProvider.java new file mode 100644 index 00000000000..643ea50031d --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/GradientPaintConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.GradientPaintConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.GradientPaint; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class GradientPaintConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return GradientPaint.class; + } + + @Override + public Class> getConverterType() { + return GradientPaintConverter.class; + } +} diff --git a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ParseException.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/IconConverterProvider.java similarity index 54% rename from subprojects/griffon-core/src/main/java/griffon/core/formatters/ParseException.java rename to subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/IconConverterProvider.java index 98d36715574..ea23ed1391b 100644 --- a/subprojects/griffon-core/src/main/java/griffon/core/formatters/ParseException.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/IconConverterProvider.java @@ -15,27 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.core.formatters; +package griffon.swing.converters.spi; + +import griffon.swing.converters.IconConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import javax.swing.Icon; /** * @author Andres Almiray - * @since 2.0.0 + * @since 3.0.0 */ -public class ParseException extends RuntimeException { - private static final long serialVersionUID = -4827147485351497115L; - - public ParseException() { - } - - public ParseException(String s) { - super(s); - } - - public ParseException(String s, Throwable throwable) { - super(s, throwable); +@ServiceProviderFor(ConverterProvider.class) +public class IconConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Icon.class; } - public ParseException(Throwable throwable) { - super(throwable); + @Override + public Class> getConverterType() { + return IconConverter.class; } } diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ImageConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ImageConverterProvider.java new file mode 100644 index 00000000000..12cb50b665b --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/ImageConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.ImageConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Image; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class ImageConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Image.class; + } + + @Override + public Class> getConverterType() { + return ImageConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/InsetsConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/InsetsConverterProvider.java new file mode 100644 index 00000000000..6870f9f3e8a --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/InsetsConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.InsetsConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Insets; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class InsetsConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Insets.class; + } + + @Override + public Class> getConverterType() { + return InsetsConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/LineraGradientPaintConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/LineraGradientPaintConverterProvider.java new file mode 100644 index 00000000000..9c3a72415ce --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/LineraGradientPaintConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.LinearGradientPaintConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.LinearGradientPaint; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class LineraGradientPaintConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return LinearGradientPaint.class; + } + + @Override + public Class> getConverterType() { + return LinearGradientPaintConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Point2DConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Point2DConverterProvider.java new file mode 100644 index 00000000000..60f47e78b7a --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Point2DConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.Point2DConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.geom.Point2D; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class Point2DConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Point2D.class; + } + + @Override + public Class> getConverterType() { + return Point2DConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PointConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PointConverterProvider.java new file mode 100644 index 00000000000..4bc54ddd205 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PointConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.PointConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Point; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class PointConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Point.class; + } + + @Override + public Class> getConverterType() { + return PointConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PolygonConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PolygonConverterProvider.java new file mode 100644 index 00000000000..c995a871913 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/PolygonConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.PolygonConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Polygon; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class PolygonConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Polygon.class; + } + + @Override + public Class> getConverterType() { + return PolygonConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RadialGradientPaintConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RadialGradientPaintConverterProvider.java new file mode 100644 index 00000000000..d6144d87d88 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RadialGradientPaintConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.RadialGradientPaintConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.RadialGradientPaint; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class RadialGradientPaintConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return RadialGradientPaint.class; + } + + @Override + public Class> getConverterType() { + return RadialGradientPaintConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Rectangle2DConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Rectangle2DConverterProvider.java new file mode 100644 index 00000000000..2c7ec377412 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/Rectangle2DConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.Rectangle2DConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.geom.Rectangle2D; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class Rectangle2DConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Rectangle2D.class; + } + + @Override + public Class> getConverterType() { + return Rectangle2DConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RectangleConverterProvider.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RectangleConverterProvider.java new file mode 100644 index 00000000000..a256d66207a --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/RectangleConverterProvider.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi; + +import griffon.swing.converters.RectangleConverter; +import org.kordamp.jipsy.ServiceProviderFor; + +import javax.application.converter.Converter; +import javax.application.converter.spi.ConverterProvider; +import java.awt.Rectangle; + +/** + * @author Andres Almiray + * @since 3.0.0 + */ +@ServiceProviderFor(ConverterProvider.class) +public class RectangleConverterProvider implements ConverterProvider { + @Override + public Class getTargetType() { + return Rectangle.class; + } + + @Override + public Class> getConverterType() { + return RectangleConverter.class; + } +} diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/package-info.java b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/package-info.java new file mode 100644 index 00000000000..4ec9bd85073 --- /dev/null +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/converters/spi/package-info.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Swing specific type converter providers. + * + * @since 3.0.0 + */ + +package griffon.swing.converters.spi; diff --git a/subprojects/griffon-swing/src/main/java/griffon/swing/formatters/ColorFormatter.java b/subprojects/griffon-swing/src/main/java/griffon/swing/formatters/ColorFormatter.java index 8abad711c86..e9859108951 100644 --- a/subprojects/griffon-swing/src/main/java/griffon/swing/formatters/ColorFormatter.java +++ b/subprojects/griffon-swing/src/main/java/griffon/swing/formatters/ColorFormatter.java @@ -17,16 +17,15 @@ */ package griffon.swing.formatters; -import griffon.core.formatters.AbstractFormatter; -import griffon.core.formatters.ParseException; import griffon.swing.support.Colors; +import org.kordamp.jsr377.formatter.AbstractFormatter; +import org.kordamp.jsr377.formatter.ParseException; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.awt.Color; import java.util.Arrays; -import static griffon.util.GriffonNameUtils.isBlank; import static griffon.util.GriffonNameUtils.requireNonBlank; import static java.lang.Integer.toHexString; import static java.util.Objects.requireNonNull; @@ -53,7 +52,7 @@ *

* * @author Andres Almiray - * @see griffon.core.formatters.Formatter + * @see org.kordamp.jsr377.formatter.Formatter * @since 2.0.0 */ public class ColorFormatter extends AbstractFormatter { @@ -113,7 +112,9 @@ public class ColorFormatter extends AbstractFormatter { *

Returns a {@code ColorFormatter} given a color pattern.

* * @param pattern the input pattern. Must be one of the 4 supported color patterns. + * * @return a {@code ColorPattern} instance + * * @throws IllegalArgumentException if the supplied {@code pattern} is not supported */ @Nonnull @@ -172,12 +173,14 @@ public String getPattern() { * *

* The input string may also be any of the Color constants identified by - * {@code griffon.swing.support.Colors}. + * {@code griffon.pivot.support.Colors}. * * @param str the string representation of a {@code java.awt.Color} + * * @return a {@code java.awt.Color} instance matching the supplied RGBA color components + * * @throws ParseException if the string cannot be parsed by the chosen pattern - * @see griffon.swing.support.Colors + * @see griffon.pivot.support.Colors */ @Nonnull @SuppressWarnings("ConstantConditions") @@ -407,4 +410,12 @@ public Color parse(@Nonnull String str) throws ParseException { private static String padLeft(String self, String padding) { return 2 <= self.length() ? self : padding + self; } + + private static int parseHexInt(@Nonnull String val, @Nonnull Class klass) throws ParseException { + try { + return Integer.parseInt(String.valueOf(requireNonNull(val)).trim(), 16) & 0xFF; + } catch (NumberFormatException e) { + throw parseError(val, klass, e); + } + } } diff --git a/subprojects/griffon-swing/src/main/java/org/codehaus/griffon/runtime/swing/controller/SwingGriffonControllerAction.java b/subprojects/griffon-swing/src/main/java/org/codehaus/griffon/runtime/swing/controller/SwingGriffonControllerAction.java index 172ca8e56ce..9454dd81b84 100644 --- a/subprojects/griffon-swing/src/main/java/org/codehaus/griffon/runtime/swing/controller/SwingGriffonControllerAction.java +++ b/subprojects/griffon-swing/src/main/java/org/codehaus/griffon/runtime/swing/controller/SwingGriffonControllerAction.java @@ -20,7 +20,6 @@ import griffon.core.artifact.GriffonController; import griffon.core.controller.ActionManager; import griffon.core.controller.ActionMetadata; -import griffon.core.editors.PropertyEditorResolver; import griffon.core.properties.PropertyChangeEvent; import griffon.core.threading.UIThreadManager; import griffon.swing.support.SwingAction; @@ -28,11 +27,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.application.converter.Converter; +import javax.application.converter.ConverterRegistry; import javax.swing.Action; import javax.swing.Icon; import javax.swing.KeyStroke; import java.awt.event.ActionEvent; -import java.beans.PropertyEditor; import static griffon.util.GriffonNameUtils.isNotBlank; import static java.util.Objects.requireNonNull; @@ -106,9 +106,12 @@ protected void handlePropertyChange(@Nonnull PropertyChangeEvent evt) { protected void handleIcon(@Nullable Object value, @Nonnull String key) { if (value != null) { - PropertyEditor editor = PropertyEditorResolver.findEditor(Icon.class); - editor.setValue(value); - toolkitAction.putValue(key, editor.getValue()); + Converter converter = getController().getApplication() + .getInjector().getInstance(ConverterRegistry.class) + .findConverter(Icon.class); + if (converter != null) { + toolkitAction.putValue(key, converter.fromObject(value)); + } } } diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/BufferedImagePropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/BufferedImageConverterSpec.groovy similarity index 77% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/BufferedImagePropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/BufferedImageConverterSpec.groovy index cd3d8adb02a..21e328172e2 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/BufferedImagePropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/BufferedImageConverterSpec.groovy @@ -15,26 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class BufferedImagePropertyEditorSpec extends Specification { - +class BufferedImageConverterSpec extends Specification { void "BufferedImage format '#format' should be equal to #image"() { setup: - PropertyEditor editor = new BufferedImagePropertyEditor() + def converter = new BufferedImageConverter() when: - - editor.value = format + def converted = converter.fromObject(format) then: - image == editor.value + image == converted where: image | format @@ -45,15 +43,13 @@ class BufferedImagePropertyEditorSpec extends Specification { void "Invalid image format '#format'"() { setup: - - PropertyEditor editor = new BufferedImagePropertyEditor() + def converter = new BufferedImageConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ColorPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ColorConverterSpec.groovy similarity index 85% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ColorPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ColorConverterSpec.groovy index 7ca146da36a..7a93f23bdc4 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ColorPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ColorConverterSpec.groovy @@ -15,28 +15,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import griffon.swing.support.Colors import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Color -import java.beans.PropertyEditor @Unroll -class ColorPropertyEditorSpec extends Specification { +class ColorConverterSpec extends Specification { void "Color format '#format' should be equal to #color"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - editor.value = format + Color parsedColor = converter.fromObject(format) then: - - color == editor.value + color == parsedColor where: color | format @@ -76,15 +74,13 @@ class ColorPropertyEditorSpec extends Specification { void "Invalid color format '#format'"() { setup: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -94,7 +90,7 @@ class ColorPropertyEditorSpec extends Specification { [1, 2, 3, 4, 5], [new Object()], [new Object(), new Object(), new Object()], - [r: new Object()], + [red: new Object()], 'F00', '#F0', '#FF0000FF00', @@ -105,17 +101,13 @@ class ColorPropertyEditorSpec extends Specification { void "Formatted color '#expected' with format #format"() { given: - - PropertyEditor editor = new ColorPropertyEditor() + ColorConverter converter = new ColorConverter() when: - - editor.format = format - editor.value = value - String actual = editor.asText + converter.format = format + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/DimensionPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/DimensionConverterSpec.groovy similarity index 82% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/DimensionPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/DimensionConverterSpec.groovy index 97a783b4d2f..a49df9a38ef 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/DimensionPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/DimensionConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Dimension -import java.beans.PropertyEditor @Unroll -class DimensionPropertyEditorSpec extends Specification { +class DimensionConverterSpec extends Specification { @Shared private Dimension dimension = new Dimension(10, 20) void "Dimension format '#format' should be equal to #dimension"() { setup: - - PropertyEditor editor = new DimensionPropertyEditor() + def converter = new DimensionConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -68,15 +66,13 @@ class DimensionPropertyEditorSpec extends Specification { void "Invalid dimension format '#format'"() { setup: - - PropertyEditor editor = new DimensionPropertyEditor() + def converter = new DimensionConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -93,16 +89,12 @@ class DimensionPropertyEditorSpec extends Specification { void "Formatted dimension '#expected'"() { given: - - PropertyEditor editor = new DimensionPropertyEditor() + def converter = new DimensionConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/FontPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/FontConverterSpec.groovy similarity index 88% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/FontPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/FontConverterSpec.groovy index 21c028aba75..38d22f82270 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/FontPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/FontConverterSpec.groovy @@ -15,30 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import griffon.swing.TestUtils import spock.lang.IgnoreIf import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Font -import java.beans.PropertyEditor @Unroll @IgnoreIf({ TestUtils.headless }) -class FontPropertyEditorSpec extends Specification { +class FontConverterSpec extends Specification { void "Font format '#format' should be equal to #font"() { setup: - - PropertyEditor editor = new FontPropertyEditor() + def converter = new FontConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - font == editor.value + font == converted where: font | format @@ -64,15 +62,13 @@ class FontPropertyEditorSpec extends Specification { void "Invalid font format '#format'"() { setup: - - PropertyEditor editor = new FontPropertyEditor() + def converter = new FontConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -91,16 +87,12 @@ class FontPropertyEditorSpec extends Specification { void "Formatted font '#expected'"() { given: - - PropertyEditor editor = new FontPropertyEditor() + def converter = new FontConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/GradientPaintPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/GradientPaintConverterSpec.groovy similarity index 82% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/GradientPaintPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/GradientPaintConverterSpec.groovy index 3db00a5df86..9830b723a19 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/GradientPaintPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/GradientPaintConverterSpec.groovy @@ -15,34 +15,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.GradientPaint -import java.beans.PropertyEditor import static java.awt.Color.BLACK import static java.awt.Color.WHITE @Unroll -class GradientPaintPropertyEditorSpec extends Specification { +class GradientPaintConverterSpec extends Specification { @Shared private GradientPaint gradientPaint = new GradientPaint(0f, 0f, BLACK, 1f, 1f, WHITE) void "GradientPaint format '#format' is supported"() { setup: - - PropertyEditor editor = new GradientPaintPropertyEditor() + def converter = new GradientPaintConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - paintsAreEqual value, editor.value + paintsAreEqual value, converted where: value | format @@ -74,16 +72,13 @@ class GradientPaintPropertyEditorSpec extends Specification { void "Invalid gradientPaint format '#format'"() { setup: - - PropertyEditor editor = new GradientPaintPropertyEditor() + def converter = new GradientPaintConverter() when: - editor.value = format - println editor.value + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -101,16 +96,12 @@ class GradientPaintPropertyEditorSpec extends Specification { void "Formatted gradient paint '#expected'"() { given: - - PropertyEditor editor = new GradientPaintPropertyEditor() + def converter = new GradientPaintConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/IconPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/IconConverterSpec.groovy similarity index 78% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/IconPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/IconConverterSpec.groovy index a6d7a2024f2..78567f2c4d3 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/IconPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/IconConverterSpec.groovy @@ -15,26 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class IconPropertyEditorSpec extends Specification { - +class IconConverterSpec extends Specification { void "Icon format '#format' should be equal to #icon"() { setup: - PropertyEditor editor = new IconPropertyEditor() + def converter = new IconConverter() when: - - editor.value = format + def converted = converter.fromObject(format) then: - icon == editor.value + icon == converted where: icon | format @@ -45,15 +43,13 @@ class IconPropertyEditorSpec extends Specification { void "Invalid icon format '#format'"() { setup: - - PropertyEditor editor = new IconPropertyEditor() + def converter = new IconConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ImagePropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ImageConverterSpec.groovy similarity index 77% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ImagePropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ImageConverterSpec.groovy index 238c59d43dd..fd8ca9dded0 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/ImagePropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/ImageConverterSpec.groovy @@ -15,26 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Specification import spock.lang.Unroll -import java.beans.PropertyEditor +import javax.application.converter.ConversionException @Unroll -class ImagePropertyEditorSpec extends Specification { - +class ImageConverterSpec extends Specification { void "Image format '#format' should be equal to #image"() { setup: - PropertyEditor editor = new ImagePropertyEditor() + def converter = new ImageConverter() when: - - editor.value = format + def converted = converter.fromObject(format) then: - image == editor.value + image == converted where: image | format @@ -45,15 +43,14 @@ class ImagePropertyEditorSpec extends Specification { void "Invalid image format '#format'"() { setup: - - PropertyEditor editor = new ImagePropertyEditor() + def converter = new ImageConverter() when: - editor.value = format + converter.fromObject(format) then: - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/InsetsPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/InsetsConverterSpec.groovy similarity index 84% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/InsetsPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/InsetsConverterSpec.groovy index edacfee28c9..89ad920cdea 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/InsetsPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/InsetsConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Insets -import java.beans.PropertyEditor @Unroll -class InsetsPropertyEditorSpec extends Specification { +class InsetsConverterSpec extends Specification { @Shared private Insets insets = new Insets(1, 2, 3, 4) void "Insets format '#format' should be equal to #insets"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + def converter = new InsetsConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -70,15 +68,13 @@ class InsetsPropertyEditorSpec extends Specification { void "Invalid insets format '#format'"() { setup: - - PropertyEditor editor = new InsetsPropertyEditor() + def converter = new InsetsConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -96,16 +92,12 @@ class InsetsPropertyEditorSpec extends Specification { void "Formatted insets '#expected'"() { given: - - PropertyEditor editor = new InsetsPropertyEditor() + def converter = new InsetsConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/LinearGradientPaintPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/LinearGradientPaintConverterSpec.groovy similarity index 87% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/LinearGradientPaintPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/LinearGradientPaintConverterSpec.groovy index 2bf68cfd586..5352273ffbd 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/LinearGradientPaintPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/LinearGradientPaintConverterSpec.groovy @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Color import java.awt.LinearGradientPaint -import java.beans.PropertyEditor import static java.awt.Color.BLACK import static java.awt.Color.RED @@ -32,7 +32,7 @@ import static java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE import static java.awt.MultipleGradientPaint.CycleMethod.REPEAT @Unroll -class LinearGradientPaintPropertyEditorSpec extends Specification { +class LinearGradientPaintConverterSpec extends Specification { @Shared private LinearGradientPaint sharedPaint = new LinearGradientPaint(1, 2, 3, 4, [0, 1] as float[], [BLACK, WHITE] as Color[], NO_CYCLE) @@ -41,15 +41,13 @@ class LinearGradientPaintPropertyEditorSpec extends Specification { void "LinearGradientPaint format '#format' is supported"() { setup: - - PropertyEditor editor = new LinearGradientPaintPropertyEditor() + def converter = new LinearGradientPaintConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - paintsAreEqual value, editor.value + paintsAreEqual value, converted where: value | format @@ -83,15 +81,13 @@ class LinearGradientPaintPropertyEditorSpec extends Specification { void "Invalid gradientPaint format '#format'"() { setup: - - PropertyEditor editor = new LinearGradientPaintPropertyEditor() + def converter = new LinearGradientPaintConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -114,16 +110,12 @@ class LinearGradientPaintPropertyEditorSpec extends Specification { void "Formatted linear gradient '#expected'"() { given: - - PropertyEditor editor = new LinearGradientPaintPropertyEditor() + def converter = new LinearGradientPaintConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Point2DPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Point2DConverterSpec.groovy similarity index 82% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Point2DPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Point2DConverterSpec.groovy index c7311c336ca..2465dc15aeb 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Point2DPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Point2DConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.geom.Point2D -import java.beans.PropertyEditor @Unroll -class Point2DPropertyEditorSpec extends Specification { +class Point2DConverterSpec extends Specification { @Shared private Point2D point = new Point2D.Double(10, 20) void "Point2D format '#format' should be equal to #point"() { setup: - - PropertyEditor editor = new Point2DPropertyEditor() + def converter = new Point2DConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -66,15 +64,13 @@ class Point2DPropertyEditorSpec extends Specification { void "Invalid point format '#format'"() { setup: - - PropertyEditor editor = new Point2DPropertyEditor() + def converter = new Point2DConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +88,12 @@ class Point2DPropertyEditorSpec extends Specification { void "Formatted point '#expected'"() { given: - - PropertyEditor editor = new Point2DPropertyEditor() + def converter = new Point2DConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PointPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PointConverterSpec.groovy similarity index 81% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PointPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PointConverterSpec.groovy index 66d97f648d8..de2cfcd56f8 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PointPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PointConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Point -import java.beans.PropertyEditor @Unroll -class PointPropertyEditorSpec extends Specification { +class PointConverterSpec extends Specification { @Shared private Point point = new Point(10, 20) void "Point format '#format' should be equal to #point"() { setup: - - PropertyEditor editor = new PointPropertyEditor() + def converter = new PointConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -66,15 +64,13 @@ class PointPropertyEditorSpec extends Specification { void "Invalid point format '#format'"() { setup: - - PropertyEditor editor = new PointPropertyEditor() + def converter = new PointConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -91,16 +87,12 @@ class PointPropertyEditorSpec extends Specification { void "Formatted point '#expected'"() { given: - - PropertyEditor editor = new PointPropertyEditor() + def converter = new PointConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PolygonPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PolygonConverterSpec.groovy similarity index 80% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PolygonPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PolygonConverterSpec.groovy index b38cbfde5cf..97932de28f4 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/PolygonPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/PolygonConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Polygon -import java.beans.PropertyEditor @Unroll -class PolygonPropertyEditorSpec extends Specification { +class PolygonConverterSpec extends Specification { @Shared private Polygon polygon = new Polygon([0, 2] as int[], [1, 3] as int[], 2) void "Polygon format '#format' should be supported"() { setup: - - PropertyEditor editor = new PolygonPropertyEditor() + def converter = new PolygonConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - polygonsAreEqual value, editor.value + polygonsAreEqual value, converted where: value | format @@ -68,15 +66,13 @@ class PolygonPropertyEditorSpec extends Specification { void "Invalid polygon format '#format'"() { setup: - - PropertyEditor editor = new PolygonPropertyEditor() + def converter = new PolygonConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +88,12 @@ class PolygonPropertyEditorSpec extends Specification { void "Formatted polygon '#expected'"() { given: - - PropertyEditor editor = new PolygonPropertyEditor() + def converter = new PolygonConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RadialGradientPaintPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RadialGradientPaintConverterSpec.groovy similarity index 87% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RadialGradientPaintPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RadialGradientPaintConverterSpec.groovy index 32629ab8ca7..4bec37589e1 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RadialGradientPaintPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RadialGradientPaintConverterSpec.groovy @@ -15,16 +15,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Color import java.awt.RadialGradientPaint import java.awt.geom.Point2D -import java.beans.PropertyEditor import static java.awt.Color.BLACK import static java.awt.Color.RED @@ -33,7 +33,7 @@ import static java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE import static java.awt.MultipleGradientPaint.CycleMethod.REPEAT @Unroll -class RadialGradientPaintPropertyEditorSpec extends Specification { +class RadialGradientPaintConverterSpec extends Specification { @Shared private RadialGradientPaint sharedPaint = new RadialGradientPaint(new Point2D.Float(2f, 2f), 5f, new Point2D.Float(4f, 4f), [0, 1] as float[], [BLACK, WHITE] as Color[], NO_CYCLE) @@ -42,15 +42,13 @@ class RadialGradientPaintPropertyEditorSpec extends Specification { void "RadialGradientPaint format '#format' is supported"() { setup: - - PropertyEditor editor = new RadialGradientPaintPropertyEditor() + def converter = new RadialGradientPaintConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - paintsAreEqual value, editor.value + paintsAreEqual value, converted where: value | format @@ -85,15 +83,13 @@ class RadialGradientPaintPropertyEditorSpec extends Specification { void "Invalid gradientPaint format '#format'"() { setup: - - PropertyEditor editor = new RadialGradientPaintPropertyEditor() + def converter = new RadialGradientPaintConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -116,16 +112,12 @@ class RadialGradientPaintPropertyEditorSpec extends Specification { void "Formatted radial gradient '#expected'"() { given: - - PropertyEditor editor = new RadialGradientPaintPropertyEditor() + def converter = new RadialGradientPaintConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Rectangle2DPropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Rectangle2DConverterSpec.groovy similarity index 84% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Rectangle2DPropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Rectangle2DConverterSpec.groovy index 45508d1891a..7696bda51a1 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/Rectangle2DPropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/Rectangle2DConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.geom.Rectangle2D -import java.beans.PropertyEditor @Unroll -class Rectangle2DPropertyEditorSpec extends Specification { +class Rectangle2DConverterSpec extends Specification { @Shared private Rectangle2D rectangle = new Rectangle2D.Double(10, 20, 30, 40) void "Rectangle2D format '#format' should be equal to #rectangle"() { setup: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + def converter = new Rectangle2DConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -64,15 +62,13 @@ class Rectangle2DPropertyEditorSpec extends Specification { void "Invalid rectangle format '#format'"() { setup: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + def converter = new Rectangle2DConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +88,12 @@ class Rectangle2DPropertyEditorSpec extends Specification { void "Formatted rectangle '#expected'"() { given: - - PropertyEditor editor = new Rectangle2DPropertyEditor() + def converter = new Rectangle2DConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RectanglePropertyEditorSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RectangleConverterSpec.groovy similarity index 83% rename from subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RectanglePropertyEditorSpec.groovy rename to subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RectangleConverterSpec.groovy index 927bf19ec00..7a4b4ca1ea9 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/editors/RectanglePropertyEditorSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/RectangleConverterSpec.groovy @@ -15,31 +15,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package griffon.swing.editors +package griffon.swing.converters import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll +import javax.application.converter.ConversionException import java.awt.Rectangle -import java.beans.PropertyEditor @Unroll -class RectanglePropertyEditorSpec extends Specification { +class RectangleConverterSpec extends Specification { @Shared private Rectangle rectangle = new Rectangle(10, 20, 30, 40) void "Rectangle format '#format' should be equal to #rectangle"() { setup: - - PropertyEditor editor = new RectanglePropertyEditor() + def converter = new RectangleConverter() when: - editor.value = format + def converted = converter.fromObject(format) then: - - value == editor.value + value == converted where: value | format @@ -64,15 +62,13 @@ class RectanglePropertyEditorSpec extends Specification { void "Invalid rectangle format '#format'"() { setup: - - PropertyEditor editor = new RectanglePropertyEditor() + def converter = new RectangleConverter() when: - editor.value = format + converter.fromObject(format) then: - - thrown(IllegalArgumentException) + thrown(ConversionException) where: format << [ @@ -92,16 +88,12 @@ class RectanglePropertyEditorSpec extends Specification { void "Formatted rectangle '#expected'"() { given: - - PropertyEditor editor = new RectanglePropertyEditor() + def converter = new RectangleConverter() when: - - editor.value = value - String actual = editor.asText + String actual = converter.toString(converter.fromObject(value)) then: - expected == actual where: diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/spi/ConverterProviderSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/spi/ConverterProviderSpec.groovy new file mode 100644 index 00000000000..24b0951d37b --- /dev/null +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/converters/spi/ConverterProviderSpec.groovy @@ -0,0 +1,86 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2008-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package griffon.swing.converters.spi + +import griffon.swing.converters.BufferedImageConverter +import griffon.swing.converters.ColorConverter +import griffon.swing.converters.DimensionConverter +import griffon.swing.converters.FontConverter +import griffon.swing.converters.GradientPaintConverter +import griffon.swing.converters.IconConverter +import griffon.swing.converters.ImageConverter +import griffon.swing.converters.InsetsConverter +import griffon.swing.converters.LinearGradientPaintConverter +import griffon.swing.converters.Point2DConverter +import griffon.swing.converters.PointConverter +import griffon.swing.converters.PolygonConverter +import griffon.swing.converters.RadialGradientPaintConverter +import griffon.swing.converters.Rectangle2DConverter +import griffon.swing.converters.RectangleConverter +import spock.lang.Specification +import spock.lang.Unroll + +import javax.application.converter.Converter +import javax.application.converter.spi.ConverterProvider +import javax.swing.Icon +import java.awt.Color +import java.awt.Dimension +import java.awt.Font +import java.awt.GradientPaint +import java.awt.Image +import java.awt.Insets +import java.awt.LinearGradientPaint +import java.awt.Point +import java.awt.Polygon +import java.awt.RadialGradientPaint +import java.awt.Rectangle +import java.awt.geom.Point2D +import java.awt.geom.Rectangle2D +import java.awt.image.BufferedImage + +@Unroll +class ConverterProviderSpec extends Specification { + public void "Provider for #targetType is related to #converterType"(Class targetType, Class> converterType) { + given: + ServiceLoader providers = ServiceLoader.load(ConverterProvider) + + when: + ConverterProvider converterProvider = providers.iterator().find { it.targetType == targetType } + + then: + converterProvider.converterType == converterType + + where: + targetType | converterType + BufferedImage | BufferedImageConverter + Color | ColorConverter + Dimension | DimensionConverter + Font | FontConverter + GradientPaint | GradientPaintConverter + Icon | IconConverter + Image | ImageConverter + Insets | InsetsConverter + LinearGradientPaint | LinearGradientPaintConverter + Point2D | Point2DConverter + Point | PointConverter + Polygon | PolygonConverter + RadialGradientPaint | RadialGradientPaintConverter + Rectangle2D | Rectangle2DConverter + Rectangle | RectangleConverter + } +} diff --git a/subprojects/griffon-swing/src/test/groovy/griffon/swing/formatters/ColorFormatterSpec.groovy b/subprojects/griffon-swing/src/test/groovy/griffon/swing/formatters/ColorFormatterSpec.groovy index 3934aaeff92..1906fffac14 100644 --- a/subprojects/griffon-swing/src/test/groovy/griffon/swing/formatters/ColorFormatterSpec.groovy +++ b/subprojects/griffon-swing/src/test/groovy/griffon/swing/formatters/ColorFormatterSpec.groovy @@ -17,7 +17,7 @@ */ package griffon.swing.formatters -import griffon.core.formatters.ParseException +import org.kordamp.jsr377.formatter.ParseException import spock.lang.Specification import spock.lang.Unroll diff --git a/templates/griffon-javafx-groovy-templates/templates/griffon-javafx-groovy/build.gradle b/templates/griffon-javafx-groovy-templates/templates/griffon-javafx-groovy/build.gradle index 76cea442a1f..01613182a3b 100644 --- a/templates/griffon-javafx-groovy-templates/templates/griffon-javafx-groovy/build.gradle +++ b/templates/griffon-javafx-groovy-templates/templates/griffon-javafx-groovy/build.gradle @@ -108,11 +108,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-javafx-java-templates/templates/griffon-javafx-java/build.gradle b/templates/griffon-javafx-java-templates/templates/griffon-javafx-java/build.gradle index aa1ca482552..1153a584d16 100644 --- a/templates/griffon-javafx-java-templates/templates/griffon-javafx-java/build.gradle +++ b/templates/griffon-javafx-java-templates/templates/griffon-javafx-java/build.gradle @@ -108,11 +108,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-lanterna-groovy-templates/templates/griffon-lanterna-groovy/build.gradle b/templates/griffon-lanterna-groovy-templates/templates/griffon-lanterna-groovy/build.gradle index 5fd6e6d5d31..5fef32b1e7c 100644 --- a/templates/griffon-lanterna-groovy-templates/templates/griffon-lanterna-groovy/build.gradle +++ b/templates/griffon-lanterna-groovy-templates/templates/griffon-lanterna-groovy/build.gradle @@ -93,11 +93,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-lanterna-java-templates/templates/griffon-lanterna-java/build.gradle b/templates/griffon-lanterna-java-templates/templates/griffon-lanterna-java/build.gradle index b4b561f4ec5..99a1a309972 100644 --- a/templates/griffon-lanterna-java-templates/templates/griffon-lanterna-java/build.gradle +++ b/templates/griffon-lanterna-java-templates/templates/griffon-lanterna-java/build.gradle @@ -93,11 +93,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-lanterna3-groovy-templates/templates/griffon-lanterna3-groovy/build.gradle b/templates/griffon-lanterna3-groovy-templates/templates/griffon-lanterna3-groovy/build.gradle index d63468fa264..a6409f818cd 100644 --- a/templates/griffon-lanterna3-groovy-templates/templates/griffon-lanterna3-groovy/build.gradle +++ b/templates/griffon-lanterna3-groovy-templates/templates/griffon-lanterna3-groovy/build.gradle @@ -93,11 +93,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-lanterna3-java-templates/templates/griffon-lanterna3-java/build.gradle b/templates/griffon-lanterna3-java-templates/templates/griffon-lanterna3-java/build.gradle index 17922883cb6..f120d151261 100644 --- a/templates/griffon-lanterna3-java-templates/templates/griffon-lanterna3-java/build.gradle +++ b/templates/griffon-lanterna3-java-templates/templates/griffon-lanterna3-java/build.gradle @@ -93,11 +93,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-pivot-groovy-templates/templates/griffon-pivot-groovy/build.gradle b/templates/griffon-pivot-groovy-templates/templates/griffon-pivot-groovy/build.gradle index 2877ab48bd6..22182d29fca 100644 --- a/templates/griffon-pivot-groovy-templates/templates/griffon-pivot-groovy/build.gradle +++ b/templates/griffon-pivot-groovy-templates/templates/griffon-pivot-groovy/build.gradle @@ -94,11 +94,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-pivot-java-templates/templates/griffon-pivot-java/build.gradle b/templates/griffon-pivot-java-templates/templates/griffon-pivot-java/build.gradle index ebdc0534021..b556884c476 100644 --- a/templates/griffon-pivot-java-templates/templates/griffon-pivot-java/build.gradle +++ b/templates/griffon-pivot-java-templates/templates/griffon-pivot-java/build.gradle @@ -94,11 +94,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-swing-groovy-templates/templates/griffon-swing-groovy/build.gradle b/templates/griffon-swing-groovy-templates/templates/griffon-swing-groovy/build.gradle index ffb6bf9932c..cffd6783f4e 100644 --- a/templates/griffon-swing-groovy-templates/templates/griffon-swing-groovy/build.gradle +++ b/templates/griffon-swing-groovy-templates/templates/griffon-swing-groovy/build.gradle @@ -94,11 +94,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/templates/griffon-swing-java-templates/templates/griffon-swing-java/build.gradle b/templates/griffon-swing-java-templates/templates/griffon-swing-java/build.gradle index f0765fc0870..87403dd82fd 100644 --- a/templates/griffon-swing-java-templates/templates/griffon-swing-java/build.gradle +++ b/templates/griffon-swing-java-templates/templates/griffon-swing-java/build.gradle @@ -94,11 +94,6 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } startScripts { diff --git a/tutorials/javafx-app/build.gradle b/tutorials/javafx-app/build.gradle index b6e92e08751..6caf78f5f32 100644 --- a/tutorials/javafx-app/build.gradle +++ b/tutorials/javafx-app/build.gradle @@ -121,9 +121,4 @@ shadowJar { transform(ServiceFileTransformer) { path = 'META-INF/types' } - transform(PropertiesFileTransformer) { - paths = [ - 'META-INF/editors/java.beans.PropertyEditor' - ] - } } \ No newline at end of file