FileDocCategorySizeDatePackage
ImageGraphicAttribute.javaAPI DocAndroid 1.5 API5146Wed May 06 22:41:54 BST 2009java.awt.font

ImageGraphicAttribute

public final class ImageGraphicAttribute extends GraphicAttribute
The ImageGraphicAttribute class provides an opportunity to insert images to a text.
since
Android 1.0

Fields Summary
private Image
fImage
The image.
private float
fOriginX
The origin x.
private float
fOriginY
The origin y.
private float
fImgWidth
The img width.
private float
fImgHeight
The img height.
Constructors Summary
public ImageGraphicAttribute(Image image, int alignment, float originX, float originY)
Instantiates a new ImageGraphicAttribute with the specified image, alignment and origins.

param
image the Image to be rendered by ImageGraphicAttribute.
param
alignment the alignment of the ImageGraphicAttribute.
param
originX the origin X coordinate in the image of ImageGraphicAttribute.
param
originY the origin Y coordinate in the image of ImageGraphicAttribute.

        super(alignment);

        this.fImage = image;
        this.fOriginX = originX;
        this.fOriginY = originY;

        this.fImgWidth = fImage.getWidth(null);
        this.fImgHeight = fImage.getHeight(null);

    
public ImageGraphicAttribute(Image image, int alignment)
Instantiates a new ImageGraphicAttribute with the specified image and alignment.

param
image the Image to be rendered by ImageGraphicAttribute.
param
alignment the alignment of the ImageGraphicAttribute.

        this(image, alignment, 0, 0);
    
Methods Summary
public voiddraw(java.awt.Graphics2D g2, float x, float y)

        g2.drawImage(fImage, (int)(x - fOriginX), (int)(y - fOriginY), null);
    
public booleanequals(java.awt.font.ImageGraphicAttribute iga)
Compares the specified ImageGraphicAttribute object with this ImageGraphicAttribute object.

param
iga the ImageGraphicAttribute object to be compared.
return
true, if the specified ImageGraphicAttribute object is equal to this ImageGraphicAttribute object, false otherwise.

        if (iga == null) {
            return false;
        }

        if (iga == this) {
            return true;
        }

        return (fOriginX == iga.fOriginX && fOriginY == iga.fOriginY
                && getAlignment() == iga.getAlignment() && fImage.equals(iga.fImage));
    
public booleanequals(java.lang.Object obj)
Compares the specified Object with this ImageGraphicAttribute object.

param
obj the Object to be compared.
return
true, if the specified Object is equal to this ImageGraphicAttribute object, false otherwise.

        try {
            return equals((ImageGraphicAttribute)obj);
        } catch (ClassCastException e) {
            return false;
        }

    
public floatgetAdvance()

        return Math.max(0, fImgWidth - fOriginX);
    
public floatgetAscent()

        return Math.max(0, fOriginY);
    
public java.awt.geom.Rectangle2DgetBounds()

        return new Rectangle2D.Float(-fOriginX, -fOriginY, fImgWidth, fImgHeight);
    
public floatgetDescent()

        return Math.max(0, fImgHeight - fOriginY);
    
public inthashCode()
Returns a hash code of this ImageGraphicAttribute object.

return
the hash code of this ImageGraphicAttribute object.

        HashCode hash = new HashCode();

        hash.append(fImage.hashCode());
        hash.append(getAlignment());
        return hash.hashCode();