javax.swing.text

Class AbstractWriter

Known Direct Subclasses:
HTMLWriter, MinimalHTMLWriter

public abstract class AbstractWriter
extends Object

This is an abstract base class for writing Document instances to a Writer. A concrete subclass must implement a method to iterate over the Elements of the Document and correctly format them.

Field Summary

protected static char
NEWLINE
The default line separator character.

Constructor Summary

AbstractWriter(Writer writer, Document doc)
Create a new AbstractWriter with the indicated Writer and Document.
AbstractWriter(Writer writer, Document doc, int pos, int len)
Create a new AbstractWriter with the indicated Writer and Document.
AbstractWriter(Writer writer, Element elt)
Create a new AbstractWriter with the indicated Writer and Element.
AbstractWriter(Writer writer, Element elt, int pos, int len)
Create a new AbstractWriter with the indicated Writer and Element.

Method Summary

protected void
decrIndent()
Decrement the indent level.
protected boolean
getCanWrapLines()
Return true if lines printed via write() will wrap, false otherwise.
protected int
getCurrentLineLength()
Return the current line length.
protected Document
getDocument()
Return this writer's Document.
protected ElementIterator
getElementIterator()
Return the ElementIterator for this writer.
int
getEndOffset()
Return the index of the Document at which output ends.
protected int
getIndentLevel()
Return the current indent level.
protected int
getIndentSpace()
Return the number of spaces per indent level.
protected int
getLineLength()
Return the maximum line length.
String
getLineSeparator()
Return the current line separator.
int
getStartOffset()
Return the index of the Document at which output starts.
protected String
getText(Element elt)
Return the text of the Document that is associated with the given Element.
protected Writer
getWriter()
Return the Writer to which we are writing.
protected boolean
inRange(Element elt)
Return true if the Element's range overlaps our desired output range; false otherwise.
protected void
incrIndent()
Increment the indent level.
protected void
indent()
Indent this line by emitting spaces, according to the current indent level and the current number of spaces per indent.
protected boolean
isLineEmpty()
Return true if the line is empty, false otherwise.
protected void
output(char[] data, int start, int len)
This method calls Writer.write on the indicated data, and updates the current line length.
protected void
setCanWrapLines(boolean canWrapLines)
Set the flag indicating whether lines will wrap.
protected void
setCurrentLineLength(int lineLength)
Set the current line length.
protected void
setIndentSpace(int indentSpace)
Set the number of spaces per indent level.
protected void
setLineLength(int maxLineLength)
Set the maximum line length.
void
setLineSeparator(String lineSeparator)
Set the current line separator.
protected void
text(Element elt)
Output the text of the indicated Element, properly clipping it to the range of the Document specified when the AbstractWriter was created.
protected abstract void
write()
This method must be overridden by a concrete subclass.
protected void
write(char ch)
Write a single character.
protected void
write(char[] data, int start, int len)
Write a character array to the output Writer, properly handling newlines and, if needed, wrapping lines as they are output.
protected void
write(String s)
Write a String.
protected void
writeAttributes(AttributeSet attrs)
Print the given AttributeSet as a sequence of assignment-like strings, e.g.
protected void
writeLineSeparator()
Write a line separator using the output method, and then reset the current line length.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

NEWLINE

protected static final char NEWLINE
The default line separator character.
Field Value:
'\n'

Constructor Details

AbstractWriter

protected AbstractWriter(Writer writer,
                         Document doc)
Create a new AbstractWriter with the indicated Writer and Document. The full range of the Document will be used. The internal ElementIterator will be initialized with the Document's root node.

AbstractWriter

protected AbstractWriter(Writer writer,
                         Document doc,
                         int pos,
                         int len)
Create a new AbstractWriter with the indicated Writer and Document. The full range of the Document will be used. The internal ElementIterator will be initialized with the Document's root node.

AbstractWriter

protected AbstractWriter(Writer writer,
                         Element elt)
Create a new AbstractWriter with the indicated Writer and Element. The full range of the Element will be used.

AbstractWriter

