Crossfire JXClient, Trunk  R20561
GUIOneLineLabel.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.label;
23 
27 import java.awt.Color;
28 import java.awt.Dimension;
29 import java.awt.Font;
30 import java.awt.Graphics;
31 import java.awt.Graphics2D;
32 import java.awt.image.BufferedImage;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
40 public class GUIOneLineLabel extends GUILabel {
41 
45  private static final long serialVersionUID = 1;
46 
59  public GUIOneLineLabel(@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) {
60  super(tooltipManager, elementListener, name, picture, text, font, color, backgroundColor, alignment);
61  }
62 
66  @Override
67  public void paintComponent(@NotNull final Graphics g) {
68  super.paintComponent(g);
69  drawLine((Graphics2D)g, 0, getHeight(), getText());
70  }
71 
75  @Nullable
76  @Override
77  public Dimension getPreferredSize() {
78  return getMinimumSizeInt();
79  }
80 
84  @Nullable
85  @Override
86  public Dimension getMinimumSize() {
87  return getMinimumSizeInt();
88  }
89 
94  @NotNull
95  private Dimension getMinimumSizeInt() {
96  return GuiUtils.getTextDimension(getText(), getFontMetrics(getTextFont()));
97  }
98 
99 }
GUIOneLineLabel(@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.
A AbstractLabel that renders the text as a plain string.
final TooltipManager tooltipManager
The TooltipManager to update.
Dimension getMinimumSizeInt()
Returns the minimal size needed to display this component.
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.
Definition: GuiUtils.java:51
void drawLine(@NotNull final Graphics2D g, final int y0, final int h0, @NotNull final String text)
Draws one line of text.
Definition: GUILabel.java:83
final GUIElementListener elementListener
The GUIElementListener to notify.
Abstract base class for labels that render text.
Definition: GUILabel.java:38
final Color backgroundColor
If set, the opaque background color.
Utility class for Gui related functions.
Definition: GuiUtils.java:35
static final long serialVersionUID
The serial version UID.