Class Style

java.lang.Object
com.dua3.utility.text.Style
All Implemented Interfaces:
Iterable<Map.Entry<String,Object>>

public final class Style extends Object implements Iterable<Map.Entry<String,Object>>
A Style is a set of property names and corresponding values that control the appearance of RichText.
  • Field Details

    • FONT

      public static final String FONT
      property for the font.
      See Also:
    • FONT_CLASS

      public static final String FONT_CLASS
      property name for the font class.
      See Also:
    • FONT_CLASS_VALUE_MONOSPACE

      public static final String FONT_CLASS_VALUE_MONOSPACE
      Constant representing the value for monospace font class.
      See Also:
    • FONT_CLASS_VALUE_SERIF

      public static final String FONT_CLASS_VALUE_SERIF
      Constant representing the value for serif font class.
      See Also:
    • FONT_CLASS_VALUE_SANS_SERIF

      public static final String FONT_CLASS_VALUE_SANS_SERIF
      Constant representing the value for sansserif font class.
      See Also:
    • FONT_FAMILIES

      public static final String FONT_FAMILIES
      property name for the font families
      See Also:
    • FONT_FAMILIES_VALUE_SANS_SERIF

      public static final List<String> FONT_FAMILIES_VALUE_SANS_SERIF
      Constant representing the commonly used sans-serif font families.
    • FONT_FAMILIES_VALUE_SERIF

      public static final List<String> FONT_FAMILIES_VALUE_SERIF
      Constant representing the commonly used serif font families.
    • FONT_FAMILIES_VALUE_MONOSPACED

      public static final List<String> FONT_FAMILIES_VALUE_MONOSPACED
      Constant representing the commonly used monospace font families.
    • FONT_STYLE

      public static final String FONT_STYLE
      property name for the font style
      See Also:
    • FONT_STYLE_VALUE_NORMAL

      public static final String 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

      public static final String FONT_STYLE_VALUE_ITALIC
      Represents the italic font style.
      See Also:
    • FONT_STYLE_VALUE_OBLIQUE

      public static final String 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

      public static final String FONT_SIZE
      property name for the font size
      See Also:
    • FONT_SCALE

      public static final String FONT_SCALE
      property name for the font scale
      See Also:
    • FONT_WEIGHT

      public static final String FONT_WEIGHT
      property name for the font weight
      See Also:
    • FONT_WEIGHT_VALUE_BOLD

      public static final String FONT_WEIGHT_VALUE_BOLD
      Represents the font weight property value for bold text.
      See Also:
    • FONT_WEIGHT_VALUE_NORMAL

      public static final String FONT_WEIGHT_VALUE_NORMAL
      Represents the normal font weight value for text styling.
      See Also:
    • FONT_VARIANT

      public static final String FONT_VARIANT
      property name for the font variant
      See Also:
    • FONT_VARIANT_VALUE_NORMAL

      public static final String FONT_VARIANT_VALUE_NORMAL
      Represents the normal variant value for font.
      See Also:
    • TEXT_DECORATION_UNDERLINE

      public static final String TEXT_DECORATION_UNDERLINE
      property name for the underline text decoration
      See Also:
    • TEXT_DECORATION_UNDERLINE_VALUE_LINE

      public static final Boolean TEXT_DECORATION_UNDERLINE_VALUE_LINE
      Indicates that text decoration underline should be applied.
    • TEXT_DECORATION_UNDERLINE_VALUE_NO_LINE

      public static final Boolean TEXT_DECORATION_UNDERLINE_VALUE_NO_LINE
      Indicates that text decoration underline should not be applied.
    • TEXT_DECORATION_LINE_THROUGH

      public static final String TEXT_DECORATION_LINE_THROUGH
      property name for the line-through text decoration
      See Also:
    • TEXT_DECORATION_LINE_THROUGH_VALUE_LINE

      public static final Boolean 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

      public static final Boolean TEXT_DECORATION_LINE_THROUGH_VALUE_NO_LINE
      Indicates that text decoration line-through should not be applied.
    • TEXT_INDENT_LEFT

      public static final String TEXT_INDENT_LEFT
      text indentation
      See Also:
    • TEXT_INDENT_LEFT_VALUE_0

      public static final String 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

      public static final String TEXT_INDENT_LEFT_VALUE_1
      Represents the left text indentation value of 40 points.
      See Also:
    • COLOR

      public static final String COLOR
      foreground color
      See Also:
    • BACKGROUND_COLOR

      public static final String BACKGROUND_COLOR
      background color
      See Also:
    • EMPTY

      public static final Style EMPTY
      Empty style, not defining any attributes.
    • SANS_SERIF

      public static final Style SANS_SERIF
      Default Sansserif font.
    • SERIF

      public static final Style SERIF
      Default Serif font.
    • MONOSPACE

      public static final Style MONOSPACE
      Default Monospace font.
    • BOLD

      public static final Style BOLD
      Bold style.
    • NORMAL

      public static final Style NORMAL
      Normal (=not bold) style.
    • ITALIC

      public static final Style ITALIC
      Italics style.
    • REGULAR

      public static final Style REGULAR
      Regular style.
    • UNDERLINE

      public static final Style UNDERLINE
      Underline style.
    • NO_UNDERLINE

      public static final Style NO_UNDERLINE
      No-Underline style.
    • LINE_THROUGH

      public static final Style LINE_THROUGH
      Line-through (=strikethrough) style.
    • NO_LINE_THROUGH

      public static final Style NO_LINE_THROUGH
      No-Line-through (=no-strikethrough) style.
    • BLACK

      public static final Style BLACK
      Black text.
    • WHITE

      public static final Style WHITE
      White text.
    • RED

      public static final Style RED
      Red text.
    • GREEN

      public static final Style GREEN
      Green text.
    • BLUE

      public static final Style BLUE
      Blue text.
    • YELLOW

      public static final Style YELLOW
      Yellow text.
    • GRAY

      public static final Style GRAY
      Gray text.
    • DARKGRAY

      public static final Style DARKGRAY
      Darkgray text.
    • LIGHTGRAY

      public static final Style 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 name
      args - Map.Entry to set as properties of this style
      Returns:
      new instance
    • create

      public static Style create(String styleName, Map<String,@Nullable Object> args)
      Create a new Style.
      Parameters:
      styleName - the style name
      args - list of key-value pairs to set as properties of this style
      Returns:
      new instance
    • toString

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

      public String name()
      Get style name.
      Returns:
      the style name
    • get

      public @Nullable Object get(String property)
      Get a property's value.
      Parameters:
      property - the property name
      Returns:
      the value of the property or null if no value was set
    • getOrDefault

      public <T extends @Nullable Object> T getOrDefault(String property, T dflt)
      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 retrieve
      dflt - 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 property
      action - 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 property
      defaultSupplier - supplier of a default value to be used when the property is not set
      action - 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 property
      defaultValue - the default value to be used when the property is not set
      action - the consumer
      Throws:
      ClassCastException - if the property value does not match the requested type
    • getFontDef

      public FontDef getFontDef()
      Get FontDef for this style.
      Returns:
      the FontDef
    • getFont

      public Optional<Font> 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

      public Font getFont(Font baseFont)
      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

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • iterator

      public Iterator<Map.Entry<String,@Nullable Object>> iterator()
      Specified by:
      iterator in interface Iterable<Map.Entry<String,Object>>
    • stream

      public Stream<Map.Entry<String,@Nullable Object>> stream()
      Get a stream of this style's entries.
      Returns:
      stream of entries
    • forEach

      public void forEach(BiConsumer<String,@Nullable Object> action)
      Perform action for each entry of this style.
      Parameters:
      action - the action to perform
    • create

      public static Style create(Font font)
      Create a style for the given font.
      Parameters:
      font - the font
      Returns:
      the created style
    • create

      public static Style create(Font font, Color foreground, Color background)
      Creates a new style with the specified font, foreground color, and background color.
      Parameters:
      font - the font to be used in the style
      foreground - the foreground color of the style
      background - the background color of the style
      Returns:
      a new Style instance configured with the specified font, foreground color, and background color