Class StringFormatter<K,​T extends games.stendhal.client.gui.textformat.FormatSet<K,​T>>

java.lang.Object
games.stendhal.client.gui.textformat.StringFormatter<K,​T>
Type Parameters:
K - type of the TextFormatSet internal data
T - type holding the text attributes

public class StringFormatter<K,​T extends games.stendhal.client.gui.textformat.FormatSet<K,​T>> extends Object
A class for creating attributed strings from strings using the stendhal style markup. The rules are:
  1. Text starts in a defined font and color mode.
  2. A special character changes to a mode specific to that character.
  3. If a new special mode is started while the previous is in effect, their effects are combined, the definitions of the newer mode overriding the other where they would be in conflict.
  4. If the markup character is followed by a single quote " ' ", the mode ends at the next single quote. Otherwise the mode ends at the next white space or punctuation character. Only the last active mode is terminated.
  5. If a markup character would start a new mode that is the same as the current effective, the markup character is treated as if it was a normal character.
  6. The backslash character '\' can be used to prevent the normal effect of the special characters to allow printing them. Backslash can be printed by escaping it with itself '\\'.
  • Constructor Details

    • StringFormatter

      public StringFormatter()
  • Method Details

    • addStyle

      public void addStyle(Character c, T attributes)
      Add a formatting style.
      Parameters:
      c - character for turning on the style
      attributes - attributes to be used for the text in the style
    • format

      public void format(String s, T normalAttributes, AttributedTextSink<T> dest)
      Format a string.
      Parameters:
      s - string which may contain formatting markup
      normalAttributes - attributes for the normal text
      dest - destination to write parsed and attributed output