wyvern.common.util
Class AWTImageList

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bywyvern.common.util.AWTImageList
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class AWTImageList
extends java.awt.Canvas

An image list that doesn't use any components, so it can manage its own drawing (for speed).

Version:
1.0, Aug 5, 2002
Author:
Steve Yegge
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int DEFAULT_WIDTH
           
static int ITEM_HEIGHT
           
static int LEFT_GUTTER_WIDTH
           
 
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
AWTImageList()
          Constructs a new AWTImageList
 
Method Summary
 void add(java.lang.String caption, java.awt.Image img)
          Adds an item to the end of the list.
 void add(java.lang.String caption, int tile, int index, short offset)
          Adds the specified text/picture to the list at the specified index.
 void add(java.lang.String caption, int tile, short offset)
          Adds an item to the end of the list.
 void addExtraRows(int rows)
          Tells the list to size itself vertically larger, so you can scroll down until the last item is at the top of the view.
 void addNotify()
          Now that the peer is built, create the offscreen buffer.
protected  java.awt.Graphics createGraphics()
          You have to override this to provide a Graphics context for the list, so it can figure out how wide to be (based on font metrics) before it comes onscreen.
 void ensureBuffers()
          Creates the offscreen buffers.
protected  java.awt.Image getImage(int tile, int x, int y)
          Gets the image from the ClientImageCache
protected  java.awt.Image getImage(int tile, short offset)
          Returns a piece of an image given its offsets.
 java.awt.Dimension getMaximumSize()
          Returns the max size.
 java.awt.Dimension getMinimumSize()
          Returns the desired size for this list entry.
 int getNumItems()
          Returns the size of the list.
 java.awt.Dimension getPreferredSize()
          Computes the desired size.
 java.lang.String getTextValueAt(int index)
          Returns the text of the specified item.
 void itemSelected(int index, java.awt.event.MouseEvent e)
          An item at a particular index was selected.
 int mouseToIndex(int y)
          Returns the index of the item selected, given a mouse Y-coordinate
 void paint(java.awt.Graphics g)
          Draws the list.
 void remove(int index)
          Removes the item at the specified index.
 void removeAll()
          Removes all the items.
 void replaceItem(java.lang.String caption, short tile, int index, short offset)
          Replaces the item at the specified location.
 void setBackgroundImage(java.awt.Image img)
          Sets the background drawing image.
 void setFont(int size)
          Sets the font for the text labels.
 void setTextColor(int index, java.awt.Color c)
          Sets the color of the text at the passed index.
 void update(java.awt.Graphics g)
          Avoids flicker.
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ITEM_HEIGHT

public static final int ITEM_HEIGHT
See Also:
Constant Field Values

LEFT_GUTTER_WIDTH

public static final int LEFT_GUTTER_WIDTH
See Also:
Constant Field Values

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
See Also:
Constant Field Values
Constructor Detail

AWTImageList

public AWTImageList()
Constructs a new AWTImageList

Method Detail

add

public void add(java.lang.String caption,
                int tile,
                int index,
                short offset)
Adds the specified text/picture to the list at the specified index.

Parameters:
caption - the item text
tile - the TileDatabase index of the object's picture, -1 if the object has no visible representation.
index - the position at which to insert the item. -1 means add to the end of the list.
offset - the offset at which to draw the image.

add

public void add(java.lang.String caption,
                int tile,
                short offset)
Adds an item to the end of the list.

Parameters:
caption - the item text
tile - the TileDatabase index of the object's picture, -1 if the object has no visible representation.
offset - the offset at which to draw the image.

add

public void add(java.lang.String caption,
                java.awt.Image img)
Adds an item to the end of the list.

Parameters:
caption - the item text
img - the item image

replaceItem

public void replaceItem(java.lang.String caption,
                        short tile,
                        int index,
                        short offset)
Replaces the item at the specified location.

Parameters:
caption - the item text
tile - the TileDatabase index of the object's picture, -1 if the object has no visible representation.
index - the index of the item to replace

remove

public void remove(int index)
Removes the item at the specified index.

Parameters:
index - the index to remove

removeAll

public void removeAll()
Removes all the items.


getTextValueAt

public java.lang.String getTextValueAt(int index)
Returns the text of the specified item.

Parameters:
index - the index of the item to get
Returns:
the item caption, or null if not found

setFont

public void setFont(int size)
Sets the font for the text labels.


getNumItems

public int getNumItems()
Returns the size of the list.


setTextColor

public void setTextColor(int index,
                         java.awt.Color c)
Sets the color of the text at the passed index.


getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the desired size for this list entry.


getMaximumSize

public java.awt.Dimension getMaximumSize()
Returns the max size.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Computes the desired size.


addExtraRows

public void addExtraRows(int rows)
Tells the list to size itself vertically larger, so you can scroll down until the last item is at the top of the view.

Parameters:
rows - the new number of empty rows to show at the bottom of the list

createGraphics

protected java.awt.Graphics createGraphics()
You have to override this to provide a Graphics context for the list, so it can figure out how wide to be (based on font metrics) before it comes onscreen.


update

public void update(java.awt.Graphics g)
Avoids flicker.


paint

public void paint(java.awt.Graphics g)
Draws the list.


addNotify

public void addNotify()
Now that the peer is built, create the offscreen buffer.


ensureBuffers

public void ensureBuffers()
Creates the offscreen buffers.


getImage

protected java.awt.Image getImage(int tile,
                                  short offset)
Returns a piece of an image given its offsets.

Parameters:
offset - the image offsets

getImage

protected java.awt.Image getImage(int tile,
                                  int x,
                                  int y)
Gets the image from the ClientImageCache

Parameters:
tile - the tile number
x - the x offset
y - the y offset

mouseToIndex

public int mouseToIndex(int y)
Returns the index of the item selected, given a mouse Y-coordinate


itemSelected

public void itemSelected(int index,
                         java.awt.event.MouseEvent e)
An item at a particular index was selected.


setBackgroundImage

public void setBackgroundImage(java.awt.Image img)
Sets the background drawing image.