com.realtime.crossfire.jxclient.gui.gui
Class GUIElement

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.realtime.crossfire.jxclient.gui.gui.GUIElement
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
AbstractGUIMap, AbstractLabel, ActivatableGUIElement, GUIDupGauge, GUIFill, GUIGauge, GUILog, GUIPicture

public abstract class GUIElement
extends javax.swing.JComponent

Abstract base class for GUI elements to be shown in Guis.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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  java.awt.image.BufferedImage bufferedImage
          The backbuffer image of this element.
protected  java.lang.Object bufferedImageSync
          Object used to synchronize on bufferedImage contents.
private  boolean changed
          Whether bufferedImage has changed.
private  GUIElementChangedListener changedListener
          The GUIElementChangedListener to be notified whenever the changed flag is set.
private  GUIElementListener elementListener
          The GUIElementListener to notify.
private  Extent extent
          The extent of this element.
private  Gui gui
          The Gui this element is part of.
private  boolean ignore
          Whether this gui element should be ignored for user interaction.
private  boolean isDefault
          Whether this element is the default element.
private  java.lang.String name
          The name of this element.
private static long serialVersionUID
          The serial version UID.
private  TooltipManager tooltipManager
          The TooltipManager to update.
private  TooltipText tooltipText
          The tooltip text to show when the mouse is inside this element.
private  int transparency
          The transparency for bufferedImage.
private  boolean visible
          Whether this element is visible.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
protected GUIElement(TooltipManager tooltipManager, GUIElementListener elementListener, java.lang.String name, Extent extent, int transparency)
          Creates a new instance.
 
Method Summary
private  void createBuffer()
          Allocates bufferedImage with the element's current size.
protected  java.awt.Graphics2D createBufferGraphics()
          Calls BufferedImage.createGraphics() on bufferedImage.
 void dispose()
          Releases all allocated resources.
 int getElementX()
          Returns the element's absolute screen coordinate.
 int getElementY()
          Returns the element's absolute screen coordinate.
 Gui getGui()
          Returns the Gui this element is part of.
 java.lang.String getName()
          
 TooltipText getTooltipText()
          Returns the tooltip text to show when the mouse is inside this element.
protected  boolean hasBufferedImage()
          Returns whether the backbuffer for this element has been created.
 boolean isChanged()
          Returns the changed flag.
 boolean isDefault()
          Returns whether this element is the default element.
 boolean isElementAtPoint(int x, int y)
          Returns whether this element includes a given point.
 boolean isElementVisible()
          Returns whether this element is visible.
 boolean isIgnore()
          Returns whether this gui element should be ignored for user interaction.
 void mouseClicked(java.awt.event.MouseEvent e)
          Will be called when the user has clicked (pressed+released) this element.
 void mouseDragged(java.awt.event.MouseEvent e)
          Will be called when the mouse moves within this component while the button is pressed.
 void mouseEntered(java.awt.event.MouseEvent e)
          Will be called when the mouse has entered the bounding box of this element.
 void mouseExited(java.awt.event.MouseEvent e)
          Will be called when the mouse has left the bounding box of this element.
 void mouseMoved(java.awt.event.MouseEvent e)
          Will be called when the mouse moves within this component.
 void mousePressed(java.awt.event.MouseEvent e)
          Will be called when the user has pressed the mouse inside this element.
 void mouseReleased(java.awt.event.MouseEvent e)
          Will be called when the user has released the mouse.
 void paintComponent(java.awt.Graphics g)
          
private  void render()
          Re-creates the contents of bufferedImage.
protected abstract  void render(java.awt.Graphics2D g2)
          Paints the element's contents into the passed graphics.
 void resetChanged()
          Clears the changed flag.
 void setChanged()
          Records that bufferedImage has changed and must be repainted.
 void setChangedListener(GUIElementChangedListener changedListener)
          Sets the GUIElementChangedListener to be notified.
protected  void setChangedNoListeners()
          Records that bufferedImage has changed and must be repainted.
 void setDefault(boolean isDefault)
          Sets whether this element is the default element.
 void setElementLocation(int x, int y)
          Changes the location of this gui element.
