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.adapter
Class SpinnerAdapterFactory

    java.lang.Object
      com.jgoodies.binding.adapter.SpinnerAdapterFactory

    public final class SpinnerAdapterFactory

extends Object

A factory that vends `SpinnerModel` implementations that are bound to a ValueModel. Can be used to bind a ValueModel to instances of JSpinner.

To keep the ValueModel and SpinnerModel synchronized, this class listens to changes in both sides and updates the other silently, i.e. without firing a duplicate change event.

Constraints: The ValueModel's type must be compatible with the type required by the referenced SpinnerModel. For example a `SpinnerNumberModel` requires `Number` values. Example:

     // General Connection
     ValueModel   levelModel   = new PropertyAdapter(settings, "level", true);
     SpinnerModel spinnerModel = new SpinnerNumberModel(9, 5, 10, 1);
     Object defaultValue       = new Integer(9);
     SpinnerAdapterFactory.connect(spinnerModel, levelModel, defaultValue);
     JSpinner levelSpinner = new JSpinner(spinnerModel);

     // Short Form
     ValueModel levelModel = new PropertyAdapter(settings, "level", true);
     SpinnerNumberModel spinnerModel =
         SpinnerAdapterFactory.createNumberAdapter(levelModel, 5, 10, 1);
     JSpinner levelSpinner = new JSpinner(spinnerModel);

Since:
  1.1
Version:
  $Revision: 1.17 $
Author:
  Karsten Lentzsch
See Also:
  `ValueModel`, `SpinnerModel`, `JSpinner`

Method Summary
`static void` | `connect(SpinnerModel spinnerModel, ValueModel valueModel, Object defaultValue)` Connects the given ValueModel and SpinnerModel by synchronizing their values.
`static SpinnerDateModel` | `createDateAdapter(ValueModel valueModel, Date defaultDate)` Creates and returns a `SpinnerDateModel` bound to the given `valueModel`.
`static SpinnerDateModel` | `createDateAdapter(ValueModel valueModel, Date defaultDate, Comparable<Date> start, Comparable<Date> end, int calendarField)` Creates and returns a `SpinnerDateModel` that represents a sequence of dates and is bound to the given `valueModel`.
`static SpinnerNumberModel` | `createNumberAdapter(ValueModel valueModel, int defaultValue, int minValue, int maxValue, int stepSize)` Creates and returns a `SpinnerNumberModel` that is connected to the given `ValueModel` and that honors the specified minimum, maximum and step values.
`static SpinnerNumberModel` | `createNumberAdapter(ValueModel valueModel, Number defaultValue, Comparable<? extends Number> minValue, Comparable<? extends Number> maxValue, Number stepSize)` Creates and returns a `SpinnerNumberModel` that is connected to the given `ValueModel` and that honors the specified minimum, maximum and step values.

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

Method Detail

### createDateAdapter

    public static SpinnerDateModel createDateAdapter(ValueModel valueModel,
                                                     Date defaultDate)

  Creates and returns a `SpinnerDateModel` bound to the given `valueModel`. The `calendarField` is equal to `Calendar.DAY_OF_MONTH`; there are no `start`/`end` limits.

  Parameters:
    `valueModel` - a `Date` typed model that holds the spinner value
    `defaultDate` - the date used if the valueModel's value is `null`
  Returns:
    a `SpinnerDateModel` bound to the given `valueModel` without start and end limits using `Calendar.DAY_OF_MONTH` as calendar field
  Throws:
    `NullPointerException` - if the valueModel or defaultDate is `null`

