/[classpath]/classpath/javax/swing/DefaultListSelectionModel.java
ViewVC logotype

Diff of /classpath/javax/swing/DefaultListSelectionModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7.2.7 by tromey, Thu Oct 6 00:32:39 2005 UTC revision 1.7.2.8 by gnu_andrew, Wed Nov 2 00:43:43 2005 UTC
# Line 238  public class DefaultListSelectionModel i Line 238  public class DefaultListSelectionModel i
238     */     */
239    public void setLeadSelectionIndex(int leadIndex)    public void setLeadSelectionIndex(int leadIndex)
240    {    {
241        // Only set the lead selection index to < 0 if anchorSelectionIndex < 0.
242        if (leadIndex < 0)
243          {
244            if (anchorSelectionIndex < 0)
245              leadSelectionIndex = -1;
246            else
247              return;
248          }
249    
250        // Only touch the lead selection index if the anchor is >= 0.
251        if (anchorSelectionIndex < 0)
252          return;
253    
254        if (selectionMode == SINGLE_SELECTION)
255          setSelectionInterval (leadIndex, leadIndex);
256        
257      int oldLeadIndex = leadSelectionIndex;      int oldLeadIndex = leadSelectionIndex;
258        if (oldLeadIndex == -1)
259          oldLeadIndex = leadIndex;
260      if (setLeadCalledFromAdd == false)      if (setLeadCalledFromAdd == false)
261        oldSel = sel.clone();        oldSel = sel.clone();
262      leadSelectionIndex = leadIndex;      leadSelectionIndex = leadIndex;
263    
264      if (anchorSelectionIndex == -1)      if (anchorSelectionIndex == -1)
265        return;        return;    
266        
267      int R1 = Math.min(anchorSelectionIndex, oldLeadIndex);      int R1 = Math.min(anchorSelectionIndex, oldLeadIndex);
268      int R2 = Math.max(anchorSelectionIndex, oldLeadIndex);      int R2 = Math.max(anchorSelectionIndex, oldLeadIndex);
269      int S1 = Math.min(anchorSelectionIndex, leadIndex);      int S1 = Math.min(anchorSelectionIndex, leadIndex);
# Line 254  public class DefaultListSelectionModel i Line 272  public class DefaultListSelectionModel i
272      int lo = Math.min(R1, S1);      int lo = Math.min(R1, S1);
273      int hi = Math.max(R2, S2);      int hi = Math.max(R2, S2);
274    
     BitSet oldRange = sel.get(lo, hi+1);  
   
275      if (isSelectedIndex(anchorSelectionIndex))      if (isSelectedIndex(anchorSelectionIndex))
276        {        {
277          sel.clear(R1, R2+1);          sel.clear(R1, R2+1);
# Line 265  public class DefaultListSelectionModel i Line 281  public class DefaultListSelectionModel i
281        {        {
282          sel.set(R1, R2+1);          sel.set(R1, R2+1);
283          sel.clear(S1, S2+1);          sel.clear(S1, S2+1);
284        }        }    
       
     BitSet newRange = sel.get(lo, hi+1);  
     newRange.xor(oldRange);  
285    
286      int beg = sel.nextSetBit(0), end = -1;      int beg = sel.nextSetBit(0), end = -1;
287      for(int i=beg; i >= 0; i=sel.nextSetBit(i+1))      for(int i=beg; i >= 0; i=sel.nextSetBit(i+1))
# Line 278  public class DefaultListSelectionModel i Line 291  public class DefaultListSelectionModel i
291    }    }
292    
293    /**    /**
294       * Moves the lead selection index to <code>leadIndex</code> without
295       * changing the selection values.
296       *
297       * If leadAnchorNotificationEnabled is true, send a notification covering the
298       * old and new lead cells.
299       *
300       * @param leadIndex the new lead selection index
301       * @since 1.5
302       */
303      public void moveLeadSelectionIndex (int leadIndex)
304      {
305        if (leadSelectionIndex == leadIndex)
306          return;
307        
308        leadSelectionIndex = leadIndex;
309        if (isLeadAnchorNotificationEnabled())
310          fireValueChanged(Math.min(leadSelectionIndex, leadIndex),
311                           Math.max(leadSelectionIndex, leadIndex));
312      }
313      
314      /**
315     * Gets the value of the {@link #leadAnchorNotificationEnabled} property.     * Gets the value of the {@link #leadAnchorNotificationEnabled} property.
316     *     *
317     * @return The current property value     * @return The current property value
# Line 388  public class DefaultListSelectionModel i Line 422  public class DefaultListSelectionModel i
422     */     */
423    public boolean isSelectedIndex(int a)    public boolean isSelectedIndex(int a)
424    {    {
425        // TODO: Probably throw an exception here?
426        if (a >= sel.length() || a < 0)
427          return false;
428      return sel.get(a);      return sel.get(a);
429    }    }
430    
# Line 415  public class DefaultListSelectionModel i Line 452  public class DefaultListSelectionModel i
452      oldSel = sel.clone();      oldSel = sel.clone();
453    
454      if (selectionMode == SINGLE_SELECTION)      if (selectionMode == SINGLE_SELECTION)
455        sel.clear();        setSelectionInterval(index0, index1);
456    
457      // COMPAT: Like Sun (but not like IBM), we allow calls to      // COMPAT: Like Sun (but not like IBM), we allow calls to
458      // addSelectionInterval when selectionMode is      // addSelectionInterval when selectionMode is
# Line 426  public class DefaultListSelectionModel i Line 463  public class DefaultListSelectionModel i
463              isSelectedIndex(index1) ||              isSelectedIndex(index1) ||
464              isSelectedIndex(Math.max(lo-1,0)) ||              isSelectedIndex(Math.max(lo-1,0)) ||
465              isSelectedIndex(Math.min(hi+1,sel.size()))))              isSelectedIndex(Math.min(hi+1,sel.size()))))
466          sel.clear();          sel.clear();    
       
     if (selectionMode == SINGLE_SELECTION)  
       index0 = index1;  
467    
468      // We have to update the anchorSelectionIndex and leadSelectionIndex      // We have to update the anchorSelectionIndex and leadSelectionIndex
469      // variables      // variables

Legend:
Removed from v.1.7.2.7  
changed lines
  Added in v.1.7.2.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26