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:
10 March 2005
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.
protected  javax.swing.ImageIcon getIcon()
          Returns the image to use for display purposes.
 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.
 
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. The imageFilename parameter may name a file in the jar file, may be the absolute name of a file in the current file system, or may be the name of a file in the current directory.

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.


getIcon

protected javax.swing.ImageIcon getIcon()
Returns 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. If the named file is not found or the file is malformed, the display will fall back to the DefaultDisplay class.

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