Hi,
the GapContent was broken which lead to misfunctional textfields and
editorpanes. The attached patch fixes this (was a misplaced curly brace
of an if() statement of a boundary check) and adds some cleanup. The
insertString and remove methods both now call the protected replace()
implementation.
2005-08-12 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/GapContent.java
(insertString): Use replace() to actually insert content.
(remove): Use replace() to actually remove content.
(shiftGap): Repaired misplaced curly brace in if block of
boudary check.
(replace): Check for null argument for addItems.
/Roman
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.20
diff -u -r1.20 GapContent.java
--- javax/swing/text/GapContent.java 2 Aug 2005 14:44:05 -0000 1.20
+++ javax/swing/text/GapContent.java 12 Aug 2005 15:24:29 -0000
@@ -228,19 +228,8 @@
throw new BadLocationException("the where argument cannot be greater"
+ " than the content length", where);
- // check if the gap is big enough to hold the string
- if ((gapEnd - gapStart) < strLen)
- // make room for this string and some more
- shiftEnd(strLen + DEFAULT_BUFSIZE);
-
- // are we at the gap boundary?
- if (where != gapStart)
- shiftGap(where);
-
- // now we can simple copy the string into the gap and adjust the
- // gap boundaries
- System.arraycopy(str.toCharArray(), 0, buffer, gapStart, strLen);
- gapStart += strLen;
+ replace(where, 0, str.toCharArray(), str.length());
+
return null;
}
@@ -268,12 +257,8 @@
throw new BadLocationException("where + nitems cannot be greater"
+ " than the content length", where + nitems);
- // check if we are at the gap boundary
- if (where != gapStart)
- shiftGap(where);
+ replace(where, nitems, null, 0);
- // now we simply have to enlarge the gap
- gapEnd += nitems;
return null;
}
@@ -419,40 +404,40 @@
// Update the positions between newGapEnd and (old) gapEnd. The marks
// must be shifted by (gapEnd - newGapEnd).
- int index1 = Collections.binarySearch(positions, new GapContentPosition(
- gapEnd));
- int index2 = Collections.binarySearch(positions, new GapContentPosition(
- newGapEnd));
+ int index1 = Collections.binarySearch(positions,
+ new GapContentPosition(gapEnd));
+ int index2 = Collections.binarySearch(positions,
+ new GapContentPosition(newGapEnd));
if (index1 > 0 && index2 > 0)
- {
- int i1 = Math.min(index1, index2);
- int i2 = Math.max(index1, index2);
- for (ListIterator i = positions.listIterator(i1); i.hasNext();)
{
- if (i.nextIndex() > i2)
- break;
-
- GapContentPosition p = (GapContentPosition) i.next();
- p.mark += gapEnd - newGapEnd;
+ int i1 = Math.min(index1, index2);
+ int i2 = Math.max(index1, index2);
+ for (ListIterator i = positions.listIterator(i1); i.hasNext();)
+ {
+ if (i.nextIndex() > i2)
+ break;
+
+ GapContentPosition p = (GapContentPosition) i.next();
+ p.mark += gapEnd - newGapEnd;
+ }
}
- if (newGapStart == gapStart)
- return;
- else if (newGapStart < gapStart)
+ if (newGapStart == gapStart)
+ return;
+ else if (newGapStart < gapStart)
{
System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart
- - newGapStart);
+ - newGapStart);
gapStart = newGapStart;
gapEnd = newGapEnd;
}
- else
+ else
{
System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart
- - gapStart);
+ - gapStart);
gapStart = newGapStart;
gapEnd = newGapEnd;
}
- }
}
/**
@@ -473,7 +458,8 @@
* @param addItems the items to add at location
* @param addSize the number of items to add
*/
- protected void replace(int position, int rmSize, Object addItems, int addSize)
+ protected void replace(int position, int rmSize, Object addItems,
+ int addSize)
{
// Remove content
shiftGap(position);
@@ -484,7 +470,10 @@
shiftEnd(addSize);
// Add new items to the buffer.
- System.arraycopy(addItems, 0, buffer, gapStart, addSize);
- gapStart += addSize;
+ if (addItems != null)
+ {
+ System.arraycopy(addItems, 0, buffer, gapStart, addSize);
+ gapStart += addSize;
+ }
}
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches