< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  78      */
  79     protected boolean leadAnchorNotificationEnabled = true;
  80 
  81     /** {@inheritDoc} */
  82     public int getMinSelectionIndex() { return isSelectionEmpty() ? -1 : minIndex; }
  83 
  84     /** {@inheritDoc} */
  85     public int getMaxSelectionIndex() { return maxIndex; }
  86 
  87     /** {@inheritDoc} */
  88     public boolean getValueIsAdjusting() { return isAdjusting; }
  89 
  90     /** {@inheritDoc} */
  91     public int getSelectionMode() { return selectionMode; }
  92 
  93     /**
  94      * {@inheritDoc}
  95      * @throws IllegalArgumentException {@inheritDoc}
  96      */
  97     public void setSelectionMode(int selectionMode) {
  98         int oldMode = this.selectionMode;
  99         switch (selectionMode) {
 100         case SINGLE_SELECTION:
 101         case SINGLE_INTERVAL_SELECTION:
 102         case MULTIPLE_INTERVAL_SELECTION:
 103             this.selectionMode = selectionMode;
 104             break;
 105         default:
 106             throw new IllegalArgumentException("invalid selectionMode");
 107         }
 108 
 109         /*
 110         This code will only be executed when selection needs to be updated on
 111         changing selection mode. It will happen only if selection mode is changed
 112         from MULTIPLE_INTERVAL to SINGLE_INTERVAL or SINGLE or from
 113         SINGLE_INTERVAL to SINGLE
 114          */
 115         if (oldMode > this.selectionMode) {
 116             if (this.selectionMode == SINGLE_SELECTION) {
 117                 setSelectionInterval(minIndex, minIndex);
 118             } else if (this.selectionMode == SINGLE_INTERVAL_SELECTION) {
 119                 int selectionEndindex = minIndex;
 120                 while (value.get(selectionEndindex+1)) {
 121                     selectionEndindex++;
 122                 }
 123                 setSelectionInterval(minIndex, selectionEndindex);
 124             }
 125         }
 126     }
 127 
 128     /** {@inheritDoc} */
 129     public boolean isSelectedIndex(int index) {
 130         return ((index < minIndex) || (index > maxIndex)) ? false : value.get(index);
 131     }
 132 
 133     /** {@inheritDoc} */
 134     public boolean isSelectionEmpty() {
 135         return (minIndex > maxIndex);
 136     }
 137 
 138     /** {@inheritDoc} */
 139     public void addListSelectionListener(ListSelectionListener l) {
 140         listenerList.add(ListSelectionListener.class, l);
 141     }
 142 
 143     /** {@inheritDoc} */
 144     public void removeListSelectionListener(ListSelectionListener l) {


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  78      */
  79     protected boolean leadAnchorNotificationEnabled = true;
  80 
  81     /** {@inheritDoc} */
  82     public int getMinSelectionIndex() { return isSelectionEmpty() ? -1 : minIndex; }
  83 
  84     /** {@inheritDoc} */
  85     public int getMaxSelectionIndex() { return maxIndex; }
  86 
  87     /** {@inheritDoc} */
  88     public boolean getValueIsAdjusting() { return isAdjusting; }
  89 
  90     /** {@inheritDoc} */
  91     public int getSelectionMode() { return selectionMode; }
  92 
  93     /**
  94      * {@inheritDoc}
  95      * @throws IllegalArgumentException {@inheritDoc}
  96      */
  97     public void setSelectionMode(int selectionMode) {

  98         switch (selectionMode) {
  99         case SINGLE_SELECTION:
 100         case SINGLE_INTERVAL_SELECTION:
 101         case MULTIPLE_INTERVAL_SELECTION:
 102             this.selectionMode = selectionMode;
 103             break;
 104         default:
 105             throw new IllegalArgumentException("invalid selectionMode");


















 106         }
 107     }
 108 
 109     /** {@inheritDoc} */
 110     public boolean isSelectedIndex(int index) {
 111         return ((index < minIndex) || (index > maxIndex)) ? false : value.get(index);
 112     }
 113 
 114     /** {@inheritDoc} */
 115     public boolean isSelectionEmpty() {
 116         return (minIndex > maxIndex);
 117     }
 118 
 119     /** {@inheritDoc} */
 120     public void addListSelectionListener(ListSelectionListener l) {
 121         listenerList.add(ListSelectionListener.class, l);
 122     }
 123 
 124     /** {@inheritDoc} */
 125     public void removeListSelectionListener(ListSelectionListener l) {


< prev index next >