HTMLWriter
, MinimalHTMLWriter
public abstract class AbstractWriter extends Object
Modifier and Type | Field | Description |
---|---|---|
protected static final char |
NEWLINE |
How the text packages models newlines. |
Modifier | Constructor | Description |
---|---|---|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
Modifier and Type | Method | Description |
---|---|---|
protected void |
decrIndent() |
Decrements the indent level. |
protected boolean |
getCanWrapLines() |
Returns whether or not the lines can be wrapped. |
protected int |
getCurrentLineLength() |
Returns the current line length. |
protected Document |
getDocument() |
Fetches the document. |
protected ElementIterator |
getElementIterator() |
Fetches the ElementIterator. |
int |
getEndOffset() |
Returns the last offset to be output. |
protected int |
getIndentLevel() |
Returns the current indentation level. |
protected int |
getIndentSpace() |
Returns the amount of space to indent. |
protected int |
getLineLength() |
Returns the maximum line length. |
String |
getLineSeparator() |
Returns the string used to represent newlines. |
int |
getStartOffset() |
Returns the first offset to be output. |
protected String |
getText |
Returns the text associated with the element. |
protected Writer |
getWriter() |
Returns the Writer that is used to output the content. |
protected void |
incrIndent() |
Increments the indent level. |
protected void |
indent() |
Does indentation. |
protected boolean |
inRange |
This method determines whether the current element is in the range specified. |
protected boolean |
isLineEmpty() |
Returns true if the current line should be considered empty. |
protected void |
output |
The last stop in writing out content. |
protected void |
setCanWrapLines |
Sets whether or not lines can be wrapped. |
protected void |
setCurrentLineLength |
Sets the current line length. |
protected void |
setIndentSpace |
Enables subclasses to specify how many spaces an indent maps to. |
protected void |
setLineLength |
Enables subclasses to set the number of characters they want written per line. |
void |
setLineSeparator |
Sets the String used to represent newlines. |
protected void |
text |
Writes out text. |
protected abstract void |
write() |
This abstract method needs to be implemented by subclasses. |
protected void |
write |
Writes out a character. |
protected void |
write |
All write methods call into this one. |
protected void |
write |
Writes out a string. |
protected void |
writeAttributes |
Writes out the set of attributes as " <name>=<value>" pairs. |
protected void |
writeLineSeparator() |
Writes the line separator. |
protected static final char NEWLINE
protected AbstractWriter(Writer w, Document doc)
w
- a Writer.doc
- a Documentprotected AbstractWriter(Writer w, Document doc, int pos, int len)
w
- a Writerdoc
- an Elementpos
- The location in the document to fetch the content.len
- The amount to write out.protected AbstractWriter(Writer w, Element root)
w
- a Writerroot
- an Elementprotected AbstractWriter(Writer w, Element root, int pos, int len)
w
- a Writerroot
- an Elementpos
- The location in the document to fetch the content.len
- The amount to write out.public int getStartOffset()
public int getEndOffset()
protected ElementIterator getElementIterator()
protected Writer getWriter()
protected Document getDocument()
protected boolean inRange(Element next)
next
- an Element.protected abstract void write() throws IOException, BadLocationException
IOException
- if an I/O problem has occurredBadLocationException
- for an invalid location within the documentprotected String getText(Element elem) throws BadLocationException
elem
- an Element
String
BadLocationException
- if pos represents an invalid location within the documentprotected void text(Element elem) throws BadLocationException, IOException
elem
- an Element.IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.protected void setLineLength(int l)
l
- the maximum line length.protected int getLineLength()
protected void setCurrentLineLength(int length)
length
- the new line lengthprotected int getCurrentLineLength()
protected boolean isLineEmpty()
getCurrentLineLength
== 0 || indent
has been invoked on an empty line.protected void setCanWrapLines(boolean newValue)
newValue
- new value for line wrappingprotected boolean getCanWrapLines()
protected void setIndentSpace(int space)
space
- an int representing the space to indent mapping.protected int getIndentSpace()
public void setLineSeparator(String value)
value
- the new line separatorpublic String getLineSeparator()
protected void incrIndent()
getIndentSpace()
*getIndentLevel()
to be > than getLineLength()
this will not cause an indent.protected void decrIndent()
protected int getIndentLevel()
incrIndent
has been invoked minus the number of times decrIndent
has been invoked.protected void indent() throws IOException
IOException
- on any I/O errorprotected void write(char ch) throws IOException
write
method that takes a char[].ch
- a char.IOException
- on any I/O errorprotected void write(String content) throws IOException
write
method that takes a char[].content
- a String.IOException
- on any I/O errorprotected void writeLineSeparator() throws IOException
output
directly as well as setting the lineLength
to 0.IOException
- on any I/O errorprotected void write(char[] chars, int startIndex, int length) throws IOException
getCanWrapLines()
returns false, this will call output
with each sequence of chars
that doesn't contain a NEWLINE, followed by a call to writeLineSeparator
. On the other hand, if getCanWrapLines()
returns true, this will split the string, as necessary, so getLineLength
is honored. The only exception is if the current string contains no whitespace, and won't fit in which case the line length will exceed getLineLength
.chars
- characters to outputstartIndex
- starting indexlength
- length of outputIOException
- on any I/O errorprotected void writeAttributes(AttributeSet attr) throws IOException
attr
- an AttributeSet.IOException
- on any I/O errorprotected void output(char[] content, int start, int length) throws IOException
write
on the Writer. This method also updates the line length based on length
. If this is invoked to output a newline, the current line length will need to be reset as will no longer be valid. If it is up to the caller to do this. Use writeLineSeparator
to write out a newline, which will property update the current line length.
content
- characters to outputstart
- starting indexlength
- length of outputIOException
- on any I/O error
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/text/AbstractWriter.html