--- /home/cpdev/src/classpath/javax/swing/DefaultListSelectionModel.java	2005-07-08 05:32:53.000000000 +0000
+++ javax/swing/DefaultListSelectionModel.java	2005-06-30 05:35:08.000000000 +0000
@@ -78,6 +78,7 @@
    */
   int selectionMode = MULTIPLE_INTERVAL_SELECTION;
 
+
   /**
    * The index of the "lead" of the most recent selection. The lead is the
    * second argument in any call to {@link #setSelectionInterval}, {@link
@@ -87,6 +88,7 @@
    */
   int leadSelectionIndex = -1;
 
+
   /**
    * The index of the "anchor" of the most recent selection. The anchor is
    * the first argument in any call to {@link #setSelectionInterval},
@@ -100,6 +102,7 @@
    */
   int anchorSelectionIndex = -1;
 
+
   /**
    * controls the range of indices provided in any {@link
    * ListSelectionEvent} fired by the selectionModel. Let
@@ -117,6 +120,7 @@
    */
   protected boolean leadAnchorNotificationEnabled = true;
 
+
   /**
    * Whether the selection is currently "adjusting". Any {@link
    * ListSelectionEvent} events constructed in response to changes in this
@@ -136,18 +140,6 @@
    */
   BitSet sel = new BitSet();
 
-  /**
-   * A variable to store the previous value of sel.
-   * Used to make sure we only fireValueChanged when the BitSet
-   * actually does change.
-   */
-  Object oldSel;
-
-  /**
-   * Whether this call of setLeadSelectionInterval was called locally
-   * from addSelectionInterval
-   */
-  boolean setLeadCalledFromAdd = false;
 
   /**
    * Gets the value of the {@link #selectionMode} property.
@@ -239,8 +231,6 @@
   public void setLeadSelectionIndex(int leadIndex)
   {
     int oldLeadIndex = leadSelectionIndex;
-    if (setLeadCalledFromAdd == false)
-      oldSel = sel.clone();
     leadSelectionIndex = leadIndex;
 
     if (anchorSelectionIndex == -1)
@@ -250,7 +240,7 @@
     int R2 = Math.max(anchorSelectionIndex, oldLeadIndex);
     int S1 = Math.min(anchorSelectionIndex, leadIndex);
     int S2 = Math.max(anchorSelectionIndex, leadIndex);
-
+    
     int lo = Math.min(R1, S1);
     int hi = Math.max(R2, S2);
 
@@ -272,9 +262,10 @@
 
     int beg = sel.nextSetBit(0), end = -1;
     for(int i=beg; i >= 0; i=sel.nextSetBit(i+1)) 
-      end = i;
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(beg, end, valueIsAdjusting);    
+      { 
+        end = i;
+      }
+    fireValueChanged(beg, end, valueIsAdjusting);    
   }
 
   /**
@@ -301,6 +292,7 @@
     leadAnchorNotificationEnabled = l;
   }
 
+
   /**
    * Gets the value of the {@link #valueIsAdjusting} property.
    *
@@ -336,13 +328,14 @@
     return sel.isEmpty();
   }
 
+
   /**
    * Gets the smallest index which is currently a member of a selection
    * interval.
    *
    * @return The least integer <code>i</code> such that <code>i >=
-   *     0</code> and <code>i</code> is a member of a selected interval, or
-   *     <code>-1</code> if there are no selected intervals
+   * 0</code> and <code>i</code> is a member of a selected interval, or
+   * <code>-1</code> if there are no selected intervals
    *
    * @see #getMaxSelectionIndex
    */
@@ -359,8 +352,8 @@
    * interval.
    *
    * @return The greatest integer <code>i</code> such that <code>i >=
-   *     0</code> and <code>i</code> is a member of a selected interval, or
-   *     <code>-1</code> if there are no selected intervals
+   * 0</code> and <code>i</code> is a member of a selected interval, or
+   * <code>-1</code> if there are no selected intervals
    *
    * @see #getMinSelectionIndex
    */
@@ -384,7 +377,7 @@
    * @param a The index to search for
    *
    * @return <code>true</code> if the index is a member of a selection interval,
