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 SingleListSelectionAdapter

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

All Implemented Interfaces:
  ListSelectionModel

    public final class SingleListSelectionAdapter

extends Object
implements ListSelectionModel

A `ListSelectionModel` implementation that has the list index bound to a `ValueModel`. Therefore this class supports only the `SINGLE_SELECTION` mode where only one list index can be selected at a time. In this mode the setSelectionInterval and addSelectionInterval methods are equivalent, and only the second index argument (the "lead index") is used.

Example:

     SelectionInList selectionInList = new SelectionInList(...);
     JList list = new JList();
     list.setModel(selectionInList);
     list.setSelectionModel(new SingleListSelectionAdapter(
                   selectionInList.getSelectionIndexHolder()));

Version:
  $Revision: 1.4 $
Author:
  Karsten Lentzsch, Jeanette Winzenburg
See Also:
  `ValueModel`, `JList`, `JTable`

Field Summary

Fields inherited from interface javax.swing.ListSelectionModel
`MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION`

Constructor Summary
`SingleListSelectionAdapter(ValueModel selectionIndexHolder)` Constructs a `SingleListSelectionAdapter` with the given selection index holder.

Method Summary
`void` | `addListSelectionListener(ListSelectionListener listener)` Add a listener to the list that's notified each time a change to the selection occurs.
`void` | `addSelectionInterval(int index0, int index1)` Sets the selection interval using the given indices.
`void` | `clearSelection()` Changes the selection to have no index selected.
`int` | `getAnchorSelectionIndex()` Returns the selection index.
`int` | `getLeadSelectionIndex()` Returns the selection index.
`ListSelectionListener[]` | `getListSelectionListeners()` Returns an array of all the list selection listeners registered on this `DefaultListSelectionModel`.
`int` | `getMaxSelectionIndex()` Returns the selection index.
`int` | `getMinSelectionIndex()` Returns the selection index.
`int` | `getSelectionMode()` Returns the fixed selection mode `SINGLE_SELECTION`.
`boolean` | `getValueIsAdjusting()` Returns true if the value is undergoing a series of changes.
`void` | `insertIndexInterval(int index, int length, boolean before)` Inserts length indices beginning before/after index.
`boolean` | `isSelectedIndex(int index)` Checks and answers if the given index is selected or not.
`boolean` | `isSelectionEmpty()` Returns true if no index is selected.
`void` | `removeIndexInterval(int index0, int index1)` Remove the indices in the interval index0,index1 (inclusive) from the selection model.
`void` | `removeListSelectionListener(ListSelectionListener listener)` Remove a listener from the list that's notified each time a change to the selection occurs.
`void` | `removeSelectionInterval(int index0, int index1)` Clears the selection if it is equals to index0.
`void` | `setAnchorSelectionIndex(int newSelectionIndex)` Sets the selection index.
`void` | `setLeadSelectionIndex(int newSelectionIndex)` Sets the selection index.
`void` | `setSelectionInterval(int index0, int index1)` Sets the selection index to `index1`.
`void` | `setSelectionMode(int selectionMode)` Sets the selection mode.
`void` | `setValueIsAdjusting(boolean newValueIsAdjusting)` This property is true if upcoming changes to the value of the model should be considered a single event.

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

Constructor Detail

### SingleListSelectionAdapter

    public SingleListSelectionAdapter(ValueModel selectionIndexHolder)

  Constructs a `SingleListSelectionAdapter` with the given selection index holder.

  Parameters:
    `selectionIndexHolder` - holds the selection index

Method Detail

### setSelectionInterval

    public void setSelectionInterval(int index0,
                                     int index1)

  Sets the selection index to `index1`. Since this model supports only a single selection index, the index0 is ignored. This is the behavior the `DefaultListSelectionModel` uses in single selection mode.

  If this represents a change to the current selection, then notify each ListSelectionListener. Note that index0 doesn't have to be less than or equal to index1.

  Specified by:
    `setSelectionInterval` in interface `ListSelectionModel`
  Parameters:
    `index0` - one end of the interval.
    `index1` - other end of the interval
  See Also:
    `addListSelectionListener(ListSelectionListener)`

