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.gui.gui.AbstractGUIElement.name
final String name
Definition: AbstractGUIElement.java:77
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.commandList
final CommandList commandList
Definition: GUIGauge.java:65
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.paintComponent
void paintComponent(@NotNull final Graphics g)
Definition: GUITextGauge.java:95
com.realtime.crossfire.jxclient.gui.commandlist.CommandList
Definition: CommandList.java:34
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.stats
final Stats stats
Definition: GUIGauge.java:71
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.serialVersionUID
static final long serialVersionUID
Definition: GUITextGauge.java:49
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge
Definition: GUIGauge.java:47
com.realtime.crossfire.jxclient.stats.Stats
Definition: Stats.java:44
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.tooltipFormat
final String tooltipFormat
Definition: GUIGauge.java:59
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.tooltipText
String tooltipText
Definition: GUIGauge.java:77
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge
Definition: GUITextGauge.java:44
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)
Definition: GUITextGauge.java:88
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.color
final Color color
Definition: GUITextGauge.java:55
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.alpha
final float alpha
Definition: GUIGauge.java:100
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.elementListener
final GUIElementListener elementListener
Definition: AbstractGUIElement.java:89
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.gauge.GUIGauge.orientation
final Orientation orientation
Definition: GUIGauge.java:89
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.font
final Font font
Definition: GUITextGauge.java:61
com.realtime
com
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)
Definition: GUITextGauge.java:109
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.setChanged
void setChanged()
Definition: AbstractGUIElement.java:223
com.realtime.crossfire.jxclient.gui.gauge.GUITextGauge.labelText
String labelText
Definition: GUITextGauge.java:67
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.guiFactory
final GuiFactory guiFactory
Definition: AbstractGUIElement.java:48
com.realtime.crossfire.jxclient.gui.gauge.Orientation
Definition: Orientation.java:29
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement.tooltipManager
final TooltipManager tooltipManager
Definition: AbstractGUIElement.java:83
com.realtime.crossfire.jxclient.stats
Definition: ActiveSkillWatcher.java:23