22 package com.realtime.crossfire.jxclient.gui.misc;
30 import java.awt.Color;
31 import java.awt.Dimension;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.Image;
36 import java.awt.Transparency;
37 import java.awt.event.MouseEvent;
38 import java.awt.geom.RectangularShape;
39 import java.awt.image.BufferedImage;
40 import org.jetbrains.annotations.NotNull;
108 super(tooltipManager, elementListener, name, Transparency.TRANSLUCENT);
109 if (checkedImage.getWidth() != uncheckedImage.getWidth()) {
110 throw new IllegalArgumentException(
"'checked' width is "+checkedImage.getWidth()+
" but 'unchecked' width is "+uncheckedImage.getWidth());
136 super.paintComponent(g);
137 final Graphics2D g2 = (Graphics2D)g;
141 final RectangularShape rectangle = font.getStringBounds(text, g2.getFontRenderContext());
142 final int y = (int)Math.round(getHeight()-rectangle.getMaxY()-rectangle.getMinY())/2;
143 g2.drawString(text, checkedImage.getWidth()+4, y);
171 result.width += checkedImage.getWidth()+4;
172 result.height = checkedImage.getHeight();
188 super.mouseClicked(e);
189 final int b = e.getButton();
191 case MouseEvent.BUTTON1:
195 case MouseEvent.BUTTON2:
198 case MouseEvent.BUTTON3:
208 super.mousePressed(e);
209 final int b = e.getButton();
211 case MouseEvent.BUTTON1:
215 case MouseEvent.BUTTON2:
218 case MouseEvent.BUTTON3:
235 public void mouseEntered(@NotNull
final MouseEvent e,
final boolean debugGui) {
239 super.mouseEntered(e, debugGui);
Listener for GUIElement related events.
Dimension getPreferredSize()
final TooltipManager tooltipManager
The TooltipManager to update.
final GUIElementListener elementListener
The GUIElementListener to notify.
static Dimension getTextDimension(@NotNull final String text, @NotNull final FontMetrics fontMetrics)
Returns the extents of a string when rendered in a given Font on this component.
void mouseEntered(@NotNull final MouseEvent e, final boolean debugGui)
Will be called when the mouse has entered the bounding box of this element.the mouse event relative t...
GUICheckBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final BufferedImage checkedImage, @NotNull final BufferedImage uncheckedImage, @NotNull final Font font, @NotNull final Color color, @NotNull final CheckBoxOption option, @NotNull final String text)
Creates a new instance.
static final long serialVersionUID
The serial version UID.
void mouseClicked(@NotNull final MouseEvent e)
Will be called when the user has clicked (pressed+released) this element.This event will be delivered...
final OptionListener optionListener
The OptionListener attached to option.
String getTooltipText()
Returns the tooltip text to explain this option.
Dimension getMinimumSizeInt()
Returns the minimal size needed to display both icon and text.
void setActive(final boolean active)
Sets the active state of a GUI element.
final String name
The name of this element.
A GUIElement that can be set to active or inactive.
void removeOptionListener(@NotNull final OptionListener listener)
Removes a listener for state changes.
final BufferedImage checkedImage
The image for the checked [x] state.
Dimension getMinimumSize()
Utility class for Gui related functions.
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...
void dispose()
Releases all allocated resources.
Interface for listeners for attribute changes of Options.
final Image uncheckedImage
The image for the unchecked [ ] state.
final String text
The text.
final Color color
The text color.
void paintComponent(@NotNull final Graphics g)
void mousePressed(@NotNull final MouseEvent e)
Will be called when the user has pressed the mouse inside this element.the mouse event relative to th...
final Font font
The font to use.
boolean hasTooltipText()
Returns whether the tooltip is enabled.whether the tooltip is enabled
boolean isChecked()
Returns the current state.
final CheckBoxOption option
The option to display.
The base class for all check box options.
void addOptionListener(@NotNull final OptionListener listener)
Adds a listener for state changes.
void toggleChecked()
Toggles the checked state.