Class VisibleWhitespaceTokenPainter

java.lang.Object
org.fife.ui.rsyntaxtextarea.DefaultTokenPainter
org.fife.ui.rsyntaxtextarea.VisibleWhitespaceTokenPainter
All Implemented Interfaces:
TokenPainter

public class VisibleWhitespaceTokenPainter extends DefaultTokenPainter
A token painter that visibly renders whitespace (spaces and tabs).

The current implementation paints as follows:

  • The first tab or space, if any, is found in the token.
  • If a tab was found, all characters up to it are painted as a group.
  • If a space was found, all characters up to and including it are painted (it is painted with a special symbol to denote it as a space).
  • If neither a tab nor a whitespace was found, all characters in the token are painted.
  • Repeat until all characters are painted.
This means that rendering hints are applied to all groups of characters within a token, excluding whitespace and tabs.

A problem with this implementation is that FontMetrics.charsWidth() is still used to calculate the width of a group of chars painted. Thus, the group of characters will be painted with the rendering hints specified, but the following tab (or group of characters if the current group was the end of a token) will not necessarily be painted at the proper x-coordinate (as FontMetrics.charsWidth() returns an int and not a float). The way around this would be to calculate the token's width in such a way that a float is returned (Font.getStringBounds()?).

See Also:
  • Constructor Details

    • VisibleWhitespaceTokenPainter

      public VisibleWhitespaceTokenPainter()
  • Method Details

    • paintImpl

      protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean selected, boolean useSTC)
      Description copied from class: DefaultTokenPainter
      Does the dirty-work of actually painting the token.
      Overrides:
      paintImpl in class DefaultTokenPainter
    • paintSpaceText

      protected void paintSpaceText(Graphics2D g, float x, float y, int ascent, int width, int height)
      Draws the textual indication of a space, i.e. a single dot. The background has already been filled in properly, and the foreground color properly set.
      Parameters:
      g - The graphics context.
      x - The x-value at which to paint.
      y - The y-value of the current line.
      ascent - The ascent of the current font.
      width - The width of the space character.
      height - The height of the current line of text being painted.
    • paintTabText

      protected void paintTabText(Graphics2D g, float x, float y, float nextTabStop, int ascent, int height)
      Draws the text representing a tab. The background has already been filled in if necessary, and the foreground color properly set.
      Parameters:
      g - The graphics context.
      x - The x-value at which to paint.
      y - The y-value of the current line.
      nextTabStop - Where the next tab stop would start.
      ascent - The ascent of the current font.
      height - The height of the line of text being painted.