Class FontConf

java.lang.Object
swingtree.style.FontConf

@Immutable public final class FontConf extends Object
An immutable, wither-like method based config API for font styles that is part of the full StyleConf configuration object.

The following properties with their respective purpose are available:

  1. Name

    The name of the font, which is essentially the font family. This will ultimately translate to Font.getFamily().
    You may specify the font family name through the family(String) method.

  2. Size

    The size of the font in points, which will ultimately translate to Font.getSize(). Use the size(int) method to specify the size of the font.

  3. Posture

    The posture of the font, which is a value between 0 and 1.
    A value of 0 means that the font is not italic, while a value of 1 means that the font is "fully" italic.
    You can use the posture(float) method to specify the posture of the font.

  4. Weight

    The weight of the font (boldness, see Font.BOLD), which is a value between 0 and 2.

    The weight of the font can be specified using the weight(double) method.

  5. Spacing (Tracking)

    This property controls the tracking which is a floating point number with the default value of 0, meaning no additional tracking is added to the font.

    Useful constant values are the predefined TextAttribute.TRACKING_TIGHT and TextAttribute.TRACKING_LOOSE values, which represent values of -0.04 and 0.04,

    The tracking value is multiplied by the font point size and passed through the font transform to determine an additional amount to add to the advance of each glyph cluster. Positive tracking values will inhibit formation of optional ligatures. Tracking values are typically between -0.1 and 0.3; values outside this range are generally not desirable.

    You can use the spacing(float) method to specify the tracking of the font.

  6. Color

    The color of the font, which translates to the text property TextAttribute.FOREGROUND.

    You can use the color(Color) or color(String) methods to specify the color of the font.

  7. Background Color

    The background color of the font which translates to the text property TextAttribute.BACKGROUND.

  8. Selection Color

    The selection color of the font, which translates to JTextComponent.setSelectionColor(Color).
    Note that this property is only relevant for text components, most components do not support text selection.

  9. Underlined

    Whether or not the font is underlined. This will ultimately translate to TextAttribute.UNDERLINE.

  10. Strike

    Whether or not the font is strike through. This will ultimately translate to TextAttribute.STRIKETHROUGH.

  11. Transform

    The transform of the font, which is an AffineTransform instance.

  12. Paint

    The paint of the font, which is a Paint instance. Note that specifying a custom paint will override the effects of the color property as the color property is in essence merely a convenience property for a paint painting across the entire font area homogeneously using the specified color.

  13. Background Paint

    The background paint of the font, which is a Paint instance that is used to paint the background of the font.

  14. Horizontal Alignment

    The horizontal alignment of the font.
    Note that this property is not relevant for all components, It will usually only be relevant for JLabel, AbstractButton and JTextField types or maybe some custom components. Not all components support horizontal alignment.

  15. Vertical Alignment

    The vertical alignment of the font.
    Note that this property is not relevant for all components, It will usually only be relevant for JLabel, AbstractButton and JTextField types or maybe some custom components. Not all components support vertical alignment.

You can use the none() method to specify that no font should be used, as the instance returned by that method is a font style with an empty string as its name, and other properties set to their default values, effectively making it a representation of the absence of a font style.

