Crossfire JXClient, Trunk  R20561
GUITextGauge.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.gauge;
23 
27 import java.awt.Color;
28 import java.awt.Font;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.Image;
32 import java.awt.geom.RectangularShape;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
41 public class GUITextGauge extends GUIGauge {
42 
46  private static final long serialVersionUID = 1;
47 
51  @NotNull
52  private final Color color;
53 
57  @NotNull
58  private final Font font;
59 
63  @NotNull
64  private String labelText = "";
65 
81  public GUITextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFull, @Nullable final Image pictureNegative, @NotNull final Image pictureEmpty, @NotNull final Orientation orientation, @Nullable final String tooltipPrefix, @NotNull final Color color, @NotNull final Font font, final float alpha, @Nullable final CommandList commandList) {
82  super(tooltipManager, elementListener, name, pictureFull, pictureNegative, pictureEmpty, orientation, tooltipPrefix, alpha, commandList);
83  this.color = color;
84  this.font = font;
85  }
86 
90  @Override
91  public void paintComponent(@NotNull final Graphics g) {
92  super.paintComponent(g);
93  final Graphics2D g2 = (Graphics2D)g;
94  g2.setBackground(new Color(0, 0, 0, 0.0f));
95  g2.setColor(color);
96  g2.setFont(font);
97  final String text = labelText;
98  final RectangularShape rectangle = font.getStringBounds(text, g2.getFontRenderContext());
99  final int x = (int)Math.round((getWidth()-rectangle.getWidth())/2);
100  final int y = (int)Math.round(getHeight()-rectangle.getMaxY()-rectangle.getMinY())/2;
101  g2.drawString(text, x, y);
102  }
103 
107  @Override
108  public void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText) {
109  super.setValues(curValue, minValue, maxValue, labelText, tooltipText);
110  this.labelText = labelText;
111  setChanged();
112  }
113 
114 }
final TooltipManager tooltipManager
The TooltipManager to update.
void setChanged()
Records that the contents have changed and must be repainted.
final GUIElementListener elementListener
The GUIElementListener to notify.
void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText)
Sets the values to display.the values to display the minimum possible value the maximum possible valu...
final float alpha
The gauge alpha value, 1 is opaque and 0 full transparent.
Definition: GUIGauge.java:91
final Orientation orientation
The gauge's orientation.
Definition: GUIGauge.java:80
static final long serialVersionUID
The serial version UID.
final CommandList commandList
The CommandList that is executed on button 2.
Definition: GUIGauge.java:62
GUITextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFull, @Nullable final Image pictureNegative, @NotNull final Image pictureEmpty, @NotNull final Orientation orientation, @Nullable final String tooltipPrefix, @NotNull final Color color, @NotNull final Font font, final float alpha, @Nullable final CommandList commandList)
Creates a new instance.
String tooltipText
The default tooltip text.
Definition: GUIGauge.java:68
Displays a value as a graphical gauge that's filling state depends on the value.
Definition: GUIGauge.java:44
A GUIGauge which displays the current value as a text string on top of the gauge. ...