[Patch] javax.swing.JTextArea
Michael Koch
konqueror@gmx.de
Mon Sep 27 19:17:00 GMT 2004
Hi list,
The attached patch fixes access of JTextComponent's document. GCJ from
java-gui-branch has a bug here which is fixed in HEAD ... I recognized
this while doing merging to GNU classpath and using jikes as bytecode
compiler.
Michael
2004-09-27 Michael Koch <konqueror@gmx.de>
* javax/swing/JTextArea.java:
Don't use JTextComponent.doc directly. GCJ from java-gui-branch has a
bug here which is fixed in HEAD ...
-------------- next part --------------
Index: javax/swing/JTextArea.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextArea.java,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 JTextArea.java
--- javax/swing/JTextArea.java 27 Sep 2004 06:46:30 -0000 1.1.2.7
+++ javax/swing/JTextArea.java 27 Sep 2004 07:17:24 -0000
@@ -371,7 +371,7 @@
public int getLineCount()
{
- return doc.getDefaultRootElement().getElementCount();
+ return getDocument().getDefaultRootElement().getElementCount();
}
public int getLineStartOffset(int line)
@@ -382,7 +382,7 @@
if (line < 0 || line > lineCount)
throw new BadLocationException("Non-existing line number", line);
- Element lineElem = doc.getDefaultRootElement().getElement(line);
+ Element lineElem = getDocument().getDefaultRootElement().getElement(line);
return lineElem.getStartOffset();
}
@@ -394,13 +394,15 @@
if (line < 0 || line > lineCount)
throw new BadLocationException("Non-existing line number", line);
- Element lineElem = doc.getDefaultRootElement().getElement(line);
+ Element lineElem = getDocument().getDefaultRootElement().getElement(line);
return lineElem.getEndOffset();
}
public int getLineOfOffset(int offset)
throws BadLocationException
{
+ Document doc = getDocument();
+
if (offset < doc.getStartPosition().getOffset()
|| offset >= doc.getEndPosition().getOffset())
throw new BadLocationException("offset outside of document", offset);
@@ -422,7 +424,7 @@
* @param string The string of text to insert.
* @param position The position at which to insert the supplied text.
* @throws IllegalArgumentException if the position is < 0 or greater
- * than the length of the current text.
+ * than the length of the current text.
*/
public void insert(String string, int position)
{
@@ -442,6 +444,8 @@
public void replaceRange(String text, int start, int end)
{
+ Document doc = getDocument();
+
if (start > end
|| start < doc.getStartPosition().getOffset()
|| end >= doc.getEndPosition().getOffset())
@@ -457,5 +461,4 @@
// This cannot happen as we check offset above.
}
}
-
}
More information about the Java-patches
mailing list