Top Description Fields Constructors Methods
org.eclipse.swt.custom

pack-priv abstract Class StyledTextWriterBase

extends TextWriter
Class Inheritance
Known Direct Subclasses
org.eclipse.swt.custom.HTMLWriter, org.eclipse.swt.custom.RTFWriter
Imports
org.eclipse.swt.*, org.eclipse.swt.graphics.*

The base class encapsulating the logic used to write styled content as a rich format (HTML, RTF, maybe more). It contains the common parts: iterates on lines, then on each line iterates on plain text and StyleRange(s).

toString() is guaranteed to return a valid formatted string only after close() has been called.

Whole and partial lines and line breaks can be written. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget. All styles are applied to the stream like they are rendered by the widget. In addition, the widget font name and size is used for the whole text.

Field Summary

Modifier and TypeField and Description
pack-priv final StyledText

Constructor Summary

AccessConstructor and Description
public
StyledTextWriterBase(StyledText
the widget to produce the RTF from
styledText
,
int
start offset of content to write, 0 based from beginning of document
start
,
int
length of content to write
length
)

Creates a writer that processed content starting at offset "start" in the document.

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract String

Returns:

the escaped text
escapeText
(String
the text to escape
text
)

Takes plain text and returns the same text escaped using the rules of the output format.

pack-priv abstract void
writeEmptyLine()

Invoked at the end of each line, writeLineEnd, if there was no text output.

pack-priv void
writeEscaped(String
string to copy a segment from. Must not contain line breaks. Line breaks should be written using writeLineDelimiter()
string
,
int
start offset of segment. 0 based.
start
,
int
end offset of segment
end
)

Appends the specified segment of "string" to the output data.

pack-priv abstract void
writeHeader()

Writes the part that only shows once, at the beginning of the output data.

public void
writeLine(String
line text to write. Must not contain line breaks Line breaks should be written using writeLineDelimiter(String)
line
,
int
offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.
lineOffset
)

Overrides org.eclipse.swt.custom.TextWriter.writeLine.

Appends the specified line text to the output data.
pack-priv void
writeLineEnd(String
the leftover text prepared by writeLineStart
prepared
)

Invoked at the end of of each line in the original widget.

pack-priv abstract String

Returns:

the text to append at the end of the line
writeLineStart
(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)

Invoked at the beginning of each line in the original widget.

pack-priv void
writeSpanEnd(String
the leftover text prepared by writeSpanStart
prepared
)

Invoked at the end of of each styled span fragment in the original widget.

pack-priv abstract String

Returns:

the text to append at the end of the styled span
writeSpanStart
(StyleRange style)

Invoked at the beginning of each styled span fragment in the original widget.

pack-priv void
writeStyledLine(String
line text to write as RTF. Must not contain line breaks Line breaks should be written using writeLineDelimiter()
line
,
int
offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.
lineOffset
,
int[] ranges, StyleRange[]
styles to use for formatting. Must not be null.
styles
,
Color
line background color to use for formatting. May be null.
lineBackground
,
int indent, int verticalIndent, int alignment, boolean justify)

Appends the specified line text to the output data.

Inherited from org.eclipse.swt.custom.TextWriter:
closegetCharCountgetStartisClosedtoStringwritewritewritewritewriteLineDelimiter

Field Detail

styledTextback to summary
pack-priv final StyledText styledText

Constructor Detail

StyledTextWriterBaseback to summary
public StyledTextWriterBase(StyledText styledText, int start, int length)

Creates a writer that processed content starting at offset "start" in the document. start and length can be set to specify partial lines.

Parameters
styledText:StyledText

the widget to produce the RTF from

start:int

start offset of content to write, 0 based from beginning of document

length:int

length of content to write

Method Detail

escapeTextback to summary
pack-priv abstract String escapeText(String text)

Takes plain text and returns the same text escaped using the rules of the output format.

Parameters
text:String

the text to escape

Returns:String

the escaped text

writeEmptyLineback to summary
pack-priv abstract void writeEmptyLine()

Invoked at the end of each line, writeLineEnd, if there was no text output.

This is needed for HTML, which does not render empty paragraphs.

writeEscapedback to summary
pack-priv void writeEscaped(String string, int start, int end)

Appends the specified segment of "string" to the output data. Copy from start up to, but excluding, end.

Parameters
string:String

string to copy a segment from. Must not contain line breaks. Line breaks should be written using writeLineDelimiter()

start:int

start offset of segment. 0 based.

end:int

end offset of segment

writeHeaderback to summary
pack-priv abstract void writeHeader()

Writes the part that only shows once, at the beginning of the output data.

writeLineback to summary
public void writeLine(String line, int lineOffset)

Overrides org.eclipse.swt.custom.TextWriter.writeLine.

Appends the specified line text to the output data. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget.

Parameters
line:String

line text to write. Must not contain line breaks Line breaks should be written using writeLineDelimiter(String)

lineOffset:int

offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.

Annotations
@Override
Exceptions
SWTException:
ERROR_IO when the writer is closed.
writeLineEndback to summary
pack-priv void writeLineEnd(String prepared)

Invoked at the end of of each line in the original widget.

It receives whatever text writeLineStart(Color, int, int, int, boolean) returned and it will output it. A class might override it to do more.

Parameters
prepared:String

the leftover text prepared by writeLineStart

writeLineStartback to summary
pack-priv abstract String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)

Invoked at the beginning of each line in the original widget.

It should output whatever tags are appropriate to start a new line in the output format.
It will return the text that has to be output at the end of the line.

Returns:String

the text to append at the end of the line

writeSpanEndback to summary
pack-priv void writeSpanEnd(String prepared)

Invoked at the end of of each styled span fragment in the original widget.

It receives whatever text writeSpanStart(StyleRange) returned and it will output it. A class might override it to do more.

Parameters
prepared:String

the leftover text prepared by writeSpanStart

writeSpanStartback to summary
pack-priv abstract String writeSpanStart(StyleRange style)

Invoked at the beginning of each styled span fragment in the original widget.

It should output whatever tags are appropriate to start a formatted span in the output format.
It will return the text that has to be output at the end of the span (to close it).

Returns:String

the text to append at the end of the styled span

writeStyledLineback to summary
pack-priv void writeStyledLine(String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)

Appends the specified line text to the output data.

Use the colors and font styles specified in styles and lineBackground. Formatting is written to reflect the text rendering by the text widget. Style background colors take precedence over the line background color.

Parameters
line:String

line text to write as RTF. Must not contain line breaks Line breaks should be written using writeLineDelimiter()

lineOffset:int

offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.

styles:StyleRange[]

styles to use for formatting. Must not be null.

lineBackground:Color

line background color to use for formatting. May be null.