22 package com.realtime.crossfire.jxclient.gui.gauge;
28 import java.awt.Color;
29 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Image;
32 import java.awt.Transparency;
33 import java.awt.event.MouseEvent;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
121 super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
127 gaugeStateDiv =
new GaugeState(fullImageDiv, null, 0, 0);
128 final int w = getWidth();
129 final int h = getHeight();
130 gaugeStateMod =
new GaugeState(fullImageMod, null, 0, h/2);
131 orientationDiv.setExtends(w, h);
132 orientationMod.setExtends(w, h);
133 orientationDiv.setValues(0, 0, 9);
134 orientationMod.setValues(0, 0, 9);
145 super.paintComponent(g);
146 g.setColor(
new Color(0, 0, 0, 0.0f));
147 g.fillRect(0, 0, getWidth(), getHeight());
148 if (emptyImage != null) {
149 g.drawImage(emptyImage, 0, 0, null);
151 gaugeStateDiv.
draw(g);
152 gaugeStateMod.
draw(g);
191 return new Dimension(Math.max(div.width, mod.width), div.height+mod.height);
198 public void setValues(
final int curValue,
final int minValue,
final int maxValue, @NotNull
final String labelText, @NotNull
final String tooltipText) {
200 throw new IllegalArgumentException(
"minValue="+minValue);
202 if (maxValue != 99) {
203 throw new IllegalArgumentException(
"maxValue="+maxValue);
205 if (!orientationDiv.
setValues(curValue/10, 0, 9) && !orientationMod.
setValues(curValue%10, 0, 9) && this.labelText.equals(labelText) && this.tooltipText.equals(tooltipText)) {
212 if (gaugeStateDiv.
setValues(orientationDiv)) {
215 if (gaugeStateMod.
setValues(orientationMod)) {
227 if (tooltipPrefix == null || tooltipPrefix.isEmpty()) {
229 }
else if (tooltipText.isEmpty()) {
240 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
241 super.setBounds(x, y, width, height);
242 gaugeStateMod.
setDy(height/2);
260 super.mouseClicked(e);
261 switch (e.getButton()) {
262 case MouseEvent.BUTTON1:
265 case MouseEvent.BUTTON2:
266 if (commandList != null) {
271 case MouseEvent.BUTTON3:
Listener for GUIElement related events.
static final long serialVersionUID
The serial version UID.
Interface which is implemented by all listener classes.
void mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.This event will be delivered...
final TooltipManager tooltipManager
The TooltipManager to update.
void setHidden(final boolean hidden)
Specify whether this item should hide itself, independent of the "visibility" state.whether the gauge is hidden
Dimension getMinimumSize()
void draw(@NotNull final Graphics g)
Draws the gauge image into the given graphics context.
void setChanged()
Records that the contents have changed and must be repainted.
Interface for orientation images.
final CommandList commandList
The CommandList that is executed on button 2.
Dimension getPreferredSize()
Returns the preferred size.
void paintComponent(@NotNull final Graphics g)
Dimension getGaugeStateSize()
Returns the maximum size of gaugeStateDiv and gaugeStateMod.
final GUIElementListener elementListener
The GUIElementListener to notify.
void updateTooltipText()
Updates the tooltip's text from tooltipPrefix ad tooltipText.
Dimension getMaximumSize()
GUIDupGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Image fullImageDiv, @NotNull final Image fullImageMod, @Nullable final Image emptyImage, @NotNull final Orientation orientationDiv, @NotNull final Orientation orientationMod, @Nullable final String tooltipPrefix, @Nullable final CommandList commandList)
Creates a new instance.
final String name
The name of this element.
boolean setValues(int cur, int min, int max)
Sets the gauge's values.
void setDy(final int dy)
Sets the y-offset for drawing.
final GaugeState gaugeStateDiv
The gauge state.
Dimension getPreferredSize()
void setTooltipText(@Nullable final String tooltipText)
Sets the tooltip text to show when the mouse is inside this element.the text to show ornull to disab...
String tooltipText
The tooltip suffix.
final Orientation orientationMod
The gauge's orientation.
boolean setExtends(int width, int height)
Sets the extends of the image.
Displays a value as a graphical gauge that's filling state depends on the value.
final GaugeState gaugeStateMod
The gauge state.
void setBounds(final int x, final int y, final int width, final int height)
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 Image emptyImage
The image representing an empty gauge.
String labelText
The label text.
boolean setValues(@NotNull final Orientation orientation)
Updates the values from a Orientation state.
Abstract base class for GUI elements to be shown in Guis.
final String tooltipPrefix
The tooltip prefix.
A list of GUICommand instances.
final Orientation orientationDiv
The gauge's orientation.
void execute()
Execute the command list by calling GUICommand#execute() for each command in order.