com.realtime.crossfire.jxclient.gui.gui
Class Gui

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by com.realtime.crossfire.jxclient.gui.gui.Gui
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Gui
extends java.awt.Container

Combines a list of GUIElements to for a gui.

A dialog can be modal. Such dialogs do not propagate key or mouse events to lower dialogs.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  ActivatableGUIElement activeElement
          The gui element which has the focus.
private  boolean autoSize
          Whether this dialog is auto-sizing.
private  Extent extent
          The extent of this dialog, or null.
private  ActivatableGUIElement forcedActive
          If non-null, this element is always active.
private  GuiAutoCloseListener guiAutoCloseListener
          If set, the auto-close listener to notify if this dialog looses the active gui element.
private  boolean hasChangedElements
          Records whether at least one gui element has changed since last redraw.
private  java.util.Collection<RendererGuiState> hideInStates
          The gui states that do not show this dialog.
private  boolean initialPositionSet
          Whether an initial position has been set.
private  KeyBindings keyBindings
          The KeyBindings for this gui.
private  boolean modal
          Whether this dialog is modal.
private  MouseTracker mouseTracker
          The MouseTracker if in GUI debug mode or null otherwise.
private static long serialVersionUID
          The serial version UID.
private  boolean stateChanged
          Whether the state (position or size) has changed.
private  java.util.Collection<GUIElement> visibleElements
          The list of GUIElements comprising this gui.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Gui(MouseTracker mouseTracker, Commands commands, CommandCallback commandCallback, Macros macros)
          Creates a new instance.
 
Method Summary
 GUIText activateCommandInput()
          Returns the first command text field of this gui and make it active.
 void activateDefaultElement()
          Activates the first default gui element of this gui.
private  GUIText activateFirstTextArea()
          Returns the first GUIText gui element of this gui and make it active.
 void addElement(GUIElement element)
          Adds a GUIElement to this gui.
 void autoSize(int screenWidth, int screenHeight)
          Auto-resizes the dialog.
 boolean deactivateCommandInput()
          Deactivates the command text input field of this dialog.
 ActivatableGUIElement getActiveElement()
          Returns the gui element owning the focus.
private  GUIElement getDefaultElement()
          Returns the first default gui element of this gui.
 GUIElement getElementFromPoint(int x, int y)
          Determines the GUIElement for a given coordinate.
<T extends GUIElement>
T
getFirstElement(java.lang.Class<T> class_)
          Returns the first gui element of this gui belonging to the given class.
<T extends GUIElement>
T
getFirstElement(java.lang.Class<T> class_, java.lang.String name)
          Returns the first gui element of this gui belonging to the given class and having the given name.
<T extends GUIElement>
T
getFirstElementEndingWith(java.lang.Class<T> class_, java.lang.String ending)
          Returns the first gui element of this gui which belongs to the given class and that's name ends with the given ending.
<T extends GUIElement>
T
getFirstElementNotEndingWith(java.lang.Class<T> class_, java.lang.String ending)
          Returns the first gui element of this gui which belongs to the given class and that's name does not end with the given ending.
 KeyBindings getKeyBindings()
          Returns the key bindings instance for this gui.
 boolean handleKeyPress(java.awt.event.KeyEvent e)
          Dispatches a key press KeyEvent.
 boolean handleKeyTyped(java.awt.event.KeyEvent e)
          Dispatches a key typed KeyEvent.
 void hideInState(RendererGuiState state)
          Hides the dialog in a state.
private  boolean isActiveElement(ActivatableGUIElement activeElement)
          Returns whether a given gui element is the active element of this dialog.
 boolean isAutoSize()
          Returns the auto-size state.
 boolean isChangedFromDefault()
          Returns whether this dialog has changed from its default state.
 boolean isHidden(RendererGuiState state)
          Returns whether this gui is visible in a state.
 boolean isModal()
          Returns the modal state.
 boolean isWithinDrawingArea(int x, int y)
          Returns whether a given point is within this dialog's drawing area.
 boolean needRedraw()
          Checks whether any visible gui element of this gui has been changed since it was painted last time.
 void redraw(java.awt.Graphics g)
          Repaints the gui and clear the changed flags of all repainted elements.
 void setActiveElement(ActivatableGUIElement activeElement, boolean active)
          Sets the gui element owning the focus.
 void setAutoSize(boolean autoSize)
          Sets the auto-size state.
 void setChangedElements()
          Notifies that one gui element has changed since last redraw.
 void setExtent(Extent extent)
          Sets the extent of this dialog.
 void setForcedActive(ActivatableGUIElement forcedActive)
          Sets an ActivatableGUIElement that is always active.
 void setGuiAutoCloseListener(GuiAutoCloseListener guiAutoCloseListener)
          Sets the GuiAutoCloseListener to be notified when this dialog becomes inactive.
 void setHideInput(boolean hideInput)
          Enables or disables hidden text in the first input field.
 void setModal(boolean modal)
          Sets the modal state.
 void setPosition(int x, int y)
          Sets the position of this dialog.
 void setSize(int width, int height)
          Sets the size of this dialog.
 void setStateChanged(boolean stateChanged)
          Sets whether the state (position or size) has changed.
 java.lang.String toString()
          
 void updateVisibleElement(GUIElement element)
          Adds or removes a GUIElement from this gui.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

