Class RichTextPainter
java.lang.Object
org.eclipse.nebula.widgets.richtext.RichTextPainter
public class RichTextPainter
extends java.lang.Object
The
RichTextPainter
is used to parse and render HTML input to a GC
. It works well
with HTML input generated by ckeditor.-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTRIBUTE_PARAGRAPH_MARGIN_LEFT
static java.lang.String
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN
static java.lang.String
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT
static java.lang.String
ATTRIBUTE_STYLE
static java.lang.String
ATTRIBUTE_STYLE_BACKGROUND_COLOR
static java.lang.String
ATTRIBUTE_STYLE_COLOR
static java.lang.String
ATTRIBUTE_STYLE_FONT_FAMILY
static java.lang.String
ATTRIBUTE_STYLE_FONT_SIZE
static java.lang.String[]
BULLETS
static java.lang.String
CONTROL_CHARACTER_REGEX
(package private) javax.xml.stream.XMLInputFactory
factory
static java.lang.String
FAKE_ROOT_TAG_END
static java.lang.String
FAKE_ROOT_TAG_START
static java.lang.String
SPACE
static java.lang.String
TAG_BOLD
static java.lang.String
TAG_BR
static java.lang.String
TAG_EM
static java.lang.String
TAG_LIST_ITEM
static java.lang.String
TAG_ORDERED_LIST
static java.lang.String
TAG_PARAGRAPH
static java.lang.String
TAG_SPAN
static java.lang.String
TAG_STRIKETHROUGH
static java.lang.String
TAG_STRONG
static java.lang.String
TAG_UNDERLINE
static java.lang.String
TAG_UNORDERED_LIST
-
Constructor Summary
Constructors Constructor Description RichTextPainter()
Create a newRichTextPainter
with disabled word wrapping.RichTextPainter(boolean wordWrap)
Create a newRichTextPainter
. -
Method Summary
Modifier and Type Method Description protected int
calculateListIndentation(org.eclipse.swt.graphics.GC gc)
Calculates the indentation to use for list items.protected java.lang.String
getBulletCharacter(int listDepth)
int
getParagraphSpace()
org.eclipse.swt.graphics.Point
getPreferredSize()
Returns the preferred size of the content.void
paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds)
Processes the HTML input and paints the result to the givenGC
.protected void
paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean render)
Processes the HTML input.void
preCalculate(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean calculateWithWrapping)
Processes the HTML input to calculate the preferred size.void
setEntityReplacer(EntityReplacer entityReplacer)
Set anEntityReplacer
that should be used to replaceEntityReference
s in the HTML snippet to parse.void
setParagraphSpace(int paragraphSpace)
void
setWordSplitRegex(java.lang.String wordSplitRegex)
-
Field Details
-
TAG_SPAN
public static final java.lang.String TAG_SPAN- See Also:
- Constant Field Values
-
TAG_STRONG
public static final java.lang.String TAG_STRONG- See Also:
- Constant Field Values
-
TAG_BOLD
public static final java.lang.String TAG_BOLD- See Also:
- Constant Field Values
-
TAG_EM
public static final java.lang.String TAG_EM- See Also:
- Constant Field Values
-
TAG_UNDERLINE
public static final java.lang.String TAG_UNDERLINE- See Also:
- Constant Field Values
-
TAG_STRIKETHROUGH
public static final java.lang.String TAG_STRIKETHROUGH- See Also:
- Constant Field Values
-
TAG_PARAGRAPH
public static final java.lang.String TAG_PARAGRAPH- See Also:
- Constant Field Values
-
TAG_UNORDERED_LIST
public static final java.lang.String TAG_UNORDERED_LIST- See Also:
- Constant Field Values
-
TAG_ORDERED_LIST
public static final java.lang.String TAG_ORDERED_LIST- See Also:
- Constant Field Values
-
TAG_LIST_ITEM
public static final java.lang.String TAG_LIST_ITEM- See Also:
- Constant Field Values
-
TAG_BR
public static final java.lang.String TAG_BR- See Also:
- Constant Field Values
-
ATTRIBUTE_STYLE
public static final java.lang.String ATTRIBUTE_STYLE- See Also:
- Constant Field Values
-
ATTRIBUTE_STYLE_COLOR
public static final java.lang.String ATTRIBUTE_STYLE_COLOR- See Also:
- Constant Field Values
-
ATTRIBUTE_STYLE_BACKGROUND_COLOR
public static final java.lang.String ATTRIBUTE_STYLE_BACKGROUND_COLOR- See Also:
- Constant Field Values
-
ATTRIBUTE_STYLE_FONT_SIZE
public static final java.lang.String ATTRIBUTE_STYLE_FONT_SIZE- See Also:
- Constant Field Values
-
ATTRIBUTE_STYLE_FONT_FAMILY
public static final java.lang.String ATTRIBUTE_STYLE_FONT_FAMILY- See Also:
- Constant Field Values
-
ATTRIBUTE_PARAGRAPH_MARGIN_LEFT
public static final java.lang.String ATTRIBUTE_PARAGRAPH_MARGIN_LEFT- See Also:
- Constant Field Values
-
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN
public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN- See Also:
- Constant Field Values
-
ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT
public static final java.lang.String ATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHT- See Also:
- Constant Field Values
-
CONTROL_CHARACTER_REGEX
public static final java.lang.String CONTROL_CHARACTER_REGEX- See Also:
- Constant Field Values
-
FAKE_ROOT_TAG_START
public static final java.lang.String FAKE_ROOT_TAG_START- See Also:
- Constant Field Values
-
FAKE_ROOT_TAG_END
public static final java.lang.String FAKE_ROOT_TAG_END- See Also:
- Constant Field Values
-
BULLETS
public static final java.lang.String[] BULLETS -
SPACE
public static final java.lang.String SPACE- See Also:
- Constant Field Values
-
factory
javax.xml.stream.XMLInputFactory factory
-
-
Constructor Details
-
RichTextPainter
public RichTextPainter()Create a newRichTextPainter
with disabled word wrapping. -
RichTextPainter
public RichTextPainter(boolean wordWrap)Create a newRichTextPainter
.- Parameters:
wordWrap
-true
if automatic word wrapping should be enabled,false
if not.
-
-
Method Details
-
preCalculate
public void preCalculate(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean calculateWithWrapping)Processes the HTML input to calculate the preferred size. Does not perform rendering.- Parameters:
html
- The HTML string to process.gc
- TheGC
to operate on.bounds
- The available space for painting.calculateWithWrapping
-true
if calculation should be performed with enabled word wrapping,false
if not
-
paintHTML
public void paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds)Processes the HTML input and paints the result to the givenGC
.- Parameters:
html
- The HTML string to process.gc
- TheGC
to operate on.bounds
- The available space for painting.
-
paintHTML
protected void paintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean render)Processes the HTML input.- Parameters:
html
- The HTML string to process.gc
- TheGC
to operate on.bounds
- The available space for painting.render
-true
if the processing result should be painted to theGC
,false
if not (in case of pre calculation).
-
calculateListIndentation
protected int calculateListIndentation(org.eclipse.swt.graphics.GC gc)Calculates the indentation to use for list items.- Parameters:
gc
- The currentGC
for calculating the text extend.- Returns:
- The indentation to use for list items.
-
getBulletCharacter
protected java.lang.String getBulletCharacter(int listDepth)- Parameters:
listDepth
- The list depth of the current list. Needs to be 1 for the top level list.- Returns:
- The bullet character to use for list items of an unordered list.
-
setEntityReplacer
Set anEntityReplacer
that should be used to replaceEntityReference
s in the HTML snippet to parse.- Parameters:
entityReplacer
- TheEntityReplacer
to use.
-
getPreferredSize
public org.eclipse.swt.graphics.Point getPreferredSize()Returns the preferred size of the content. It is calculated after processing the content.- Returns:
- The preferred size of the content.
- See Also:
preCalculate(String, GC, Rectangle, boolean)
-
getParagraphSpace
public int getParagraphSpace()- Returns:
- The space that should be used before and after a paragraph.
Note: Between two paragraphs the paragraphSpace * 2 is added as space.
-
setParagraphSpace
public void setParagraphSpace(int paragraphSpace)- Parameters:
paragraphSpace
- The space that should be applied before and after a paragraph.
Note: Between two paragraphs the paragraphSpace * 2 is added as space.
-
setWordSplitRegex
public void setWordSplitRegex(java.lang.String wordSplitRegex)- Parameters:
wordSplitRegex
- The regular expression that will be used to determine word boundaries. The default is "\s".- Since:
- 1.3.0
-