< prev index next >

## src/java.desktop/share/classes/javax/swing/ListSelectionModel.java

Print this page

     315      *
     316      * @param x the ListSelectionListener
     317      * @see #removeListSelectionListener
     318      * @see #setSelectionInterval
     319      * @see #addSelectionInterval
     320      * @see #removeSelectionInterval
     321      * @see #clearSelection
     322      * @see #insertIndexInterval
     323      * @see #removeIndexInterval
     324      */
     325     void addListSelectionListener(ListSelectionListener x);
     326
     327     /**
     328      * Remove a listener from the list that's notified each time a
     329      * change to the selection occurs.
     330      *
     331      * @param x the ListSelectionListener
     332      * @see #addListSelectionListener
     333      */
     334     void removeListSelectionListener(ListSelectionListener x);

     335 }
     315      *
     316      * @param x the ListSelectionListener
     317      * @see #removeListSelectionListener
     318      * @see #setSelectionInterval
     319      * @see #addSelectionInterval
     320      * @see #removeSelectionInterval
     321      * @see #clearSelection
     322      * @see #insertIndexInterval
     323      * @see #removeIndexInterval
     324      */
     325     void addListSelectionListener(ListSelectionListener x);
     326
     327     /**
     328      * Remove a listener from the list that's notified each time a
     329      * change to the selection occurs.
     330      *
     331      * @param x the ListSelectionListener
     332      * @see #addListSelectionListener
     333      */
     334     void removeListSelectionListener(ListSelectionListener x);
     335
     336     /**
     337      * Returns an array of all of the selected indices, in increasing
     338      * order.
     339      *
     340      * @return all of the selected indices, in increasing order,
     341      *         or an empty array if nothing is selected
     342      * @see #removeSelectionInterval
     343      * @see #addListSelectionListener
     344      */
     345     default int[] getSelectedIndices() {
     346         int iMin = getMinSelectionIndex();
     347         int iMax = getMaxSelectionIndex();
     348
     349         if ((iMin < 0) || (iMax < 0)) {
     350             return new int[0];
     351         }
     352
     353         int[] rvTmp = new int[1+ (iMax - iMin)];
     354         int n = 0;
     355         for(int i = iMin; i <= iMax; i++) {
     356             if (isSelectedIndex(i)) {
     357                 rvTmp[n++] = i;
     358             }
     359         }
     360         int[] rv = new int[n];
     361         System.arraycopy(rvTmp, 0, rv, 0, n);
     362         return rv;
     363     }
     364
     365     /**
     366      * Returns the number of selected items.
     367      *
     368      * @return the number of selected items, 0 if no items are selected
     369      */
     370     default int getSelectedItemsCount() {
     371         int iMin = getMinSelectionIndex();
     372         int iMax = getMaxSelectionIndex();
     373         int count = 0;
     374
     375         for(int i = iMin; i <= iMax; i++) {
     376             if (isSelectedIndex(i)) {
     377                 count++;
     378             }
     379         }
     380         return count;
     381     }
     382 }

< prev index next >