Class FontConf
StyleConf
configuration object.
The following properties with their respective purpose are available:
- 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 thefamily(String)
method. - Size
The size of the font in points, which will ultimately translate to
Font.getSize()
. Use thesize(int)
method to specify the size of the font. - 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 theposture(float)
method to specify the posture of the font. - 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. - 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
andTextAttribute.TRACKING_LOOSE
values, which represent values of-0.04
and0.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
and0.3
; values outside this range are generally not desirable.You can use the
spacing(float)
method to specify the tracking of the font. - Color
The color of the font, which translates to the text property
TextAttribute.FOREGROUND
.You can use the
color(Color)
orcolor(String)
methods to specify the color of the font. - Background Color
The background color of the font which translates to the text property
TextAttribute.BACKGROUND
. - 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. - Underlined
Whether or not the font is underlined. This will ultimately translate to
TextAttribute.UNDERLINE
. - Strike
Whether or not the font is strike through. This will ultimately translate to
TextAttribute.STRIKETHROUGH
. - Transform
The transform of the font, which is an
AffineTransform
instance. - 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. - Background Paint
The background paint of the font, which is a
Paint
instance that is used to paint the background of the font. - Horizontal Alignment
The horizontal alignment of the font.
Note that this property is not relevant for all components, It will usually only be relevant forJLabel
,AbstractButton
andJTextField
types or maybe some custom components. Not all components support horizontal alignment. - Vertical Alignment
The vertical alignment of the font.
Note that this property is not relevant for all components, It will usually only be relevant forJLabel
,AbstractButton
andJTextField
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 Summary
Modifier and TypeMethodDescriptionbackgroundColor
(Color backgroundColor) Returns an updated font config with the specified background color.backgroundColor
(String colorString) Returns an updated font config with the specified background color string used to define the background color.backgroundGradient
(Configurator<GradientConf> configurator) Configures a gradient function basedPaint
for the background of the font appearance, using a configurator function that takes aGradientConf
instance and returns an updatedGradientConf
instance with the desired properties.backgroundNoise
(Configurator<NoiseConf> configurator) backgroundPaint
(@Nullable Paint backgroundPaint) Returns an updated font config with the specified background paint.Returns an updated font config with the specified color, which will be used for theTextAttribute.FOREGROUND
property of the resultingFont
instance.Returns an updated font config with the specified color string used to define the font color.boolean
Returns an updated font config with the specified font family name.gradient
(Configurator<GradientConf> configurator) Configures a gradient function basedPaint
for the font appearance, using a configurator function that takes aGradientConf
instance and returns an updatedGradientConf
instance with the desired properties.int
hashCode()
noise
(Configurator<NoiseConf> configurator) static FontConf
none()
Returns an updated font config with the specified paint.posture
(float posture) Returns an updated font config with the specified posture, defining the tilt of the font.selectionColor
(Color selectionColor) Returns an updated font config with the specified selection color.selectionColor
(String colorString) Returns an updated font config with the specified selection color string used to define the selection color.size
(int fontSize) Returns an updated font config with the specified font size, which will translate to aFont
instance with the specified size (seeFont.getSize()
).spacing
(float spacing) Returns an updated font config with the specified spacing, defining the tracking of the font.strikeThrough
(boolean strike) Returns an updated font config with the specified strike through property.style
(UI.FontStyle fontStyle) Determines if the font should be plain, bold, italic or bold and italic based on the providedUI.FontStyle
parameter, which may beUI.FontStyle.PLAIN
,UI.FontStyle.BOLD
,UI.FontStyle.ITALIC
orUI.FontStyle.BOLD_ITALIC
.
Note that this will override any previous bold or italic settings.toString()
transform
(@Nullable AffineTransform transform) Returns an updated font config with the specified transform.underlined
(boolean underlined) Returns an updated font config with the specified underlined property.weight
(double fontWeight) Returns an updated font config with the specified weight, defining the boldness of the font.
-
Method Details
-
none
-
family
Returns an updated font config with the specified font family name.- Parameters:
fontFamily
- The font family name to use for theFont.getFamily()
property.- Returns:
- A new font style with the specified font family name.
-
size
Returns an updated font config with the specified font size, which will translate to aFont
instance with the specified size (seeFont.getSize()
).- Parameters:
fontSize
- The font size to use for theFont.getSize()
property.- Returns:
- A new font style with the specified font size.
-
posture
Returns an updated font config with the specified posture, defining the tilt of the font. AFont
with a higher posture value will be more italic. (seeFont.isItalic()
).- Parameters:
posture
- The posture to use for theFont.isItalic()
property.- Returns:
- A new font style with the specified posture.
-
weight
Returns an updated font config with the specified weight, defining the boldness of the font. AFont
with a higher weight value will be bolder. (seeFont.isBold()
).- Parameters:
fontWeight
- The weight to use for theFont.isBold()
property.- Returns:
- A new font style with the specified weight.
-
style
Determines if the font should be plain, bold, italic or bold and italic based on the providedUI.FontStyle
parameter, which may beUI.FontStyle.PLAIN
,UI.FontStyle.BOLD
,UI.FontStyle.ITALIC
orUI.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 theUI.FontStyle
enum.- Returns:
- An updated font config with the specified font style.
-
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
and0.3
; values outside this range are generally not desirable.- Parameters:
spacing
- The spacing to use for theTextAttribute.TRACKING
property.- Returns:
- A new font style with the specified spacing.
-
color
Returns an updated font config with the specified color, which will be used for theTextAttribute.FOREGROUND
property of the resultingFont
instance.- Parameters:
color
- The color to use for theTextAttribute.FOREGROUND
property.- Returns:
- A new font style with the specified color.
-
color
Returns an updated font config with the specified color string used to define the font color. The color will be used for theTextAttribute.FOREGROUND
property of the resultingFont
instance.- Parameters:
colorString
- The color string to use for theTextAttribute.FOREGROUND
property.- Returns:
- A new font style with the specified color.
-
backgroundColor
Returns an updated font config with the specified background color. The color value will be used for theTextAttribute.BACKGROUND
property of the resultingFont
instance.- Parameters:
backgroundColor
- The background color to use for theTextAttribute.BACKGROUND
property.- Returns:
- A new font style with the specified background color.
-
backgroundColor
Returns an updated font config with the specified background color string used to define the background color. The background color will be used for theTextAttribute.BACKGROUND
property of the resultingFont
instance.- Parameters:
colorString
- The color string to use for theTextAttribute.BACKGROUND
property.- Returns:
- A new font style with the specified background 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
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
Returns an updated font config with the specified underlined property. This boolean will translate to theTextAttribute.UNDERLINE
property of the resultingFont
instance.- Parameters:
underlined
- Whether the font should be underlined.- Returns:
- A new font style with the specified underlined property.
-
strikeThrough
Returns an updated font config with the specified strike through property. This boolean will translate to theTextAttribute.STRIKETHROUGH
property of the resultingFont
instance.- Parameters:
strike
- Whether the font should be strike through.- Returns:
- A new font style with the specified strike through property.
-
transform
Returns an updated font config with the specified transform. This transform will be used for theTextAttribute.TRANSFORM
property of the resultingFont
instance.- Parameters:
transform
- The transform to use for theTextAttribute.TRANSFORM
property.- Returns:
- A new font style with the specified transform.
-
paint
Returns an updated font config with the specified paint. This paint will be used for theTextAttribute.FOREGROUND
property of the resultingFont
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 thecolor(Color)
,color(String)
,noise(Configurator)
orgradient(Configurator)
methods as a font can only have one paint.- Parameters:
paint
- The paint to use for theTextAttribute.FOREGROUND
property.- Returns:
- A new font style with the specified paint.
-
noise
Configures a noise function basedPaint
for the font appearance, using a configurator function that takes aNoiseConf
instance and returns an updatedNoiseConf
instance with the desired properties.
Keep in mind that this will override the effects of thecolor(Color)
,color(String)
,paint(Paint)
orgradient(Configurator)
methods as a font can only have one paint. -
gradient
Configures a gradient function basedPaint
for the font appearance, using a configurator function that takes aGradientConf
instance and returns an updatedGradientConf
instance with the desired properties.
Keep in mind that this will override the effects of thecolor(Color)
,color(String)
,paint(Paint)
ornoise(Configurator)
methods as a font can only have one paint.- Parameters:
configurator
- The configurator function that takes aGradientConf
instance and returns an updatedGradientConf
instance with the desired properties.- Returns:
- A new font style with the specified gradient paint.
-
backgroundPaint
Returns an updated font config with the specified background paint. This paint will be used for theTextAttribute.BACKGROUND
property of the resultingFont
instance.- Parameters:
backgroundPaint
- The background paint to use for theTextAttribute.BACKGROUND
property.- Returns:
- A new font style with the specified background paint.
-
backgroundNoise
Configures a noise function basedPaint
for the background of the font appearance, using a configurator function that takes aNoiseConf
instance and returns an updatedNoiseConf
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 thebackgroundPaint(Paint)
,backgroundGradient(Configurator)
, andbackgroundColor(String)
methods. -
backgroundGradient
Configures a gradient function basedPaint
for the background of the font appearance, using a configurator function that takes aGradientConf
instance and returns an updatedGradientConf
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 thebackgroundPaint(Paint)
,backgroundNoise(Configurator)
, andbackgroundColor(String)
methods.- Parameters:
configurator
- The configurator function that takes aGradientConf
instance and returns an updatedGradientConf
instance with the desired properties.- Returns:
- A new font style with the specified gradient background paint.
-
hashCode
public int hashCode() -
equals
-
toString
-