On this page
Class MinimalHTMLWriter
public class MinimalHTMLWriter extends AbstractWriter
<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>
Field Summary
Fields declared in class javax.swing.text.AbstractWriter
NEWLINE
Constructor Summary
Constructor | Description |
---|---|
MinimalHTMLWriter |
Creates a new MinimalHTMLWriter.
|
MinimalHTMLWriter |
Creates a new MinimalHTMLWriter.
|
Method Summary
Modifier and Type | Method | Description |
---|---|---|
protected void |
endFontTag() |
This is no longer used, instead <span> will be written out.
|
protected boolean |
inFontTag() |
Returns true if we are currently in a <font> tag.
|
protected boolean |
isText |
Returns true if the element is a text element.
|
protected void |
startFontTag |
This is no longer used, instead <span> will be written out.
|
protected void |
text |
Writes out text.
|
void |
write() |
Generates HTML output from a StyledDocument.
|
protected void |
writeAttributes |
Writes out all the attributes for the following types: StyleConstants.ParagraphConstants, StyleConstants.CharacterConstants, StyleConstants.FontConstants, StyleConstants.ColorConstants.
|
protected void |
writeBody() |
Iterates over the elements in the document and processes elements based on whether they are branch elements or leaf elements.
|
protected void |
writeComponent |
Responsible for handling Component Elements; deliberately unimplemented.
|
protected void |
writeContent |
Writes out the attribute set in an HTML-compliant manner.
|
protected void |
writeEndParagraph() |
Emits an end tag for a <p> tag.
|
protected void |
writeEndTag |
Writes out an end tag appropriately indented.
|
protected void |
writeHeader() |
Writes out the <head> and <style> tags, and then invokes writeStyles() to write out all the named styles as the content of the <style> tag.
|
protected void |
writeHTMLTags |
Generates bold <b>, italic <i>, and <u> tags for the text based on its attribute settings.
|
protected void |
writeImage |
Responsible for handling Icon Elements; deliberately unimplemented.
|
protected void |
writeLeaf |
Responsible for writing out other non-text leaf elements.
|
protected void |
writeNonHTMLAttributes |
Writes out the remaining character-level attributes (attributes other than bold, italic, and underline) in an HTML-compliant way.
|
protected void |
writeStartParagraph |
Emits the start tag for a paragraph.
|
protected void |
writeStartTag |
Writes out a start tag appropriately indented.
|
protected void |
writeStyles() |
Writes out all the named styles as the content of the <style> tag.
|
Methods declared in class 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
Constructor Details
MinimalHTMLWriter
public MinimalHTMLWriter(Writer w, StyledDocument doc)
- Parameters:
w
- Writerdoc
- StyledDocument
MinimalHTMLWriter
public MinimalHTMLWriter(Writer w, StyledDocument doc, int pos, int len)
- Parameters:
w
- Writerdoc
- StyledDocumentpos
- The location in the document to fetch the content.len
- The amount to write out.
Method Details
write
public void write() throws IOException, BadLocationException
- Specified by:
write
in classAbstractWriter
- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
writeAttributes
protected void writeAttributes(AttributeSet attr) throws IOException
- Overrides:
writeAttributes
in classAbstractWriter
- Parameters:
attr
- an AttributeSet.- Throws:
IOException
- on any I/O error
text
protected void text(Element elem) throws IOException, BadLocationException
- Overrides:
text
in classAbstractWriter
- Parameters:
elem
- an Element.- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
writeStartTag
protected void writeStartTag(String tag) throws IOException
- Parameters:
tag
- a start tag- Throws:
IOException
- on any I/O error
writeEndTag
protected void writeEndTag(String endTag) throws IOException
- Parameters:
endTag
- an end tag- Throws:
IOException
- on any I/O error
writeHeader
protected void writeHeader() throws IOException
- Throws:
IOException
- on any I/O error
writeStyles
protected void writeStyles() throws IOException
- Throws:
IOException
- on any I/O error
writeBody
protected void writeBody() throws IOException, BadLocationException
- Throws:
IOException
- on any I/O errorBadLocationException
- if we are in an invalid location within the document.
writeEndParagraph
protected void writeEndParagraph() throws IOException
- Throws:
IOException
- on any I/O error
writeStartParagraph
protected void writeStartParagraph(Element elem) throws IOException
- Parameters:
elem
- an element- Throws:
IOException
- on any I/O error
writeLeaf
protected void writeLeaf(Element elem) throws IOException
- Parameters:
elem
- an element- Throws:
IOException
- on any I/O error
writeImage
protected void writeImage(Element elem) throws IOException
- Parameters:
elem
- an element of type StyleConstants.IconElementName- Throws:
IOException
- if I/O error occured.
writeComponent
protected void writeComponent(Element elem) throws IOException
- Parameters:
elem
- an element of type StyleConstants.ComponentElementName- Throws:
IOException
- if I/O error occured.
isText
protected boolean isText(Element elem)
- Parameters:
elem
- an element- Returns:
true
if the element is a text element.
writeContent
protected void writeContent(Element elem, boolean needsIndenting) throws IOException, BadLocationException
- Parameters:
elem
- an elementneedsIndenting
- indention will be added ifneedsIndenting
istrue
- Throws:
IOException
- on any I/O errorBadLocationException
- if pos represents an invalid location within the document.
writeHTMLTags
protected void writeHTMLTags(AttributeSet attr) throws IOException
- Parameters:
attr
- a set of attributes- Throws:
IOException
- on any I/O error
writeNonHTMLAttributes
protected void writeNonHTMLAttributes(AttributeSet attr) throws IOException
- Parameters:
attr
- a set of attributes- Throws:
IOException
- on any I/O error
inFontTag
protected boolean inFontTag()
- Returns:
true
if we are currently in a <font> tag.
endFontTag
protected void endFontTag() throws IOException
Writes out an end tag for the <font> tag.
- Throws:
IOException
- on any I/O error
startFontTag
protected void startFontTag(String style) throws IOException
Writes out a start tag for the <font> tag. Because font tags cannot be nested, this method closes out any enclosing font tag before writing out a new start tag.
- Parameters:
style
- a font style- Throws:
IOException
- on any I/O error
© 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/html/MinimalHTMLWriter.html