/* @(#)ImageTile.java 1.0  12 October 2004 */

import edu.neu.ccs.gui.*;

import java.awt.*;
import java.awt.geom.*;

/**
 * <p>Class <code>ImageTile</code> is a special purpose class for the
 * construction of tile objects based on images.</p>
 */
public class ImageTile extends PaintableComponent {
    
    /** The encapsulated image. */
    private Image image = null;
    
    /** Whether or not the tile should respond to mouse clicks. */
    private boolean active = true;
    
    
    /**
     * <p>Constructs an image tile using the given image,
     * the given tile background,
     * the given tile width and height,
     * the initial visibility setting for the tile image,
     * and the initial mouse activity setting.</p>
     */
    public ImageTile(
        Image image,
        Color background,
        int width,
        int height,
        boolean visible,
        boolean active)
    {
        super(new ImagePaintable(image), background, true);
        
        this.image = image;
        this.active = active;
        
        ImagePaintable paintable = (ImagePaintable) getPaintable();
        
        Rectangle2D bounds = new Rectangle2D.Double(0, 0, width, height);
        paintable.setDefaultBounds2D(bounds);
        
        paintable.setVisible(visible);
    }
    
    
    /** Returns the encapsulated image. */
    public Image getImage() { return image; }
    
    
    /** Set the image to a new Image. */
    public void setImage(Image image) {
        this.image = image;
        setPaintable(new ImagePaintable(image));
    }
    
    /** Returns the visibility of the tile image. */
    public boolean isTileVisible() { return getPaintable().isVisible(); }
    
    
    /** Sets the visibility of the tile image. */
    public void setTileVisible(boolean visible) { getPaintable().setVisible(visible); }
    
    
    /** Returns whether or not the tile should respond to mouse clicks. */
    public boolean isMouseActive() { return active; }
    
    
    /** Sets whether or not the tile should respond to mouse clicks. */
    public void setMouseActive(boolean active) { this.active = active; }
    
    
    /**
     * Tests equality of two image tiles by testing if their encapsulated
     * images are identical.
     */
    public boolean isEqualTo(ImageTile tile) {
        if (tile == null)
            return false;
        
        return image == tile.getImage();
    }
    
}