00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.gui.label;
00023
00024 import com.realtime.crossfire.jxclient.gui.gui.GUIElementListener;
00025 import com.realtime.crossfire.jxclient.gui.gui.TooltipManager;
00026 import java.awt.Color;
00027 import java.awt.Font;
00028 import java.awt.Graphics2D;
00029 import java.awt.geom.RectangularShape;
00030 import java.awt.image.BufferedImage;
00031 import org.jetbrains.annotations.NotNull;
00032 import org.jetbrains.annotations.Nullable;
00033
00038 public abstract class GUILabel extends AbstractLabel {
00039
00043 private static final long serialVersionUID = 1;
00044
00048 @NotNull
00049 private final Alignment textAlignment;
00050
00063 protected GUILabel(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final BufferedImage picture, @NotNull final String text, @NotNull final Font textFont, @NotNull final Color textColor, @Nullable final Color backgroundColor, @NotNull final Alignment textAlignment) {
00064 super(tooltipManager, elementListener, name, text, textFont, textColor, picture, backgroundColor);
00065 this.textAlignment = textAlignment;
00066 }
00067
00071 @Override
00072 protected void textChanged() {
00073 setChanged();
00074 }
00075
00083 protected void drawLine(@NotNull final Graphics2D g, final int y0, final int h0, @NotNull final String text) {
00084 g.setBackground(new Color(0, 0, 0, 0.0f));
00085 g.setFont(getTextFont());
00086 g.setColor(getTextColor());
00087 final RectangularShape rectangle = getTextFont().getStringBounds(text, g.getFontRenderContext());
00088 final int y = y0+(int)(Math.round(h0-rectangle.getHeight())/2-rectangle.getY());
00089 switch (textAlignment) {
00090 case LEFT:
00091 g.drawString(text, 0, y);
00092 break;
00093
00094 case CENTER:
00095 g.drawString(text, (int)Math.round((getWidth()-rectangle.getWidth())/2), y);
00096 break;
00097
00098 case RIGHT:
00099 g.drawString(text, (int)Math.round(getWidth()-rectangle.getWidth()), y);
00100 break;
00101 }
00102 }
00103
00104 }