Class StyledString

java.lang.Object
swingtree.style.StyledString

public final class StyledString extends Object
A StyledString is a uniformly styled snippet of text which is typically part of a sequence of styled strings that together make up a visually rich text in the SwingTree style API. More specifically, you can pass instances of this to TextConf.content(StyledString...) as part of a ComponentStyleDelegate.text(Configurator) sub-style configuration.
This class has value semantics and is immutable, so any potential Configurator referenced by an instance of this class is expected to be a pure function that produces the same output given the same input and has no side effects.
See Also:
  • Method Details

    • of

      public static StyledString of(String string)
      Creates a styled string with the given string but no style information.
      The style of the string will be inherited from the context in which it is used within the style engine.
      Parameters:
      string - The string content of the styled string. It must not be null.
      Returns:
      A new styled string with the given string and no style information.
      Throws:
      NullPointerException - if the given string is null.
    • of

      public static StyledString of(Configurator<FontConf> fontConfigurator, String string)
      Creates a styled string with the given string and style information provided by the given font Configurator.
      The font configurator takes in an inherited FontConf and produces a new FontConf derived to hold the desired style information for the string.
      Parameters:
      fontConfigurator - A configurator that takes in an inherited FontConf and produces a new FontConf derived to hold the desired style information for the string. It must not be null and must be a pure function that produces the same output given the same input and has no side effects.
      string - The string content of the styled string. It must not be null.
      Returns:
      A new styled string with the given string and style information provided by the given font configurator.
      Throws:
      NullPointerException - if the given string or font configurator is null.
    • string

      public String string()
      Returns the string content of this styled string. This is the actual text that will be rendered when this styled string is used in a style configuration.
      Returns:
      The string content of this styled string. It is guaranteed to be non-null.
    • withString

      public StyledString withString(String string)
      Returns a new styled string with the same style information as this styled string but with a new string content.
      This is useful for when you want to reuse the same style information for different string content.
      Parameters:
      string - The new string content for the styled string. It must not be null.
      Returns:
      A new styled string with the same style information as this styled string but with the given string content.
      Throws:
      NullPointerException - if the given string is null.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object