### addSelectionInterval

    public void addSelectionInterval(int index0,
                                     int index1)

  Sets the selection interval using the given indices.

  If this represents a change to the current selection, then notify each ListSelectionListener. Note that index0 doesn't have to be less than or equal to index1.

  Specified by:
    `addSelectionInterval` in interface `ListSelectionModel`
  Parameters:
    `index0` - one end of the interval.
    `index1` - other end of the interval
  See Also:
    `addListSelectionListener(ListSelectionListener)`

### removeSelectionInterval

    public void removeSelectionInterval(int index0,
                                        int index1)

  Clears the selection if it is equals to index0. Since this model supports only a single selection index, the index1 can be ignored for the selection.

  If this represents a change to the current selection, then notify each ListSelectionListener. Note that index0 doesn't have to be less than or equal to index1.

  Specified by:
    `removeSelectionInterval` in interface `ListSelectionModel`
  Parameters:
    `index0` - one end of the interval.
    `index1` - other end of the interval
  See Also:
    `addListSelectionListener(ListSelectionListener)`

### getMinSelectionIndex

    public int getMinSelectionIndex()

  Returns the selection index.

  Specified by:
    `getMinSelectionIndex` in interface `ListSelectionModel`
  Returns:
    the selection index
  See Also:
    `getMinSelectionIndex()`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`

### getMaxSelectionIndex

    public int getMaxSelectionIndex()

  Returns the selection index.

  Specified by:
    `getMaxSelectionIndex` in interface `ListSelectionModel`
  Returns:
    the selection index
  See Also:
    `getMinSelectionIndex()`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`

### isSelectedIndex

    public boolean isSelectedIndex(int index)

  Checks and answers if the given index is selected or not.

  Specified by:
    `isSelectedIndex` in interface `ListSelectionModel`
  Parameters:
    `index` - the index to be checked
  Returns:
    true if selected, false if deselected
  See Also:
    `ListSelectionModel.isSelectedIndex(int)`

### getAnchorSelectionIndex

    public int getAnchorSelectionIndex()

  Returns the selection index.

  Specified by:
    `getAnchorSelectionIndex` in interface `ListSelectionModel`
  Returns:
    the selection index
  See Also:
    `getAnchorSelectionIndex()`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`

### setAnchorSelectionIndex

    public void setAnchorSelectionIndex(int newSelectionIndex)

  Sets the selection index.

  Specified by:
    `setAnchorSelectionIndex` in interface `ListSelectionModel`
  Parameters:
    `newSelectionIndex` - the new selection index
  See Also:
    `getLeadSelectionIndex()`

### getLeadSelectionIndex

    public int getLeadSelectionIndex()

  Returns the selection index.

  Specified by:
    `getLeadSelectionIndex` in interface `ListSelectionModel`
  Returns:
    the selection index
  See Also:
    `getAnchorSelectionIndex()`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`

### setLeadSelectionIndex

    public void setLeadSelectionIndex(int newSelectionIndex)

  Sets the selection index.

  Specified by:
    `setLeadSelectionIndex` in interface `ListSelectionModel`
  Parameters:
    `newSelectionIndex` - the new selection index
  See Also:
    `getLeadSelectionIndex()`

### clearSelection

    public void clearSelection()

  Changes the selection to have no index selected. If this represents a change to the current selection then notify each ListSelectionListener.

  Specified by:
    `clearSelection` in interface `ListSelectionModel`
  See Also:
    `addListSelectionListener(ListSelectionListener)`

### isSelectionEmpty

    public boolean isSelectionEmpty()

  Returns true if no index is selected.

  Specified by:
    `isSelectionEmpty` in interface `ListSelectionModel`
  Returns:
    true if no index is selected

### insertIndexInterval

    public void insertIndexInterval(int index,
                                    int length,
                                    boolean before)

  Inserts length indices beginning before/after index. If the value This method is typically called to synchronize the selection model with a corresponding change in the data model.

  Specified by:
    `insertIndexInterval` in interface `ListSelectionModel`
  Parameters:
    `index` - the index to start the insertion
    `length` - the length of the inserted interval
    `before` - true to insert before the start index

