< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/SelectionModel.java

Print this page




  45      * Selection Properties                                                    *
  46      *                                                                         *
  47      **************************************************************************/
  48 
  49     /**
  50      * <p>Refers to the selected index property, which is used to indicate
  51      * the currently selected index value in the selection model. The selected
  52      * index is either -1,
  53      * to represent that there is no selection, or an integer value that is within
  54      * the range of the underlying data model size.
  55      *
  56      * <p>The selected index property is most commonly used when the selection
  57      * model only allows single selection, but is equally applicable when in
  58      * multiple selection mode. When in this mode, the selected index will always
  59      * represent the last selection made.
  60      *
  61      * <p>Note that in the case of multiple selection, it is possible to add
  62      * a {@link ListChangeListener} to the collection returned by
  63      * {@link MultipleSelectionModel#getSelectedIndices()} to be informed whenever
  64      * the selection changes, and this will also work in the case of single selection.

  65      */
  66     public final ReadOnlyIntegerProperty selectedIndexProperty() { return selectedIndex.getReadOnlyProperty(); }
  67     private ReadOnlyIntegerWrapper selectedIndex = new ReadOnlyIntegerWrapper(this, "selectedIndex", -1);
  68     protected final void setSelectedIndex(int value) { selectedIndex.set(value); }
  69 
  70     /**
  71      * <p>Returns the integer value indicating the currently selected index in
  72      * this model. If there are multiple items selected, this will return the
  73      * most recent selection made.
  74      *
  75      * <p>Note that the returned value is a snapshot in time - if you wish to
  76      * observe the selection model for changes to the selected index, you can
  77      * add a ChangeListener as such:
  78      *
  79      * <pre><code>
  80      * SelectionModel sm = ...;
  81      * InvalidationListener listener = ...;
  82      * sm.selectedIndexProperty().addListener(listener);
  83      * </code></pre>

  84      */
  85     public final int getSelectedIndex() { return selectedIndexProperty().get(); }
  86 
  87     /**
  88      * <p>Refers to the selected item property, which is used to indicate
  89      * the currently selected item in the selection model. The selected item is
  90      * either null,
  91      * to represent that there is no selection, or an Object that is retrieved
  92      * from the underlying data model of the control the selection model is
  93      * associated with.
  94      *
  95      * <p>The selected item property is most commonly used when the selection
  96      * model is set to be single selection, but is equally applicable when in
  97      * multiple selection mode. When in this mode, the selected item will always
  98      * represent the last selection made.

  99      */
 100     public final ReadOnlyObjectProperty<T> selectedItemProperty() { return selectedItem.getReadOnlyProperty(); }
 101     private ReadOnlyObjectWrapper<T> selectedItem = new ReadOnlyObjectWrapper<T>(this, "selectedItem");
 102     protected final void setSelectedItem(T value) { selectedItem.set(value); }
 103 
 104     /**
 105      * Returns the currently selected object (which resides in the selected index
 106      * position). If there are multiple items selected, this will return the
 107      * object contained at the index returned by getSelectedIndex() (which is
 108      * always the index to the most recently selected item).
 109      *
 110      * <p>Note that the returned value is a snapshot in time - if you wish to
 111      * observe the selection model for changes to the selected item, you can
 112      * add a ChangeListener as such:
 113      *
 114      * <pre><code>
 115      * SelectionModel sm = ...;
 116      * InvalidationListener listener = ...;
 117      * sm.selectedItemProperty().addListener(listener);
 118      * </code></pre>

 119      */
 120     public final T getSelectedItem() { return selectedItemProperty().get(); }
 121 
 122 
 123     /***************************************************************************
 124      *                                                                         *
 125      * Constructor                                                             *
 126      *                                                                         *
 127      **************************************************************************/
 128 
 129     /**
 130      * Creates a default SelectionModel instance.
 131      */
 132     public SelectionModel() { }
 133 
 134 
 135     /***************************************************************************
 136      *                                                                         *
 137      * Selection API                                                           *
 138      *                                                                         *




  45      * Selection Properties                                                    *
  46      *                                                                         *
  47      **************************************************************************/
  48 
  49     /**
  50      * <p>Refers to the selected index property, which is used to indicate
  51      * the currently selected index value in the selection model. The selected
  52      * index is either -1,
  53      * to represent that there is no selection, or an integer value that is within
  54      * the range of the underlying data model size.
  55      *
  56      * <p>The selected index property is most commonly used when the selection
  57      * model only allows single selection, but is equally applicable when in
  58      * multiple selection mode. When in this mode, the selected index will always
  59      * represent the last selection made.
  60      *
  61      * <p>Note that in the case of multiple selection, it is possible to add
  62      * a {@link ListChangeListener} to the collection returned by
  63      * {@link MultipleSelectionModel#getSelectedIndices()} to be informed whenever
  64      * the selection changes, and this will also work in the case of single selection.
  65      * @return the selected index property
  66      */
  67     public final ReadOnlyIntegerProperty selectedIndexProperty() { return selectedIndex.getReadOnlyProperty(); }
  68     private ReadOnlyIntegerWrapper selectedIndex = new ReadOnlyIntegerWrapper(this, "selectedIndex", -1);
  69     protected final void setSelectedIndex(int value) { selectedIndex.set(value); }
  70 
  71     /**
  72      * <p>Returns the integer value indicating the currently selected index in
  73      * this model. If there are multiple items selected, this will return the
  74      * most recent selection made.
  75      *
  76      * <p>Note that the returned value is a snapshot in time - if you wish to
  77      * observe the selection model for changes to the selected index, you can
  78      * add a ChangeListener as such:
  79      *
  80      * <pre><code>
  81      * SelectionModel sm = ...;
  82      * InvalidationListener listener = ...;
  83      * sm.selectedIndexProperty().addListener(listener);
  84      * </code></pre>
  85      * @return the selected index
  86      */
  87     public final int getSelectedIndex() { return selectedIndexProperty().get(); }
  88 
  89     /**
  90      * <p>Refers to the selected item property, which is used to indicate
  91      * the currently selected item in the selection model. The selected item is
  92      * either null,
  93      * to represent that there is no selection, or an Object that is retrieved
  94      * from the underlying data model of the control the selection model is
  95      * associated with.
  96      *
  97      * <p>The selected item property is most commonly used when the selection
  98      * model is set to be single selection, but is equally applicable when in
  99      * multiple selection mode. When in this mode, the selected item will always
 100      * represent the last selection made.
 101      * @return the selected item property
 102      */
 103     public final ReadOnlyObjectProperty<T> selectedItemProperty() { return selectedItem.getReadOnlyProperty(); }
 104     private ReadOnlyObjectWrapper<T> selectedItem = new ReadOnlyObjectWrapper<T>(this, "selectedItem");
 105     protected final void setSelectedItem(T value) { selectedItem.set(value); }
 106 
 107     /**
 108      * Returns the currently selected object (which resides in the selected index
 109      * position). If there are multiple items selected, this will return the
 110      * object contained at the index returned by getSelectedIndex() (which is
 111      * always the index to the most recently selected item).
 112      *
 113      * <p>Note that the returned value is a snapshot in time - if you wish to
 114      * observe the selection model for changes to the selected item, you can
 115      * add a ChangeListener as such:
 116      *
 117      * <pre><code>
 118      * SelectionModel sm = ...;
 119      * InvalidationListener listener = ...;
 120      * sm.selectedItemProperty().addListener(listener);
 121      * </code></pre>
 122      * @return the selected item
 123      */
 124     public final T getSelectedItem() { return selectedItemProperty().get(); }
 125 
 126 
 127     /***************************************************************************
 128      *                                                                         *
 129      * Constructor                                                             *
 130      *                                                                         *
 131      **************************************************************************/
 132 
 133     /**
 134      * Creates a default SelectionModel instance.
 135      */
 136     public SelectionModel() { }
 137 
 138 
 139     /***************************************************************************
 140      *                                                                         *
 141      * Selection API                                                           *
 142      *                                                                         *


< prev index next >