Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.eireneh.swing
Class DocumentWriter  view DocumentWriter download DocumentWriter.java

java.lang.Object
  extended byjava.io.Writer
      extended bycom.eireneh.swing.DocumentWriter

public class DocumentWriter
extends java.io.Writer

A DocumentWriter is-a Writer that uses a Document so all text printed to the Writer ends up in the JTextArea. A Document is a Container for text that supports editing and provides notification of changes (serves as the model in an MVC relationship).
Distribution Licence:
Project B is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, by writing to Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, Or locally at the Licence link below.
The copyright to this program is held by it's authors.


Nested Class Summary
(package private)  class DocumentWriter.Updater
          For Thread/Swing correctness we should only update in the GUI thread
 
Field Summary
protected  boolean closed
          The destination Document
protected  javax.swing.text.Document doc
          The destination Document
protected  java.lang.Object lock
          The object to lock on to read or write the queue or the updater
protected  java.lang.String queue
          The queue of strings to be added to the GUI
protected  DocumentWriter.Updater updater
          The updater waiting to be run
 
Constructor Summary
DocumentWriter()
          Create the DocumentWriter with no Document, that just dumps the text it get into the bin
DocumentWriter(javax.swing.text.Document doc)
          Create the DocumentWriter with a Document to write to
 
Method Summary
 void close()
          Close the stream, flushing it first.
 void flush()
          Flush the stream.
 javax.swing.text.Document getDocument()
          Accessor for the Document that we are updating
 void setDocument(javax.swing.text.Document doc)
          Accessor for the Document that we are updating
private  void update()
          Set up the gui to read an update.
 void write(char[] cbuf)
          Write an array of characters.
 void write(char[] cbuf, int off, int len)
          Write a portion of an array of characters.
 void write(int c)
          Write a single character.
 void write(java.lang.String str)
          Write a string.
 void write(java.lang.String str, int off, int len)
          Write a portion of a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

protected java.lang.Object lock
The object to lock on to read or write the queue or the updater


queue

protected java.lang.String queue
The queue of strings to be added to the GUI


doc

protected javax.swing.text.Document doc
The destination Document


closed

protected boolean closed
The destination Document


updater

protected DocumentWriter.Updater updater
The updater waiting to be run

Constructor Detail

DocumentWriter

public DocumentWriter()
Create the DocumentWriter with no Document, that just dumps the text it get into the bin


DocumentWriter

public DocumentWriter(javax.swing.text.Document doc)
Create the DocumentWriter with a Document to write to

Method Detail

getDocument

public javax.swing.text.Document getDocument()
Accessor for the Document that we are updating


setDocument

public void setDocument(javax.swing.text.Document doc)
Accessor for the Document that we are updating


write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Write a portion of an array of characters.


write

public void write(int c)
           throws java.io.IOException
Write a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.


write

public void write(char[] cbuf)
           throws java.io.IOException
Write an array of characters.


write

public void write(java.lang.String str)
           throws java.io.IOException
Write a string.


write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
Write a portion of a string.


update

private void update()
Set up the gui to read an update. Note this must only be called from within a synchronized (lock) section of code


flush

public void flush()
           throws java.io.IOException
Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.


close

public void close()
           throws java.io.IOException
Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect.