Class 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 Details

    • EMPTY

      public static final String EMPTY
      See Also:
    • DOT

      public static final String DOT
      See Also:
    • 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:
    • NEW_LINE_PATTERN

      public static final Pattern NEW_LINE_PATTERN
      The Pattern 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

      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 Details

    • 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 Details

    • convertDataType

      protected String convertDataType(ILayerCell cell, IConfigRegistry configRegistry)
      Convert the data value of the cell using the IDisplayConverter from the IConfigRegistry
      Parameters:
      cell - The cell whose data value should be converted.
      configRegistry - The IConfigRegistry to 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 - The GC that is used for rendering.
      cellStyle - The IStyle to retrieve the styling options.
    • resetGC

      public void resetGC(org.eclipse.swt.graphics.GC gc)
      Reset the GC to the original values.
      Parameters:
      gc - The GC that 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:
      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
    • 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 is true
      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 - The IStyle that contains the styling information for rendering.
      gc - the GC used to paint
      x - start x of the text
      y - start y of the text
      length - length of the text
      fontHeight - 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 is true.
      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 is true.
      Since:
      2.3