Class AbstractTextPainter
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.painter.cell.AbstractCellPainter
-
- org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
-
- org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
-
- org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter
-
- All Implemented Interfaces:
ICellPainter
- Direct Known Subclasses:
TextPainter,VerticalTextImagePainter,VerticalTextPainter
public abstract class AbstractTextPainter extends BackgroundPainter
Abstract TextPainter the contains general methods for drawing text into a cell. Can handle word wrapping and/or word cutting and/or automatic calculation and resizing of the cell height or width if the text does not fit into the cell.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancalculateByTextHeightprotected booleancalculateByTextLengthstatic StringDOTstatic StringEMPTYstatic StringLINE_SEPARATORprotected intlineSpacingstatic StringNEW_LINE_REGEXThe regular expression to find predefined new lines in the text to show.protected booleanpaintBgprotected booleanpaintFgprotected intspacingprotected booleanwordWrappingprotected booleanwrapText
-
Constructor Summary
Constructors Constructor Description AbstractTextPainter()AbstractTextPainter(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract intcalculatePadding(ILayerCell cell, int availableLength)This method is used to determine the padding from the cell to the available length.protected StringconvertDataType(ILayerCell cell, IConfigRegistry configRegistry)Convert the data value of the cell using theIDisplayConverterfrom theIConfigRegistryprotected intgetLengthFromCache(org.eclipse.swt.graphics.GC gc, String text)Calculates the length of a given text by using the GC.intgetLineSpacing()Return the number of pixels that are added between lines.protected intgetNumberOfNewLines(String text)Scans for new line characters and counts the number of lines for the given text.protected StringgetTextToDisplay(ILayerCell cell, org.eclipse.swt.graphics.GC gc, int availableLength, String text)Computes dependent on the configuration of the TextPainter the text to display.booleanisCalculateByTextHeight()booleanisCalculateByTextLength()booleanisTrimText()booleanisWordWrapping()Return whether word wrapping is enabled or not.booleanisWrapText()protected voidpaintDecoration(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 booleanrenderStrikethrough(IStyle cellStyle)Checks if there is a strikethrough text decoration configured within the given cell style.protected booleanrenderUnderlined(IStyle cellStyle)Checks if there is a underline text decoration configured within the given cell style.voidresetGC(org.eclipse.swt.graphics.GC gc)Reset the GC to the original values.voidsetCalculateByTextHeight(boolean calculateByTextHeight)Configure whether the text painter should calculate the cell dimensions by containing text height.voidsetCalculateByTextLength(boolean calculateByTextLength)Configure whether the text painter should calculate the cell dimensions by containing text length.voidsetLineSpacing(int spacing)Specify the number of pixels that should be added between lines.protected abstract voidsetNewMinLength(ILayerCell cell, int contentLength)This method gets only called if automatic length calculation is enabled.voidsetStrikethrough(boolean strikethrough)Set if the text should be rendered strikethrough or not.voidsetTrimText(boolean trimText)voidsetUnderline(boolean underline)Set if the text should be rendered underlined or not.voidsetupGCFromConfig(org.eclipse.swt.graphics.GC gc, IStyle cellStyle)Setup the GC by the values defined in the given cell style.voidsetWordWrapping(boolean wordWrapping)Configure whether word wrapping should be enabled or not.voidsetWrapText(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 Detail
-
EMPTY
public static final String EMPTY
- See Also:
- Constant Field Values
-
DOT
public static final String DOT
- See Also:
- Constant Field Values
-
NEW_LINE_REGEX
public static final String 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:
- Constant Field Values
-
LINE_SEPARATOR
public static final String 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 Detail
-
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 Detail
-
convertDataType
protected String convertDataType(ILayerCell cell, IConfigRegistry configRegistry)
Convert the data value of the cell using theIDisplayConverterfrom theIConfigRegistry- Parameters:
cell- The cell whose data value should be converted.configRegistry- TheIConfigRegistryto retrieve the converter.- Returns:
- The data value converted to a String.
-
setupGCFromConfig
public void setupGCFromConfig(org.eclipse.swt.graphics.GC gc, IStyle cellStyle)Setup the GC by the values defined in the given cell style.- Parameters:
gc- TheGCthat is used for rendering.cellStyle- TheIStyleto retrieve the styling options.
-
resetGC
public void resetGC(org.eclipse.swt.graphics.GC gc)
Reset the GC to the original values.- Parameters:
gc- TheGCthat is used for rendering.- Since:
- 1.4
-
renderUnderlined
protected boolean renderUnderlined(IStyle cellStyle)
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:
trueif there is a underline text decoration configured,falseotherwise.
-
renderStrikethrough
protected boolean renderStrikethrough(IStyle cellStyle)
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:
trueif there is a strikethrough text decoration configured,falseotherwise.
-
getNumberOfNewLines
protected int getNumberOfNewLines(String text)
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
protected int getLengthFromCache(org.eclipse.swt.graphics.GC gc, String text)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
protected abstract void setNewMinLength(ILayerCell cell, int contentLength)
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
protected abstract int calculatePadding(ILayerCell cell, int availableLength)
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-trueif the text should be printed underlined,falseif not
-
setStrikethrough
public void setStrikethrough(boolean strikethrough)
Set if the text should be rendered strikethrough or not.- Parameters:
strikethrough-trueif the text should be printed strikethrough,falseif not
-
isCalculateByTextLength
public boolean isCalculateByTextLength()
- Returns:
trueif 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-trueto calculate and modify the cell dimension according to the text length,falseto not modifying the cell dimensions.
-
isCalculateByTextHeight
public boolean isCalculateByTextHeight()
- Returns:
trueif 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-trueto calculate and modify the cell dimension according to the text height,falseto not modifying the cell dimensions.
-
isTrimText
public boolean isTrimText()
- Returns:
trueif the text to display should be trimmed,falseif not. Default istrue- Since:
- 1.3
-
setTrimText
public void setTrimText(boolean trimText)
- Parameters:
trimText-trueif the text to display should be trimmed,falseif not.- Since:
- 1.3
-
isWrapText
public boolean isWrapText()
- Returns:
trueif the text will be wrapped,falseif not.- Since:
- 1.4
-
setWrapText
public void setWrapText(boolean wrapText)
- Parameters:
wrapText-trueif the text should be wrapped,falseif 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- TheIStylethat contains the styling information for rendering.gc- theGCused 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:
trueif word wrapping is enabled,falseif 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-trueto enable word wrapping,falseto 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
-
-