edu.kzoo.grid.display
Class ScaledImageDisplay

java.lang.Object
  |
  +--edu.kzoo.grid.display.ScaledDisplay
        |
        +--edu.kzoo.grid.display.ScaledImageDisplay
All Implemented Interfaces:
GridObjectDisplay
Direct Known Subclasses:
PictureBlockDisplay

public class ScaledImageDisplay
extends ScaledDisplay

Grid Display Package:
A ScaledImageDisplay uses an image read from a file to represent an object in a location in a grid. Images can be rotated or tinted using appropriate decorators. ScaledImageDisplay provides a tint method that can be used by a tint decorator.

Version:
13 December 2003
Author:
Alyce Brady (based on FishImageDisplay by Julie Zelenski)

Constructor Summary
protected ScaledImageDisplay()
          Internal constructor that does not initialize the icon instance variable; subclasses must be sure to set the icon using the setIcon method (e.g., at the beginning of a redefined draw method).
  ScaledImageDisplay(java.lang.String imageFilename)
          Constructs an object that knows how to display a GridObject object as an image.
 
Method Summary
 void draw(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Draws a unit-length object using an image.
 boolean imageLoadedOK()
          Returns true if the image loaded OK; false otherwise.
protected  void setIcon(javax.swing.ImageIcon icon)
          Defines the image to use for display purposes.
 void tint(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Adjusts the graphics system to use an object's color to tint an image.
 
Methods inherited from class edu.kzoo.grid.display.ScaledDisplay
addDecorator, adjust, draw, removeDecorator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaledImageDisplay

protected ScaledImageDisplay()
Internal constructor that does not initialize the icon instance variable; subclasses must be sure to set the icon using the setIcon method (e.g., at the beginning of a redefined draw method).


ScaledImageDisplay

public ScaledImageDisplay(java.lang.String imageFilename)
Constructs an object that knows how to display a GridObject object as an image. Looks for the named file first in the jar file, then in the current directory. If the named file is not found or the file is malformed, the display will fall back to the DefaultDisplay class.

Parameters:
imageFilename - name of file containing image
Method Detail

imageLoadedOK

public boolean imageLoadedOK()
Returns true if the image loaded OK; false otherwise.


setIcon

protected void setIcon(javax.swing.ImageIcon icon)
Defines the image to use for display purposes.


draw

public void draw(GridObject obj,
                 java.awt.Component comp,
                 java.awt.Graphics2D g2)
Draws a unit-length object using an image. This implementation draws the object by scaling the image provided to the constructor. It calls the adjust method to make further adjustments (for example, rotating and tinting the image) as appropriate.

Specified by:
draw in class ScaledDisplay
Parameters:
obj - object we want to draw
comp - the component we're drawing on
g2 - drawing surface

tint

public void tint(GridObject obj,
                 java.awt.Component comp,
                 java.awt.Graphics2D g2)
Adjusts the graphics system to use an object's color to tint an image. (Precondition: obj has a color method.)

Parameters:
obj - object we want to draw
comp - the component we're drawing on
g2 - drawing surface