- java.lang.Object
-
- javax.swing.text.AbstractWriter
-
- 已知直接子类:
-
HTMLWriter,MinimalHTMLWriter
public abstract class AbstractWriter extends Object
AbstractWriter是一个抽象类,它实际上完成了包含属性的元素树的写入工作。 关于每行写出多少,作者默认为100.但是该值可以由子类设置。
-
-
Field Summary
Fields Modifier and Type Field 描述 protected static charNEWLINE文本包如何模型换行。
-
构造方法摘要
构造方法 Modifier Constructor 描述 protectedAbstractWriter(Writer w, Document doc)创建一个新的AbstractWriter。protectedAbstractWriter(Writer w, Document doc, int pos, int len)创建一个新的AbstractWriter。protectedAbstractWriter(Writer w, Element root)创建一个新的AbstractWriter。protectedAbstractWriter(Writer w, Element root, int pos, int len)创建一个新的AbstractWriter。
-
方法摘要
所有方法 接口方法 抽象方法 具体的方法 Modifier and Type 方法 描述 protected voiddecrIndent()减少缩进级别。protected booleangetCanWrapLines()返回是否可以包装线。protected intgetCurrentLineLength()返回当前行长度。protected DocumentgetDocument()获取文档。protected ElementIteratorgetElementIterator()获取ElementIterator。intgetEndOffset()返回要输出的最后一个偏移量。protected intgetIndentLevel()返回当前缩进级别。protected intgetIndentSpace()返回要缩进的空间量。protected intgetLineLength()返回最大行长度。StringgetLineSeparator()返回用于表示换行符的字符串。intgetStartOffset()返回要输出的第一个偏移量。protected StringgetText(Element elem)返回与元素关联的文本。protected WritergetWriter()返回用于输出内容的Writer。protected voidincrIndent()增加缩进级别。protected voidindent()缩进protected booleaninRange(Element next)此方法确定当前元素是否在指定的范围内。protected booleanisLineEmpty()如果当前行被视为空,则返回true。protected voidoutput(char[] content, int start, int length)写出内容的最后一站。protected voidsetCanWrapLines(boolean newValue)设置是否可以包装线。protected voidsetCurrentLineLength(int length)设置当前行长度。protected voidsetIndentSpace(int space)启用子类来指定缩进映射到的空格。protected voidsetLineLength(int l)启用子类来设置每行要写入的字符数。voidsetLineSeparator(String value)设置用于表示换行符的字符串。protected voidtext(Element elem)写出文字。protected abstract voidwrite()这个抽象方法需要由子类实现。protected voidwrite(char ch)写出一个字符protected voidwrite(char[] chars, int startIndex, int length)所有写入方法都调用到这一个中。protected voidwrite(String content)写出一个字符串。protected voidwriteAttributes(AttributeSet attr)将属性集写入“<name> = <value>”对。protected voidwriteLineSeparator()写行分隔符。
-
-
-
构造方法详细信息
-
AbstractWriter
protected AbstractWriter(Writer w, Document doc)
创建一个新的AbstractWriter。 使用文档的默认根目录初始化ElementIterator。- 参数
-
w- 作家。 -
doc- 一份文件
-
AbstractWriter
protected AbstractWriter(Writer w, Document doc, int pos, int len)
创建一个新的AbstractWriter。 使用传入的元素初始化ElementIterator。- 参数
-
w- 作家 -
doc- 一个元素 -
pos- 文档中提取内容的位置。 -
len- 写出的金额。
-
AbstractWriter
protected AbstractWriter(Writer w, Element root)
创建一个新的AbstractWriter。 使用传入的元素初始化ElementIterator。- 参数
-
w- 作家 -
root- 一个元素
-
-
方法详细信息
-
getStartOffset
public int getStartOffset()
返回要输出的第一个偏移量。- 结果
- 要输出的第一个偏移量
- 从以下版本开始:
- 1.3
-
getEndOffset
public int getEndOffset()
返回要输出的最后一个偏移量。- 结果
- 要输出的最后一个偏移量
- 从以下版本开始:
- 1.3
-
getElementIterator
protected ElementIterator getElementIterator()
获取ElementIterator。- 结果
- ElementIterator。
-
getWriter
protected Writer getWriter()
返回用于输出内容的Writer。- 结果
- 用于输出内容的Writer
- 从以下版本开始:
- 1.3
-
getDocument
protected Document getDocument()
获取文档。- 结果
- 文件。
-
inRange
protected boolean inRange(Element next)
此方法确定当前元素是否在指定的范围内。 当没有指定范围时,范围被初始化为整个文档。 如果指定的范围与元素的范围相交,则inRange()将返回true。- 参数
-
next- 一个元素。 - 结果
- boolean表示元素是否在范围内。
-
write
protected abstract void write() throws IOException, BadLocationException这个抽象方法需要由子类实现。 它的责任是迭代元素,并使用write()方法生成所需格式的输出。- 异常
-
IOException- 如果发生I / O问题 -
BadLocationException- 对于文档中的无效位置
-
getText
protected String getText(Element elem) throws BadLocationException
返回与元素关联的文本。 这里的假设是元素是叶元素。 遇到BadLocationException时遇到。- 参数
-
elem- 一个Element - 结果
-
文字为
String - 异常
-
BadLocationException- 如果pos表示文档中的无效位置
-
text
protected void text(Element elem) throws BadLocationException, IOException
写出文字。 如果在调用构造函数时指定了一个范围,则只写出适当的文本范围。- 参数
-
elem- 元素。 - 异常
-
IOException- 在任何I / O错误 -
BadLocationException- 如果pos表示文档中的无效位置。
-
setLineLength
protected void setLineLength(int l)
启用子类来设置每行要写入的字符数。 默认值为100。- 参数
-
l- 最大线路长度。
-
getLineLength
protected int getLineLength()
返回最大行长度。- 结果
- 最大线长
- 从以下版本开始:
- 1.3
-
setCurrentLineLength
protected void setCurrentLineLength(int length)
设置当前行长度。- 参数
-
length- 新行长度 - 从以下版本开始:
- 1.3
-
getCurrentLineLength
protected int getCurrentLineLength()
返回当前行长度。- 结果
- 当前行长度
- 从以下版本开始:
- 1.3
-
isLineEmpty
protected boolean isLineEmpty()
如果当前行被视为空,则返回true。 这是真的,当getCurrentLineLength== 0 ||indent已被空白线调用。- 结果
- 如果当前行被视为空,则为true
- 从以下版本开始:
- 1.3
-
setCanWrapLines
protected void setCanWrapLines(boolean newValue)
设置是否可以包装线。 在写线时可以切换。 例如,输出HTML可能会在输出引用的字符串时将其设置为false。- 参数
-
newValue- 换行的新值 - 从以下版本开始:
- 1.3
-
getCanWrapLines
protected boolean getCanWrapLines()
返回是否可以包装线。 如果这是false,则不会输出lineSeparator的输出。- 结果
- 是否可以包裹线
- 从以下版本开始:
- 1.3
-
setIndentSpace
protected void setIndentSpace(int space)
启用子类来指定缩进映射到的空格。 当缩进发生时,缩进级乘以此映射。 默认值为2。- 参数
-
space- 表示缩进映射空间的int。
-
getIndentSpace
protected int getIndentSpace()
返回要缩进的空间量。- 结果
- 缩进的空间量
- 从以下版本开始:
- 1.3
-
setLineSeparator
public void setLineSeparator(String value)
设置用于表示换行符的字符串。 这是在Document或System属性line.separator的构造函数中初始化的。- 参数
-
value- 新行分隔符 - 从以下版本开始:
- 1.3
-
getLineSeparator
public String getLineSeparator()
返回用于表示换行符的字符串。- 结果
- 用于表示换行符的字符串
- 从以下版本开始:
- 1.3
-
incrIndent
protected void incrIndent()
增加缩进级别。 如果缩进会导致getIndentSpace()*getIndentLevel()>>getLineLength()这不会造成缩进。
-
decrIndent
protected void decrIndent()
减少缩进级别。
-
getIndentLevel
protected int getIndentLevel()
返回当前缩进级别。 也就是说,已经调用次数incrIndent减去已被调用的次数decrIndent。- 结果
- 当前缩进级别
- 从以下版本开始:
- 1.3
-
indent
protected void indent() throws IOException缩进 写出的空格数是缩进级别映射映射空间。 如果当前行为空,则不会使当前行为空。- 异常
-
IOException- 任何I / O错误
-
write
protected void write(char ch) throws IOException写出一个字符 这是为了调用采用char []的write方法实现的。- 参数
-
ch- 一个char。 - 异常
-
IOException- 在任何I / O错误
-
write
protected void write(String content) throws IOException
写出一个字符串。 这是为了调用采用char []的write方法实现的。- 参数
-
content- 一个字符串。 - 异常
-
IOException- 在任何I / O错误
-
writeLineSeparator
protected void writeLineSeparator() throws IOException写行分隔符。 这直接调用output以及将lineLength设置为0。- 异常
-
IOException- 任何I / O错误 - 从以下版本开始:
- 1.3
-
write
protected void write(char[] chars, int startIndex, int length) throws IOException所有写入方法都调用到这一个中。 如果getCanWrapLines()返回false,这将调用output,每个序列的chars不包含NEWLINE,其次是调用writeLineSeparator。 另一方面,如果getCanWrapLines()返回true,这将分割字符串,如有必要,所以getLineLength是荣幸的。 唯一的例外是如果当前字符串不包含空格,并且不适合在这种情况下行长度将超过getLineLength。- 参数
-
chars- 要输出的字符 -
startIndex- 起始索引 -
length- 输出长度 - 异常
-
IOException- 在任何I / O错误 - 从以下版本开始:
- 1.3
-
writeAttributes
protected void writeAttributes(AttributeSet attr) throws IOException
将属性集写入“<name> = <value>”对。 遇到IO时,会抛出IOException。- 参数
-
attr- 属性集。 - 异常
-
IOException- 在任何I / O错误
-
output
protected void output(char[] content, int start, int length) throws IOException写出内容的最后一站。 所有的写入方法最终都会使用这个方法,这个方法在Writer上调用了write。此方法还会根据
length更新行长度。 如果调用此方法来输出换行符,则当前行长度将不再重新设置为不再有效。 如果由呼叫者来做到这一点。 使用writeLineSeparator写出一个换行符,它将更新当前的行长度。- 参数
-
content- 要输出的字符 -
start- 起始索引 -
length- 输出长度 - 异常
-
IOException- 任何I / O错误 - 从以下版本开始:
- 1.3
-
-