### createDateAdapter

    public static SpinnerDateModel createDateAdapter(ValueModel valueModel,
                                                     Date defaultDate,
                                                     Comparable<Date> start,
                                                     Comparable<Date> end,
                                                     int calendarField)

  Creates and returns a `SpinnerDateModel` that represents a sequence of dates and is bound to the given `valueModel`. The dates are between `start` and `end`. The `nextValue` and `previousValue` methods compute elements of the sequence by advancing or reversing the current date `value` by the `calendarField` time unit. For a precise description of what it means to increment or decrement a `Calendar` `field`, see the `add` method in `java.util.Calendar`.

  The `start` and `end` parameters can be `null` to indicate that the range doesn't have an upper or lower bound. If `value` or `calendarField` is `null`, or if both `start` and `end` are specified and `minimum &gt; maximum` then an `IllegalArgumentException` is thrown. Similarly if `(minimum &lt;= value &lt;= maximum)` is false, an IllegalArgumentException is thrown.

  This method has not been tested.

  Parameters:
    `valueModel` - a `Date` typed model that holds the spinner value
    `defaultDate` - the date used if the valueModel's value is `null`
    `start` - the first date in the sequence or `null`
    `end` - the last date in the sequence or `null`
    `calendarField` - one of
    - `Calendar.ERA`
    - `Calendar.YEAR`
    - `Calendar.MONTH`
    - `Calendar.WEEK_OF_YEAR`
    - `Calendar.WEEK_OF_MONTH`
    - `Calendar.DAY_OF_MONTH`
    - `Calendar.DAY_OF_YEAR`
    - `Calendar.DAY_OF_WEEK`
    - `Calendar.DAY_OF_WEEK_IN_MONTH`
    - `Calendar.AM_PM`
    - `Calendar.HOUR`
    - `Calendar.HOUR_OF_DAY`
    - `Calendar.MINUTE`
    - `Calendar.SECOND`
    - `Calendar.MILLISECOND`
  Returns:
    a `SpinnerDateModel` bound to the given `valueModel` using the specified start and end dates and calendar field.
  Throws:
    `NullPointerException` - if the valueModel or defaultDate is `null`
    `IllegalArgumentException` - if `calendarField` isn't valid, or if the following expression is false: `(start &lt;= value &lt;= end)`.
  See Also:
    `Calendar`, `Date`

### createNumberAdapter

    public static SpinnerNumberModel createNumberAdapter(ValueModel valueModel,
                                                         int defaultValue,
                                                         int minValue,
                                                         int maxValue,
                                                         int stepSize)

  Creates and returns a `SpinnerNumberModel` that is connected to the given `ValueModel` and that honors the specified minimum, maximum and step values.

  Parameters:
    `valueModel` - an `Integer` typed model that holds the spinner value
    `defaultValue` - the number used if the valueModel's value is `null`
    `minValue` - the lower bound of the spinner number
    `maxValue` - the upper bound of the spinner number
    `stepSize` - used to increment and decrement the current value
  Returns:
    a `SpinnerNumberModel` that is connected to the given `ValueModel`
  Throws:
    `NullPointerException` - if the valueModel is `null`

### createNumberAdapter

    public static SpinnerNumberModel createNumberAdapter(ValueModel valueModel,
                                                         Number defaultValue,
                                                         Comparable<? extends Number> minValue,
                                                         Comparable<? extends Number> maxValue,
                                                         Number stepSize)

  Creates and returns a `SpinnerNumberModel` that is connected to the given `ValueModel` and that honors the specified minimum, maximum and step values.

  Parameters:
    `valueModel` - a `Number` typed model that holds the spinner value
    `defaultValue` - the number used if the valueModel's value is `null`
    `minValue` - the lower bound of the spinner number
    `maxValue` - the upper bound of the spinner number
    `stepSize` - used to increment and decrement the current value
  Returns:
    a `SpinnerNumberModel` that is connected to the given `ValueModel`
  Throws:
    `NullPointerException` - if the valueModel or defaultValue is `null`

### connect

    public static void connect(SpinnerModel spinnerModel,
                               ValueModel valueModel,
                               Object defaultValue)

  Connects the given ValueModel and SpinnerModel by synchronizing their values.

  Parameters:
    `spinnerModel` - the underlying SpinnerModel implementation
    `valueModel` - provides a value
    `defaultValue` - the value used if the valueModel's value is `null`
  Throws:
    `NullPointerException` - if the spinnerModel, valueModel or defaultValue 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.