public class TextSegment extends AbstractSegment
Line
which should be displayed without changing
attributes.Modifier and Type | Field and Description |
---|---|
private boolean |
bold
Whether bold face is enabled.
|
private java.awt.Color |
color
The color to use.
|
private FontID |
font
The font to use.
|
private boolean |
italic
Whether italic face is enabled.
|
private java.lang.String |
text
The text to display.
|
private boolean |
underline
Whether underlining is enabled.
|
private int |
underlineOffset
The distance of the underline to the base line.
|
Constructor and Description |
---|
TextSegment(java.lang.String text,
boolean bold,
boolean italic,
boolean underline,
FontID font,
java.awt.Color color)
Creates a new segment.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(java.awt.Graphics g,
int y,
Fonts fonts)
Draws this segment to a
Graphics instance. |
private java.awt.Font |
getFont(Fonts fonts)
Returns the
Font to use for a given Segment . |
java.awt.geom.RectangularShape |
getSize(Fonts fonts,
java.awt.font.FontRenderContext context)
Returns the size of this segment in pixels.
|
java.lang.String |
getText()
Returns the text to display.
|
boolean |
matches(boolean bold,
boolean italic,
boolean underline,
FontID font,
java.awt.Color color)
Returns whether this segment matches the given attributes.
|
java.lang.String |
toString() |
void |
updateAttributes(Fonts fonts,
java.awt.font.FontRenderContext context)
Updates the cached attributes of this segment.
|
private final boolean bold
@Nullable private final java.awt.Color color
null
means "default color".@NotNull private final FontID font
private final boolean italic
@NotNull private final java.lang.String text
private final boolean underline
private int underlineOffset
0
if
unknown.public TextSegment(@NotNull java.lang.String text, boolean bold, boolean italic, boolean underline, @NotNull FontID font, @Nullable java.awt.Color color)
text
- the text to displaybold
- whether bold face is enableditalic
- whether italic face is enabledunderline
- whether underlining is enabledfont
- the font to usecolor
- the color to use; null
means "default color"public void draw(@NotNull java.awt.Graphics g, int y, @NotNull Fonts fonts)
Graphics
instance.g
- the graphics to draw toy
- the y-coordinate to draw tofonts
- the fonts to use@NotNull private java.awt.Font getFont(@NotNull Fonts fonts)
Font
to use for a given Segment
.fonts
- the Fonts
instance to use@NotNull public java.awt.geom.RectangularShape getSize(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context)
fonts
- the fonts instance to usecontext
- the font render context to use@NotNull public java.lang.String getText()
public boolean matches(boolean bold, boolean italic, boolean underline, @NotNull FontID font, @Nullable java.awt.Color color)
bold
- the bold attributeitalic
- the italic attributeunderline
- the underline attributefont
- the font attributecolor
- the color attribute@NotNull public java.lang.String toString()
toString
in class java.lang.Object
public void updateAttributes(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context)
fonts
- the fonts instance to usecontext
- the font render context to use