activeElement

@Nullable
private ActivatableGUIElement activeElement
The gui element which has the focus. Set to null if no such element exists.


autoSize

private boolean autoSize
Whether this dialog is auto-sizing. Auto-sizing dialogs cannot be moved or resized manually.


extent

@Nullable
private Extent extent
The extent of this dialog, or null.


forcedActive

@Nullable
private ActivatableGUIElement forcedActive
If non-null, this element is always active. No other element can become active.


guiAutoCloseListener

@Nullable
private GuiAutoCloseListener guiAutoCloseListener
If set, the auto-close listener to notify if this dialog looses the active gui element.


hasChangedElements

private boolean hasChangedElements
Records whether at least one gui element has changed since last redraw.


hideInStates

@NotNull
private final java.util.Collection<RendererGuiState> hideInStates
The gui states that do not show this dialog.


initialPositionSet

private boolean initialPositionSet
Whether an initial position has been set.


keyBindings

@NotNull
private final KeyBindings keyBindings
The KeyBindings for this gui.


modal

private boolean modal
Whether this dialog is modal. Modal dialogs consume all key presses.


mouseTracker

@Nullable
private final MouseTracker mouseTracker
The MouseTracker if in GUI debug mode or null otherwise.


serialVersionUID

private static final long serialVersionUID
The serial version UID.

See Also:
Constant Field Values

stateChanged

private boolean stateChanged
Whether the state (position or size) has changed.


visibleElements

@NotNull
private final java.util.Collection<GUIElement> visibleElements
The list of GUIElements comprising this gui.

Constructor Detail

Gui

public Gui(@Nullable
           MouseTracker mouseTracker,
           @NotNull
           Commands commands,
           @NotNull
           CommandCallback commandCallback,
           @NotNull
           Macros macros)
Creates a new instance.

Parameters:
mouseTracker - the mouse tracker when in debug GUI mode or null otherwise
commands - the commands instance for executing commands
commandCallback - the command callback to use
macros - the macros instance to use
Method Detail

activateCommandInput

@Nullable
public GUIText activateCommandInput()
Returns the first command text field of this gui and make it active.

Returns:
the comment text field, or null if this gui does not contain any command text fields

activateDefaultElement

public void activateDefaultElement()
Activates the first default gui element of this gui.


activateFirstTextArea

@Nullable
private GUIText activateFirstTextArea()
Returns the first GUIText gui element of this gui and make it active.

Returns:
the GUIText element, or null if this gui does not contain any GUIText gui elements

addElement

public void addElement(@NotNull
                       GUIElement element)
Adds a GUIElement to this gui. The element must not be added to more than one gui at a time.

Parameters:
element - the GUIElement to add

autoSize

public void autoSize(int screenWidth,
                     int screenHeight)
Auto-resizes the dialog. Does nothing if this dialog is not auto-sizing.

Parameters:
screenWidth - the screen width
screenHeight - the screen height

deactivateCommandInput

public boolean deactivateCommandInput()
Deactivates the command text input field of this dialog. Does nothing if the command text input field is not active or if this dialog has no command text input field.

Returns:
whether the command text input field has been deactivated

getActiveElement

@Nullable
public ActivatableGUIElement getActiveElement()
Returns the gui element owning the focus.

Returns:
the gui element owning the focus, or null if no such element exists

getDefaultElement

@Nullable
private GUIElement getDefaultElement()
Returns the first default gui element of this gui.

Returns:
the default gui element, or null

getElementFromPoint

@Nullable
public GUIElement getElementFromPoint(int x,
                                               int y)
Determines the GUIElement for a given coordinate.

Parameters:
x - the x-coordinate to check
y - the y-coordinate to check
Returns:
the GUIElement at the given coordinate, or null if none was found

getFirstElement

@Nullable
public <T extends GUIElement> T getFirstElement(@NotNull
                                                         java.lang.Class<T> class_)
Returns the first gui element of this gui belonging to the given class.

Parameters:
class_ - the class to search for
Returns:
the gui element or null if not found

getFirstElement

@Nullable
public <T extends GUIElement> T getFirstElement(@NotNull
                                                         java.lang.Class<T> class_,
                                                         @NotNull
                                                         java.lang.String name)
Returns the first gui element of this gui belonging to the given class and having the given name.

Parameters:
class_ - the class to search for
name - the button's name
Returns:
the button or null if no button matches

getFirstElementEndingWith

@Nullable
public <T extends GUIElement> T getFirstElementEndingWith(@NotNull
                                                                   java.lang.Class<T> class_,
                                                                   @NotNull
                                                                   java.lang.String ending)
Returns the first gui element of this gui which belongs to the given class and that's name ends with the given ending.