protected AbstractWriter(Writer writer,
                         Element elt,
                         int pos,
                         int len)
Create a new AbstractWriter with the indicated Writer and Element. The full range of the Element will be used. The range will be limited to the indicated range of the Document.

Method Details

decrIndent

protected void decrIndent()
Decrement the indent level.

getCanWrapLines

protected boolean getCanWrapLines()
Return true if lines printed via write() will wrap, false otherwise.
Since:
1.3

getCurrentLineLength

protected int getCurrentLineLength()
Return the current line length.
Since:
1.3

getDocument

protected Document getDocument()
Return this writer's Document.

getElementIterator

protected ElementIterator getElementIterator()
Return the ElementIterator for this writer.

getEndOffset

public int getEndOffset()
Return the index of the Document at which output ends.
Since:
1.3

getIndentLevel

protected int getIndentLevel()
Return the current indent level.
Since:
1.3

getIndentSpace

protected int getIndentSpace()
Return the number of spaces per indent level.
Since:
1.3

getLineLength

protected int getLineLength()
Return the maximum line length.
Since:
1.3

getLineSeparator

public String getLineSeparator()
Return the current line separator.
Since:
1.3

getStartOffset

public int getStartOffset()
Return the index of the Document at which output starts.
Since:
1.3

getText

protected String getText(Element elt)
            throws BadLocationException
Return the text of the Document that is associated with the given Element. If the Element is not a leaf Element, this will throw BadLocationException.
Throws:
BadLocationException - if the element is not a leaf

getWriter

protected Writer getWriter()
Return the Writer to which we are writing.
Since:
1.3

inRange

protected boolean inRange(Element elt)
Return true if the Element's range overlaps our desired output range; false otherwise.

incrIndent

protected void incrIndent()
Increment the indent level.

indent

protected void indent()
            throws IOException
Indent this line by emitting spaces, according to the current indent level and the current number of spaces per indent. After this method is called, the current line is no longer considered to be empty, even if no spaces are actually written.

isLineEmpty

protected boolean isLineEmpty()
Return true if the line is empty, false otherwise. The line is empty if nothing has been written since the last newline, and indent has not been invoked.

output

protected void output(char[] data,
                      int start,
                      int len)
            throws IOException
This method calls Writer.write on the indicated data, and updates the current line length. This method does not look for newlines in the written data; the caller is responsible for that.
Since:
1.3

setCanWrapLines

protected void setCanWrapLines(boolean canWrapLines)
Set the flag indicating whether lines will wrap. This affects the behavior of write().
Since:
1.3

setCurrentLineLength

protected void setCurrentLineLength(int lineLength)
Set the current line length.
Since:
1.3

setIndentSpace

protected void setIndentSpace(int indentSpace)
Set the number of spaces per indent level.
Since:
1.3

setLineLength

protected void setLineLength(int maxLineLength)
Set the maximum line length.

setLineSeparator

public void setLineSeparator(String lineSeparator)
Set the current line separator.
Since:
1.3

text

protected void text(Element elt)
            throws BadLocationException,
                   IOException
Output the text of the indicated Element, properly clipping it to the range of the Document specified when the AbstractWriter was created.

write

protected abstract void write()
            throws IOException,
                   BadLocationException
This method must be overridden by a concrete subclass. It is responsible for iterating over the Elements of the Document and writing them out.

write

protected void write(char ch)
            throws IOException
Write a single character.

write

protected void write(char[] data,
                     int start,
                     int len)
            throws IOException
Write a character array to the output Writer, properly handling newlines and, if needed, wrapping lines as they are output.
Since:
1.3

write

protected void write(String s)
            throws IOException
Write a String.

writeAttributes

protected void writeAttributes(AttributeSet attrs)
            throws IOException
Print the given AttributeSet as a sequence of assignment-like strings, e.g. "key=value".

writeLineSeparator

protected void writeLineSeparator()
            throws IOException
Write a line separator using the output method, and then reset the current line length.
Since:
1.3

AbstractWriter.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath 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. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.