java.lang.Object
javax.swing.text.AbstractWriter
javax.swing.text.html.MinimalHTMLWriter
MinimalHTMLWriter 是 HTMLEditorKit 使用的后备编写器,用于为不是由 EditorKit 生成的文档写出 HTML。文档格式为:
<html>
<head>
<style>
<!-- list of named styles
p.normal {
font-family: SansSerif;
margin-height: 0;
font-size: 14
}
-->
</style>
</head>
<body>
<p style=normal>
Bold, italic, and underline attributes
of the run are emitted as HTML tags.
The remaining attributes are emitted as
part of the style attribute of a <span> tag.
The syntax is similar to inline styles.
</p>
</body>
</html>
-
字段摘要
在类 javax.swing.text.AbstractWriter 中声明的字段
NEWLINE -
构造方法总结
构造方法构造方法描述MinimalHTMLWriter(Writer w, StyledDocument doc) 创建一个新的 MinimalHTMLWriter。MinimalHTMLWriter(Writer w, StyledDocument doc, int pos, int len) 创建一个新的 MinimalHTMLWriter。 -
方法总结
修饰符和类型方法描述protected void这不再使用,而是 <span> 将被写出。protected boolean如果我们当前位于 <font> 标记中,则返回 true。protected boolean如果元素是文本元素,则返回 true。protected voidstartFontTag(String style) 这不再使用,而是 <span> 将被写出。protected void写出文本。voidwrite()从 StyledDocument 生成 HTML 输出。protected voidwriteAttributes(AttributeSet attr) 写出以下类型的所有属性:StyleConstants.ParagraphConstants、StyleConstants.CharacterConstants、StyleConstants.FontConstants、StyleConstants.ColorConstants。protected void迭代文档中的元素并根据它们是分支元素还是叶元素来处理元素。protected voidwriteComponent(Element elem) 负责处理Component Elements;故意未实现。protected voidwriteContent(Element elem, boolean needsIndenting) 以符合 HTML 的方式写出属性集。protected void发出 <p> 标签的结束标签。protected voidwriteEndTag(String endTag) 写出适当缩进的结束标记。protected void写出 <head> 和 <style> 标签,然后调用 writeStyles() 将所有命名样式写出作为 <style> 标签的内容。protected voidwriteHTMLTags(AttributeSet attr) 根据文本的属性设置为文本生成粗体 <b>、斜体 <i> 和 <u> 标记。protected voidwriteImage(Element elem) 负责处理图标元素;故意未实现。protected void负责写出其他非文本叶元素。protected void以符合 HTML 的方式写出剩余的字符级属性(粗体、斜体和下划线以外的属性)。protected voidwriteStartParagraph(Element elem) 发出段落的开始标记。protected voidwriteStartTag(String tag) 写出适当缩进的开始标记。protected void写出所有命名样式作为 <style> 标签的内容。在类 javax.swing.text.AbstractWriter 中声明的方法
decrIndent, getCanWrapLines, getCurrentLineLength, getDocument, getElementIterator, getEndOffset, getIndentLevel, getIndentSpace, getLineLength, getLineSeparator, getStartOffset, getText, getWriter, incrIndent, indent, inRange, isLineEmpty, output, setCanWrapLines, setCurrentLineLength, setIndentSpace, setLineLength, setLineSeparator, write, write, write, writeLineSeparator
-
构造方法详细信息
-
MinimalHTMLWriter
创建一个新的 MinimalHTMLWriter。- 参数:
w- 作家doc- 样式文件
-
MinimalHTMLWriter
创建一个新的 MinimalHTMLWriter。- 参数:
w- 作家doc- 样式文件pos- 文档中获取内容的位置。len- 要写出的数量。
-
-
方法详情
-
write
从 StyledDocument 生成 HTML 输出。- 指定者:
write在类AbstractWriter中- 抛出:
IOException- 出现任何 I/O 错误BadLocationException- 如果 pos 表示文档中的无效位置。
-
writeAttributes
写出以下类型的所有属性:StyleConstants.ParagraphConstants、StyleConstants.CharacterConstants、StyleConstants.FontConstants、StyleConstants.ColorConstants。属性名称和值由冒号分隔。每对由分号分隔。- 重写:
writeAttributes在类AbstractWriter中- 参数:
attr- 一个属性集。- 抛出:
IOException- 出现任何 I/O 错误
-
text
写出文本。- 重写:
text在类AbstractWriter中- 参数:
elem- 一个元素。- 抛出:
IOException- 出现任何 I/O 错误BadLocationException- 如果 pos 表示文档中的无效位置。
-
writeStartTag
写出适当缩进的开始标记。还增加缩进级别。- 参数:
tag- 开始标签- 抛出:
IOException- 出现任何 I/O 错误
-
writeEndTag
写出适当缩进的结束标记。同时减少缩进级别。- 参数:
endTag- 结束标记- 抛出:
IOException- 出现任何 I/O 错误
-
writeHeader
写出 <head> 和 <style> 标签,然后调用 writeStyles() 将所有命名样式写出作为 <style> 标签的内容。内容被有效的 HTML 注释标记包围,以确保文档在不支持该标记的应用程序/浏览器中可见。- 抛出:
IOException- 出现任何 I/O 错误
-
writeStyles
写出所有命名样式作为 <style> 标签的内容。- 抛出:
IOException- 出现任何 I/O 错误
-
writeBody
迭代文档中的元素并根据它们是分支元素还是叶元素来处理元素。此方法专门处理作为文本的叶元素。- 抛出:
IOException- 出现任何 I/O 错误BadLocationException- 如果我们在文档中的无效位置。
-
writeEndParagraph
发出 <p> 标签的结束标签。在写出标签之前,此方法确保已打开的所有其他标签都适当关闭。- 抛出:
IOException- 出现任何 I/O 错误
-
writeStartParagraph
发出段落的开始标记。如果段落有与之关联的命名样式,则此方法还会为 <p> 标记生成一个类属性,并将其值设置为样式的名称。- 参数:
elem- 一个元素- 抛出:
IOException- 出现任何 I/O 错误
-
writeLeaf
负责写出其他非文本叶元素。- 参数:
elem- 一个元素- 抛出:
IOException- 出现任何 I/O 错误
-
writeImage
负责处理图标元素;故意未实现。如何实现这个方法是一个策略问题。例如,如果您要生成一个 <img> 标签,您应该如何表示 src 属性(图像的位置)?在某些情况下,它可能是一个 URL,在其他情况下,它可能是从流中读取的。- 参数:
elem- StyleConstants.IconElementName 类型的元素- 抛出:
IOException- 如果发生 I/O 错误。
-
writeComponent
负责处理Component Elements;故意未实现。如何实现此方法是策略问题。- 参数:
elem- StyleConstants.ComponentElementName 类型的元素- 抛出:
IOException- 如果发生 I/O 错误。
-
isText
如果元素是文本元素,则返回 true。- 参数:
elem- 一个元素- 返回:
true如果元素是文本元素。
-
writeContent
protected void writeContent(Element elem, boolean needsIndenting) throws IOException , BadLocationException 以符合 HTML 的方式写出属性集。- 参数:
elem- 一个元素needsIndenting- 如果needsIndenting是true,将添加缩进- 抛出:
IOException- 出现任何 I/O 错误BadLocationException- 如果 pos 表示文档中的无效位置。
-
writeHTMLTags
根据文本的属性设置为文本生成粗体 <b>、斜体 <i> 和 <u> 标记。- 参数:
attr- 一组属性- 抛出:
IOException- 出现任何 I/O 错误
-
writeNonHTMLAttributes
以符合 HTML 的方式写出剩余的字符级属性(粗体、斜体和下划线以外的属性)。鉴于字体系列和字体大小等属性没有直接映射到 HTML 标记,因此生成了一个 <span> 标记,并将其样式属性设置为包含其余属性的列表,就像内联样式一样。- 参数:
attr- 一组属性- 抛出:
IOException- 出现任何 I/O 错误
-
inFontTag
protected boolean inFontTag()如果我们当前位于 <font> 标记中,则返回 true。- 返回:
true如果我们当前位于 <font> 标记中。
-
endFontTag
这不再使用,而是 <span> 将被写出。写出 <font> 标签的结束标签。
- 抛出:
IOException- 出现任何 I/O 错误
-
startFontTag
这不再使用,而是 <span> 将被写出。写出 <font> 标签的开始标签。因为不能嵌套字体标签,所以此方法在写出新的开始标签之前关闭所有封闭的字体标签。
- 参数:
style- 字体样式- 抛出:
IOException- 出现任何 I/O 错误
-