Parameters:
class_ - the class to search for
ending - the ending to search for
Returns:
the gui element or null if not found
No Inspection:
TypeMayBeWeakened

getFirstElementNotEndingWith

@Nullable
public <T extends GUIElement> T getFirstElementNotEndingWith(@NotNull
                                                                      java.lang.Class<T> class_,
                                                                      @NotNull
                                                                      java.lang.String ending)
Returns the first gui element of this gui which belongs to the given class and that's name does not end with the given ending.

Parameters:
class_ - the class to search for
ending - the ending to search for
Returns:
the gui element or null if not found
No Inspection:
TypeMayBeWeakened

getKeyBindings

@NotNull
public KeyBindings getKeyBindings()
Returns the key bindings instance for this gui.

Returns:
the key bindings

handleKeyPress

public boolean handleKeyPress(@NotNull
                              java.awt.event.KeyEvent e)
Dispatches a key press KeyEvent.

Parameters:
e - the event to dispatch
Returns:
whether a gui element did handle the event

handleKeyTyped

public boolean handleKeyTyped(@NotNull
                              java.awt.event.KeyEvent e)
Dispatches a key typed KeyEvent.

Parameters:
e - the event to dispatch
Returns:
whether a gui element did handle the event

hideInState

public void hideInState(@NotNull
                        RendererGuiState state)
Hides the dialog in a state.

Parameters:
state - the state

isActiveElement

private boolean isActiveElement(@Nullable
                                ActivatableGUIElement activeElement)
Returns whether a given gui element is the active element of this dialog.

Parameters:
activeElement - the gui element
Returns:
whether the given gui element is active

isAutoSize

public boolean isAutoSize()
Returns the auto-size state. Auto-size dialogs cannot be moved or resized manually.

Returns:
the auto-size state

isChangedFromDefault

public boolean isChangedFromDefault()
Returns whether this dialog has changed from its default state.

Returns:
whether the state has changed

isHidden

public boolean isHidden(@NotNull
                        RendererGuiState state)
Returns whether this gui is visible in a state.

Parameters:
state - the state
Returns:
whether this gui is hidden

isModal

public boolean isModal()
Returns the modal state.

Returns:
the modal state

isWithinDrawingArea

public boolean isWithinDrawingArea(int x,
                                   int y)
Returns whether a given point is within this dialog's drawing area.

Parameters:
x - the x-coordinate of the the point
y - the y-coordinate of the the point
Returns:
whether the coordinate is within the drawing area

needRedraw

public boolean needRedraw()
Checks whether any visible gui element of this gui has been changed since it was painted last time.

Returns:
true if any gui element has changed; false otherwise

redraw

public void redraw(@NotNull
                   java.awt.Graphics g)
Repaints the gui and clear the changed flags of all repainted elements.

Parameters:
g - the Graphics to paint into

setActiveElement

public void setActiveElement(@NotNull
                             ActivatableGUIElement activeElement,
                             boolean active)
Sets the gui element owning the focus.

Parameters:
activeElement - the gui element
active - the new active state

setAutoSize

public void setAutoSize(boolean autoSize)
Sets the auto-size state. Auto-size dialogs cannot be moved or resized manually.

Parameters:
autoSize - the new auto-size state

setChangedElements

public void setChangedElements()
Notifies that one gui element has changed since last redraw.


setExtent

public void setExtent(@NotNull
                      Extent extent)
Sets the extent of this dialog.

Parameters:
extent - the extent

setForcedActive

public void setForcedActive(@Nullable
                            ActivatableGUIElement forcedActive)
Sets an ActivatableGUIElement that is always active. It prevents any other element from getting active.

Parameters:
forcedActive - the element to set or null to unset

setGuiAutoCloseListener

public void setGuiAutoCloseListener(@Nullable
                                    GuiAutoCloseListener guiAutoCloseListener)
Sets the GuiAutoCloseListener to be notified when this dialog becomes inactive.

Parameters:
guiAutoCloseListener - the listener to be notified or null

setHideInput

public void setHideInput(boolean hideInput)
Enables or disables hidden text in the first input field.

Parameters:
hideInput - if set, hide input; else show input

setModal

public void setModal(boolean modal)
Sets the modal state.

Parameters:
modal - the new modal state

setPosition

public void setPosition(int x,
                        int y)
Sets the position of this dialog.

Parameters:
x - the x-coordinate
y - the y-coordinate

setSize

public void setSize(int width,
                    int height)
Sets the size of this dialog. Marks this gui as a "dialog".

Overrides:
setSize in class java.awt.Component
Parameters:
width - the width
height - the height

setStateChanged

public void setStateChanged(boolean stateChanged)
Sets whether the state (position or size) has changed.

Parameters:
stateChanged - whether the state has changed

toString

@NotNull
public java.lang.String toString()

Overrides:
toString in class java.awt.Component

updateVisibleElement

public void updateVisibleElement(@NotNull
                                 GUIElement element)
Adds or removes a GUIElement from this gui. The gui element is added if it is visible or removed if it is invisible.

Parameters:
element - the gui element