Class TextPainter
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
org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter
- All Implemented Interfaces:
ICellPainter
- Direct Known Subclasses:
AutomaticRowHeightTextPainter
,BlendedBackgroundPainter
,GroupByCellTextPainter
,PasswordTextPainter
TextPainter that draws text into a cell horizontally. Can handle word
wrapping and/or word cutting and/or automatic calculation and resizing of the
cell width and height if the text does not fit into the cell.
-
Field Summary
Fields inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter
calculateByTextHeight, calculateByTextLength, DOT, EMPTY, LINE_SEPARATOR, lineSpacing, NEW_LINE_PATTERN, NEW_LINE_REGEX, paintBg, paintFg, spacing, wordWrapping, wrapText
-
Constructor Summary
ConstructorDescriptionCreates aTextPainter
that does not wrap text and paints the background.TextPainter
(boolean wrapText, boolean paintBg) TextPainter
(boolean wrapText, boolean paintBg, boolean calculate) TextPainter
(boolean wrapText, boolean paintBg, boolean calculateByTextLength, boolean calculateByTextHeight) TextPainter
(boolean wrapText, boolean paintBg, int spacing) TextPainter
(boolean wrapText, boolean paintBg, int spacing, boolean calculate) TextPainter
(boolean wrapText, boolean paintBg, int spacing, boolean calculateByTextLength, boolean calculateByTextHeight) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
calculatePadding
(ILayerCell cell, int availableLength) This method is used to determine the padding from the cell to the available length.int
getPreferredHeight
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the preferred height of the cell when rendered by this painter.int
getPreferredWidth
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Get the preferred width of the cell when rendered by this painter.boolean
void
paintCell
(ILayerCell cell, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rectangle, IConfigRegistry configRegistry) protected boolean
performRowResize
(int contentHeight, org.eclipse.swt.graphics.Rectangle rectangle) Checks if a row resize needs to be triggered.void
setCalculateWrappedHeight
(boolean calculateWrappedHeight) Configure howgetPreferredHeight(ILayerCell, GC, IConfigRegistry)
calculates the height.protected void
setNewMinLength
(ILayerCell cell, int contentWidth) This method gets only called if automatic length calculation is enabled.Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter
convertDataType, getLengthFromCache, getLineSpacing, getNumberOfNewLines, getTextToDisplay, isCalculateByTextHeight, isCalculateByTextLength, isCutText, isTrimText, isWordWrapping, isWrapText, paintDecoration, renderStrikethrough, renderUnderlined, resetGC, setCalculateByTextHeight, setCalculateByTextLength, setCutText, setLineSpacing, setStrikethrough, setTrimText, setUnderline, setupGCFromConfig, setWordWrapping, setWrapText
Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
getBackgroundColour
Methods inherited from class org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
getCellPainterAt, getWrappedPainter, getWrappedPainterBounds, setWrappedPainter
-
Constructor Details
-
TextPainter
public TextPainter()Creates aTextPainter
that does not wrap text and paints the background. -
TextPainter
public TextPainter(boolean wrapText, boolean paintBg) - Parameters:
wrapText
- split text over multiple linespaintBg
- skips painting the background if is FALSE
-
TextPainter
public TextPainter(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
-
TextPainter
public TextPainter(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
-
TextPainter
public TextPainter(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
-
TextPainter
public TextPainter(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
-
TextPainter
public TextPainter(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
-
getPreferredWidth
public int getPreferredWidth(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Description copied from interface:ICellPainter
Get the preferred width of the cell when rendered by this painter. Used for auto-resize.- Specified by:
getPreferredWidth
in interfaceICellPainter
- Overrides:
getPreferredWidth
in classCellPainterWrapper
- Parameters:
cell
- The cell for which the preferred width is requested.gc
- The GC that is used for rendering.configRegistry
- The IConfigRegistry that contains the configuration used for rendering.- Returns:
- The preferred width of the given cell when rendered by this painter.
-
getPreferredHeight
public int getPreferredHeight(ILayerCell cell, org.eclipse.swt.graphics.GC gc, IConfigRegistry configRegistry) Description copied from interface:ICellPainter
Get the preferred height of the cell when rendered by this painter. Used for auto-resize.- Specified by:
getPreferredHeight
in interfaceICellPainter
- Overrides:
getPreferredHeight
in classCellPainterWrapper
- Parameters:
cell
- The cell for which the preferred height is requested.gc
- The GC that is used for rendering.configRegistry
- The IConfigRegistry that contains the configuration used for rendering.- Returns:
- The preferred height of the given cell when rendered by this painter.
-
paintCell
public void paintCell(ILayerCell cell, org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle rectangle, IConfigRegistry configRegistry) - Specified by:
paintCell
in interfaceICellPainter
- Overrides:
paintCell
in classBackgroundPainter
-
setNewMinLength
Description copied from class:AbstractTextPainter
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.- Specified by:
setNewMinLength
in classAbstractTextPainter
- Parameters:
cell
- the current cell that is paintedcontentWidth
- the length of the content
-
calculatePadding
Description copied from class:AbstractTextPainter
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.- Specified by:
calculatePadding
in classAbstractTextPainter
- 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
-
performRowResize
protected boolean performRowResize(int contentHeight, org.eclipse.swt.graphics.Rectangle rectangle) Checks if a row resize needs to be triggered.- Parameters:
contentHeight
- The necessary height to show the content completelyrectangle
- The available rectangle to render to- Returns:
true
if a row resize needs to be performed,false
if not
-
isCalculateWrappedHeight
public boolean isCalculateWrappedHeight()- Returns:
- Whether the preferred height is calculated on the wrapped text or
on the text that would be rendered without wrapping. Default is
false
. - Since:
- 1.6
-
setCalculateWrappedHeight
public void setCalculateWrappedHeight(boolean calculateWrappedHeight) Configure howgetPreferredHeight(ILayerCell, GC, IConfigRegistry)
calculates the height. Either based on the text as is, or taking text-wrapping into account if enabled.- Parameters:
calculateWrappedHeight
-true
if the preferred height should be calculated on the wrapped text,false
if the preferred height should be calculated without wrapping.- Since:
- 1.6
-