classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Adding read/write to javax/swing/text/JTextComponent.j


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Adding read/write to javax/swing/text/JTextComponent.java (fixing bug #13640)
Date: Tue, 05 Jul 2005 09:40:50 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This should close the recently submitted bug #13640. These two missing methods are not complicated. As the field 'doc' is not directly assigned, I added the check for null. We do not know how the user may override setText.

2005-07-05  Audrius Meskauskas  <address@hidden>

* javax/swing/text/JTextComponent.java (read, write): New methods.
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v
retrieving revision 1.32
diff -u -r1.32 JTextComponent.java
--- javax/swing/text/JTextComponent.java        2 Jul 2005 20:32:51 -0000       
1.32
+++ javax/swing/text/JTextComponent.java        5 Jul 2005 07:28:00 -0000
@@ -54,6 +54,8 @@
 import java.awt.event.InputMethodListener;
 import java.awt.event.KeyEvent;
 import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
@@ -1611,4 +1613,55 @@
   {
     navigationFilter = filter;
   }
+  
+  /**
+   * Read and set the content this component. If not overridden, the
+   * method reads the component content as a plain text.
+   *
+   * The second parameter of this method describes the input stream. It can
+   * be String, URL, File and so on. If not null, this object is added to
+   * the properties of the associated document under the key
+   * address@hidden Document#StreamDescriptionProperty}.
+   *
+   * @param input an input stream to read from.
+   * @param streamDescription an object, describing the stream.
+   *
+   * @throws IOException if the reader throws it.
+   *
+   * @see getDocument()
+   * @see Document#getProperty(Object)
+   */
+  public void read(Reader input, Object streamDescription)
+            throws IOException
+  {
+    if (streamDescription != null)
+      {
+        Document d = getDocument();
+        if (d != null)
+          d.putProperty(Document.StreamDescriptionProperty, streamDescription);
+      }
+
+    StringBuffer b = new StringBuffer();
+    int c;
+
+    // Read till -1 (EOF).
+    while ((c = input.read()) >= 0)
+      b.append((char) c);
+
+    setText(b.toString());
+  }
+
+  /**
+   * Write the content of this component to the given stream. If not
+   * overridden, the method writes the component content as a plain text.
+   *
+   * @param output the writer to write into.
+   *
+   * @throws IOException if the writer throws it.
+   */
+  public void write(Writer output)
+             throws IOException
+  {
+    output.write(getText());
+  }  
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]