/[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.26 by rabbit78, Tue Sep 13 23:22:27 2005 UTC revision 1.27 by rabbit78, Thu Sep 29 17:32:18 2005 UTC
# Line 116  public class GapContent Line 116  public class GapContent
116      public int getOffset()      public int getOffset()
117      {      {
118        // Check precondition.        // Check precondition.
119        assert mark <= gapStart || mark > gapEnd : "mark: " + mark        assert mark <= gapStart || mark >= gapEnd : "mark: " + mark
120                                                 + ", gapStart: " + gapStart                                                 + ", gapStart: " + gapStart
121                                                 + ", gapEnd: " + gapEnd;                                                 + ", gapEnd: " + gapEnd;
122    
# Line 379  public class GapContent Line 379  public class GapContent
379      if (index < 0)      if (index < 0)
380        index = -(index + 1);        index = -(index + 1);
381      positions.add(index, pos);      positions.add(index, pos);
382        
383      return pos;      return pos;
384    }    }
385    
# Line 426  public class GapContent Line 426  public class GapContent
426        return;        return;
427    
428      int newGapEnd = newGapStart + gapEnd - gapStart;      int newGapEnd = newGapStart + gapEnd - gapStart;
   
429      if (newGapStart < gapStart)      if (newGapStart < gapStart)
430        {        {
431          // Update the positions between newGapStart and (old) gapStart. The marks          // Update the positions between newGapStart and (old) gapStart. The marks
432          // must be shifted by (gapEnd - gapStart).          // must be shifted by (gapEnd - gapStart).
433          Vector v = getPositionsInRange(null, newGapStart + 1,          Vector v = getPositionsInRange(null, newGapStart,
434                                         gapStart - newGapStart + 1);                                         gapStart - newGapStart);
435          for (Iterator i = v.iterator(); i.hasNext();)          for (Iterator i = v.iterator(); i.hasNext();)
436            {            {
437              GapContentPosition p = (GapContentPosition) i.next();              GapContentPosition p = (GapContentPosition) i.next();
# Line 459  public class GapContent Line 458  public class GapContent
458          gapStart = newGapStart;          gapStart = newGapStart;
459          gapEnd = newGapEnd;          gapEnd = newGapEnd;
460        }        }
461        if (gapStart == 0)
462          resetMarksAtZero();
463    }    }
464    
465    /**    /**
# Line 530  public class GapContent Line 531  public class GapContent
531    protected void replace(int position, int rmSize, Object addItems,    protected void replace(int position, int rmSize, Object addItems,
532                           int addSize)                           int addSize)
533    {    {
534        if (gapStart != position)
535          shiftGap(position);
536      // Remove content      // Remove content
537      shiftGap(position);      if (rmSize > 0)
538      shiftGapEndUp(gapEnd + rmSize);        shiftGapEndUp(gapEnd + rmSize);
539    
540      // If gap is too small, enlarge the gap.      // If gap is too small, enlarge the gap.
541      if ((gapEnd - gapStart) <= addSize)      if ((gapEnd - gapStart) <= addSize)
# Line 605  public class GapContent Line 608  public class GapContent
608        }        }
609      return res;      return res;
610    }    }
611    
612      /**
613       * Resets all <code>Position</code> that have an offset of <code>0</code>,
614       * to also have an array index of <code>0</code>. This might be necessary
615       * after a call to <code>shiftGap(0)</code>, since then the marks at offset
616       * <code>0</code> get shifted to <code>gapEnd</code>.
617       */
618      protected void resetMarksAtZero()
619      {
620        if (gapStart != 0)
621          return;
622    
623        Vector zeroMarks = getPositionsInRange(null, gapEnd, 0);
624        for (Iterator i = zeroMarks.iterator(); i.hasNext();)
625          {
626            GapContentPosition pos = (GapContentPosition) i.next();
627            pos.mark = 0;
628          }
629      }
630  }  }

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

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