 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.gui.gui;
31 import java.awt.Component;
32 import java.awt.Container;
33 import java.awt.Dimension;
34 import java.awt.event.KeyEvent;
35 import java.util.Collection;
36 import java.util.EnumSet;
37 import javax.swing.JComponent;
38 import javax.swing.JFrame;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
55 private final JComponent
component =
new JComponent() {
60 private static final long serialVersionUID = 1L;
221 final int count =
component.getComponentCount();
222 for (
int i = 0; i < count; i++) {
223 final Component
component = this.component.getComponent(i);
237 if (defaultElement !=
null) {
252 final int count =
component.getComponentCount();
253 for (
int i = 0; i < count; i++) {
254 final Component
component = this.component.getComponent(i);
256 return class_.cast(element);
273 final int count =
component.getComponentCount();
274 for (
int i = 0; i < count; i++) {
275 final Component
component = this.component.getComponent(i);
277 return class_.cast(element);
292 final int count =
component.getComponentCount();
293 for (
int i = 0; i < count; i++) {
294 final Component
component = this.component.getComponent(i);
296 return class_.cast(element);
312 Component
component = this.component.findComponentAt(x, y);
339 if (previousActiveElement !=
null) {
342 assert this.activeElement !=
null;
343 this.activeElement.activeChanged();
351 this.activeElement =
null;
352 assert previousActiveElement !=
null;
370 return this.activeElement !=
null && this.activeElement ==
activeElement;
394 switch (e.getKeyCode()) {
395 case KeyEvent.VK_ENTER:
396 case KeyEvent.VK_SPACE:
398 if (defaultElement !=
null) {
404 case KeyEvent.VK_TAB:
434 if (!textArea.
getName().equals(
"command")) {
452 public <T extends GUIElement> T
getFirstElement(@NotNull
final Class<T> class_, @NotNull
final String name) {
453 final int count =
component.getComponentCount();
454 for (
int i = 0; i < count; i++) {
455 final Component
component = this.component.getComponent(i);
457 return class_.cast(element);
521 return (name ==
null ?
"" : name)+
"["+
component.getWidth()+
"x"+
component.getHeight()+
"]";
530 public void autoSize(
final int screenWidth,
final int screenHeight) {
537 if (extent !=
null) {
538 final Dimension preferredSize =
component.getPreferredSize();
539 x = extent.
getX(screenWidth, screenHeight, preferredSize.width, preferredSize.height);
540 y = extent.
getY(screenWidth, screenHeight, preferredSize.width, preferredSize.height);
541 w = extent.
getW(screenWidth, screenHeight, preferredSize.width, preferredSize.height);
542 h = extent.
getH(screenWidth, screenHeight, preferredSize.width, preferredSize.height);
549 final Dimension preferredSize =
component.getPreferredSize();
552 x = screenWidth/2-preferredSize.width;
554 x =
defaultX.
evaluate(screenWidth, screenHeight, preferredSize.width, preferredSize.height)-preferredSize.width/2;
558 y = screenHeight/2-preferredSize.height;
560 y =
defaultY.
evaluate(screenWidth, screenHeight, preferredSize.width, preferredSize.height)-preferredSize.height/2;
562 w = preferredSize.width;
563 h = preferredSize.height;
565 setBounds(x, y, w, h, screenWidth, screenHeight);
602 final int count =
component.getComponentCount();
603 for (
int i = 0; i < count; i++) {
604 final Component
component = this.component.getComponent(i);
606 element.notifyOpen();
641 public void setBounds(
final int x,
final int y,
final int width,
final int height,
final int windowWidth,
final int windowHeight) {
642 int newWidth = width;
643 int newHeight = height;
644 final Dimension maximumSize =
component.getMaximumSize();
645 if (maximumSize !=
null) {
646 if (newWidth > maximumSize.width) {
647 newWidth = maximumSize.width;
649 if (newHeight > maximumSize.height) {
650 newHeight = maximumSize.height;
653 final Dimension minimumSize =
component.getMinimumSize();
654 if (minimumSize !=
null) {
655 if (newWidth < minimumSize.width) {
656 newWidth = minimumSize.width;
658 if (newHeight < minimumSize.height) {
659 newHeight = minimumSize.height;
662 final int newX = Math.max(Math.min(x, windowWidth-newWidth), 0);
663 final int newY = Math.max(Math.min(y, windowHeight-newHeight), 0);
664 component.setBounds(newX, newY, newWidth, newHeight);
676 if (c instanceof JFrame) {
695 final int count =
component.getComponentCount();
696 for (
int i = 0; i < count; i++) {
697 final Component
component = this.component.getComponent(i);
699 dialogBackground.setOpaqueDialogBackground(opaque);
710 final int count =
component.getComponentCount();
711 for (
int i = 0; i < count; i++) {
712 final Component
component = this.component.getComponent(i);
714 messageLog.setShowSentCommands(showSentCommands);
724 final int count =
component.getComponentCount();
725 for (
int i = 0; i < count; i++) {
726 final Component
component = this.component.getComponent(i);
728 messageLog.setShowTimestamps(showTimestamps);
Utility class for Swing related functions.
boolean isAutoSize()
Returns whether this dialog is an auto-size dialog.
void setGuiAutoCloseListener(@Nullable final GuiAutoCloseListener guiAutoCloseListener)
Sets the GuiAutoCloseListener to be notified when this dialog becomes inactive.
Combines a list of GUIElements to for a gui.
void setHelp(@NotNull final GUIPicture help)
Sets the help icon of this dialog.
void setDefaultPosition(@NotNull final Expression defaultX, @NotNull final Expression defaultY)
Sets the default position for this dialog.
boolean isWithinDrawingArea(final int x, final int y)
Returns whether a given point is within this dialog's drawing area.
abstract void activeChanged()
Will be called whenever the active state has changed.
Expression defaultX
The default x-coordinate for this dialog.
void autoSize(final int screenWidth, final int screenHeight)
Auto-resizes the dialog.
static final int NONE
The mask for "no modifier".
int getW(final int width, final int height, final int prefWidth, final int prefHeight)
Returns the width.
void autoClosed()
Called when a dialog has been auto-closed.
abstract void execute()
Executes the actions associated with this GUI element.
boolean handleKeyPress(@NotNull final KeyEvent2 e)
Dispatches a key press KeyEvent.
void activateNextElement()
Activates the following element.
Abstract base class for GUI elements to be shown in Guis.
boolean isHidden(@NotNull final RendererGuiState state)
Returns whether this gui is visible in a state.
static void invokeLater(@NotNull final Runnable runnable)
Calls SwingUtilities#invokeLater(Runnable) if not on the EDT or calls the Runnable directly if on the...
GUIPicture getHelp()
Returns the help icon of this dialog.
A GUIElement that can be set to active or inactive.
void hideInState(@NotNull final RendererGuiState state)
Hides the dialog in a state.
void setActiveElementActive(final boolean active)
Activates or deactivates the GUI element owning the focus.
Represents a pressed or released key.
A gui element implementing the message window.
An expression yielding an integer value derived from a screen resolution.
void setActiveElement(@NotNull final ActivatableGUIElement activeElement, final boolean active)
Sets the gui element owning the focus.
boolean isUserResizable()
Returns whether the dialog is user-resizable.
Manages a set of key bindings.
void setShowSentCommands(final boolean showSentCommands)
Sets whether the commands sent to the server should be shown in the messages dialog.
Expression defaultY
The default y-coordinate for this dialog.
void setSaveDialog()
Makes this dialog retain its position across restarts.
Interface defining an abstract GUI element.
boolean handleKeyPress(@NotNull final KeyEvent2 e)
Executes a "key press" event.
Interface for clients interested in auto-close events of Gui instances.
void validate()
Calls Container#validate() on the top-level frame.
boolean saveDialog
Whether this dialog retains its position across restarts.
boolean isDefault
Whether this element is the default element.
Encapsulates the extent of a GUI element.
AbstractGUIElement getElementFromPoint(final int x, final int y)
Determines the GUIElement for a given coordinate.
void setOpaqueDialogBackground(final boolean opaque)
Sets whether the dialog's background is opaque.
void activateDefaultElement()
Activates the first default gui element of this gui.
boolean userResizable
Whether this dialog is user-resizable.
void setForcedActive(@Nullable final ActivatableGUIElement forcedActive)
Sets an ActivatableGUIElement that is always active.
static final int MASK
The mask for all used modifiers.
void setUserResizable(final boolean userResizable)
Sets whether the dialog is user-resizable.
void setBounds(final int x, final int y, final int width, final int height, final int windowWidth, final int windowHeight)
Sets the position and size of this dialog.
GuiAutoCloseListener guiAutoCloseListener
If set, the auto-close listener to notify if this dialog looses the active gui element.
void activatePrevElement()
Activates the previous element.
static final int SHIFT
The mask for "shift".
final Collection< RendererGuiState > hideInStates
The gui states that do not show this dialog.
void setShowTimestamps(final boolean showTimestamps)
Sets whether timestamps should be shown in the messages dialog.
JComponent getComponent()
Returns the JComponent for this instance.
boolean isModal()
Returns the modal state.
KeyBindings getKeyBindings()
Returns the key bindings instance for this gui.
int evaluate(final int width, final int height, final int prefWidth, final int prefHeight)
Evaluates the expression into a constant.
String getName()
Returns the internal name of this gui element.
Interface for classes that may handle "pressed" key events.
final KeyBindings keyBindings
The KeyBindings for this gui.
int getX(final int width, final int height, final int prefWidth, final int prefHeight)
Returns the x coordinate.
boolean isActiveElement(@Nullable final ActivatableGUIElement activeElement)
Returns whether a given gui element is the active element of this dialog.
Gui(@NotNull final String name, @NotNull final KeyBindings keyBindings)
Creates a new instance.
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_)
Returns the first gui element of this gui belonging to the given class.
A background image for dialog windows.
A AbstractGUIElement that displays a picture.
Extent autoSize
The extent of the dialog if it is auto-sizing or.
boolean modal
Whether this dialog is modal.
void repaint()
Repaints this component.
void setModal(final boolean modal)
Sets the modal state.
boolean initialPositionSet
Whether an initial position has been set.
boolean deactivateCommandInput()
Deactivates the command text input field of this dialog.
public< T extends GUIElement > T getFirstElementEndingWith(@NotNull final Class< T > class_, @NotNull final String ending)
Returns the first gui element of this gui which belongs to the given class and that's name ends with ...
final JComponent component
The JComponent for this instance.
ActivatableGUIElement activeElement
The gui element which has the focus.
int getY(final int width, final int height, final int prefWidth, final int prefHeight)
Returns the y coordinate.
void setAutoSize(@Nullable final Extent autoSize)
Sets the auto-size state.
GUIPicture help
The help icon of the dialog.
void setActive(final boolean active)
Sets the active state of a GUI element.
static void invokeAndWait(@NotNull final Runnable runnable)
Calls SwingUtilities#invokeAndWait(Runnable) if not on the EDT or calls the Runnable directly if on t...
ActivatableGUIElement getDefaultElement()
Returns the first default gui element of this gui.
void notifyOpen()
Called each time the enclosing dialog is opened (or raised).
void notifyOpen()
Call GUIElement#notifyOpen() for all GUI elements.
int getH(final int width, final int height, final int prefWidth, final int prefHeight)
Returns the height.
ActivatableGUIElement forcedActive
If non-.
boolean isSaveDialog()
Returns whether this dialog retains its position across restarts.
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_, @NotNull final String name)
Returns the first gui element of this gui belonging to the given class and having the given name.
public< T extends GUIElement > T getFirstElementNotEndingWith(@NotNull final Class< T > class_, @NotNull final String ending)
Returns the first gui element of this gui which belongs to the given class and that's name does not e...
All gui states of JXCWindowRenderer.