Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jgoodies.binding.value
Class ConverterFactory

    java.lang.Object
      com.jgoodies.binding.value.ConverterFactory

    public final class ConverterFactory

extends Object

A factory that vends ValueModels that convert types, for example Dates to Strings. More formally, a converting ValueModel VM1 converts the type T2 of an object being held as a value in one ValueModel VM2 into another type T1. When reading a value from VM1, instances of T2 are read from VM2 and are converted to T1. When storing a new value to VM1, the type converter will perform the inverse conversion and will convert an instance of T1 to T2.

Type converters should be used judiciously. To bind non-Strings to a text UI component you should favor to use a `JFormattedTextField`. They provide a powerful means to convert Strings to objects and handle many cases that arise around invalid input.

Version:
  $Revision: 1.12 $
Author:
  Karsten Lentzsch
See Also:
  `ValueModel`, `Format`, `JFormattedTextField`

Nested Class Summary
`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.

Method Summary
`static ValueModel` | `createBooleanNegator(ValueModel booleanSource)` Creates and returns a ValueModel that negates Booleans and leaves `null` unchanged.
`static ValueModel` | `createBooleanToStringConverter(ValueModel booleanSubject, String trueText, 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 booleanSource, String trueText, String falseText, 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 doubleSource, double multiplier)` Creates and returns a ValueModel that converts Doubles using the specified multiplier.
`static ValueModel` | `createDoubleToIntegerConverter(ValueModel doubleSource)` Creates and returns a ValueModel that converts Doubles to Integer, and vice versa.
`static ValueModel` | `createDoubleToIntegerConverter(ValueModel doubleSource, int multiplier)` Creates and returns a ValueModel that converts Doubles to Integer, and vice versa.
`static ValueModel` | `createFloatConverter(ValueModel floatSource, float multiplier)` Creates and returns a ValueModel that converts Floats using the specified multiplier.
`static ValueModel` | `createFloatToIntegerConverter(ValueModel floatSource)` Creates and returns a ValueModel that converts Floats to Integer, and vice versa.
`static ValueModel` | `createFloatToIntegerConverter(ValueModel floatSource, int multiplier)` Creates and returns a ValueModel that converts Floats to Integer, and vice versa.
`static ValueModel` | `createIntegerConverter(ValueModel integerSource, double multiplier)` Creates and returns a ValueModel that converts Integers using the specified multiplier.
`static ValueModel` | `createLongConverter(ValueModel longSource, 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 longSource, int multiplier)` Creates and returns a ValueModel that converts Longs to Integer and vice versa.
`static ValueModel` | `createStringConverter(ValueModel source, Format format)` Creates and returns a ValueModel that converts objects to Strings and vice versa.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### createBooleanNegator

    public static ValueModel createBooleanNegator(ValueModel booleanSource)

  Creates and returns a ValueModel that negates Booleans and leaves `null` unchanged.

  Parameters:
    `booleanSource` - a Boolean ValueModel
  Returns:
    a ValueModel that inverts Booleans
  Throws:
    `NullPointerException` - if the `booleanSource` is `null`

### createBooleanToStringConverter

    public static ValueModel createBooleanToStringConverter(ValueModel booleanSubject,
                                                            String trueText,
                                                            String falseText)

  Creates and returns a ValueModel that converts Booleans to the associated of the two specified strings, and vice versa. `null` is mapped to an empty string. Ignores cases when setting a text.

  Parameters:
    `booleanSubject` - a Boolean ValueModel
    `trueText` - the text associated with `Boolean.TRUE`
    `falseText` - the text associated with `Boolean.FALSE`
  Returns:
    a ValueModel that converts boolean to the associated text
  Throws:
    `NullPointerException` - if `booleanSource`, `trueText`, `falseText` or `nullText` is `null`
    `IllegalArgumentException` - if `trueText` equals `falseText`

### createBooleanToStringConverter

    public static ValueModel createBooleanToStringConverter(ValueModel booleanSource,
                                                            String trueText,
                                                            String falseText,
                                                            String nullText)

  Creates and returns a ValueModel that converts Booleans to the associated of the two specified strings, and vice versa. `null` is mapped to the specified text. Ignores cases when setting a text.

  Parameters:
    `booleanSource` - a Boolean ValueModel
    `trueText` - the text associated with `Boolean.TRUE`
    `falseText` - the text associated with `Boolean.FALSE`
    `nullText` - the text associated with `null`
  Returns:
    a ValueModel that converts boolean to the associated text
  Throws:
    `NullPointerException` - if `booleanSource`, `trueText`, `falseText` or `nullText` is `null`
    `IllegalArgumentException` - if `trueText` equals `falseText`

### createDoubleConverter

    public static ValueModel createDoubleConverter(ValueModel doubleSource,
                                                   double multiplier)

  Creates and returns a ValueModel that converts Doubles using the specified multiplier.

  Examples: multiplier=100, Double(1.23) -> Double(123), multiplier=1000, Double(1.23) -> Double(1230)

  Parameters:
    `doubleSource` - a Double ValueModel
    `multiplier` - the multiplier used for the conversion
  Returns:
    a ValueModel that converts Doubles using the specified multiplier
  Throws:
    `NullPointerException` - if `doubleSource` is `null`
  Since:
    1.0.2

### createDoubleToIntegerConverter

    public static ValueModel createDoubleToIntegerConverter(ValueModel doubleSource)

  Creates and returns a ValueModel that converts Doubles to Integer, and vice versa.

  Parameters:
    `doubleSource` - a Double ValueModel
  Returns:
    a ValueModel that converts Doubles to Integer
  Throws:
    `NullPointerException` - if `doubleSource` is `null`

### createDoubleToIntegerConverter

    public static ValueModel createDoubleToIntegerConverter(ValueModel doubleSource,
                                                            int multiplier)

  Creates and returns a ValueModel that converts Doubles to Integer, and vice versa. The multiplier can be used to convert Doubles to percent, permill, etc. For a percentage, set the multiplier to be 100, for a permill, set the multiplier to be 1000.

  Examples: multiplier=100, Double(1.23) -> Integer(123), multiplier=1000, Double(1.23) -> Integer(1230)

  Parameters:
    `doubleSource` - a Double ValueModel
    `multiplier` - the multiplier used to convert the Double to Integer
  Returns:
    a ValueModel that converts Doubles to Integer
  Throws:
    `NullPointerException` - if `doubleSource` is `null`

### createFloatConverter

    public static ValueModel createFloatConverter(ValueModel floatSource,
                                                  float multiplier)

  Creates and returns a ValueModel that converts Floats using the specified multiplier.

  Examples: multiplier=100, Float(1.23) -> Float(123), multiplier=1000, Float(1.23) -> Float(1230)

  Parameters:
    `floatSource` - a Float ValueModel
    `multiplier` - the multiplier used for the conversion
  Returns:
    a ValueModel that converts Float using the specified multiplier
  Throws:
    `NullPointerException` - if `floatSource` is `null`
  Since:
    1.0.2

### createFloatToIntegerConverter

    public static ValueModel createFloatToIntegerConverter(ValueModel floatSource)

  Creates and returns a ValueModel that converts Floats to Integer, and vice versa. s

  Parameters:
    `floatSource` - a Float ValueModel
  Returns:
    a ValueModel that converts Floats to Integer
  Throws:
    `NullPointerException` - if `floatSource` is `null`

### createFloatToIntegerConverter

    public static ValueModel createFloatToIntegerConverter(ValueModel floatSource,
                                                           int multiplier)

  Creates and returns a ValueModel that converts Floats to Integer, and vice versa. The multiplier can be used to convert Floats to percent, permill, etc. For a percentage, set the multiplier to be 100, for a permill, set the multiplier to be 1000.

  Parameters:
    `floatSource` - a Float ValueModel
    `multiplier` - the multiplier used to convert the Float to Integer
  Returns:
    a ValueModel that converts Floats to Integer
  Throws:
    `NullPointerException` - if `floatSource` is `null`

### createIntegerConverter

    public static ValueModel createIntegerConverter(ValueModel integerSource,
                                                    double multiplier)

  Creates and returns a ValueModel that converts Integers using the specified multiplier.

  Examples: multiplier=100, Integer(3) -> Integer(300), multiplier=1000, Integer(3) -> Integer(3000)

  Parameters:
    `integerSource` - a Integer ValueModel
    `multiplier` - the multiplier used for the conversion
  Returns:
    a ValueModel that converts Integers using the specified multiplier
  Throws:
    `NullPointerException` - if `integerSource` is `null`
  Since:
    1.0.2

### createLongConverter

    public static ValueModel createLongConverter(ValueModel longSource,
                                                 double multiplier)

  Creates and returns a ValueModel that converts Long using the specified multiplier.

  Examples: multiplier=100, Long(3) -> Long(300), multiplier=1000, Long(3) -> Long(3000)

  Parameters:
    `longSource` - a Long ValueModel
    `multiplier` - the multiplier used for the conversion
  Returns:
    a ValueModel that converts Longs using the specified multiplier
  Throws:
    `NullPointerException` - if `longSource` is `null`
  Since:
    1.0.2

### createLongToIntegerConverter

    public static ValueModel createLongToIntegerConverter(ValueModel longSubject)

  Creates and returns a ValueModel that converts Longs to Integer and vice versa.

  Constraints: The subject is of type `Long`, values written to the converter are of type `Integer`.

  Parameters:
    `longSubject` - a Long ValueModel
  Returns:
    a ValueModel that converts Longs to Integer
  Throws:
    `NullPointerException` - if the subject is `null`

### createLongToIntegerConverter

    public static ValueModel createLongToIntegerConverter(ValueModel longSource,
                                                          int multiplier)

  Creates and returns a ValueModel that converts Longs to Integer and vice versa.

  Constraints: The subject is of type `Long`, values written to the converter are of type `Integer`.

  Parameters:
    `longSource` - a Long ValueModel
    `multiplier` - used to multiply the Long when converting to Integer
  Returns:
    a ValueModel that converts Longs to Integer
  Throws:
    `NullPointerException` - if `longSource` is `null`

### createStringConverter

    public static ValueModel createStringConverter(ValueModel source,
                                                   Format format)

  Creates and returns a ValueModel that converts objects to Strings and vice versa. The conversion is performed by a `Format`.

  Constraints: The source is of type `Object`; it must be formattable and parsable via the given `Format`.

  Parameters:
    `source` - the underlying ValueModel.
    `format` - the `Format` used to format and parse
  Returns:
    a ValueModel that converts objects to Strings and vice versa
  Throws:
    `NullPointerException` - if `source` or `format` is `null`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2013 JGoodies Software GmbH. All Rights Reserved.