22 package com.realtime.crossfire.jxclient.gui.log;
24 import java.awt.Color;
26 import java.awt.Graphics;
27 import java.awt.font.FontRenderContext;
28 import java.awt.font.LineMetrics;
29 import java.awt.geom.RectangularShape;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
49 private final boolean bold;
88 public TextSegment(@NotNull
final String text,
final boolean bold,
final boolean italic,
final boolean underline, @NotNull
final FontID font, @Nullable
final Color color) {
115 return fonts.getFontPrint();
118 return bold ? fonts.getFontFixedBold() : fonts.getFontFixed();
121 return fonts.getFontArcane();
124 return fonts.getFontPrint();
127 return fonts.getFontPrint();
130 throw new AssertionError();
137 public void draw(@NotNull
final Graphics g,
final int y, @NotNull
final Fonts fonts) {
140 final int segmentX =
getX();
141 final int segmentY =
getY();
142 g.drawString(text, segmentX, y+segmentY);
144 g.drawLine(segmentX, y+segmentY+underlineOffset, segmentX+
getWidth()-1, y+segmentY+underlineOffset);
153 final LineMetrics lineMetrics =
getFont(fonts).getLineMetrics(text, context);
154 underlineOffset = Math.round(lineMetrics.getUnderlineOffset());
162 public RectangularShape
getSize(@NotNull
final Fonts fonts, @NotNull
final FontRenderContext context) {
163 return getFont(fonts).getStringBounds(text, context);
175 public boolean matches(
final boolean bold,
final boolean italic,
final boolean underline, @NotNull
final FontID font, @Nullable
final Color color) {
176 return this.bold == bold && this.italic == italic && this.underline == underline && this.font == font && this.color ==
color;
185 final StringBuilder sb =
new StringBuilder();
186 sb.append(
"segment:");
191 sb.append(
"(italic)");
194 sb.append(
"(underline)");
197 sb.append(
'(').append(font.toString().toLowerCase()).append(
')');
204 return sb.toString();
String getText()
Returns the text to display.
Abstract base class for Segment implementations.
void draw(@NotNull final Graphics g, final int y, @NotNull final Fonts fonts)
Draws this segment to a Graphics instance.the graphics to draw to the y-coordinate to draw to the fon...
final boolean italic
Whether italic face is enabled.
Parser for parsing drawextinfo messages received from a Crossfire server to update a Buffer instance...
int y
The y-coordinate to display the segment.
int getX()
Returns the x-coordinate to display the segment.
int underlineOffset
The distance of the underline to the base line.
final FontID font
The font to use.
One segment of a Line which should be displayed without changing attributes.
int getWidth()
Returns the width to display the segment.
void updateAttributes(@NotNull final Fonts fonts, @NotNull final FontRenderContext context)
Updates the cached attributes of this segment.the fonts instance to use the font render context to us...
int getY()
Returns the y-coordinate to display the segment.
Font getFont(@NotNull final Fonts fonts)
Returns the Font to use for a given Segment.
final String text
The text to display.
final boolean bold
Whether bold face is enabled.
static String toString(@NotNull final Color color)
Returns the string representation for a color.
TextSegment(@NotNull final String text, final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID font, @Nullable final Color color)
Creates a new segment.
RectangularShape getSize(@NotNull final Fonts fonts, @NotNull final FontRenderContext context)
Returns the size of this segment in pixels.the fonts instance to use the font render context to use t...
boolean matches(final boolean bold, final boolean italic, final boolean underline, @NotNull final FontID font, @Nullable final Color color)
Returns whether this segment matches the given attributes.
final boolean underline
Whether underlining is enabled.
final Color color
The color to use.