22 package com.realtime.crossfire.jxclient.gui.label;
27 import java.awt.Color;
28 import java.awt.Dimension;
30 import java.awt.FontMetrics;
31 import java.awt.Graphics;
32 import java.awt.Graphics2D;
33 import java.awt.image.BufferedImage;
34 import java.util.regex.Pattern;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
75 super(tooltipManager, elementListener, name, picture, text, font, color, backgroundColor, alignment);
76 lines = LINE_SEPARATOR_PATTERN.split(
getText(), -1);
84 lines = LINE_SEPARATOR_PATTERN.split(
getText(), -1);
93 super.paintComponent(g);
95 if (lines.length <= 0) {
99 final Graphics2D g2 = (Graphics2D)g;
101 final int lineHeight = rectangle.height;
104 for (
final String line : lines) {
135 final FontMetrics fontMetrics = getFontMetrics(
getTextFont());
138 for (
final String line : lines) {
140 if (width < dimension.width) {
141 width = dimension.width;
146 final int height = lines.length*rectangle.height;
148 return new Dimension(width, height);
Listener for GUIElement related events.
Dimension getPreferredSize()
static final Pattern LINE_SEPARATOR_PATTERN
The pattern to split the text into lines.
void paintComponent(@NotNull final Graphics g)
A AbstractLabel that renders the text as a list of plain strings.
final TooltipManager tooltipManager
The TooltipManager to update.
static Dimension getTextDimension(@NotNull final String text, @NotNull final FontMetrics fontMetrics)
Returns the extents of a string when rendered in a given Font on this component.
void drawLine(@NotNull final Graphics2D g, final int y0, final int h0, @NotNull final String text)
Draws one line of text.
static final long serialVersionUID
The serial version UID.
Dimension getMinimumSize()
final GUIElementListener elementListener
The GUIElementListener to notify.
Abstract base class for labels that render text.
final Color backgroundColor
If set, the opaque background color.
final String name
The name of this element.
Font getTextFont()
Returns the font.
Utility class for Gui related functions.
String getText()
Returns the label text.
String text
The label text.
GUIMultiLineLabel(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final BufferedImage picture, @NotNull final Font font, @NotNull final Color color, @Nullable final Color backgroundColor, @NotNull final Alignment alignment, @NotNull final String text)
Creates a new instance.
Dimension getTextSize()
Returns the minimal size of this component to display all of lines.
String [] lines
The text lines to draw.