Package swingtree.style
Class StyledString
java.lang.Object
swingtree.style.StyledString
A
This class has value semantics and is immutable, so any potential
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 Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()static StyledStringCreates 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.static StyledStringof(Configurator<FontConf> fontConfigurator, String string) Creates a styled string with the given string and style information provided by the given fontConfigurator.
The font configurator takes in an inheritedFontConfand produces a newFontConfderived to hold the desired style information for the string.string()Returns the string content of this styled string.toString()withString(String string) Returns a new styled string with the same style information as this styled string but with a new string content.
-
Method Details
-
of
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
Creates a styled string with the given string and style information provided by the given fontConfigurator.
The font configurator takes in an inheritedFontConfand produces a newFontConfderived to hold the desired style information for the string.- Parameters:
fontConfigurator- A configurator that takes in an inheritedFontConfand produces a newFontConfderived 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
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
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
-
equals
-
hashCode
public int hashCode()
-