Class ScaledImageDisplay

ScaledImageDisplay

public class ScaledImageDisplay

Environment-Based Applications:
A ScaledImageDisplay uses an image read from a file to represent an object with a location in an environment. This display class does not rotate or tint the image, but subclasses could redefine the draw method to do so. The ScaledDisplay superclass provides an adjustForDirection method, and ScaledImageDisplay provides a tint method.


Constructor Summary
ScaledImageDisplay(java.lang.String imageFilename)
          Constructs an object that knows how to display a Locatable object as an image.
 
Method Summary
 void adjust(Locatable obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Adjusts the graphics system for drawing an object, as appropriate.
 void draw(Locatable obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Draws a unit-length object using an image.
 void tint(Locatable obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Adjusts the graphics system to use an object's color to tint an image.
 

Constructor Detail

ScaledImageDisplay

public ScaledImageDisplay(java.lang.String imageFilename)
Constructs an object that knows how to display a Locatable 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

draw

public void draw(Locatable 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. methods
Parameters:
obj - object we want to draw
comp - the component we're drawing on
g2 - drawing surface

adjust

public void adjust(Locatable obj,
                   java.awt.Component comp,
                   java.awt.Graphics2D g2)
Adjusts the graphics system for drawing an object, as appropriate. This method actually makes no further adjustments, but subclasses could override this method to rotate or color the object, for example.

tint

public void tint(Locatable 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