Also note that this class is immutable, which means that wither-like methods will always return new instances of this class, leaving the original instance untouched.
This means that you can not modify a font style instance directly, but you can easily create a modified copy of it by calling one of the wither-like methods.

  • Method Details

    • none

      public static FontConf none()
    • family

      public FontConf family(String fontFamily)
      Returns an updated font config with the specified font family name.
      Parameters:
      fontFamily - The font family name to use for the Font.getFamily() property.
      Returns:
      A new font style with the specified font family name.
    • size

      public FontConf size(int fontSize)
      Returns an updated font config with the specified font size, which will translate to a Font instance with the specified size (see Font.getSize()).
      Parameters:
      fontSize - The font size to use for the Font.getSize() property.
      Returns:
      A new font style with the specified font size.
    • posture

      public FontConf posture(float posture)
      Returns an updated font config with the specified posture, defining the tilt of the font. A Font with a higher posture value will be more italic. (see Font.isItalic()).
      Parameters:
      posture - The posture to use for the Font.isItalic() property.
      Returns:
      A new font style with the specified posture.
    • weight

      public FontConf weight(double fontWeight)
      Returns an updated font config with the specified weight, defining the boldness of the font. A Font with a higher weight value will be bolder. (see Font.isBold()).
      Parameters:
      fontWeight - The weight to use for the Font.isBold() property.
      Returns:
      A new font style with the specified weight.
    • style

      public FontConf style(UI.FontStyle fontStyle)
      Determines if the font should be plain, bold, italic or bold and italic based on the provided UI.FontStyle parameter, which may be UI.FontStyle.PLAIN, UI.FontStyle.BOLD, UI.FontStyle.ITALIC or UI.FontStyle.BOLD_ITALIC.
      Note that this will override any previous bold or italic settings.
      Parameters:
      fontStyle - The font style to use for the font in the UI.FontStyle enum.
      Returns:
      An updated font config with the specified font style.
    • spacing

      public FontConf spacing(float spacing)
      Returns an updated font config with the specified spacing, defining the tracking of the font. The tracking value is multiplied by the font point size and passed through the font transform to determine an additional amount to add to the advance of each glyph cluster. Positive tracking values will inhibit formation of optional ligatures. Tracking values are typically between -0.1 and 0.3; values outside this range are generally not desirable.
      Parameters:
      spacing - The spacing to use for the TextAttribute.TRACKING property.
      Returns:
      A new font style with the specified spacing.
    • color

      public FontConf color(Color color)
      Returns an updated font config with the specified color, which will be used for the TextAttribute.FOREGROUND property of the resulting Font instance.
      Parameters:
      color - The color to use for the TextAttribute.FOREGROUND property.
      Returns:
      A new font style with the specified color.
    • color

      public FontConf color(String colorString)
      Returns an updated font config with the specified color string used to define the font color. The color will be used for the TextAttribute.FOREGROUND property of the resulting Font instance.
      Parameters:
      colorString - The color string to use for the TextAttribute.FOREGROUND property.
      Returns:
      A new font style with the specified color.
    • backgroundColor

      public FontConf backgroundColor(Color backgroundColor)
      Returns an updated font config with the specified background color. The color value will be used for the TextAttribute.BACKGROUND property of the resulting Font instance.
      Parameters:
      backgroundColor - The background color to use for the TextAttribute.BACKGROUND property.
      Returns:
      A new font style with the specified background color.
    • backgroundColor

      public FontConf backgroundColor(String colorString)
      Returns an updated font config with the specified background color string used to define the background color. The background color will be used for the TextAttribute.BACKGROUND property of the resulting Font instance.
      Parameters:
      colorString - The color string to use for the TextAttribute.BACKGROUND property.
      Returns:
      A new font style with the specified background color.
    • selectionColor

      public FontConf selectionColor(Color selectionColor)
      Returns an updated font config with the specified selection color. The selection color will be used for the selection color of the font. Note that not all components support text selection, so this property may not have an effect on all components.
      Parameters:
      selectionColor - The selection color to use for the selection color of the font.
      Returns:
      A new font style with the specified selection color.
    • selectionColor

      public FontConf selectionColor(String colorString)
      Returns an updated font config with the specified selection color string used to define the selection color. The selection color will be used for the selection color of the font. Note that not all components support text selection, so this property may not have an effect on all components.
      Parameters:
      colorString - The color string to use for the selection color of the font.
      Returns:
      A new font style with the specified selection color.
    • underlined

      public FontConf underlined(boolean underlined)
      Returns an updated font config with the specified underlined property. This boolean will translate to the TextAttribute.UNDERLINE property of the resulting Font instance.
      Parameters:
      underlined - Whether the font should be underlined.
      Returns:
      A new font style with the specified underlined property.
    • strikeThrough

      public FontConf strikeThrough(boolean strike)
      Returns an updated font config with the specified strike through property. This boolean will translate to the TextAttribute.STRIKETHROUGH property of the resulting Font instance.
      Parameters:
      strike - Whether the font should be strike through.
      Returns:
      A new font style with the specified strike through property.
    • transform

      public FontConf transform(@Nullable AffineTransform transform)
      Returns an updated font config with the specified transform. This transform will be used for the TextAttribute.TRANSFORM property of the resulting Font instance.
      Parameters:
      transform - The transform to use for the TextAttribute.TRANSFORM property.
      Returns:
      A new font style with the specified transform.
    • paint

      public FontConf paint(@Nullable Paint paint)
      Returns an updated font config with the specified paint. This paint will be used for the TextAttribute.FOREGROUND property of the resulting Font instance. Note that specifying a custom paint will override the effects of the color property as the color property is in essence merely a convenience property for a paint painting across the entire font area homogeneously using the specified color.
      Note that this will override the effects of the color(Color), color(String), noise(Configurator) or gradient(Configurator) methods as a font can only have one paint.
      Parameters:
      paint - The paint to use for the TextAttribute.FOREGROUND property.
      Returns:
      A new font style with the specified paint.
    • noise

      public FontConf noise(Configurator<NoiseConf> configurator)
      Configures a noise function based Paint for the font appearance, using a configurator function that takes a NoiseConf instance and returns an updated NoiseConf instance with the desired properties.
      Keep in mind that this will override the effects of the color(Color), color(String), paint(Paint) or gradient(Configurator) methods as a font can only have one paint.
      Parameters:
      configurator - The configurator function that takes a NoiseConf instance and returns an updated NoiseConf instance with the desired properties.
      Returns:
      A new font style with the specified noise paint.
    • gradient

      public FontConf gradient(Configurator<GradientConf> configurator)
      Configures a gradient function based Paint for the font appearance, using a configurator function that takes a GradientConf instance and returns an updated GradientConf instance with the desired properties.
      Keep in mind that this will override the effects of the color(Color), color(String), paint(Paint) or noise(Configurator) methods as a font can only have one paint.
      Parameters:
      configurator - The configurator function that takes a GradientConf instance and returns an updated GradientConf instance with the desired properties.
      Returns:
      A new font style with the specified gradient paint.
    • backgroundPaint

      public FontConf backgroundPaint(@Nullable Paint backgroundPaint)
      Returns an updated font config with the specified background paint. This paint will be used for the TextAttribute.BACKGROUND property of the resulting Font instance.
      Parameters:
      backgroundPaint - The background paint to use for the TextAttribute.BACKGROUND property.
      Returns:
      A new font style with the specified background paint.
    • backgroundNoise

      public FontConf backgroundNoise(Configurator<NoiseConf> configurator)
      Configures a noise function based Paint for the background of the font appearance, using a configurator function that takes a NoiseConf instance and returns an updated NoiseConf instance with the desired properties.
      Note that the background can only have one paint, so specifying a noise based paint will override the effects of the backgroundPaint(Paint), backgroundGradient(Configurator), and backgroundColor(String) methods.
      Parameters:
      configurator - The configurator function that takes a NoiseConf instance and returns an updated NoiseConf instance with the desired properties.
      Returns:
      A new font style with the specified noise background paint.
    • backgroundGradient

      public FontConf backgroundGradient(Configurator<GradientConf> configurator)
      Configures a gradient function based Paint for the background of the font appearance, using a configurator function that takes a GradientConf instance and returns an updated GradientConf instance with the desired properties.
      The background of a font can only have one paint, so specifying a gradient based paint will override the effects of the backgroundPaint(Paint), backgroundNoise(Configurator), and backgroundColor(String) methods.
      Parameters:
      configurator - The configurator function that takes a GradientConf instance and returns an updated GradientConf instance with the desired properties.
      Returns:
      A new font style with the specified gradient background paint.
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object