Package com.dua3.utility.text
Class Style
java.lang.Object
com.dua3.utility.text.Style
A Style is a set of property names and corresponding values that control the appearance of
RichText
.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
background colorstatic final Style
Black text.static final Style
Blue text.static final Style
Bold style.static final String
foreground colorstatic final Style
Darkgray text.static final Style
Empty style, not defining any attributes.static final String
property for the font.static final String
property name for the font class.static final String
Constant representing the value for monospace font class.static final String
Constant representing the value for sansserif font class.static final String
Constant representing the value for serif font class.static final String
property name for the font familiesConstant representing the commonly used monospace font families.Constant representing the commonly used sans-serif font families.Constant representing the commonly used serif font families.static final String
property name for the font scalestatic final String
property name for the font sizestatic final String
property name for the font stylestatic final String
Represents the italic font style.static final String
Specifies the normal font style.static final String
Represents the value for the oblique font style.static final String
property name for the font variantstatic final String
Represents the normal variant value for font.static final String
property name for the font weightstatic final String
Represents the font weight property value for bold text.static final String
Represents the normal font weight value for text styling.static final Style
Gray text.static final Style
Green text.static final Style
Italics style.static final Style
Lightgray text.static final Style
Line-through (=strikethrough) style.static final Style
Default Monospace font.static final Style
No-Line-through (=no-strikethrough) style.static final Style
No-Underline style.static final Style
Normal (=not bold) style.static final Style
Red text.static final Style
Regular style.static final Style
Default Sansserif font.static final Style
Default Serif font.static final String
property name for the line-through text decorationstatic final Boolean
Indicates that text decoration line-through should be applied.static final Boolean
Indicates that text decoration line-through should not be applied.static final String
property name for the underline text decorationstatic final Boolean
Indicates that text decoration underline should be applied.static final Boolean
Indicates that text decoration underline should not be applied.static final String
text indentationstatic final String
Represents the left text indentation value of 0.static final String
Represents the left text indentation value of 40 points.static final Style
Underline style.static final Style
White text.static final Style
Yellow text. -
Method Summary
Modifier and TypeMethodDescriptionstatic Style
Create a style for the given font.static Style
Creates a new style with the specified font, foreground color, and background color.static Style
Create a new Style.static Style
Create a new Style.boolean
void
forEach
(BiConsumer<String, @Nullable Object> action) Perform action for each entry of this style.@Nullable Object
Get a property's value.getFont()
Get Font for this style.Get Font for this style.Get FontDef for this style.<T extends @Nullable Object>
TgetOrDefault
(String property, T dflt) Retrieves the value associated with the specified property, or returns the provided default value if the property is not set.int
hashCode()
<T extends @Nullable Object>
voidConsume value if property is set.<T extends @Nullable Object>
voidifPresentOrElse
(String key, @Nullable T defaultValue, Consumer<T> action) Consume value of a property.<T extends @Nullable Object>
voidifPresentOrElseGet
(String key, Supplier<@Nullable T> defaultSupplier, Consumer<? super T> action) Consume the value of a property.iterator()
name()
Get style name.stream()
Get a stream of this style's entries.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
FONT
property for the font.- See Also:
-
FONT_CLASS
property name for the font class.- See Also:
-
FONT_CLASS_VALUE_MONOSPACE
Constant representing the value for monospace font class.- See Also:
-
FONT_CLASS_VALUE_SERIF
Constant representing the value for serif font class.- See Also:
-
FONT_CLASS_VALUE_SANS_SERIF
Constant representing the value for sansserif font class.- See Also:
-
FONT_FAMILIES
property name for the font families- See Also:
-
FONT_FAMILIES_VALUE_SANS_SERIF
Constant representing the commonly used sans-serif font families. -
FONT_FAMILIES_VALUE_SERIF
Constant representing the commonly used serif font families. -
FONT_FAMILIES_VALUE_MONOSPACED
Constant representing the commonly used monospace font families. -
FONT_STYLE
property name for the font style- See Also:
-
FONT_STYLE_VALUE_NORMAL
Specifies the normal font style. This value can be used as a setting for the font style to indicate no special styling, such as italic or oblique, and to maintain the default, standard text appearance.- See Also:
-
FONT_STYLE_VALUE_ITALIC
Represents the italic font style.- See Also:
-
FONT_STYLE_VALUE_OBLIQUE
Represents the value for the oblique font style. This is typically used to render text in a slanted manner.- See Also:
-
FONT_SIZE
property name for the font size- See Also:
-
FONT_SCALE
property name for the font scale- See Also:
-
FONT_WEIGHT
property name for the font weight- See Also:
-
FONT_WEIGHT_VALUE_BOLD
Represents the font weight property value for bold text.- See Also:
-
FONT_WEIGHT_VALUE_NORMAL
Represents the normal font weight value for text styling.- See Also:
-
FONT_VARIANT
property name for the font variant- See Also:
-
FONT_VARIANT_VALUE_NORMAL
Represents the normal variant value for font.- See Also:
-
TEXT_DECORATION_UNDERLINE
property name for the underline text decoration- See Also:
-
TEXT_DECORATION_UNDERLINE_VALUE_LINE
Indicates that text decoration underline should be applied. -
TEXT_DECORATION_UNDERLINE_VALUE_NO_LINE
Indicates that text decoration underline should not be applied. -
TEXT_DECORATION_LINE_THROUGH
property name for the line-through text decoration- See Also:
-
TEXT_DECORATION_LINE_THROUGH_VALUE_LINE
Indicates that text decoration line-through should be applied.This boolean constant is used to indicate that text within a style should be rendered with a line through the middle, often used for indicating deleted or inactive text.
-
TEXT_DECORATION_LINE_THROUGH_VALUE_NO_LINE
Indicates that text decoration line-through should not be applied. -
TEXT_INDENT_LEFT
text indentation- See Also:
-
TEXT_INDENT_LEFT_VALUE_0
Represents the left text indentation value of 0.This constant can be used to specify no indentation for a text element in a styling context.
- See Also:
-
TEXT_INDENT_LEFT_VALUE_1
Represents the left text indentation value of 40 points.- See Also:
-
COLOR
foreground color- See Also:
-
BACKGROUND_COLOR
background color- See Also:
-
EMPTY
Empty style, not defining any attributes. -
SANS_SERIF
Default Sansserif font. -
SERIF
Default Serif font. -
MONOSPACE
Default Monospace font. -
BOLD
Bold style. -
NORMAL
Normal (=not bold) style. -
ITALIC
Italics style. -
REGULAR
Regular style. -
UNDERLINE
Underline style. -
NO_UNDERLINE
No-Underline style. -
LINE_THROUGH
Line-through (=strikethrough) style. -
NO_LINE_THROUGH
No-Line-through (=no-strikethrough) style. -
BLACK
Black text. -
WHITE
White text. -
RED
Red text. -
GREEN
Green text. -
BLUE
Blue text. -
YELLOW
Yellow text. -
GRAY
Gray text. -
DARKGRAY
Darkgray text. -
LIGHTGRAY
Lightgray text.
-
-
Method Details
-
create
@SafeVarargs public static Style create(String styleName, Map.Entry<String, @Nullable Object>... args) Create a new Style.- Parameters:
styleName
- the style nameargs
- Map.Entry to set as properties of this style- Returns:
- new instance
-
create
Create a new Style.- Parameters:
styleName
- the style nameargs
- list of key-value pairs to set as properties of this style- Returns:
- new instance
-
toString
-
name
Get style name.- Returns:
- the style name
-
get
Get a property's value.- Parameters:
property
- the property name- Returns:
- the value of the property or
null
if no value was set
-
getOrDefault
Retrieves the value associated with the specified property, or returns the provided default value if the property is not set.- Type Parameters:
T
- the type of the property value- Parameters:
property
- the name of the property to retrievedflt
- the default value to return if the property is not set- Returns:
- the value of the property if set, otherwise the provided default value
-
ifPresent
public <T extends @Nullable Object> void ifPresent(String key, Consumer<T> action) throws ClassCastException Consume value if property is set.- Type Parameters:
T
- the type of property values- Parameters:
key
- the propertyaction
- the consumer- Throws:
ClassCastException
- if the property value does not match the requested type
-
ifPresentOrElseGet
public <T extends @Nullable Object> void ifPresentOrElseGet(String key, Supplier<@Nullable T> defaultSupplier, Consumer<? super T> action) Consume the value of a property.- Type Parameters:
T
- the type of property values- Parameters:
key
- the propertydefaultSupplier
- supplier of a default value to be used when the property is not setaction
- the consumer- Throws:
ClassCastException
- if the property value does not match the requested type
-
ifPresentOrElse
public <T extends @Nullable Object> void ifPresentOrElse(String key, @Nullable T defaultValue, Consumer<T> action) Consume value of a property.- Type Parameters:
T
- the type of property values- Parameters:
key
- the propertydefaultValue
- the default value to be used when the property is not setaction
- the consumer- Throws:
ClassCastException
- if the property value does not match the requested type
-
getFontDef
Get FontDef for this style.- Returns:
- the FontDef
-
getFont
Get Font for this style.- Returns:
- Optional holding the Font if this Style's Font has been set (not if just part of the FontDef is set)
-
getFont
Get Font for this style.- Parameters:
baseFont
- the font used to derive the requested font by applying this style- Returns:
- if set, the font of this style, otherwise the resulting font of applying this style's
FontDef
to the supplied baseFont
-
equals
-
hashCode
public int hashCode() -
iterator
-
stream
Get a stream of this style's entries.- Returns:
- stream of entries
-
forEach
Perform action for each entry of this style.- Parameters:
action
- the action to perform
-
create
Create a style for the given font.- Parameters:
font
- the font- Returns:
- the created style
-
create
Creates a new style with the specified font, foreground color, and background color.- Parameters:
font
- the font to be used in the styleforeground
- the foreground color of the stylebackground
- the background color of the style- Returns:
- a new Style instance configured with the specified font, foreground color, and background color
-