rl.client.ui
Class Sprite

java.lang.Object
  extended by rl.client.ui.Sprite
All Implemented Interfaces:
java.awt.image.ImageObserver
Direct Known Subclasses:
CapitalShipHighlightSprite, HexCursorSprite, HexGameElementSprite, HexGridSprite, HexImageSprite, HexProhibitedSprite, HexShapeSprite, HexVectorSprite, SameHexArrowSprite, StraightArrowSprite

public abstract class Sprite
extends java.lang.Object
implements java.awt.image.ImageObserver

Everything in the main map view is either the board or it's a sprite displayed on top of the board. Most sprites store a transparent image which they draw onto the screen when told to. Sprites keep a bounds rectangle, so it's easy to tell when they'return onscreen.


Field Summary
protected  java.awt.Image m_Image
           
protected  javax.swing.JComponent m_ParentComponent
           
protected  boolean m_Visible
           
protected static int TRANSPARENT
           
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Sprite(javax.swing.JComponent parent)
           
 
Method Summary
protected  java.awt.Image createImage(java.awt.image.ImageProducer producer)
           
protected  java.awt.Image createImage(int width, int height)
           
 void draw(java.awt.Graphics2D g, java.awt.image.ImageObserver observer)
          Draws this sprite onto the specified graphics context.
 void draw(java.awt.Graphics2D g, java.awt.image.ImageObserver observer, boolean makeTranslucent)
           
protected abstract  java.awt.Image drawContent(java.awt.Graphics2D graph, java.awt.Image tempImage, java.awt.Rectangle bounds)
           
abstract  java.awt.Rectangle getBounds()
          Returns our bounding rectangle.
 boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int width, int height)
          When we draw our buffered images, it's necessary to implement the ImageObserver interface.
 boolean isReady()
          Are we ready to draw? By default, checks to see that our buffered image has been created.
 boolean isVisible()
           
 void prepare()
          Do any necessary preparation.
 void repaint()
           
 void setVisible(boolean visible)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSPARENT

protected static final int TRANSPARENT
See Also:
Constant Field Values

m_ParentComponent

protected javax.swing.JComponent m_ParentComponent

m_Image

protected java.awt.Image m_Image

m_Visible

protected boolean m_Visible
Constructor Detail

Sprite

public Sprite(javax.swing.JComponent parent)
Method Detail

prepare

public void prepare()
Do any necessary preparation. This is called after creation, but before drawing, when a device context is ready to draw with. DC:- Any subclasses must cater for this call being made multiple times and handle that gracefully. For classes creating dynamic images it should only get called once. For those using static images it will get called each time a draw operation fails because the outstanding image(s) have not yet been loaded and then once for each image that completes loading.


drawContent

protected abstract java.awt.Image drawContent(java.awt.Graphics2D graph,
                                              java.awt.Image tempImage,
                                              java.awt.Rectangle bounds)

repaint

public void repaint()

imageUpdate

public final boolean imageUpdate(java.awt.Image image,
                                 int infoflags,
                                 int x,
                                 int y,
                                 int width,
                                 int height)
When we draw our buffered images, it's necessary to implement the ImageObserver interface. This provides the neccesary functionality.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver

getBounds

public abstract java.awt.Rectangle getBounds()
Returns our bounding rectangle. The coordinates here are stored with the top left corner of the _board_ being 0, 0, so these do not always correspond to screen coordinates.


isReady

public boolean isReady()
Are we ready to draw? By default, checks to see that our buffered image has been created.


isVisible

public boolean isVisible()

draw

public void draw(java.awt.Graphics2D g,
                 java.awt.image.ImageObserver observer)
Draws this sprite onto the specified graphics context.


draw

public final void draw(java.awt.Graphics2D g,
                       java.awt.image.ImageObserver observer,
                       boolean makeTranslucent)

createImage

protected java.awt.Image createImage(int width,
                                     int height)

createImage

protected java.awt.Image createImage(java.awt.image.ImageProducer producer)

setVisible

public void setVisible(boolean visible)