/[classpath]/classpath/javax/swing/text/GapContent.java
ViewVC logotype

Diff of /classpath/javax/swing/text/GapContent.java

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

revision 1.27 by rabbit78, Thu Sep 29 17:32:18 2005 UTC revision 1.28 by abalkiss, Fri Sep 30 14:38:02 2005 UTC
# Line 41  package javax.swing.text; Line 41  package javax.swing.text;
41  import java.io.Serializable;  import java.io.Serializable;
42  import java.util.ArrayList;  import java.util.ArrayList;
43  import java.util.Collections;  import java.util.Collections;
 import java.util.Iterator;  
44  import java.util.ListIterator;  import java.util.ListIterator;
45  import java.util.Vector;  import java.util.Vector;
46    
# Line 398  public class GapContent Line 397  public class GapContent
397    
398      int delta = newSize - gapEnd + gapStart;      int delta = newSize - gapEnd + gapStart;
399      // Update the marks after the gapEnd.      // Update the marks after the gapEnd.
400      Vector v = getPositionsInRange(null, gapEnd, buffer.length - gapEnd);      adjustPositionsInRange(gapEnd, buffer.length - gapEnd, delta);
     for (Iterator i = v.iterator(); i.hasNext();)  
     {  
       GapContentPosition p = (GapContentPosition) i.next();  
       p.mark += delta;  
     }  
401    
402      // Copy the data around.      // Copy the data around.
403      char[] newBuf = (char[]) allocateArray(length() + newSize);      char[] newBuf = (char[]) allocateArray(length() + newSize);
# Line 430  public class GapContent Line 424  public class GapContent
424        {        {
425          // Update the positions between newGapStart and (old) gapStart. The marks          // Update the positions between newGapStart and (old) gapStart. The marks
426          // must be shifted by (gapEnd - gapStart).          // must be shifted by (gapEnd - gapStart).
427          Vector v = getPositionsInRange(null, newGapStart,          adjustPositionsInRange(newGapStart, gapStart - newGapStart, gapEnd - gapStart);
                                        gapStart - newGapStart);  
         for (Iterator i = v.iterator(); i.hasNext();)  
           {  
             GapContentPosition p = (GapContentPosition) i.next();  
             p.mark += gapEnd - gapStart;  
           }  
428          System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart          System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart
429                           - newGapStart);                           - newGapStart);
430          gapStart = newGapStart;          gapStart = newGapStart;
# Line 446  public class GapContent Line 434  public class GapContent
434        {        {
435          // Update the positions between newGapEnd and (old) gapEnd. The marks          // Update the positions between newGapEnd and (old) gapEnd. The marks
436          // must be shifted by (gapEnd - gapStart).          // must be shifted by (gapEnd - gapStart).
437          Vector v = getPositionsInRange(null, gapEnd,          adjustPositionsInRange(gapEnd, newGapEnd - gapEnd, -(gapEnd - gapStart));
                                        newGapEnd - gapEnd);  
         for (Iterator i = v.iterator(); i.hasNext();)  
           {  
             GapContentPosition p = (GapContentPosition) i.next();  
             p.mark -= gapEnd - gapStart;  
           }  
438          System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart          System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart
439                           - gapStart);                           - gapStart);
440          gapStart = newGapStart;          gapStart = newGapStart;
# Line 477  public class GapContent Line 459  public class GapContent
459    
460      assert newGapStart < gapStart : "The new gap start must be less than the "      assert newGapStart < gapStart : "The new gap start must be less than the "
461                                      + "old gap start.";                                      + "old gap start.";
462      Vector v = getPositionsInRange(null, newGapStart, gapStart - newGapStart);      setPositionsInRange(newGapStart, gapStart - newGapStart, gapStart);
     for (Iterator i = v.iterator(); i.hasNext();)  
       {  
         GapContentPosition p = (GapContentPosition) i.next();  
         p.mark = gapStart;  
       }  
