Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.gauge;
24 
30 import java.awt.Color;
31 import java.awt.Font;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.Image;
35 import java.awt.geom.RectangularShape;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 
44 public class GUITextGauge extends GUIGauge {
45 
49  private static final long serialVersionUID = 1;
50 
54  @NotNull
55  private final Color color;
56 
60  @NotNull
61  private final Font font;
62 
66  @NotNull
67  private String labelText = "";
68 
88  public GUITextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFull, @NotNull final Image pictureLow, @Nullable final Image pictureNegative, @NotNull final Image pictureEmpty, @NotNull final Orientation orientation, @Nullable final String tooltipFormat, @NotNull final Color color, @NotNull final Font font, final float alpha, @Nullable final CommandList commandList, @NotNull final GuiFactory guiFactory, @NotNull final Stats stats) {
89  super(tooltipManager, elementListener, name, pictureFull, pictureLow, pictureNegative, pictureEmpty, orientation, tooltipFormat, alpha, commandList, guiFactory, stats);
90  this.color = color;
91  this.font = font;
92  }
93 
94  @Override
95  public void paintComponent(@NotNull final Graphics g) {
96  super.paintComponent(g);
97  final Graphics2D g2 = (Graphics2D)g;
98  g2.setBackground(new Color(0, 0, 0, 0.0f));
99  g2.setColor(color);
100  g2.setFont(font);
101  final String text = labelText;
102  final RectangularShape rectangle = font.getStringBounds(text, g2.getFontRenderContext());
103  final int x = (int)Math.round((getWidth()-rectangle.getWidth())/2);
104  final int y = (int)Math.round(getHeight()-rectangle.getMaxY()-rectangle.getMinY())/2;
105  g2.drawString(text, x, y);
106  }
107 
108  @Override
109  public void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText) {
110  super.setValues(curValue, minValue, maxValue, labelText, tooltipText);
111  this.labelText = labelText;
112  setChanged();
113  }
114 
115 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge
Displays a value as a graphical gauge that's filling state depends on the value.
Definition: GUIGauge.java:47
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.tooltipFormat
final String tooltipFormat
The tooltip format.
Definition: GUIGauge.java:59
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.orientation
final Orientation orientation
The gauge's orientation.
Definition: GUIGauge.java:89
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.labelText
String labelText
The label text.
Definition: GUITextGauge.java:67
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChanged
void setChanged()
Records that the contents have changed and must be repainted.
Definition: AbstractGUIElement.java:223
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: GUITextGauge.java:49
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.stats
final Stats stats
The Stats instance to use.
Definition: GUIGauge.java:71
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.setValues
void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText)
Sets the values to display.
Definition: GUITextGauge.java:109
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
The GUIElementListener to notify.
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.gauge.Orientation
Interface for orientation images.
Definition: Orientation.java:29
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.font
final Font font
The text font.
Definition: GUITextGauge.java:61
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.tooltipText
String tooltipText
The default tooltip text.
Definition: GUIGauge.java:77
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge
A GUIGauge which displays the current value as a text string on top of the gauge.
Definition: GUITextGauge.java:44
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.alpha
final float alpha
The gauge alpha value, 1 is opaque and 0 full transparent.
Definition: GUIGauge.java:100
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.stats.Stats
This is the representation of all the statistics of a player, like its speed or its experience.
Definition: Stats.java:44
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
The global GuiFactory instance.
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.GUITextGauge
GUITextGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image pictureFull, @NotNull final Image pictureLow, @Nullable final Image pictureNegative, @NotNull final Image pictureEmpty, @NotNull final Orientation orientation, @Nullable final String tooltipFormat, @NotNull final Color color, @NotNull final Font font, final float alpha, @Nullable final CommandList commandList, @NotNull final GuiFactory guiFactory, @NotNull final Stats stats)
Creates a new instance.
Definition: GUITextGauge.java:88
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.commandList
final CommandList commandList
The CommandList that is executed on button 2.
Definition: GUIGauge.java:65
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Factory for creating Gui instances.
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.commandlist.CommandList
A list of GUICommand instances.
Definition: CommandList.java:34
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.name
final String name
The name of this element.
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Manages the tooltip display.
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.paintComponent
void paintComponent(@NotNull final Graphics g)
Definition: GUITextGauge.java:95
com.realtime
com
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.color
final Color color
The text color.
Definition: GUITextGauge.java:55
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
The TooltipManager to update.
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Listener for GUIElement related events.
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.stats
Definition: ActiveSkillWatcher.java:23