Crossfire JXClient, Trunk  R20561
GUIDupTextGauge.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 GUIDupTextGauge extends GUIDupGauge {
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 GUIDupTextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFullDiv, final Image pictureFullMod, @NotNull final Image pictureEmpty, @NotNull final Orientation orientationDiv, @NotNull final Orientation orientationMod, @Nullable final String tooltipPrefix, @NotNull final Color color, @NotNull final Font font, @Nullable final CommandList commandList) {
82  super(tooltipManager, elementListener, name, pictureFullDiv, pictureFullMod, pictureEmpty, orientationDiv, orientationMod, tooltipPrefix, 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  g2.drawString(text, (int)Math.round((getWidth()-rectangle.getWidth())/2), (int)Math.round(getHeight()-rectangle.getMaxY()-rectangle.getMinY())/2);
100  }
101 
105  @Override
106  public void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText) {
107  super.setValues(curValue, minValue, maxValue, labelText, tooltipText);
108  this.labelText = labelText;
109  setChanged();
110  }
111 
112 }
final TooltipManager tooltipManager
The TooltipManager to update.
void setChanged()
Records that the contents have changed and must be repainted.
final CommandList commandList
The CommandList that is executed on button 2.
final GUIElementListener elementListener
The GUIElementListener to notify.
GUIDupTextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFullDiv, final Image pictureFullMod, @NotNull final Image pictureEmpty, @NotNull final Orientation orientationDiv, @NotNull final Orientation orientationMod, @Nullable final String tooltipPrefix, @NotNull final Color color, @NotNull final Font font, @Nullable final CommandList commandList)
Creates a new instance.
final Orientation orientationMod
The gauge's orientation.
Displays a value as a graphical gauge that's filling state depends on the value.
final String tooltipPrefix
The tooltip prefix.
final Orientation orientationDiv
The gauge's orientation.
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...
A GUIDupGauge which displays the current value as a text string on top of the gauge.
static final long serialVersionUID
The serial version UID.