 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.gui.button;
37 import java.awt.Color;
38 import java.awt.Dimension;
40 import java.awt.FontMetrics;
41 import java.awt.Graphics;
42 import java.awt.Graphics2D;
43 import java.awt.font.FontRenderContext;
44 import java.awt.geom.RectangularShape;
45 import java.util.Iterator;
46 import org.jetbrains.annotations.NotNull;
47 import org.jetbrains.annotations.Nullable;
150 public GUITextButton(@NotNull
final TooltipManager tooltipManager, @NotNull
final GUIElementListener elementListener, @NotNull
final String
name, @NotNull
final ButtonImages up, @NotNull
final ButtonImages down, @NotNull
final String
text, @NotNull
final Font
font, @NotNull
final Color
color, @NotNull
final Color
colorSelected, @NotNull
final Color
colorDisabled,
final boolean autoRepeat, @NotNull
final CommandList commandList, @NotNull
final GuiFactory guiFactory, @NotNull
final NewCharModel newCharModel, @NotNull
final KeybindingsManager keybindingsManager) {
159 throw new IllegalArgumentException(
"'up' state height is "+preferredHeight+
" but 'down' state height is "+
down.
getHeight());
180 super.paintComponent(g);
181 final Graphics2D g2 = (Graphics2D)g;
184 final int width = getWidth();
186 final FontRenderContext fontRenderContext = g2.getFontRenderContext();
187 final RectangularShape rectangle =
font.getStringBounds(
text, fontRenderContext);
188 final int x = (int)Math.round((width-rectangle.getWidth())/2);
189 final FontMetrics fontMetrics = g2.getFontMetrics();
190 final int y = (int)Math.round(
preferredSize.height-rectangle.getHeight())/2+fontMetrics.getAscent();
191 g2.drawString(
text, x, y);
202 @SuppressWarnings(
"MethodDoesntCallSuperMethod")
204 return new Dimension(Integer.MAX_VALUE,
preferredSize.height);
229 final GUICommand keyBindingCommand = keyBinding.getCommands().getSingleCommand();
231 }).keySet().iterator();
232 return bindings.hasNext() ?
newTooltipText(bindings.next().getBindingDescription()) :
null;
final ButtonImages up
The images comprising the "up" button state.
final Color color
The text color.
boolean selected
Whether the element is currently selected.
String getDialog()
Returns the dialog to toggle.
void activeChanged()
Will be called whenever the active state has changed.
final String expectedCommand
For calculating tooltips: The expected command in the key binding.
final Font font
The font to use.
void setChanged()
Records that the contents have changed and must be repainted.
static final long serialVersionUID
The serial version UID.
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.
A GUICommand which executes a Crossfire command.
TooltipText getTooltip()
Returns the current tooltip text.
final KeybindingsManager keybindingsManager
The global KeybindingsManager instance.
void notifyOpen()
Called each time the enclosing dialog is opened (or raised).
boolean isActive()
Returns whether a GUI element is active.
String getCommandString()
Returns the command as a string.
void paintComponent(@NotNull final Graphics g)
final Color colorDisabled
The text color when disabled.
Abstract base class for key bindings.
A GUIElement that implements a button.
Dimension getMaximumSize()
Utility class for Gui related functions.
Map< KeyBinding, String > getBindings(@NotNull final Predicate< KeyBinding > predicate)
Searches bindings having a command text starting with the specified value.
GUICommand getSingleCommand()
Returns the single command of this command list.
Dimension getMinimumSizeInt()
Returns the minimal size needed to display this component.
GUITextButton(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final ButtonImages up, @NotNull final ButtonImages down, @NotNull final String text, @NotNull final Font font, @NotNull final Color color, @NotNull final Color colorSelected, @NotNull final Color colorDisabled, final boolean autoRepeat, @NotNull final CommandList commandList, @NotNull final GuiFactory guiFactory, @NotNull final NewCharModel newCharModel, @NotNull final KeybindingsManager keybindingsManager)
Creates a new instance.
General information for creating new characters.
final GuiFactory guiFactory
The global GuiFactory instance.
void select(final boolean selected)
Selects or deselects the element.
TooltipText newTooltipText(@Nullable final String tooltipText)
Creates a TooltipText instance relative to this instance.
final GUIElementListener elementListener
The GUIElementListener to notify.
Information for displaying tooltips.
Factory for creating Gui instances.
A list of GUICommand instances.
final String name
The name of this element.
final ButtonImages down
The images comprising the "down" button state.
final String text
The button text.
final TooltipManager tooltipManager
The TooltipManager to update.
A GUICommand which toggles the visibility of a dialog.
final Color colorSelected
The text color when selected.
Listener for GUIElement related events.
final Dimension preferredSize
The preferred size of this component.