protected  void setElementSize(int w, int h)
          Changes the size of this gui element.
 void setElementVisible(boolean visible)
          Sets whether this element is visible.
 void setGui(Gui gui)
          Sets the Gui this element is part of.
 void setIgnore()
          Marks this gui element to be ignored for user interaction.
 void setTooltipText(java.lang.String tooltipText)
          Sets the tooltip text to show when the mouse is inside this element.
protected  void setTooltipText(java.lang.String tooltipText, int x, int y, int w, int h)
          Sets the tooltip text to show when the mouse is inside this element.
 java.lang.String toString()
          
 void updateResolution(int screenWidth, int screenHeight)
          Updates the location and size to a new screen resolution.
protected  void updateResolutionConstant()
          Deprecated. 
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, 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

bufferedImage

@Nullable
private java.awt.image.BufferedImage bufferedImage
The backbuffer image of this element. It is updated in render() and render(Graphics2D). paintComponent(Graphics) copies the contents to screen.


bufferedImageSync

@NotNull
protected final java.lang.Object bufferedImageSync
Object used to synchronize on bufferedImage contents.


changed

private boolean changed
Whether bufferedImage has changed.


changedListener

@Nullable
private GUIElementChangedListener changedListener
The GUIElementChangedListener to be notified whenever the changed flag is set.


elementListener

@NotNull
private final GUIElementListener elementListener
The GUIElementListener to notify.


extent

@NotNull
private final Extent extent
The extent of this element.


gui

@Nullable
private Gui gui
The Gui this element is part of. Set to null if this element is not part of any gui.


ignore

private boolean ignore
Whether this gui element should be ignored for user interaction.


isDefault

private boolean isDefault
Whether this element is the default element. The default element is selected with the ENTER key.


name

@NotNull
private final java.lang.String name
The name of this element.


serialVersionUID

private static final long serialVersionUID
The serial version UID.

See Also:
Constant Field Values

tooltipManager

@NotNull
private final TooltipManager tooltipManager
The TooltipManager to update.


tooltipText

@Nullable
private TooltipText tooltipText
The tooltip text to show when the mouse is inside this element. May be null to show no tooltip.


transparency

private final int transparency
The transparency for bufferedImage.


visible

private boolean visible
Whether this element is visible.

Constructor Detail

GUIElement

protected GUIElement(@NotNull
                     TooltipManager tooltipManager,
                     @NotNull
                     GUIElementListener elementListener,
                     @NotNull
                     java.lang.String name,
                     Extent extent,
                     int transparency)
Creates a new instance.

Parameters:
tooltipManager - the tooltip manager to update
elementListener - the element listener to notify
name - the name of this element
extent - the extent of this element
transparency - the transparency value for the backing buffer
Method Detail

createBuffer

private void createBuffer()
Allocates bufferedImage with the element's current size.


createBufferGraphics

@NotNull
protected java.awt.Graphics2D createBufferGraphics()
Calls BufferedImage.createGraphics() on bufferedImage. Checks that the calling thread holds the lock bufferedImageSync.

Returns:
the graphics instance; must be released afterwards

dispose

public void dispose()
Releases all allocated resources.


getElementX

public int getElementX()
Returns the element's absolute screen coordinate.

Returns:
the element's absolute x coordinate

getElementY

public int getElementY()
Returns the element's absolute screen coordinate.

Returns:
the element's absolute y coordinate

getGui

@Nullable
public Gui getGui()
Returns the Gui this element is part of.

Returns:
the gui or null

getName

@NotNull
public java.lang.String getName()

Overrides:
getName in class java.awt.Component

getTooltipText

@Nullable
public TooltipText getTooltipText()
Returns the tooltip text to show when the mouse is inside this element.

Returns:
the text to show or null to disable the tooltip for this element

hasBufferedImage

protected boolean hasBufferedImage()
Returns whether the backbuffer for this element has been created.

Returns:
whether the backbuffer has been created

isChanged

public boolean isChanged()
Returns the changed flag.

Returns:
the changed flag

isDefault

public boolean isDefault()
Returns whether this element is the default element. The default element is selected with the ENTER key.

Returns:
whether this element is the default element

isElementAtPoint

public boolean isElementAtPoint(int x,
                                int y)
Returns whether this element includes a given point.

Parameters:
x - the point's x coordinate
y - the point's y coordinate
Returns:
whether this element includes the point

isElementVisible

public boolean isElementVisible()
Returns whether this element is visible.

Returns:
whether this element is visible

