- java.lang.Object
- 
- javax.swing.text.AbstractWriter
 
- 
- Direct Known Subclasses:
- HTMLWriter,- MinimalHTMLWriter
 
 public abstract class AbstractWriter extends Object AbstractWriter is an abstract class that actually does the work of writing out the element tree including the attributes. In terms of how much is written out per line, the writer defaults to 100. But this value can be set by subclasses.
- 
- 
Field SummaryFields Modifier and Type Field Description protected static charNEWLINEHow the text packages models newlines.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedAbstractWriter(Writer w, Document doc)Creates a new AbstractWriter.protectedAbstractWriter(Writer w, Document doc, int pos, int len)Creates a new AbstractWriter.protectedAbstractWriter(Writer w, Element root)Creates a new AbstractWriter.protectedAbstractWriter(Writer w, Element root, int pos, int len)Creates a new AbstractWriter.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voiddecrIndent()Decrements the indent level.protected booleangetCanWrapLines()Returns whether or not the lines can be wrapped.protected intgetCurrentLineLength()Returns the current line length.protected DocumentgetDocument()Fetches the document.protected ElementIteratorgetElementIterator()Fetches the ElementIterator.intgetEndOffset()Returns the last offset to be output.protected intgetIndentLevel()Returns the current indentation level.protected intgetIndentSpace()Returns the amount of space to indent.protected intgetLineLength()Returns the maximum line length.StringgetLineSeparator()Returns the string used to represent newlines.intgetStartOffset()Returns the first offset to be output.protected StringgetText(Element elem)Returns the text associated with the element.protected WritergetWriter()Returns the Writer that is used to output the content.protected voidincrIndent()Increments the indent level.protected voidindent()Does indentation.protected booleaninRange(Element next)This method determines whether the current element is in the range specified.protected booleanisLineEmpty()Returns true if the current line should be considered empty.protected voidoutput(char[] content, int start, int length)The last stop in writing out content.protected voidsetCanWrapLines(boolean newValue)Sets whether or not lines can be wrapped.protected voidsetCurrentLineLength(int length)Sets the current line length.protected voidsetIndentSpace(int space)Enables subclasses to specify how many spaces an indent maps to.protected voidsetLineLength(int l)Enables subclasses to set the number of characters they want written per line.voidsetLineSeparator(String value)Sets the String used to represent newlines.protected voidtext(Element elem)Writes out text.protected abstract voidwrite()This abstract method needs to be implemented by subclasses.protected voidwrite(char ch)Writes out a character.protected voidwrite(char[] chars, int startIndex, int length)All write methods call into this one.protected voidwrite(String content)Writes out a string.protected voidwriteAttributes(AttributeSet attr)Writes out the set of attributes as " <name>=<value>" pairs.protected voidwriteLineSeparator()Writes the line separator.
 
- 
- 
- 
Field Detail- 
NEWLINEprotected static final char NEWLINE How the text packages models newlines.- See Also:
- getLineSeparator(), Constant Field Values
 
 
- 
 - 
Constructor Detail- 
AbstractWriterprotected AbstractWriter(Writer w, Document doc) Creates a new AbstractWriter. Initializes the ElementIterator with the default root of the document.- Parameters:
- w- a Writer.
- doc- a Document
 
 - 
AbstractWriterprotected AbstractWriter(Writer w, Document doc, int pos, int len) Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.- Parameters:
- w- a Writer
- doc- an Element
- pos- The location in the document to fetch the content.
- len- The amount to write out.
 
 - 
AbstractWriterprotected AbstractWriter(Writer w, Element root) Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.- Parameters:
- w- a Writer
- root- an Element
 
 - 
AbstractWriterprotected AbstractWriter(Writer w, Element root, int pos, int len) Creates a new AbstractWriter. Initializes the ElementIterator with the element passed in.- Parameters:
- w- a Writer
- root- an Element
- pos- The location in the document to fetch the content.
- len- The amount to write out.
 
 
- 
 - 
Method Detail- 
getStartOffsetpublic int getStartOffset() Returns the first offset to be output.- Returns:
- the first offset to be output
- Since:
- 1.3
 
 - 
getEndOffsetpublic int getEndOffset() Returns the last offset to be output.- Returns:
- the last offset to be output
- Since:
- 1.3
 
 - 
getElementIteratorprotected ElementIterator getElementIterator() Fetches the ElementIterator.- Returns:
- the ElementIterator.
 
 - 
getWriterprotected Writer getWriter() Returns the Writer that is used to output the content.- Returns:
- the Writer that is used to output the content
- Since:
- 1.3
 
 - 
getDocumentprotected Document getDocument() Fetches the document.- Returns:
- the Document.
 
 - 
inRangeprotected boolean inRange(Element next) This method determines whether the current element is in the range specified. When no range is specified, the range is initialized to be the entire document. inRange() returns true if the range specified intersects with the element's range.- Parameters:
- next- an Element.
- Returns:
- boolean that indicates whether the element is in the range.
 
 - 
writeprotected abstract void write() throws IOException, BadLocationExceptionThis abstract method needs to be implemented by subclasses. Its responsibility is to iterate over the elements and use the write() methods to generate output in the desired format.- Throws:
- IOException- if an I/O problem has occurred
- BadLocationException- for an invalid location within the document
 
 - 
