com.jgoodies.binding.value
public final class ConverterFactory extends java.lang.Object
Type converters should be used judiciously and only to bridge two
ValueModels. To bind non-Strings to a text UI component
you should better use a JFormattedTextField
.
They provide a more powerful means to convert strings to objects
and handle many cases that arise around invalid input. See also the classes
Bindings
and
BasicComponentFactory
on how to
bind ValueModels to formatted text fields.
The inner converter implementations have a 'public' visibility to enable reflection access.
ValueModel
,
Format
,
JFormattedTextField
Modifier and Type | Class and Description |
---|---|
static class |
ConverterFactory.BooleanNegator
Negates Booleans leaving null unchanged.
|
static class |
ConverterFactory.BooleanToStringConverter
Converts Booleans to Strings and vice-versa using given texts for
true, false, and null.
|
static class |
ConverterFactory.DoubleConverter
Converts Doubles using a given multiplier.
|
static class |
ConverterFactory.DoubleToIntegerConverter
Converts Doubles to Integers and vice-versa.
|
static class |
ConverterFactory.FloatConverter
Converts Floats using a given multiplier.
|
static class |
ConverterFactory.FloatToIntegerConverter
Converts Floats to Integers and vice-versa.
|
static class |
ConverterFactory.IntegerConverter
Converts Integers using a given multiplier.
|
static class |
ConverterFactory.LongConverter
Converts Longs using a given multiplier.
|
static class |
ConverterFactory.LongToIntegerConverter
Converts Longs to Integers and vice-versa.
|
static class |
ConverterFactory.StringConverter
Converts Values to Strings and vice-versa using a given Format.
|
Modifier and Type | Method and Description |
---|---|
static ValueModel |
createBooleanNegator(ValueModel booleanSubject)
Creates and returns a ValueModel that negates Booleans and leaves
null unchanged.
|
static ValueModel |
createBooleanToStringConverter(ValueModel booleanSubject,
java.lang.String trueText,
java.lang.String falseText)
Creates and returns a ValueModel that converts Booleans
to the associated of the two specified strings, and vice versa.
|
static ValueModel |
createBooleanToStringConverter(ValueModel booleanSubject,
java.lang.String trueText,
java.lang.String falseText,
java.lang.String nullText)
Creates and returns a ValueModel that converts Booleans
to the associated of the two specified strings, and vice versa.
|
static ValueModel |
createDoubleConverter(ValueModel doubleSubject,
double multiplier)
Creates and returns a ValueModel that converts Doubles using the
specified multiplier.
|
static ValueModel |
createDoubleToIntegerConverter(ValueModel doubleSubject)
Creates and returns a ValueModel that converts Doubles to Integer,
and vice versa.
|
static ValueModel |
createDoubleToIntegerConverter(ValueModel doubleSubject,
int multiplier)
Creates and returns a ValueModel that converts Doubles to Integer,
and vice versa.
|
static ValueModel |
createFloatConverter(ValueModel floatSubject,
float multiplier)
Creates and returns a ValueModel that converts Floats using the
specified multiplier.
|
static ValueModel |
createFloatToIntegerConverter(ValueModel floatSubject)
Creates and returns a ValueModel that converts Floats to Integer,
and vice versa.
|
static ValueModel |
createFloatToIntegerConverter(ValueModel floatSubject,
int multiplier)
Creates and returns a ValueModel that converts Floats to Integer,
and vice versa.
|
static ValueModel |
createIntegerConverter(ValueModel integerSubject,
double multiplier)
Creates and returns a ValueModel that converts Integers using the
specified multiplier.
|
static ValueModel |
createLongConverter(ValueModel longSubject,
double multiplier)
Creates and returns a ValueModel that converts Long using the
specified multiplier.
|
static ValueModel |
createLongToIntegerConverter(ValueModel longSubject)
Creates and returns a ValueModel that converts Longs to Integer
and vice versa.
|
static ValueModel |
createLongToIntegerConverter(ValueModel longSubject,
int multiplier)
Creates and returns a ValueModel that converts Longs to Integer
and vice versa.
|
static ValueModel |
createStringConverter(ValueModel subject,
java.text.Format format)
Creates and returns a ValueModel that converts objects to Strings
and vice versa.
|
public static ValueModel createBooleanNegator(ValueModel booleanSubject)
Constraints: The subject is of type Boolean
.
booleanSubject
- a Boolean ValueModeljava.lang.NullPointerException
- if the subject is null
public static ValueModel createBooleanToStringConverter(ValueModel booleanSubject, java.lang.String trueText, java.lang.String falseText)
Constraints: The subject is of type Boolean
.
booleanSubject
- a Boolean ValueModeltrueText
- the text associated with Boolean.TRUE
falseText
- the text associated with Boolean.FALSE
java.lang.NullPointerException
- if the subject, trueText or falseText
is null
java.lang.IllegalArgumentException
- if the trueText equals the falseTextpublic static ValueModel createBooleanToStringConverter(ValueModel booleanSubject, java.lang.String trueText, java.lang.String falseText, java.lang.String nullText)
Constraints: The subject is of type Boolean
.
booleanSubject
- a Boolean ValueModeltrueText
- the text associated with Boolean.TRUE
falseText
- the text associated with Boolean.FALSE
nullText
- the text associated with null
java.lang.NullPointerException
- if the subject, trueText, falseText
or nullText is null
java.lang.IllegalArgumentException
- if the trueText equals the falseTextpublic static ValueModel createDoubleConverter(ValueModel doubleSubject, double multiplier)
Examples: multiplier=100, Double(1.23) -> Double(123), multiplier=1000, Double(1.23) -> Double(1230)
Constraints: The subject is of type Double
.
doubleSubject
- a Double ValueModelmultiplier
- the multiplier used for the conversionjava.lang.NullPointerException
- if the subject is null
public static ValueModel createDoubleToIntegerConverter(ValueModel doubleSubject)
Constraints: The subject is of type Double
.
doubleSubject
- a Double ValueModeljava.lang.NullPointerException
- if the subject is null
public static ValueModel createDoubleToIntegerConverter(ValueModel doubleSubject, int multiplier)
Examples: multiplier=100, Double(1.23) -> Integer(123), multiplier=1000, Double(1.23) -> Integer(1230)
Constraints: The subject is of type Double
.
doubleSubject
- a Double ValueModelmultiplier
- the multiplier used to convert the Double to Integerjava.lang.NullPointerException
- if the subject is null
public static ValueModel createFloatConverter(ValueModel floatSubject, float multiplier)
Examples: multiplier=100, Float(1.23) -> Float(123), multiplier=1000, Float(1.23) -> Float(1230)
Constraints: The subject is of type Float
.
floatSubject
- a Float ValueModelmultiplier
- the multiplier used for the conversionjava.lang.NullPointerException
- if the subject is null
public static ValueModel createFloatToIntegerConverter(ValueModel floatSubject)
Constraints: The subject is of type Float
.
s
floatSubject
- a Float ValueModeljava.lang.NullPointerException
- if the subject is null
public static ValueModel createFloatToIntegerConverter(ValueModel floatSubject, int multiplier)
Constraints: The subject is of type Float
.
floatSubject
- a Float ValueModelmultiplier
- the multiplier used to convert the Float to Integerjava.lang.NullPointerException
- if the subject is null
public static ValueModel createIntegerConverter(ValueModel integerSubject, double multiplier)
Examples: multiplier=100, Integer(3) -> Integer(300), multiplier=1000, Integer(3) -> Integer(3000)
Constraints: The subject is of type Integer
.
integerSubject
- a Integer ValueModelmultiplier
- the multiplier used for the conversionjava.lang.NullPointerException
- if the subject is null
public static ValueModel createLongConverter(ValueModel longSubject, double multiplier)
Examples: multiplier=100, Long(3) -> Long(300), multiplier=1000, Long(3) -> Long(3000)
Constraints: The subject is of type Long
.
longSubject
- a Long ValueModelmultiplier
- the multiplier used for the conversionjava.lang.NullPointerException
- if the subject is null
public static ValueModel createLongToIntegerConverter(ValueModel longSubject)
Constraints: The subject is of type Long
,
values written to the converter are of type Integer
.
longSubject
- a Long ValueModeljava.lang.NullPointerException
- if the subject is null
public static ValueModel createLongToIntegerConverter(ValueModel longSubject, int multiplier)
Constraints: The subject is of type Long
,
values written to the converter are of type Integer
.
longSubject
- a Long ValueModelmultiplier
- used to multiply the Long when converting to Integerjava.lang.NullPointerException
- if the subject is null
public static ValueModel createStringConverter(ValueModel subject, java.text.Format format)
Format
.
Constraints: The subject is of type Object
;
it must be formattable and parsable via the given Format
.
subject
- the underlying ValueModel.format
- the Format
used to format and parsejava.lang.NullPointerException
- if the subject or the format
is null
Copyright © 2002-2010 JGoodies Karsten Lentzsch. All Rights Reserved.