-   *     otherwise <code>false</code>
+   * otherwise <code>false</code>
    */
   public boolean isSelectedIndex(int a)
   {
@@ -393,14 +386,10 @@
 
   /**
    * If the {@link #selectionMode} property is equal to
-   * <code>SINGLE_SELECTION</code> equivalent to calling
-   * <code>setSelectionInterval(index1, index2)</code>; 
-   * If the {@link #selectionMode} property is equal to 
-   * <code>SINGLE_INTERVAL_SELECTION</code> and the interval being
-   * added is not adjacent to an already selected interval,
-   * equivalent to <code>setSelectionInterval(index1, index2)</code>.
-   * Otherwise adds the range <code>[index0, index1]</code> 
-   * to the selection interval set.
+   * <code>SINGLE_SELECTION</code> or
+   * <code>SINGLE_INTERVAL_SELECTION</code>, equivalent to calling
+   * <code>setSelectionInterval(index1, index2)</code>; otherwise adds the
+   * range <code>[index0, index1]</code> to the selection interval set.
    *
    * @param index0 The beginning of the range of indices to select
    * @param index1 The end of the range of indices to select
@@ -410,54 +399,18 @@
    */
   public void addSelectionInterval(int index0, int index1) 
   {
-    int lo = Math.min(index0, index1);
-    int hi = Math.max(index0, index1);
-    oldSel = sel.clone();
-
-    if (selectionMode == SINGLE_SELECTION)
+    if (selectionMode == SINGLE_SELECTION
+        || selectionMode == SINGLE_INTERVAL_SELECTION)
       sel.clear();
-
-    // COMPAT: Like Sun (but not like IBM), we allow calls to 
-    // addSelectionInterval when selectionMode is
-    // SINGLE_SELECTION_INTERVAL iff the interval being added
-    // is adjacent to an already selected interval
-    if (selectionMode == SINGLE_INTERVAL_SELECTION)
-      if (!(isSelectedIndex(index0) || 
-            isSelectedIndex(index1) || 
-            isSelectedIndex(Math.max(lo-1,0)) || 
-            isSelectedIndex(Math.min(hi+1,sel.size()))))
-        sel.clear();
     
     if (selectionMode == SINGLE_SELECTION)
       index0 = index1;
 
-    // We have to update the anchorSelectionIndex and leadSelectionIndex
-    // variables
-    
-    // The next if statements breaks down to "if this selection is adjacent
-    // to the previous selection and going in the same direction"
-    if ((isSelectedIndex(leadSelectionIndex)) 
-        && ((index0 - 1 == leadSelectionIndex 
-             && (index1 >= index0) 
-             && (leadSelectionIndex >= anchorSelectionIndex))
-            || (index0 + 1 == leadSelectionIndex && (index1 <= index0) 
-                && (leadSelectionIndex <= anchorSelectionIndex)))
-        && (anchorSelectionIndex != -1 || leadSelectionIndex != -1))
-      {
-        // setting setLeadCalledFromAdd to true tells setLeadSelectionIndex
-        //   not to update oldSel
-        setLeadCalledFromAdd = true;
-        setLeadSelectionIndex(index1);
-        setLeadCalledFromAdd = false;
-      }
-    else
-      {
-        leadSelectionIndex = index1;
-        anchorSelectionIndex = index0;
-        sel.set(lo, hi+1);
-        if (sel.equals(oldSel) == false)
-          fireValueChanged(lo, hi, valueIsAdjusting);
-      }
+    int lo = Math.min(index0, index1);
+    int hi = Math.max(index0, index1);
+
+    sel.set(lo, hi+1);
+    fireValueChanged(lo, hi, valueIsAdjusting);
   }
 
 
@@ -474,24 +427,10 @@
   public void removeSelectionInterval(int index0,
                                       int index1)
   {
-    oldSel = sel.clone();
     int lo = Math.min(index0, index1);
     int hi = Math.max(index0, index1);
-    
-    // if selectionMode is SINGLE_INTERVAL_SELECTION and removing the interval
-    //   (index0,index1) would leave two disjoint selection intervals, remove all
-    //   selected indices from lo to the last selected index
-    if (getMinSelectionIndex() > 0 && getMinSelectionIndex() < lo && 
-        selectionMode == SINGLE_INTERVAL_SELECTION)
-      hi = sel.size() - 1;
-
     sel.clear(lo, hi+1); 
-    //update anchorSelectionIndex and leadSelectionIndex variables
-    //TODO: will probably need MouseDragged to test properly and know if this works
-    setAnchorSelectionIndex(index0);
-    leadSelectionIndex = index1;
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(lo, hi, valueIsAdjusting);
+    fireValueChanged(lo, hi, valueIsAdjusting);
   }
 
   /**
@@ -499,11 +438,9 @@
    */
   public void clearSelection()
   {
-    oldSel = sel.clone();
     int sz = sel.size();
     sel.clear();
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(0, sz, valueIsAdjusting);
+    fireValueChanged(0, sz, valueIsAdjusting);
   }
   
   /**
@@ -517,7 +454,6 @@
    */
   public void setSelectionInterval(int index0, int index1)
   {
-    oldSel = sel.clone();
     sel.clear();
     if (selectionMode == SINGLE_SELECTION)
       index0 = index1;
@@ -525,11 +461,7 @@
     int lo = Math.min(index0, index1);
     int hi = Math.max(index0, index1);
     sel.set(lo, hi+1);
-    // update the anchorSelectionIndex and leadSelectionIndex variables
-    setAnchorSelectionIndex(index0);
-    leadSelectionIndex=index1;
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(lo, hi, valueIsAdjusting);
+    fireValueChanged(lo, hi, valueIsAdjusting);
   }
 
   /**
@@ -542,7 +474,7 @@
    * @param index The position to insert indices at
    * @param length The number of indices to insert
    * @param before Indicates whether to insert the indices before the index
-   *     or after it
+   * or after it
    */
   public void insertIndexInterval(int index,
                                   int length,
@@ -584,24 +516,6 @@
 
   /**
    * Fires a {@link ListSelectionEvent} to all the listeners of type {@link
-   * ListSelectionListener} registered with this selection model to
-   * indicate that a series of adjustment has just ended.
-   *
-   * The values of {@link #getMinSelectionIndex} and
-   * {@link getMaxSelectionIndex} are used in the {@link ListSelectionEvent}
-   * that gets fired.
-   *
-   * @param isAdjusting <code>true</code> if this is the final change
-   *     in a series of adjustments, <code>false/code> otherwise
-   */
-  protected void fireValueChanged(boolean isAdjusting)
-  {
-    fireValueChanged(getMinSelectionIndex(), getMaxSelectionIndex(),
-                     isAdjusting);
-  }
-
-  /**
-   * Fires a {@link ListSelectionEvent} to all the listeners of type {@link
    * ListSelectionListener} registered with this selection model.
    *
    * @param firstIndex The low index of the changed range
@@ -619,7 +533,7 @@
    * @param firstIndex The low index of the changed range
    * @param lastIndex The high index of the changed range
    * @param isAdjusting Whether this change is part of a seqence of adjustments
-   *     made to the selection, such as during interactive scrolling
+   * made to the selection, such as during interactive scrolling
    */
   protected void fireValueChanged(int firstIndex, int lastIndex,
 				  boolean isAdjusting)
