Class RichTextPainter
- java.lang.Object
-
- org.eclipse.nebula.widgets.richtext.RichTextPainter
-
public class RichTextPainter extends java.lang.ObjectTheRichTextPainteris used to parse and render HTML input to aGC. It works well with HTML input generated by ckeditor.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTRIBUTE_PARAGRAPH_MARGIN_LEFTstatic java.lang.StringATTRIBUTE_PARAGRAPH_TEXT_ALIGNstatic java.lang.StringATTRIBUTE_PARAGRAPH_TEXT_ALIGN_VALUE_RIGHTstatic java.lang.StringATTRIBUTE_STYLEstatic java.lang.StringATTRIBUTE_STYLE_BACKGROUND_COLORstatic java.lang.StringATTRIBUTE_STYLE_COLORstatic java.lang.StringATTRIBUTE_STYLE_FONT_FAMILYstatic java.lang.StringATTRIBUTE_STYLE_FONT_SIZEstatic java.lang.String[]BULLETSstatic java.lang.StringCONTROL_CHARACTER_REGEXprivate EntityReplacerentityReplacer(package private) javax.xml.stream.XMLInputFactoryfactorystatic java.lang.StringFAKE_ROOT_TAG_ENDstatic java.lang.StringFAKE_ROOT_TAG_STARTprivate intparagraphSpaceprivate org.eclipse.swt.graphics.PointpreferredSizestatic java.lang.StringSPACEstatic java.lang.StringTAG_BRstatic java.lang.StringTAG_EMstatic java.lang.StringTAG_LIST_ITEMstatic java.lang.StringTAG_ORDERED_LISTstatic java.lang.StringTAG_PARAGRAPHstatic java.lang.StringTAG_SPANstatic java.lang.StringTAG_STRIKETHROUGHstatic java.lang.StringTAG_STRONGstatic java.lang.StringTAG_UNDERLINEstatic java.lang.StringTAG_UNORDERED_LISTprivate java.lang.StringwordSplitRegexprivate booleanwordWrap
-
Constructor Summary
Constructors Constructor Description RichTextPainter()Create a newRichTextPainterwith disabled word wrapping.RichTextPainter(boolean wordWrap)Create a newRichTextPainter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private LinePainteraddInstruction(org.eclipse.swt.graphics.GC gc, int availableWidth, java.util.Collection<LinePainter> lines, LinePainter currentLine, TagProcessingState state, PaintInstruction instruction)protected intcalculateListIndentation(org.eclipse.swt.graphics.GC gc)Calculates the indentation to use for list items.private LinePaintercreateNewLine(java.util.Collection<LinePainter> lines)protected java.lang.StringgetBulletCharacter(int listDepth)intgetParagraphSpace()org.eclipse.swt.graphics.PointgetPreferredSize()Returns the preferred size of the content.private java.util.Map<java.lang.String,java.lang.String>getStyleProperties(java.lang.String styleString)private AlignmentStylehandleAlignmentConfiguration(javax.xml.stream.events.StartElement element)private PaintInstructionhandleStyleConfiguration(javax.xml.stream.events.StartElement element, java.util.Deque<SpanElement> spanStack, TagProcessingState state)voidpaintHTML(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 voidpaintHTML(java.lang.String html, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds, boolean render)Processes the HTML input.voidpreCalculate(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.voidsetEntityReplacer(EntityReplacer entityReplacer)Set anEntityReplacerthat should be used to replaceEntityReferences in the HTML snippet to parse.voidsetParagraphSpace(int paragraphSpace)voidsetWordSplitRegex(java.lang.String wordSplitRegex)
-
-
-
Field Detail
-
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_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
-
paragraphSpace
private int paragraphSpace
-
wordWrap
private boolean wordWrap
-
preferredSize
private final org.eclipse.swt.graphics.Point preferredSize
-
factory
javax.xml.stream.XMLInputFactory factory
-
entityReplacer
private EntityReplacer entityReplacer
-
wordSplitRegex
private java.lang.String wordSplitRegex
-
-
Constructor Detail
-
RichTextPainter
public RichTextPainter()
Create a newRichTextPainterwith disabled word wrapping.
-
RichTextPainter
public RichTextPainter(boolean wordWrap)
Create a newRichTextPainter.- Parameters:
wordWrap-trueif automatic word wrapping should be enabled,falseif not.
-
-
Method Detail
-
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- TheGCto operate on.bounds- The available space for painting.calculateWithWrapping-trueif calculation should be performed with enabled word wrapping,falseif 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- TheGCto 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- TheGCto operate on.bounds- The available space for painting.render-trueif the processing result should be painted to theGC,falseif not (in case of pre calculation).
-
addInstruction
private LinePainter addInstruction(org.eclipse.swt.graphics.GC gc, int availableWidth, java.util.Collection<LinePainter> lines, LinePainter currentLine, TagProcessingState state, PaintInstruction instruction)
-
createNewLine
private LinePainter createNewLine(java.util.Collection<LinePainter> lines)
-
handleAlignmentConfiguration
private AlignmentStyle handleAlignmentConfiguration(javax.xml.stream.events.StartElement element)
-
handleStyleConfiguration
private PaintInstruction handleStyleConfiguration(javax.xml.stream.events.StartElement element, java.util.Deque<SpanElement> spanStack, TagProcessingState state)
-
getStyleProperties
private java.util.Map<java.lang.String,java.lang.String> getStyleProperties(java.lang.String styleString)
-
calculateListIndentation
protected int calculateListIndentation(org.eclipse.swt.graphics.GC gc)
Calculates the indentation to use for list items.- Parameters:
gc- The currentGCfor 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
public void setEntityReplacer(EntityReplacer entityReplacer)
Set anEntityReplacerthat should be used to replaceEntityReferences in the HTML snippet to parse.- Parameters:
entityReplacer- TheEntityReplacerto 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
-
-