getTextprotected String getText(Element elem) throws BadLocationException Returns the text associated with the element. The assumption here is that the element is a leaf element. Throws a BadLocationException when encountered.- Parameters:
- elem- an- Element
- Returns:
- the text as a String
- Throws:
- BadLocationException- if pos represents an invalid location within the document
 
 - 
textprotected void text(Element elem) throws BadLocationException, IOException Writes out text. If a range is specified when the constructor is invoked, then only the appropriate range of text is written out.- Parameters:
- elem- an Element.
- Throws:
- IOException- on any I/O error
- BadLocationException- if pos represents an invalid location within the document.
 
 - 
setLineLengthprotected void setLineLength(int l) Enables subclasses to set the number of characters they want written per line. The default is 100.- Parameters:
- l- the maximum line length.
 
 - 
getLineLengthprotected int getLineLength() Returns the maximum line length.- Returns:
- the maximum line length
- Since:
- 1.3
 
 - 
setCurrentLineLengthprotected void setCurrentLineLength(int length) Sets the current line length.- Parameters:
- length- the new line length
- Since:
- 1.3
 
 - 
getCurrentLineLengthprotected int getCurrentLineLength() Returns the current line length.- Returns:
- the current line length
- Since:
- 1.3
 
 - 
isLineEmptyprotected boolean isLineEmpty() Returns true if the current line should be considered empty. This is true whengetCurrentLineLength== 0 ||indenthas been invoked on an empty line.- Returns:
- true if the current line should be considered empty
- Since:
- 1.3
 
 - 
setCanWrapLinesprotected void setCanWrapLines(boolean newValue) Sets whether or not lines can be wrapped. This can be toggled during the writing of lines. For example, outputting HTML might set this to false when outputting a quoted string.- Parameters:
- newValue- new value for line wrapping
- Since:
- 1.3
 
 - 
getCanWrapLinesprotected boolean getCanWrapLines() Returns whether or not the lines can be wrapped. If this is false no lineSeparator's will be output.- Returns:
- whether or not the lines can be wrapped
- Since:
- 1.3
 
 - 
setIndentSpaceprotected void setIndentSpace(int space) Enables subclasses to specify how many spaces an indent maps to. When indentation takes place, the indent level is multiplied by this mapping. The default is 2.- Parameters:
- space- an int representing the space to indent mapping.
 
 - 
getIndentSpaceprotected int getIndentSpace() Returns the amount of space to indent.- Returns:
- the amount of space to indent
- Since:
- 1.3
 
 - 
setLineSeparatorpublic void setLineSeparator(String value) Sets the String used to represent newlines. This is initialized in the constructor from either the Document, or the System property line.separator.- Parameters:
- value- the new line separator
- Since:
- 1.3
 
 - 
getLineSeparatorpublic String getLineSeparator() Returns the string used to represent newlines.- Returns:
- the string used to represent newlines
- Since:
- 1.3
 
 - 
incrIndentprotected void incrIndent() Increments the indent level. If indenting would causegetIndentSpace()*getIndentLevel()to be > thangetLineLength()this will not cause an indent.
 - 
decrIndentprotected void decrIndent() Decrements the indent level.
 - 
getIndentLevelprotected int getIndentLevel() Returns the current indentation level. That is, the number of timesincrIndenthas been invoked minus the number of timesdecrIndenthas been invoked.- Returns:
- the current indentation level
- Since:
- 1.3
 
 - 
indentprotected void indent() throws IOExceptionDoes indentation. The number of spaces written out is indent level times the space to map mapping. If the current line is empty, this will not make it so that the current line is still considered empty.- Throws:
- IOException- on any I/O error
 
 - 
writeprotected void write(char ch) throws IOExceptionWrites out a character. This is implemented to invoke thewritemethod that takes a char[].- Parameters:
- ch- a char.
- Throws:
- IOException- on any I/O error
 
 - 
writeprotected void write(String content) throws IOException Writes out a string. This is implemented to invoke thewritemethod that takes a char[].- Parameters:
- content- a String.
- Throws:
- IOException- on any I/O error
 
 - 
writeLineSeparatorprotected void writeLineSeparator() throws IOExceptionWrites the line separator. This invokesoutputdirectly as well as setting thelineLengthto 0.- Throws:
- IOException- on any I/O error
- Since:
- 1.3
 
 - 
writeprotected void write(char[] chars, int startIndex, int length) throws IOExceptionAll write methods call into this one. IfgetCanWrapLines()returns false, this will calloutputwith each sequence ofcharsthat doesn't contain a NEWLINE, followed by a call towriteLineSeparator. On the other hand, ifgetCanWrapLines()returns true, this will split the string, as necessary, sogetLineLengthis honored. The only exception is if the current string contains no whitespace, and won't fit in which case the line length will exceedgetLineLength.- Parameters:
- chars- characters to output
- startIndex- starting index
- length- length of output
- Throws:
- IOException- on any I/O error
- Since:
- 1.3
 
 - 
writeAttributesprotected void writeAttributes(AttributeSet attr) throws IOException Writes out the set of attributes as " <name>=<value>" pairs. It throws an IOException when encountered.- Parameters:
- attr- an AttributeSet.
- Throws:
- IOException- on any I/O error
 
 - 
outputprotected void output(char[] content, int start, int length) throws IOExceptionThe last stop in writing out content. All the write methods eventually make it to this method, which invokeswriteon 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. UsewriteLineSeparatorto 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
 
 
- 
 
-