463      gapStart = newGapStart;      gapStart = newGapStart;
464    }    }
465    
# Line 501  public class GapContent Line 478  public class GapContent
478    
479      assert newGapEnd > gapEnd : "The new gap end must be greater than the "      assert newGapEnd > gapEnd : "The new gap end must be greater than the "
480                                  + "old gap end.";                                  + "old gap end.";
481      Vector v = getPositionsInRange(null, gapEnd, newGapEnd - gapEnd);      setPositionsInRange(gapEnd, newGapEnd - gapEnd, newGapEnd + 1);
     for (Iterator i = v.iterator(); i.hasNext();)  
       {  
         GapContentPosition p = (GapContentPosition) i.next();  
         p.mark = newGapEnd + 1;  
       }  
482      gapEnd = newGapEnd;      gapEnd = newGapEnd;
483    }    }
484    
# Line 608  public class GapContent Line 580  public class GapContent
580        }        }
581      return res;      return res;
582    }    }
583      
584      /**
585       * Sets the mark of all <code>Position</code>s that are in the range
586       * specified by <code>offset</code> and </code>length</code> within
587       * the buffer array to <code>value</code>
588       *
589       * @param offset the start offset of the range to search
590       * @param length the length of the range to search
591       * @param value the new value for each mark
592       */
593      void setPositionsInRange(int offset, int length, int value)
594      {
595        int endOffset = offset + length;
596    
597        int index1 = Collections.binarySearch(positions,
598                                              new GapContentPosition(offset));
599        int index2 = Collections.binarySearch(positions,
600                                              new GapContentPosition(endOffset));
601        if (index1 < 0)
602          index1 = -(index1 + 1);
603        if (index2 < 0)
604          index2 = -(index2 + 1);
605        for (ListIterator i = positions.listIterator(index1); i.hasNext();)
606          {
607            if (i.nextIndex() > index2)
608              break;
609            
610            GapContentPosition p = (GapContentPosition) i.next();
611            if (p.mark >= offset && p.mark <= endOffset)
612              p.mark = value;
613          }
614      }
615      
616      /**
617       * Adjusts the mark of all <code>Position</code>s that are in the range
618       * specified by <code>offset</code> and </code>length</code> within
619       * the buffer array by <code>increment</code>
620       *
621       * @param offset the start offset of the range to search
622       * @param length the length of the range to search
623       * @param incr the increment
624       */
625      void adjustPositionsInRange(int offset, int length, int incr)
626      {
627        int endOffset = offset + length;
628    
629        int index1 = Collections.binarySearch(positions,
630                                              new GapContentPosition(offset));
631        int index2 = Collections.binarySearch(positions,
632                                              new GapContentPosition(endOffset));
633        if (index1 < 0)
634          index1 = -(index1 + 1);
635        if (index2 < 0)
636          index2 = -(index2 + 1);
637        for (ListIterator i = positions.listIterator(index1); i.hasNext();)
638          {
639            if (i.nextIndex() > index2)
640              break;
641            
642            GapContentPosition p = (GapContentPosition) i.next();
643            if (p.mark >= offset && p.mark <= endOffset)
644              p.mark += incr;
645          }
646      }
647    
648    /**    /**
649     * Resets all <code>Position</code> that have an offset of <code>0</code>,     * Resets all <code>Position</code> that have an offset of <code>0</code>,
# Line 620  public class GapContent Line 656  public class GapContent
656      if (gapStart != 0)      if (gapStart != 0)
657        return;        return;
658    
659      Vector zeroMarks = getPositionsInRange(null, gapEnd, 0);      setPositionsInRange(gapEnd, 0, 0);
     for (Iterator i = zeroMarks.iterator(); i.hasNext();)  
       {  
         GapContentPosition pos = (GapContentPosition) i.next();  
         pos.mark = 0;  
       }  
660    }    }
661  }  }

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

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