isIgnore

public boolean isIgnore()
Returns whether this gui element should be ignored for user interaction.

Returns:
whether this gui element should be ignored for user interaction

mouseClicked

public void mouseClicked(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the user has clicked (pressed+released) this element. This event will be delivered after mouseReleased(MouseEvent).

Parameters:
e - the mouse event relative to this element

mouseDragged

public void mouseDragged(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the mouse moves within this component while the button is pressed. This event will be delivered after mouseMoved(MouseEvent).

Note: if the mouse leaves this element's bounding box while the mouse button is still pressed, further mouseDragged (but no mouseMoved) events will be generated.

Parameters:
e - the mouse event relative to this element

mouseEntered

public void mouseEntered(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the mouse has entered the bounding box of this element.

Parameters:
e - the mouse event relative to this element

mouseExited

public void mouseExited(@NotNull
                        java.awt.event.MouseEvent e)
Will be called when the mouse has left the bounding box of this element. This function will not be called unless mouseEntered(MouseEvent) has been called before.

Parameters:
e - the mouse event relative to this element

mouseMoved

public void mouseMoved(@NotNull
                       java.awt.event.MouseEvent e)
Will be called when the mouse moves within this component. before.

Parameters:
e - the mouse event relative to this element

mousePressed

public void mousePressed(@NotNull
                         java.awt.event.MouseEvent e)
Will be called when the user has pressed the mouse inside this element.

Parameters:
e - the mouse event relative to this element

mouseReleased

public void mouseReleased(@NotNull
                          java.awt.event.MouseEvent e)
Will be called when the user has released the mouse. This event may be delivered even if no previous mousePressed(MouseEvent) has been delivered before.

Parameters:
e - the mouse event relative to this element

paintComponent

public void paintComponent(@NotNull
                           java.awt.Graphics g)

Overrides:
paintComponent in class javax.swing.JComponent

render

private void render()
Re-creates the contents of bufferedImage.


render

protected abstract void render(@NotNull
                               java.awt.Graphics2D g2)
Paints the element's contents into the passed graphics.

Parameters:
g2 - the graphics to paint to

resetChanged

public void resetChanged()
Clears the changed flag.


setChanged

public void setChanged()
Records that bufferedImage has changed and must be repainted.


setChangedListener

public void setChangedListener(@Nullable
                               GUIElementChangedListener changedListener)
Sets the GUIElementChangedListener to be notified. Note that at most one such listener may be set per gui element.

Parameters:
changedListener - the listener or null to unset

setChangedNoListeners

protected void setChangedNoListeners()
Records that bufferedImage has changed and must be repainted. Does not notify listeners.


setDefault

public void setDefault(boolean isDefault)
Sets whether this element is the default element. The default element is selected with the ENTER key.

Parameters:
isDefault - whether this element is the default element

setElementLocation

public void setElementLocation(int x,
                               int y)
Changes the location of this gui element.

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

setElementSize

protected void setElementSize(int w,
                              int h)
Changes the size of this gui element.

Parameters:
w - the new width
h - the new height

setElementVisible

public void setElementVisible(boolean visible)
Sets whether this element is visible.

Parameters:
visible - whether this element is visible

setGui

public void setGui(@Nullable
                   Gui gui)
Sets the Gui this element is part of.

Parameters:
gui - the gui or null

setIgnore

public void setIgnore()
Marks this gui element to be ignored for user interaction.


setTooltipText

public void setTooltipText(@Nullable
                           java.lang.String tooltipText)
Sets the tooltip text to show when the mouse is inside this element.

Parameters:
tooltipText - the text to show or null to disable the tooltip for this element

setTooltipText

protected void setTooltipText(@Nullable
                              java.lang.String tooltipText,
                              int x,
                              int y,
                              int w,
                              int h)
Sets the tooltip text to show when the mouse is inside this element.

Parameters:
tooltipText - the text to show, or null to disable the tooltip for this element
x - the x coordinate
y - the y coordinate
w - the width
h - the height

toString

@NotNull
public java.lang.String toString()

Overrides:
toString in class java.awt.Component

updateResolution

public void updateResolution(int screenWidth,
                             int screenHeight)
Updates the location and size to a new screen resolution.

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

updateResolutionConstant

@Deprecated
protected void updateResolutionConstant()
Deprecated.