### removeIndexInterval

    public void removeIndexInterval(int index0,
                                    int index1)

  Remove the indices in the interval index0,index1 (inclusive) from the selection model. This is typically called to sync the selection model width a corresponding change in the data model.

  Clears the selection if it is in the specified interval.

  Specified by:
    `removeIndexInterval` in interface `ListSelectionModel`
  Parameters:
    `index0` - the first index to remove from the selection
    `index1` - the last index to remove from the selection
  Throws:
    `IndexOutOfBoundsException` - if either `index0` or `index1` are less than -1
  See Also:
    `ListSelectionModel.removeSelectionInterval(int, int)`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`, `addListSelectionListener(ListSelectionListener)`

### setValueIsAdjusting

    public void setValueIsAdjusting(boolean newValueIsAdjusting)

  This property is true if upcoming changes to the value of the model should be considered a single event. For example if the model is being updated in response to a user drag, the value of the valueIsAdjusting property will be set to true when the drag is initiated and be set to false when the drag is finished. This property allows listeners to to update only when a change has been finalized, rather than always handling all of the intermediate values.

  Specified by:
    `setValueIsAdjusting` in interface `ListSelectionModel`
  Parameters:
    `newValueIsAdjusting` - The new value of the property.
  See Also:
    `getValueIsAdjusting()`

### getValueIsAdjusting

    public boolean getValueIsAdjusting()

  Returns true if the value is undergoing a series of changes.

  Specified by:
    `getValueIsAdjusting` in interface `ListSelectionModel`
  Returns:
    true if the value is currently adjusting
  See Also:
    `setValueIsAdjusting(boolean)`

### setSelectionMode

    public void setSelectionMode(int selectionMode)

  Sets the selection mode. Only `SINGLE_SELECTION` is allowed in this implementation. Other modes are not supported and will throw an `IllegalArgumentException`.

  With `SINGLE_SELECTION` only one list index can be selected at a time. In this mode the setSelectionInterval and addSelectionInterval methods are equivalent, and only the second index argument (the "lead index") is used.

  Specified by:
    `setSelectionMode` in interface `ListSelectionModel`
  Parameters:
    `selectionMode` - the mode to be set
  See Also:
    `getSelectionMode()`, `ListSelectionModel.setSelectionMode(int)`

### getSelectionMode

    public int getSelectionMode()

  Returns the fixed selection mode `SINGLE_SELECTION`.

  Specified by:
    `getSelectionMode` in interface `ListSelectionModel`
  Returns:
    `SINGLE_SELECTION`
  See Also:
    `setSelectionMode(int)`

### addListSelectionListener

    public void addListSelectionListener(ListSelectionListener listener)

  Add a listener to the list that's notified each time a change to the selection occurs.

  Specified by:
    `addListSelectionListener` in interface `ListSelectionModel`
  Parameters:
    `listener` - the ListSelectionListener
  See Also:
    `removeListSelectionListener(ListSelectionListener)`, `setSelectionInterval(int, int)`, `addSelectionInterval(int, int)`, `removeSelectionInterval(int, int)`, `clearSelection()`, `insertIndexInterval(int, int, boolean)`, `removeIndexInterval(int, int)`

### removeListSelectionListener

    public void removeListSelectionListener(ListSelectionListener listener)

  Remove a listener from the list that's notified each time a change to the selection occurs.

  Specified by:
    `removeListSelectionListener` in interface `ListSelectionModel`
  Parameters:
    `listener` - the ListSelectionListener
  See Also:
    `addListSelectionListener(ListSelectionListener)`

### getListSelectionListeners

    public ListSelectionListener[] getListSelectionListeners()

  Returns an array of all the list selection listeners registered on this `DefaultListSelectionModel`.

  Returns:
    all of this model's `ListSelectionListener`s or an empty array if no list selection listeners are currently registered
  See Also:
    `addListSelectionListener(ListSelectionListener)`, `removeListSelectionListener(ListSelectionListener)`

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