22 package com.realtime.crossfire.jxclient.gui.gauge;
28 import java.awt.AlphaComposite;
29 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Graphics2D;
32 import java.awt.Image;
33 import java.awt.Transparency;
34 import java.awt.event.MouseEvent;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
115 super(tooltipManager, elementListener, name, alpha < 1.0F ? Transparency.TRANSLUCENT : Transparency.OPAQUE);
120 gaugeState =
new GaugeState(fullImage, negativeImage, 0, 0);
123 orientation.setExtends(getWidth(), getHeight());
124 orientation.setHasNegativeImage(negativeImage != null);
125 orientation.setValues(0, 0, 0);
134 public void setBounds(
final int x,
final int y,
final int width,
final int height) {
135 super.setBounds(x, y, width, height);
152 final Graphics paint;
154 final Graphics2D g2d = (Graphics2D)g.create();
155 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
161 super.paintComponent(paint);
162 if (emptyImage != null) {
163 paint.drawImage(emptyImage, 0, 0, null);
165 gaugeState.
draw(paint);
175 public void setValues(
final int curValue,
final int minValue,
final int maxValue, @NotNull
final String labelText, @NotNull
final String tooltipText) {
176 if (!orientation.
setValues(curValue, minValue, maxValue) && this.tooltipText.equals(tooltipText)) {
237 super.mouseClicked(e);
238 switch (e.getButton()) {
239 case MouseEvent.BUTTON1:
242 case MouseEvent.BUTTON2:
243 if (commandList != null) {
248 case MouseEvent.BUTTON3:
265 if (tooltipFormat == null) {
268 final StringBuilder sb =
new StringBuilder();
269 final char[] formatChars = tooltipFormat.toCharArray();
271 while (i < formatChars.length) {
272 final char ch = formatChars[i++];
273 if (ch !=
'%' || i >= formatChars.length) {
276 switch (formatChars[i++]) {
282 sb.append(tooltipText);
287 sb.append(formatChars[i-1]);
292 return sb.toString();
Listener for GUIElement related events.
Interface which is implemented by all listener classes.
Dimension getMaximumSize()
final TooltipManager tooltipManager
The TooltipManager to update.
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.
Dimension getPreferredSize()
Returns the preferred size.
void mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.This event will be delivered...
static final long serialVersionUID
The serial version UID.
void paintComponent(@NotNull final Graphics g)
final GUIElementListener elementListener
The GUIElementListener to notify.
final String name
The name of this element.
boolean setValues(int cur, int min, int max)
Sets the gauge's values.
final float alpha
The gauge alpha value, 1 is opaque and 0 full transparent.
final GaugeState gaugeState
The gauge state.
final Orientation orientation
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...
boolean hidden
If true, the gauge will not paint itself, whatever its visibility.
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...
final String tooltipFormat
The tooltip format.
void setBounds(final int x, final int y, final int width, final int height)
Dimension getMinimumSize()
final CommandList commandList
The CommandList that is executed on button 2.
boolean setExtends(int width, int height)
Sets the extends of the image.
void updateTooltipText()
Updates the tooltip's text from tooltipFormat ad tooltipText.
final Image emptyImage
The image representing an empty gauge.
boolean setValues(@NotNull final Orientation orientation)
Updates the values from a Orientation state.
Abstract base class for GUI elements to be shown in Guis.
String tooltipText
The default tooltip text.
Displays a value as a graphical gauge that's filling state depends on the value.
A list of GUICommand instances.
GUIGauge(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @Nullable final Image fullImage, @Nullable final Image negativeImage, @Nullable final Image emptyImage, @NotNull final Orientation orientation, @Nullable final String tooltipFormat, final float alpha, @Nullable final CommandList commandList)
Creates a new instance.
void execute()
Execute the command list by calling GUICommand#execute() for each command in order.
String formatTooltip()
Returns a formatted string using the given format.
void setHidden(final boolean hidden)
Specify whether this item should hide itself, independent of the "visibility" state.whether the gauge is hidden
Dimension getPreferredSize()