[Patch] javax.swing.JTextArea
Michael Koch
konqueror@gmx.de
Tue Sep 28 01:02:00 GMT 2004
Hi list,
I just merged the attached patch from GNU classpath to make
javax.swing.JTextArea fully merged.
Michael
2004-09-27 Michael Koch <konqueror@gmx.de>
* javax/swing/JTextArea.java
(append): Re-implemented.
(insert): Likewise.
-------------- next part --------------
Index: javax/swing/JTextArea.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextArea.java,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 JTextArea.java
--- javax/swing/JTextArea.java 27 Sep 2004 07:20:04 -0000 1.1.2.8
+++ javax/swing/JTextArea.java 27 Sep 2004 13:06:02 -0000
@@ -195,7 +195,15 @@
*/
public void append(String toAppend)
{
- setText(getText() + toAppend);
+ try
+ {
+ getDocument().insertString(getText().length(), toAppend, null);
+ }
+ catch (BadLocationException exception)
+ {
+ /* This shouldn't happen in theory -- but, if it does... */
+ throw new RuntimeException("Unexpected exception occurred.", exception);
+ }
}
/**
@@ -428,17 +436,24 @@
*/
public void insert(String string, int position)
{
- if (position < doc.getStartPosition().getOffset()
- || position >= doc.getEndPosition().getOffset())
- throw new IllegalArgumentException();
+ // Retrieve the document model.
+ Document doc = getDocument();
+
+ // Check the model and string for validity.
+ if (doc == null
+ || string == null
+ || string.length() == 0)
+ return;
+ // Insert the text into the model.
try
{
doc.insertString(position, string, null);
}
catch (BadLocationException e)
{
- // This cannot happen as we check position above.
+ throw new IllegalArgumentException("The supplied position, "
+ + position + ", was invalid.");
}
}
More information about the Java-patches
mailing list