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

ShapeGraphicAttribute

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

Fields Summary
private Shape
fShape
The shape.
private boolean
fStroke
The stroke.
private Rectangle2D
fBounds
The bounds.
private float
fOriginX
The origin x.
private float
fOriginY
The origin y.
private float
fShapeWidth
The shape width.
private float
fShapeHeight
The shape height.
public static final boolean
STROKE
The Constant STROKE indicates whether the Shape is stroked or not.
public static final boolean
FILL
The Constant FILL indicates whether the Shape is filled or not.
Constructors Summary
public ShapeGraphicAttribute(Shape shape, int alignment, boolean stroke)
Instantiates a new ShapeGraphicAttribute object for the specified Shape.

param
shape the shape to be rendered by this ShapeGraphicAttribute.
param
alignment the alignment of this ShapeGraphicAttribute.
param
stroke true if the Shape is stroked, false if the Shape is filled.


                                                                                   
           
        super(alignment);

        this.fShape = shape;
        this.fStroke = stroke;

        this.fBounds = fShape.getBounds2D();

        this.fOriginX = (float)fBounds.getMinX();
        this.fOriginY = (float)fBounds.getMinY();

        this.fShapeWidth = (float)fBounds.getWidth();
        this.fShapeHeight = (float)fBounds.getHeight();
    
Methods Summary
public voiddraw(java.awt.Graphics2D g2, float x, float y)

        AffineTransform at = AffineTransform.getTranslateInstance(x, y);
        if (fStroke == STROKE) {
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke());
            g2.draw(at.createTransformedShape(fShape));
            g2.setStroke(oldStroke);
        } else {
            g2.fill(at.createTransformedShape(fShape));
        }

    
public booleanequals(java.awt.font.ShapeGraphicAttribute sga)
Compares this ShapeGraphicAttribute object to the specified ShapeGraphicAttribute object.

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

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

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

        return (fStroke == sga.fStroke && getAlignment() == sga.getAlignment() && fShape
                .equals(sga.fShape));

    
public booleanequals(java.lang.Object obj)
Compares this ShapeGraphicAttribute object to the specified Object.

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

        try {
            return equals((ShapeGraphicAttribute)obj);
        } catch (ClassCastException e) {
            return false;
        }
    
public floatgetAdvance()

        return Math.max(0, fShapeWidth + fOriginX);
    
public floatgetAscent()

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

        return (Rectangle2D)fBounds.clone();
    
public floatgetDescent()

        return Math.max(0, fShapeHeight + fOriginY);
    
public inthashCode()
Returns a hash code of this ShapeGraphicAttribute object.

return
a hash code of this ShapeGraphicAttribute object.

        HashCode hash = new HashCode();

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