java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent com.realtime.crossfire.jxclient.gui.gui.GUIElement
public abstract class GUIElement
Abstract base class for GUI elements to be shown in Gui
s.
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 |
---|
@Nullable private java.awt.image.BufferedImage bufferedImage
render()
and render(Graphics2D)
. paintComponent(Graphics)
copies
the contents to screen.
@NotNull protected final java.lang.Object bufferedImageSync
bufferedImage
contents.
private boolean changed
bufferedImage
has changed.
@Nullable private GUIElementChangedListener changedListener
GUIElementChangedListener
to be notified whenever the changed
flag is set.
@NotNull private final GUIElementListener elementListener
GUIElementListener
to notify.
@NotNull private final Extent extent
@Nullable private Gui gui
Gui
this element is part of. Set to null
if this
element is not part of any gui.
private boolean ignore
private boolean isDefault
@NotNull private final java.lang.String name
private static final long serialVersionUID
@NotNull private final TooltipManager tooltipManager
TooltipManager
to update.
@Nullable private TooltipText tooltipText
null
to show no tooltip.
private final int transparency
bufferedImage
.
private boolean visible
Constructor Detail |
---|
protected GUIElement(@NotNull TooltipManager tooltipManager, @NotNull GUIElementListener elementListener, @NotNull java.lang.String name, Extent extent, int transparency)
tooltipManager
- the tooltip manager to updateelementListener
- the element listener to notifyname
- the name of this elementextent
- the extent of this elementtransparency
- the transparency value for the backing bufferMethod Detail |
---|
private void createBuffer()
bufferedImage
with the element's current size.
@NotNull protected java.awt.Graphics2D createBufferGraphics()
BufferedImage.createGraphics()
on bufferedImage
.
Checks that the calling thread holds the lock bufferedImageSync
.
public void dispose()
public int getElementX()
public int getElementY()
@Nullable public Gui getGui()
Gui
this element is part of.
null
@NotNull public java.lang.String getName()
getName
in class java.awt.Component
@Nullable public TooltipText getTooltipText()
null to disable the tooltip for
this element
protected boolean hasBufferedImage()
public boolean isChanged()
public boolean isDefault()
public boolean isElementAtPoint(int x, int y)
x
- the point's x coordinatey
- the point's y coordinate
public boolean isElementVisible()
public boolean isIgnore()
public void mouseClicked(@NotNull java.awt.event.MouseEvent e)
mouseReleased(MouseEvent)
.
e
- the mouse event relative to this elementpublic void mouseDragged(@NotNull java.awt.event.MouseEvent e)
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.
e
- the mouse event relative to this elementpublic void mouseEntered(@NotNull java.awt.event.MouseEvent e)
e
- the mouse event relative to this elementpublic void mouseExited(@NotNull java.awt.event.MouseEvent e)
mouseEntered(MouseEvent)
has been called before.
e
- the mouse event relative to this elementpublic void mouseMoved(@NotNull java.awt.event.MouseEvent e)
e
- the mouse event relative to this elementpublic void mousePressed(@NotNull java.awt.event.MouseEvent e)
e
- the mouse event relative to this elementpublic void mouseReleased(@NotNull java.awt.event.MouseEvent e)
mousePressed(MouseEvent)
has been
delivered before.
e
- the mouse event relative to this elementpublic void paintComponent(@NotNull java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
private void render()
bufferedImage
.
protected abstract void render(@NotNull java.awt.Graphics2D g2)
g2
- the graphics to paint topublic void resetChanged()
public void setChanged()
bufferedImage
has changed and must be repainted.
public void setChangedListener(@Nullable GUIElementChangedListener changedListener)
GUIElementChangedListener
to be notified. Note that at
most one such listener may be set per gui element.
changedListener
- the listener or null
to unsetprotected void setChangedNoListeners()
bufferedImage
has changed and must be repainted.
Does not notify listeners.
public void setDefault(boolean isDefault)
isDefault
- whether this element is the default elementpublic void setElementLocation(int x, int y)
x
- the new x coordinatey
- the new y coordinateprotected void setElementSize(int w, int h)
w
- the new widthh
- the new heightpublic void setElementVisible(boolean visible)
visible
- whether this element is visiblepublic void setGui(@Nullable Gui gui)
Gui
this element is part of.
gui
- the gui or null
public void setIgnore()
public void setTooltipText(@Nullable java.lang.String tooltipText)
tooltipText
- the text to show or null to disable the
tooltip for this element
protected void setTooltipText(@Nullable java.lang.String tooltipText, int x, int y, int w, int h)
tooltipText
- the text to show, or null to disable the
tooltip for this elementx
- the x coordinatey
- the y coordinatew
- the widthh
- the height
@NotNull public java.lang.String toString()
toString
in class java.awt.Component
public void updateResolution(int screenWidth, int screenHeight)
screenWidth
- the new screen widthscreenHeight
- the new screen height@Deprecated protected void updateResolutionConstant()