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.AbstractGUIElement;
00025 import com.realtime.crossfire.jxclient.gui.gui.GUIElementListener;
00026 import com.realtime.crossfire.jxclient.gui.gui.TooltipManager;
00027 import java.awt.Color;
00028 import java.awt.Font;
00029 import java.awt.Graphics;
00030 import java.awt.Transparency;
00031 import java.awt.image.BufferedImage;
00032 import javax.swing.ImageIcon;
00033 import org.jetbrains.annotations.NotNull;
00034 import org.jetbrains.annotations.Nullable;
00035
00042 public abstract class AbstractLabel extends AbstractGUIElement {
00043
00047 private static final long serialVersionUID = 1;
00048
00052 @NotNull
00053 private String text;
00054
00058 @NotNull
00059 private final Font textFont;
00060
00064 @NotNull
00065 private final Color textColor;
00066
00070 @Nullable
00071 private ImageIcon backgroundImage;
00072
00077 @Nullable
00078 private final Color backgroundColor;
00079
00092 protected AbstractLabel(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final String text, @NotNull final Font textFont, @NotNull final Color textColor, @Nullable final BufferedImage backgroundPicture, @Nullable final Color backgroundColor) {
00093 super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
00094 this.text = text;
00095 this.textFont = textFont;
00096 this.textColor = textColor;
00097 backgroundImage = backgroundPicture == null ? null : new ImageIcon(backgroundPicture);
00098 this.backgroundColor = backgroundColor;
00099 }
00100
00105 public void setText(@NotNull final String text) {
00106 if (!this.text.equals(text)) {
00107 this.text = text;
00108 textChanged();
00109 }
00110 }
00111
00115 protected abstract void textChanged();
00116
00121 @NotNull
00122 protected String getText() {
00123 return text;
00124 }
00125
00130 @NotNull
00131 protected Font getTextFont() {
00132 return textFont;
00133 }
00134
00139 @NotNull
00140 protected Color getTextColor() {
00141 return textColor;
00142 }
00143
00147 @Override
00148 public void paintComponent(@NotNull final Graphics g) {
00149 super.paintComponent(g);
00150
00151 if (backgroundImage != null) {
00152 g.drawImage(backgroundImage.getImage(), 0, 0, null);
00153 } else if (backgroundColor != null) {
00154 g.setColor(backgroundColor);
00155 g.fillRect(0, 0, getWidth(), getHeight());
00156 }
00157 }
00158
00164 protected void setBackgroundImage(@Nullable final ImageIcon backgroundImage) {
00165 this.backgroundImage = backgroundImage;
00166 setChanged();
00167 }
00168
00172 @Override
00173 public void execute() {
00174
00175 }
00176
00177 }