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 AbstractConverter

    java.lang.Object
      com.jgoodies.common.bean.AbstractBean
          com.jgoodies.binding.beans.Model
              com.jgoodies.binding.value.AbstractValueModel
                  com.jgoodies.binding.value.AbstractWrappedValueModel
                      com.jgoodies.binding.value.AbstractConverter

All Implemented Interfaces:
  ComponentModel, ComponentValueModel, ValueModel, com.jgoodies.common.bean.ObservableBean, com.jgoodies.common.bean.ObservableBean2, Serializable

Direct Known Subclasses:
  ConverterFactory.BooleanNegator, ConverterFactory.BooleanToStringConverter, ConverterFactory.DoubleConverter, ConverterFactory.DoubleToIntegerConverter, ConverterFactory.FloatConverter, ConverterFactory.FloatToIntegerConverter, ConverterFactory.IntegerConverter, ConverterFactory.LongConverter, ConverterFactory.LongToIntegerConverter, ConverterFactory.StringConverter

    public abstract class AbstractConverter

extends AbstractWrappedValueModel

An abstract class that minimizes the effort required to implement a type converter. A type converter is a ValueModel that converts the type of an object being held as a value in one ValueModel into another type.

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.

The conversion must be performed when reading and writing values, as well as in the change notification. This class specifies abstract methods for the conversion from source to output, which is used to convert in `#getValue` and in the change notification. For the write conversion you must implement `#setValue`.

Most converters can set values converted by `#convertFromSubject` with `#setValue`. However, a converter may reject subject values to be converted and may reject values to be set - as any ValueModel.

Type converters should be used judiciously and only to bridge two `ValueModel`s. Converters often use a generic but weak conversion, and so can be limited w.r.t. to localized formatting conventions.

When binding non-String values to a text UI component, consider using a `JFormattedTextField`. Formatted text fields provide a powerful means to convert strings to objects and handle many cases that arise around invalid input. Formatted text fields can be bound to `ValueModel`s using the `PropertyConnector` class.

Version:
  $Revision: 1.15 $
Author:
  Karsten Lentzsch
See Also:
  `ValueModel`, `ConverterFactory`, `JFormattedTextField`, `PropertyConnector`, Serialized Form

Field Summary
`protected ValueModel` | `subject` Holds the ValueModel that in turn holds the source value.

Fields inherited from class com.jgoodies.binding.value.AbstractValueModel
`PROPERTYNAME_VALUE`

Fields inherited from class com.jgoodies.common.bean.AbstractBean
`changeSupport`

Fields inherited from interface com.jgoodies.binding.value.ComponentValueModel
`PROPERTYNAME_EDITABLE, PROPERTYNAME_ENABLED, PROPERTYNAME_VISIBLE`

Fields inherited from interface com.jgoodies.binding.value.ComponentModel
`PROPERTY_EDITABLE, PROPERTY_ENABLED, PROPERTY_VISIBLE`

Constructor Summary
`AbstractConverter(ValueModel subject)` Constructs an AbstractConverter on the given subject.

Method Summary
`abstract Object` | `convertFromSubject(Object subjectValue)` Converts a value from the subject to the type or format used by this converter.
`protected PropertyChangeListener` | `createValueChangeHandler()`
`Object` | `getValue()` Converts the subject's value and returns the converted value.

Methods inherited from class com.jgoodies.binding.value.AbstractWrappedValueModel
`getWrappee, isEditable, isEnabled, isVisible, release, setEditable, setEnabled, setVisible`

Methods inherited from class com.jgoodies.binding.value.AbstractValueModel
`addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueString`

Methods inherited from class com.jgoodies.binding.beans.Model
`createPropertyChangeSupport, firePropertyChange`

Methods inherited from class com.jgoodies.common.bean.AbstractBean
`addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener`

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

Methods inherited from interface com.jgoodies.binding.value.ValueModel
`addValueChangeListener, removeValueChangeListener, setValue`

Methods inherited from interface com.jgoodies.common.bean.ObservableBean2
`addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener`

Methods inherited from interface com.jgoodies.common.bean.ObservableBean
`addPropertyChangeListener, removePropertyChangeListener`

Field Detail

### subject

    protected final ValueModel subject

  Holds the ValueModel that in turn holds the source value.

Constructor Detail

### AbstractConverter

    public AbstractConverter(ValueModel subject)

  Constructs an AbstractConverter on the given subject.

  Parameters:
    `subject` - the ValueModel that holds the source value
  Throws:
    `NullPointerException` - if the subject is `null`

Method Detail

### convertFromSubject

    public abstract Object convertFromSubject(Object subjectValue)

  Converts a value from the subject to the type or format used by this converter.

  Parameters:
    `subjectValue` - the subject's value
  Returns:
    the converted value in the type or format used by this converter

### getValue

    public Object getValue()

  Converts the subject's value and returns the converted value.

  Returns:
    the converted subject value

### createValueChangeHandler

    protected PropertyChangeListener createValueChangeHandler()

  Specified by:
    `createValueChangeHandler` in class `AbstractWrappedValueModel`

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-2011 JGoodies Karsten Lentzsch. All Rights Reserved.