- java.lang.Object
-
- javax.swing.text.AbstractWriter
-
- 已知直接子类:
-
HTMLWriter,MinimalHTMLWriter
public abstract class AbstractWriter extends Object
AbstractWriter是一个抽象类,它实际上完成了写出包含属性的元素树的工作。 就每行写出多少而言,编写器默认为100.但是这个值可以由子类设置。
-
-
字段汇总
字段 变量和类型 字段 描述 protected static charNEWLINE文本包如何为换行符建模。
-
构造方法摘要
构造方法 变量 构造器 描述 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。
-
方法摘要
所有方法 实例方法 抽象方法 具体的方法 变量和类型 方法 描述 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)设置用于表示换行符的String。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()写行分隔符。
-
-
-
字段详细信息
-
NEWLINE
protected static final char NEWLINE
文本包如何为换行符建模。- 另请参见:
-
getLineSeparator(), 常数字段值
-
-
构造方法详细信息
-
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()
返回是否可以换行。 如果这是假的,则不会输出lineSeparator。- 结果
- 线条是否可以包裹
- 从以下版本开始:
- 1.3
-
setIndentSpace
protected void setIndentSpace(int space)
允许子类指定缩进映射到的空格数。 缩进发生时,缩进级别乘以此映射。 默认值为2。- 参数
-
space- 表示缩进映射空间的int。
-
getIndentSpace
protected int getIndentSpace()
返回要缩进的空间量。- 结果
- 缩进的空间量
- 从以下版本开始:
- 1.3
-
setLineSeparator
public void setLineSeparator(String value)
设置用于表示换行符的String。 这是在构造函数中从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- 一个ch。 - 异常
-
IOException- 关于任何I / O错误
-
write
protected void write(String content) throws IOException
写出一个字符串。 这是为了调用带有char []的write方法。- 参数
-
content- 一个字符串。 - 异常
-
IOException- 有关任何I / O错误
-
writeLineSeparator
protected void writeLineSeparator() throws IOException写行分隔符。 这output直接调用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>”对。 遇到时抛出IOException。- 参数
-
attr- 一个AttributeSet。 - 异常
-
IOException- 关于任何I / O错误
-
output
protected void output(char[] content, int start, int length) throws IOException写出内容的最后一站。 所有的write方法最终都会使用这个方法,它在Writer上调用write。此方法还会根据
length更新行长度。 如果调用此方法输出换行符,则需要重置当前行长度,因为它将不再有效。 如果由呼叫者来做这件事。 使用writeLineSeparator写出换行符,该属性将更新当前行长度。- 参数
-
content- 要输出的字符 -
start- 起始索引 -
length- 输出长度 - 异常
-
IOException- 关于任何I / O错误 - 从以下版本开始:
- 1.3
-
-