com.anthonyeden.lib.io
Class JTextAreaWriter

java.lang.Object
  extended byjava.io.Writer
      extended bycom.anthonyeden.lib.io.JTextAreaWriter

public class JTextAreaWriter
extends java.io.Writer

A implementation of the java.io.Writer class which provides writing to a JTextArea via a stream.

Note: There appears to be bug in the Macintosh implementation of the JDK 1.1 where a PrintWriter writing to this class will not include the correct line feeds for display in a JTextArea. There is a simple test of the "java.version" system property which, if it starts with the String "1.1" will cause newlines to be written each time the buffer is flushed.

Author:
Anthony Eden

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
JTextAreaWriter(javax.swing.JTextArea textArea)
          Constructor.
 
Method Summary
 void close()
          Close the stream.
 void flush()
          Flush the data that is currently in the buffer.
protected  java.lang.StringBuffer getBuffer()
          Get the StringBuffer which holds the data prior to writing via a call to the flush() method.
 void setTextArea(javax.swing.JTextArea textArea)
          Set the JTextArea to write to.
 void write(char[] charArray)
          Write the given character array to the output stream.
 void write(char[] charArray, int offset, int length)
          Write the given character array to the output stream beginning from the given offset and proceeding to until the given length is reached.
 void write(int c)
          Write the given character to the output stream.
 void write(java.lang.String string)
          Write the given String to the output stream.
 void write(java.lang.String string, int offset, int length)
          Write the given String to the output stream beginning from the given offset and proceeding to until the given length is reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTextAreaWriter

public JTextAreaWriter(javax.swing.JTextArea textArea)
Constructor.

Parameters:
textArea - The JTextArea to write to.
Method Detail

setTextArea

public void setTextArea(javax.swing.JTextArea textArea)
Set the JTextArea to write to.

Parameters:
textArea - The JTextArea

close

public void close()
Close the stream.


flush

public void flush()
           throws java.io.IOException
Flush the data that is currently in the buffer.

Throws:
java.io.IOException

write

public void write(char[] charArray)
           throws java.io.IOException
Write the given character array to the output stream.

Parameters:
charArray - The character array
Throws:
java.io.IOException

write

public void write(char[] charArray,
                  int offset,
                  int length)
           throws java.io.IOException
Write the given character array to the output stream beginning from the given offset and proceeding to until the given length is reached.

Parameters:
charArray - The character array
offset - The start offset
length - The length to write
Throws:
java.io.IOException

write

public void write(int c)
           throws java.io.IOException
Write the given character to the output stream.

Parameters:
c - The character
Throws:
java.io.IOException

write

public void write(java.lang.String string)
           throws java.io.IOException
Write the given String to the output stream.

Parameters:
string - The String
Throws:
java.io.IOException

write

public void write(java.lang.String string,
                  int offset,
                  int length)
           throws java.io.IOException
Write the given String to the output stream beginning from the given offset and proceeding to until the given length is reached.

Parameters:
string - The String
offset - The start offset
length - The length to write
Throws:
java.io.IOException

getBuffer

protected java.lang.StringBuffer getBuffer()
Get the StringBuffer which holds the data prior to writing via a call to the flush() method. This method should never return null.

Returns:
A StringBuffer


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.