org.eclipse.nebula.widgets.nattable.painter.cell
Class AbstractTextPainter

java.lang.Object
  extended by org.eclipse.nebula.widgets.nattable.painter.cell.AbstractCellPainter
      extended by org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper
          extended by org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter
              extended by 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
protected  boolean calculateByTextHeight
           
protected  boolean calculateByTextLength
           
static String DOT
           
static String EMPTY
           
static String LINE_SEPARATOR
           
static String NEW_LINE_REGEX
          The regular expression to find predefined new lines in the text to show.
protected  boolean paintBg
           
protected  boolean paintFg
           
protected  int spacing
           
protected  boolean wrapText
           
 
Constructor Summary
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
protected 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 the IDisplayConverter from the IConfigRegistry
protected  int getLengthFromCache(org.eclipse.swt.graphics.GC gc, String text)
          Calculates the length of a given text by using the GC.
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.
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.
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 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.
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

wrapText

protected final boolean wrapText

paintBg

protected final boolean paintBg

paintFg

protected boolean paintFg

spacing

protected int spacing

calculateByTextLength

protected final boolean calculateByTextLength

calculateByTextHeight

protected final boolean calculateByTextHeight
Constructor Detail

AbstractTextPainter

public AbstractTextPainter()

AbstractTextPainter

public AbstractTextPainter(boolean wrapText,
                           boolean paintBg)
Parameters:
wrapText - split text over multiple lines
paintBg - skips painting the background if is FALSE

AbstractTextPainter

public AbstractTextPainter(boolean wrapText,
                           boolean paintBg,
                           int spacing)
Parameters:
wrapText - split text over multiple lines
paintBg - skips painting the background if is FALSE
spacing - The space between text and cell border

AbstractTextPainter

public AbstractTextPainter(boolean wrapText,
                           boolean paintBg,
                           boolean calculate)
Parameters:
wrapText - split text over multiple lines
paintBg - skips painting the background if is FALSE
calculate - 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 lines
paintBg - skips painting the background if is FALSE
calculateByTextLength - 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 calculated
calculateByTextHeight - 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 lines
paintBg - skips painting the background if is FALSE
spacing - The space between text and cell border
calculate - 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 lines
paintBg - skips painting the background if is FALSE
spacing - The space between text and cell border
calculateByTextLength - 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 calculated
calculateByTextHeight - 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 the IDisplayConverter from the IConfigRegistry


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 -
cellStyle -

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:
true if there is a underline text decoration configured, false otherwise.

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:
true if there is a strikethrough text decoration configured, false otherwise.

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 GC
text - 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 paint
gc - the current GC
availableLength - the available space for the text to display
text - 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 painted
contentLength - 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 resized
availableLength - 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


Copyright © 2014. All rights reserved.