Class AbstractTextPainter
- All Implemented Interfaces:
ICellPainter
- Direct Known Subclasses:
TextPainter
,VerticalTextImagePainter
,VerticalTextPainter
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected boolean
static final String
static final String
static final String
protected int
static final Pattern
ThePattern
to find predefined new lines in the text to show.static final String
The regular expression to find predefined new lines in the text to show.protected final boolean
protected boolean
protected int
protected boolean
protected boolean
-
Constructor Summary
ConstructorDescriptionAbstractTextPainter
(boolean wrapText, boolean paintBg) AbstractTextPainter
(boolean wrapText, boolean paintBg, boolean calculate) AbstractTextPainter
(boolean wrapText, boolean paintBg, boolean calculateByTextLength, boolean calculateByTextHeight) AbstractTextPainter
(boolean wrapText, boolean paintBg, int spacing) AbstractTextPainter
(boolean wrapText, boolean paintBg, int spacing, boolean calculate) AbstractTextPainter
(boolean wrapText, boolean paintBg, int spacing, boolean calculateByTextLength, boolean calculateByTextHeight) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
calculatePadding
(ILayerCell cell, int availableLength) This method is used to determine the padding from the cell to the available length.protected String
convertDataType
(ILayerCell cell, IConfigRegistry configRegistry) Convert the data value of the cell using theIDisplayConverter
from theIConfigRegistry
protected int
getLengthFromCache
(org.eclipse.swt.graphics.GC gc, String text) Calculates the length of a given text by using the GC.int
Return the number of pixels that are added between lines.protected int
getNumberOfNewLines
(String text) Scans for new line characters and counts the number of lines for the given text.protected String
getTextToDisplay
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, int availableLength, String text) Computes dependent on the configuration of the TextPainter the text to display.boolean
boolean
boolean
boolean
boolean
Return whether word wrapping is enabled or not.boolean
protected void
paintDecoration
(IStyle cellStyle, org.eclipse.swt.graphics.GC gc, int x, int y, int length, int fontHeight) Render a decoration to the text, e.g.protected boolean
renderStrikethrough
(IStyle cellStyle) Checks if there is a strikethrough text decoration configured within the given cell style.protected boolean
renderUnderlined
(IStyle cellStyle) Checks if there is a underline text decoration configured within the given cell style.void
resetGC
(org.eclipse.swt.graphics.GC gc) Reset the GC to the original values.void
setCalculateByTextHeight
(boolean calculateByTextHeight) Configure whether the text painter should calculate the cell dimensions by containing text height.void
setCalculateByTextLength
(boolean calculateByTextLength) Configure whether the text painter should calculate the cell dimensions by containing text length.void
setCutText
(boolean cutText) Configure the behavior for text modification if not enough space is available in the cell for rendering the text.void
setLineSpacing
(int spacing) Specify the number of pixels that should be added between lines.protected abstract void
setNewMinLength
(ILayerCell cell, int contentLength) This method gets only called if automatic length calculation is enabled.void
setStrikethrough
(boolean strikethrough) Set if the text should be rendered strikethrough or not.void
setTrimText
(boolean trimText) void
setUnderline
(boolean underline) Set if the text should be rendered underlined or not.void
setupGCFromConfig
(org.eclipse.swt.graphics.GC gc, IStyle cellStyle) Setup the GC by the values defined in the given cell style.void
setWordWrapping
(boolean wordWrapping) Configure whether word wrapping should be enabled or not.void
setWrapText
(boolean wrapText) Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
getBackgroundColour, paintCell
Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
getCellPainterAt, getPreferredHeight, getPreferredWidth, getWrappedPainter, getWrappedPainterBounds, setWrappedPainter
-
Field Details
-
EMPTY
- See Also:
-
DOT
- See Also:
-
NEW_LINE_REGEX
The regular expression to find predefined new lines in the text to show. Is used for word wrapping to preserve user defined new lines. To be platform independent \n and \r and the combination of both are used to find user defined new lines.- See Also:
-
NEW_LINE_PATTERN
ThePattern
to find predefined new lines in the text to show. Is used for word wrapping to preserve user defined new lines. To be platform independent \n and \r and the combination of both are used to find user defined new lines.- Since:
- 2.3
- See Also:
-
LINE_SEPARATOR
-
wordWrapping
protected boolean wordWrapping- Since:
- 1.5
-
wrapText
protected boolean wrapText -
paintBg
protected final boolean paintBg -
paintFg
protected boolean paintFg -
spacing
protected int spacing -
lineSpacing
protected int lineSpacing- Since:
- 1.5
-
calculateByTextLength
protected boolean calculateByTextLength -
calculateByTextHeight
protected boolean calculateByTextHeight
-
-
Constructor Details
-
AbstractTextPainter
public AbstractTextPainter() -
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSE
-
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg, int spacing) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSEspacing
- The space between text and cell border
-
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg, boolean calculate) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSEcalculate
- tells the text painter to calculate the cell borders regarding the content
-
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg, boolean calculateByTextLength, boolean calculateByTextHeight) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSEcalculateByTextLength
- tells the text painter to calculate the cell border by containing text length. For horizontal text rendering, this means the width of the cell is calculated by content, for vertical text rendering the height is calculatedcalculateByTextHeight
- tells the text painter to calculate the cell border by containing text height. For horizontal text rendering, this means the height of the cell is calculated by content, for vertical text rendering the width is calculated
-
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg, int spacing, boolean calculate) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSEspacing
- The space between text and cell bordercalculate
- tells the text painter to calculate the cell borders regarding the content
-
AbstractTextPainter
public AbstractTextPainter(boolean wrapText, boolean paintBg, int spacing, boolean calculateByTextLength, boolean calculateByTextHeight) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSEspacing
- The space between text and cell bordercalculateByTextLength
- tells the text painter to calculate the cell border by containing text length. For horizontal text rendering, this means the width of the cell is calculated by content, for vertical text rendering the height is calculatedcalculateByTextHeight
- tells the text painter to calculate the cell border by containing text height. For horizontal text rendering, this means the height of the cell is calculated by content, for vertical text rendering the width is calculated
-
-
Method Details
-
convertDataType
Convert the data value of the cell using theIDisplayConverter
from theIConfigRegistry
- Parameters:
cell
- The cell whose data value should be converted.configRegistry
- TheIConfigRegistry
to retrieve the converter.- Returns:
- The data value converted to a String.
-
setupGCFromConfig
Setup the GC by the values defined in the given cell style.- Parameters:
gc
- TheGC
that is used for rendering.cellStyle
- TheIStyle
to retrieve the styling options.
-
resetGC
public void resetGC(org.eclipse.swt.graphics.GC gc) Reset the GC to the original values.- Parameters:
gc
- TheGC
that is used for rendering.- Since:
- 1.4
-
renderUnderlined
Checks if there is a underline text decoration configured within the given cell style.- Parameters:
cellStyle
- The cell style of the current cell to check for the text decoration.- Returns:
true
if there is a underline text decoration configured,false
otherwise.
-
renderStrikethrough
Checks if there is a strikethrough text decoration configured within the given cell style.- Parameters:
cellStyle
- The cell style of the current cell to check for the text decoration.- Returns:
true
if there is a strikethrough text decoration configured,false
otherwise.
-
getNumberOfNewLines
Scans for new line characters and counts the number of lines for the given text.- Parameters:
text
- the text to scan- Returns:
- the number of lines for the given text
-
getLengthFromCache
Calculates the length of a given text by using the GC. To minimize the count of calculations, the calculation result will be stored within a Map, so the next time the length of the same text is asked for, the result is only returned by cache and is not calculated again.- Parameters:
gc
- the current GCtext
- the text to get the length for- Returns:
- the length of the text
-
getTextToDisplay
protected String getTextToDisplay(ILayerCell cell, org.eclipse.swt.graphics.GC gc, int availableLength, String text) Computes dependent on the configuration of the TextPainter the text to display. If word wrapping is enabled new lines are inserted if the available space is not enough. If calculation of available space is enabled, the space is automatically widened for the text to display, and if no calculation is enabled the text is cut and modified to end with "..." to fit into the available space- Parameters:
cell
- the current cell to paintgc
- the current GCavailableLength
- the available space for the text to displaytext
- the text that should be modified for display- Returns:
- the modified text
-
setNewMinLength
This method gets only called if automatic length calculation is enabled. Calculate the new cell width/height by using the given content length and the difference from current cell width/height to available length. If the calculated cell is greater than the current set contentLength, update the contentLength and execute a corresponding resize command.- Parameters:
cell
- the current cell that is paintedcontentLength
- the length of the content
-
calculatePadding
This method is used to determine the padding from the cell to the available length. A padding can occur for example by using a BeveledBorderDecorator or PaddingDecorator. This TextPainter is called with the available space rectangle which is calculated by the wrapping painters and decorators by subtracting paddings. As this TextPainter does not know his wrapping painters and decorators the existing padding needs to be calculated for automatic resizing. Abstract because a horizontal TextPainter uses the width while a VerticalTextPainter uses the height of the cell and the Rectangle.- Parameters:
cell
- the current cell which should be resizedavailableLength
- the length value that is available and was given into paintCell() as Rectangle argument- Returns:
- the padding between the current cell length - availableLength
-
setUnderline
public void setUnderline(boolean underline) Set if the text should be rendered underlined or not.- Parameters:
underline
-true
if the text should be printed underlined,false
if not
-
setStrikethrough
public void setStrikethrough(boolean strikethrough) Set if the text should be rendered strikethrough or not.- Parameters:
strikethrough
-true
if the text should be printed strikethrough,false
if not
-
isCalculateByTextLength
public boolean isCalculateByTextLength()- Returns:
true
if this text painter is calculating the cell dimensions by containing text length. For horizontal text rendering, this means the width of the cell is calculated by content, for vertical text rendering the height is calculated.
-
setCalculateByTextLength
public void setCalculateByTextLength(boolean calculateByTextLength) Configure whether the text painter should calculate the cell dimensions by containing text length. For horizontal text rendering, this means the width of the cell is calculated by content, for vertical text rendering the height is calculated.- Parameters:
calculateByTextLength
-true
to calculate and modify the cell dimension according to the text length,false
to not modifying the cell dimensions.
-
isCalculateByTextHeight
public boolean isCalculateByTextHeight()- Returns:
true
if this text painter is calculating the cell dimensions by containing text height. For horizontal text rendering, this means the height of the cell is calculated by content, for vertical text rendering the width is calculated.
-
setCalculateByTextHeight
public void setCalculateByTextHeight(boolean calculateByTextHeight) Configure whether the text painter should calculate the cell dimensions by containing text height. For horizontal text rendering, this means the height of the cell is calculated by content, for vertical text rendering the width is calculated.- Parameters:
calculateByTextHeight
-true
to calculate and modify the cell dimension according to the text height,false
to not modifying the cell dimensions.
-
isTrimText
public boolean isTrimText()- Returns:
true
if the text to display should be trimmed,false
if not. Default istrue
- Since:
- 1.3
-
setTrimText
public void setTrimText(boolean trimText) - Parameters:
trimText
-true
if the text to display should be trimmed,false
if not.- Since:
- 1.3
-
isWrapText
public boolean isWrapText()- Returns:
true
if the text will be wrapped,false
if not.- Since:
- 1.4
-
setWrapText
public void setWrapText(boolean wrapText) - Parameters:
wrapText
-true
if the text should be wrapped,false
if not.- Since:
- 1.4
-
paintDecoration
protected void paintDecoration(IStyle cellStyle, org.eclipse.swt.graphics.GC gc, int x, int y, int length, int fontHeight) Render a decoration to the text, e.g. underline and/or strikethrough lines.- Parameters:
cellStyle
- TheIStyle
that contains the styling information for rendering.gc
- theGC
used to paintx
- start x of the texty
- start y of the textlength
- length of the textfontHeight
- The height of the current font- Since:
- 1.4
-
isWordWrapping
public boolean isWordWrapping()Return whether word wrapping is enabled or not.Word wrapping is the wrapping behavior similar to spreadsheet applications where words are wrapped if there is not enough space. Text wrapping on the other hand only wraps whole words.
Enabling this feature could result in slow rendering performance. It is therefore disabled by default.
Note: If word wrapping is enabled, features like automatic size calculation by text length and text wrapping are ignored.
- Returns:
true
if word wrapping is enabled,false
if not.- Since:
- 1.5
-
setWordWrapping
public void setWordWrapping(boolean wordWrapping) Configure whether word wrapping should be enabled or not.Word wrapping is the wrapping behavior similar to spreadsheet applications where words are wrapped if there is not enough space. Text wrapping on the other hand only wraps whole words.
Enabling this feature could result in slow rendering performance. It is therefore disabled by default.
Note: If word wrapping is enabled, features like automatic size calculation by text length and text wrapping are ignored.
- Parameters:
wordWrapping
-true
to enable word wrapping,false
to disable it.- Since:
- 1.5
-
getLineSpacing
public int getLineSpacing()Return the number of pixels that are added between lines. Default is 0, which means that the line height is defined by the font height only.- Returns:
- The number of pixels that are added between lines
- Since:
- 1.5
-
setLineSpacing
public void setLineSpacing(int spacing) Specify the number of pixels that should be added between lines. Default is 0, which means that the line height is defined by the font height only.- Parameters:
spacing
- The number of pixels that should be added between lines- Since:
- 1.5
-
isCutText
public boolean isCutText()- Returns:
true
if the text is cut and the end of the text should be shown with ...,false
if the text is showed unmodified, which means the text cut is done by the GC clipping. Default istrue
.- Since:
- 2.3
-
setCutText
public void setCutText(boolean cutText) Configure the behavior for text modification if not enough space is available in the cell for rendering the text.- Parameters:
cutText
-true
if the text should be cut and the end of the text should be shown with ...,false
if the text should be showed unmodified, which means the text cut is done by the GC clipping. Default istrue
.- Since:
- 2.3
-