Class VisibleWhitespaceTokenPainter

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

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()?).

Version:
1.0