Class AbstractWriter
- Direct Known Subclasses:
-
HTMLWriter
,MinimalHTMLWriter
public abstract class AbstractWriter extends Object
Field Summary
Modifier and Type | Field | Description |
---|---|---|
protected static final char |
NEWLINE |
How the text packages models newlines. |
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
|
protected |
Creates a new AbstractWriter. |
Method Summary
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. |
Field Details
NEWLINE
protected static final char NEWLINE
- See Also:
Constructor Details
AbstractWriter
protected AbstractWriter(Writer w, Document doc)
- Parameters:
-
w
- a Writer. -
doc
- a Document
AbstractWriter
protected AbstractWriter(Writer w, Document doc, int pos, int len)
- Parameters:
-
w
- a Writer -
doc
- an Element -
pos
- The location in the document to fetch the content. -
len
- The amount to write out.
AbstractWriter
protected AbstractWriter(Writer w, Element root)
- Parameters:
-
w
- a Writer -
root
- an Element
AbstractWriter
protected AbstractWriter(Writer w, Element root, int pos, int len)
- Parameters:
-
w
- a Writer -
root
- an Element -
pos
- The location in the document to fetch the content. -
len
- The amount to write out.
Method Details
getStartOffset
public int getStartOffset()
- Returns:
- the first offset to be output
- Since:
- 1.3
getEndOffset
public int getEndOffset()
- Returns:
- the last offset to be output
- Since:
- 1.3
getElementIterator
protected ElementIterator getElementIterator()
- Returns:
- the ElementIterator.
getWriter
protected Writer getWriter()
- Returns:
- the Writer that is used to output the content
- Since:
- 1.3
getDocument
protected Document getDocument()
- Returns:
- the Document.
inRange
protected boolean inRange(Element next)
- Parameters:
-
next
- an Element. - Returns:
- boolean that indicates whether the element is in the range.
write
protected abstract void write() throws IOException, BadLocationException
- Throws:
-
IOException
- if an I/O problem has occurred -
BadLocationException
- for an invalid location within the document
getText
protected String getText(Element elem) throws BadLocationException
- Parameters:
-
elem
- anElement
- Returns:
- the text as a
String
- Throws:
-
BadLocationException
- if pos represents an invalid location within the document
text
protected void text(Element elem) throws BadLocationException, IOException
- Parameters:
-
elem
- an Element. - Throws:
-
IOException
- on any I/O error -
BadLocationException
- if pos represents an invalid location within the document.
setLineLength
protected void setLineLength(int l)
- Parameters:
-
l
- the maximum line length.
getLineLength
protected int getLineLength()
- Returns:
- the maximum line length
- Since:
- 1.3
setCurrentLineLength
protected void setCurrentLineLength(int length)
- Parameters:
-
length
- the new line length - Since:
- 1.3
getCurrentLineLength
protected int getCurrentLineLength()
- Returns:
- the current line length
- Since:
- 1.3
isLineEmpty
protected boolean isLineEmpty()
getCurrentLineLength
== 0 || indent
has been invoked on an empty line.- Returns:
- true if the current line should be considered empty
- Since:
- 1.3
setCanWrapLines
protected void setCanWrapLines(boolean newValue)
- Parameters:
-
newValue
- new value for line wrapping - Since:
- 1.3
getCanWrapLines
protected boolean getCanWrapLines()
- Returns:
- whether or not the lines can be wrapped
- Since:
- 1.3
setIndentSpace
protected void setIndentSpace(int space)
- Parameters:
-
space
- an int representing the space to indent mapping.
getIndentSpace
protected int getIndentSpace()
- Returns:
- the amount of space to indent
- Since:
- 1.3
setLineSeparator
public void setLineSeparator(String value)
- Parameters:
-
value
- the new line separator - Since:
- 1.3
getLineSeparator
public String getLineSeparator()
- Returns:
- the string used to represent newlines
- Since:
- 1.3
incrIndent
protected void incrIndent()
getIndentSpace()
*getIndentLevel()
to be > than getLineLength()
this will not cause an indent.decrIndent
protected void decrIndent()
getIndentLevel
protected int getIndentLevel()
incrIndent
has been invoked minus the number of times decrIndent
has been invoked.- Returns:
- the current indentation level
- Since:
- 1.3
indent
protected void indent() throws IOException
- Throws:
-
IOException
- on any I/O error
write
protected void write(char ch) throws IOException
write
method that takes a char[].- Parameters:
-
ch
- a char. - Throws:
-
IOException
- on any I/O error
write
protected void write(String content) throws IOException
write
method that takes a char[].- Parameters:
-
content
- a String. - Throws:
-
IOException
- on any I/O error
writeLineSeparator
protected void writeLineSeparator() throws IOException
output
directly as well as setting the lineLength
to 0.- Throws:
-
IOException
- on any I/O error - Since:
- 1.3
write
protected 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
.- Parameters:
-
chars
- characters to output -
startIndex
- starting index -
length
- length of output - Throws:
-
IOException
- on any I/O error - Since:
- 1.3
writeAttributes
protected void writeAttributes(AttributeSet attr) throws IOException
- Parameters:
-
attr
- an AttributeSet. - Throws:
-
IOException
- on any I/O error
output
protected 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.
- Parameters:
-
content
- characters to output -
start
- starting index -
length
- length of output - Throws:
-
IOException
- on any I/O error - Since:
- 1.3
© 1993, 2021, 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/17/docs/api/java.desktop/javax/swing/text/AbstractWriter.html