Class ResourceConverter
- java.lang.Object
-
- org.jdesktop.application.ResourceConverter
-
public abstract class ResourceConverter extends java.lang.ObjectA base class for converting arbitrary types to and from Strings, as well as a registry of ResourceConverter implementations.The supportsType method defines what types a ResourceConverter supports. By default it returns true for classes that are equal to the constructor's type argument. The parseType methods converts a string the ResourceConverter's supported type, and the toString does the inverse, it converts a supported type to a String. Concrete ResourceConverter subclasses must override parseType() and, in most cases, the toString method as well.
This class maintains a registry of ResourceConverters. The forType method returns the first ResourceConverter that supports a particular type, new ResourceConverters can be added with register(). A small set of generic ResourceConverters are registered by default. They support the following types:
- Boolean
- Integer
- Float
- Double
- Long
- Short
- Byte
- MessageFormat
- URL
- URI
The Boolean ResourceConverter returns true for "true", "on", "yes", false otherwise. The other primitive type ResourceConverters rely on the corresponding static parseType method, e.g. Integer.parseInt(). The MessageFormat ResourceConverter just creates MessageFormat object with the string as its constructor argument. The URL/URI converters just apply the corresponding constructor to the resource string.
- See Also:
ResourceMap
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceConverter.ResourceConverterException
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Classtype
-
Constructor Summary
Constructors Modifier Constructor Description protectedResourceConverter(java.lang.Class type)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ResourceConverterforType(java.lang.Class type)abstract java.lang.ObjectparseString(java.lang.String s, ResourceMap r)static voidregister(ResourceConverter resourceConverter)booleansupportsType(java.lang.Class testType)java.lang.StringtoString(java.lang.Object obj)
-
-
-
Method Detail
-
parseString
public abstract java.lang.Object parseString(java.lang.String s, ResourceMap r) throws ResourceConverter.ResourceConverterException
-
toString
public java.lang.String toString(java.lang.Object obj)
-
supportsType
public boolean supportsType(java.lang.Class testType)
-
register
public static void register(ResourceConverter resourceConverter)
-
forType
public static ResourceConverter forType(java.lang.Class type)
-
-