< prev index next >

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

Print this page

     438             }
     439             if (shouldClear) {
     440                 clear(i);
     441             }
     442         }
     443         fireValueChanged();
     444     }
     445
     446    /**
     447     * Change the selection with the effect of first clearing the values
     448     * in the inclusive range [clearMin, clearMax] then setting the values
     449     * in the inclusive range [setMin, setMax]. Do this in one pass so
     450     * that no values are cleared if they would later be set.
     451     */
     452     private void changeSelection(int clearMin, int clearMax, int setMin, int setMax) {
     453         changeSelection(clearMin, clearMax, setMin, setMax, true);
     454     }
     455
     456     /** {@inheritDoc} */
     457     public void clearSelection() {

     458         removeSelectionIntervalImpl(minIndex, maxIndex, false);
     459     }
     460
     461     /**
     462      * Changes the selection to be between {@code index0} and {@code index1}
     463      * inclusive. {@code index0} doesn't have to be less than or equal to
     464      * {@code index1}.
     465      * <p>
     466      * In {@code SINGLE_SELECTION} selection mode, only the second index
     467      * is used.
     468      * <p>
     469      * If this represents a change to the current selection, then each
     470      * {@code ListSelectionListener} is notified of the change.
     471      * <p>
     472      * If either index is {@code -1}, this method does nothing and returns
     473      * without exception. Otherwise, if either index is less than {@code -1},
     474      * an {@code IndexOutOfBoundsException} is thrown.
     475      *
     476      * @param index0 one end of the interval.
     477      * @param index1 other end of the interval
     674     /**
     675      * Remove the indices in the interval index0,index1 (inclusive) from
     676      * the selection model.  This is typically called to sync the selection
     677      * model width a corresponding change in the data model.  Note
     678      * that (as always) index0 need not be &lt;= index1.
     679      */
     680     public void removeIndexInterval(int index0, int index1)
     681     {
     682         int rmMinIndex = Math.min(index0, index1);
     683         int rmMaxIndex = Math.max(index0, index1);
     684         int gapLength = (rmMaxIndex - rmMinIndex) + 1;
     685
     686         /* Shift the entire bitset to the left to close the index0, index1
     687          * gap.
     688          */
     689         for(int i = rmMinIndex; i <= maxIndex; i++) {
     690             setState(i, value.get(i + gapLength));
     691         }
     692
     693         int leadIndex = this.leadIndex;
     694         if (leadIndex == 0 && rmMinIndex == 0) {
     695             // do nothing
     696         } else if (leadIndex > rmMaxIndex) {
     697             leadIndex = this.leadIndex - gapLength;
     698         } else if (leadIndex >= rmMinIndex) {
     699             leadIndex = rmMinIndex - 1;
     700         }
     701
     702         int anchorIndex = this.anchorIndex;
     703         if (anchorIndex == 0 && rmMinIndex == 0) {
     704             // do nothing
     705         } else if (anchorIndex > rmMaxIndex) {
     706             anchorIndex = this.anchorIndex - gapLength;
     707         } else if (anchorIndex >= rmMinIndex) {
     708             anchorIndex = rmMinIndex - 1;
     709         }
     710
     711         if (leadIndex != this.leadIndex || anchorIndex != this.anchorIndex) {
     712             updateLeadAnchorIndices(anchorIndex, leadIndex);
     713         }
     714
     715         fireValueChanged();
     716     }
     717
     718
     719     /** {@inheritDoc} */
     720     public void setValueIsAdjusting(boolean isAdjusting) {
     721         if (isAdjusting != this.isAdjusting) {
     722             this.isAdjusting = isAdjusting;
     723             this.fireValueChanged(isAdjusting);
     724         }
     725     }
     438             }
     439             if (shouldClear) {
     440                 clear(i);
     441             }
     442         }
     443         fireValueChanged();
     444     }
     445
     446    /**
     447     * Change the selection with the effect of first clearing the values
     448     * in the inclusive range [clearMin, clearMax] then setting the values
     449     * in the inclusive range [setMin, setMax]. Do this in one pass so
     450     * that no values are cleared if they would later be set.
     451     */
     452     private void changeSelection(int clearMin, int clearMax, int setMin, int setMax) {
     453         changeSelection(clearMin, clearMax, setMin, setMax, true);
     454     }
     455
     456     /** {@inheritDoc} */
     457     public void clearSelection() {
     458         updateLeadAnchorIndices(-1, -1);
     459         removeSelectionIntervalImpl(minIndex, maxIndex, false);
     460     }
     461
     462     /**
     463      * Changes the selection to be between {@code index0} and {@code index1}
     464      * inclusive. {@code index0} doesn't have to be less than or equal to
     465      * {@code index1}.
     466      * <p>
     467      * In {@code SINGLE_SELECTION} selection mode, only the second index
     468      * is used.
     469      * <p>
     470      * If this represents a change to the current selection, then each
     471      * {@code ListSelectionListener} is notified of the change.
     472      * <p>
     473      * If either index is {@code -1}, this method does nothing and returns
     474      * without exception. Otherwise, if either index is less than {@code -1},
     475      * an {@code IndexOutOfBoundsException} is thrown.
     476      *
     477      * @param index0 one end of the interval.
     478      * @param index1 other end of the interval
     675     /**
     676      * Remove the indices in the interval index0,index1 (inclusive) from
     677      * the selection model.  This is typically called to sync the selection
     678      * model width a corresponding change in the data model.  Note
     679      * that (as always) index0 need not be &lt;= index1.
     680      */
     681     public void removeIndexInterval(int index0, int index1)
     682     {
     683         int rmMinIndex = Math.min(index0, index1);
     684         int rmMaxIndex = Math.max(index0, index1);
     685         int gapLength = (rmMaxIndex - rmMinIndex) + 1;
     686
     687         /* Shift the entire bitset to the left to close the index0, index1
     688          * gap.
     689          */
     690         for(int i = rmMinIndex; i <= maxIndex; i++) {
     691             setState(i, value.get(i + gapLength));
     692         }
     693
     694         int leadIndex = this.leadIndex;
     695         if (leadIndex > rmMaxIndex) {

     696             leadIndex = this.leadIndex - gapLength;
     697         } else if (leadIndex >= rmMinIndex) {
     698             leadIndex = rmMinIndex - 1;
     699         }
     700
     701         int anchorIndex = this.anchorIndex;
     702         if (anchorIndex > rmMaxIndex) {

     703             anchorIndex = this.anchorIndex - gapLength;
     704         } else if (anchorIndex >= rmMinIndex) {
     705             anchorIndex = rmMinIndex - 1;
     706         }
     707
     708         if (leadIndex != this.leadIndex || anchorIndex != this.anchorIndex) {
     709             updateLeadAnchorIndices(anchorIndex, leadIndex);
     710         }
     711
     712         fireValueChanged();
     713     }
     714
     715
     716     /** {@inheritDoc} */
     717     public void setValueIsAdjusting(boolean isAdjusting) {
     718         if (isAdjusting != this.isAdjusting) {
     719             this.isAdjusting = isAdjusting;
     720             this.fireValueChanged(isAdjusting);
     721         }
     722     }

< prev index next >