FileDocCategorySizeDatePackage
AndroidGraphics2D.javaAPI DocAndroid 1.5 API41016Wed May 06 22:41:54 BST 2009com.android.internal.awt

AndroidGraphics2D

public class AndroidGraphics2D extends Graphics2D

Fields Summary
private int
displayWidth
private int
displayHeight
protected org.apache.harmony.awt.gl.Surface
dstSurf
protected org.apache.harmony.awt.gl.MultiRectArea
clip
protected Composite
composite
protected AffineTransform
transform
private static AndroidGraphics2D
mAg
private static android.graphics.Canvas
mC
public static android.graphics.Paint
mP
private static Font
mFnt
public static android.graphics.Matrix
mM
private static FontMetrics
mFm
private static RenderingHints
mRh
private static Color
mBc
private Area
mCurrClip
public static final double
RAD_360
private AndroidJavaBlitter
blitter
private DirectColorModel
cm
private SinglePixelPackedSampleModel
sm
private WritableRaster
wr
Constructors Summary
private AndroidGraphics2D(android.content.Context ctx, android.graphics.Canvas c, android.graphics.Paint p)

        super();
        mC = c;
        mP = p;
        mM = new Matrix();
        mM.reset();
        mM = mC.getMatrix();
        Rect r = mC.getClipBounds();
        int cl[] = {-1, r.top, r.left, -2, r.top, r.right, -2, r.bottom, r.right, -2, r.bottom, r.left};
        mCurrClip = new Area(createShape(cl));
        if(ctx != null) {
            WindowManager wm = (WindowManager)ctx.getSystemService(Context.WINDOW_SERVICE);
            Display d = wm.getDefaultDisplay();
            displayWidth = d.getWidth();
            displayHeight = d.getHeight();
        }
        blitter = new AndroidJavaBlitter(c);
        cm = new DirectColorModel(32, 0xff0000, 0xff00, 0xff, 0xff000000);
        sm = new SinglePixelPackedSampleModel(
                DataBuffer.TYPE_INT, displayWidth, displayHeight, cm.getMasks());
        wr = Raster.createWritableRaster(sm, null);
        dstSurf = new ImageSurface(cm, wr);       
    
Methods Summary
public voidaddRenderingHints(java.util.Map hints)

        if (mRh == null) {
            mRh = (RenderingHints) hints;
        }
        mRh.add((RenderingHints) hints);
    
private voidapplyHints()

        Object o;

        // TODO do something like this:
        /*
         * Set s = mRh.keySet(); Iterator it = s.iterator(); while(it.hasNext()) {
         * o = it.next(); }
         */

        // /////////////////////////////////////////////////////////////////////
        // not supported in skia
        /*
         * o = mRh.get(RenderingHints.KEY_ALPHA_INTERPOLATION); if
         * (o.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) { } else
         * if (o.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) { }
         * else if (o.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_COLOR_RENDERING); if
         * (o.equals(RenderingHints.VALUE_COLOR_RENDER_DEFAULT)) { } else if
         * (o.equals(RenderingHints.VALUE_COLOR_RENDER_QUALITY)) { } else if
         * (o.equals(RenderingHints.VALUE_COLOR_RENDER_SPEED)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_DITHERING); if
         * (o.equals(RenderingHints.VALUE_DITHER_DEFAULT)) { } else if
         * (o.equals(RenderingHints.VALUE_DITHER_DISABLE)) { } else if
         * (o.equals(RenderingHints.VALUE_DITHER_ENABLE)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_FRACTIONALMETRICS); if
         * (o.equals(RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT)) { } else
         * if (o.equals(RenderingHints.VALUE_FRACTIONALMETRICS_OFF)) { } else if
         * (o.equals(RenderingHints.VALUE_FRACTIONALMETRICS_ON)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_INTERPOLATION); if
         * (o.equals(RenderingHints.VALUE_INTERPOLATION_BICUBIC)) { } else if
         * (o.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) { } else if
         * (o .equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_RENDERING); if
         * (o.equals(RenderingHints.VALUE_RENDER_DEFAULT)) { } else if
         * (o.equals(RenderingHints.VALUE_RENDER_QUALITY)) { } else if
         * (o.equals(RenderingHints.VALUE_RENDER_SPEED)) { }
         * 
         * o = mRh.get(RenderingHints.KEY_STROKE_CONTROL); if
         * (o.equals(RenderingHints.VALUE_STROKE_DEFAULT)) { } else if
         * (o.equals(RenderingHints.VALUE_STROKE_NORMALIZE)) { } else if
         * (o.equals(RenderingHints.VALUE_STROKE_PURE)) { }
         */

        o = mRh.get(RenderingHints.KEY_ANTIALIASING);
        if (o != null) {
            if (o.equals(RenderingHints.VALUE_ANTIALIAS_DEFAULT)) {
                mP.setAntiAlias(false);
            } else if (o.equals(RenderingHints.VALUE_ANTIALIAS_OFF)) {
                mP.setAntiAlias(false);
            } else if (o.equals(RenderingHints.VALUE_ANTIALIAS_ON)) {
                mP.setAntiAlias(true);
            }
        }

        o = mRh.get(RenderingHints.KEY_TEXT_ANTIALIASING);
        if (o != null) {
            if (o.equals(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
                mP.setAntiAlias(false);
            } else if (o.equals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)) {
                mP.setAntiAlias(false);
            } else if (o.equals(RenderingHints.VALUE_TEXT_ANTIALIAS_ON)) {
                mP.setAntiAlias(true);
            }
        }
    
public voidclearRect(int x, int y, int width, int height)

        mC.clipRect(x, y, x + width, y + height);
        if (mBc != null) {
            mC.drawARGB(mBc.getAlpha(), mBc.getBlue(), mBc.getGreen(), mBc
                    .getRed());
        } else {
            mC.drawARGB(0xff, 0xff, 0xff, 0xff);
        }
    
public voidclip(java.awt.Shape s)

        mC.clipPath(getPath(s));
    
public voidclipRect(int x, int y, int width, int height)

        int cl[] = {-1, x, y, -2, x, y + width, -2, x + height, y + width, -2, x + height, y};
        Shape shp = createShape(cl);
        mCurrClip.intersect(new Area(shp));
        mC.clipRect(new Rect(x, y, x + width, y + height), Region.Op.INTERSECT);
    
public voidcopyArea(android.graphics.Canvas canvas, int sx, int sy, int width, int height, int dx, int dy)

        sx += getTransform().getTranslateX();
        sy += getTransform().getTranslateY();

        NativeUtils.nativeScrollRect(canvas,
                new Rect(sx, sy, sx + width, sy + height),
                dx, dy);
    
public voidcopyArea(int sx, int sy, int width, int height, int dx, int dy)

        copyArea(mC, sx, sy, width + dx, height + dy, dx, dy);
    
public java.awt.Graphicscreate()

        return this;
    
private float[]createAWTMatrix(float[] matrix)

        float[] at = new float[9];
        at[0] = matrix[0];
        at[1] = matrix[3];
        at[2] = matrix[1];
        at[3] = matrix[4];
        at[4] = matrix[2];
        at[5] = matrix[5];
        at[6] = 0;
        at[7] = 0;
        at[8] = 1;
        return at;
    
public static float[]createMatrix(java.awt.geom.AffineTransform Tx)

        double[] at = new double[9];
        Tx.getMatrix(at);
        float[] f = new float[at.length];
        f[0] = (float) at[0];
        f[1] = (float) at[2];
        f[2] = (float) at[4];
        f[3] = (float) at[1];
        f[4] = (float) at[3];
        f[5] = (float) at[5];
        f[6] = 0;
        f[7] = 0;
        f[8] = 1;
        return f;
    
public static android.graphics.MatrixcreateMatrixObj(java.awt.geom.AffineTransform Tx)

        Matrix m = new Matrix();
        m.reset();
        m.setValues(createMatrix(Tx));
        return m;
    
private java.awt.ShapecreateShape(int[] arr)

        Shape s = new GeneralPath();
        for(int i = 0; i < arr.length; i++) {
            int type = arr[i];    
            switch (type) {
            case -1:
                //MOVETO
                ((GeneralPath)s).moveTo(arr[++i], arr[++i]);
                break;
            case -2:
                //LINETO
                ((GeneralPath)s).lineTo(arr[++i], arr[++i]);
                break;
            case -3:
                //QUADTO
                ((GeneralPath)s).quadTo(arr[++i], arr[++i], arr[++i],
                        arr[++i]);
                break;
            case -4:
                //CUBICTO
                ((GeneralPath)s).curveTo(arr[++i], arr[++i], arr[++i],
                        arr[++i], arr[++i], arr[++i]);
                break;
            case -5:
                //CLOSE
                return s;
            default:
                break;
            }
        }
        return s;
    
public voiddispose()

            mC = null;
            mP = null;
    
public voiddraw(java.awt.Shape s)

        if (mP == null) {
            mP = new Paint();
        }
        Paint.Style tmp = mP.getStyle();
        mP.setStyle(Paint.Style.STROKE);
        mC.drawPath(getPath(s), mP);
        mP.setStyle(tmp);
    
public voiddraw(android.graphics.Path s)

        if (mP == null) {
            mP = new Paint();
        }
        Paint.Style tmp = mP.getStyle();
        mP.setStyle(Paint.Style.STROKE);
        s.transform(mM);
        mC.drawPath(s, mP);
        mP.setStyle(tmp);
    
public voiddraw3DRect(int x, int y, int width, int height, boolean raised)

        Color color = getColor();
        Color colorUp, colorDown;
        if (raised) {
            colorUp = color.brighter();
            colorDown = color.darker();
        } else {
            colorUp = color.darker();
            colorDown = color.brighter();
        }

        setColor(colorUp);
        fillRect(x, y, width, 1);
        fillRect(x, y+1, 1, height);

        setColor(colorDown);
        fillRect(x+width, y, 1, height);
        fillRect(x+1, y+height, width, 1);
    
public voiddrawArc(int x, int y, int width, int height, int sa, int ea)

            if (mP == null) {
                mP = new Paint();
            }
            mP.setStrokeWidth(0);
            mC.drawArc(new RectF(x, y, x + width, y + height), 360 - (ea + sa),
                       ea, true, mP);
    
public voiddrawBitmap(android.graphics.Bitmap bm, float x, float y, android.graphics.Paint p)

        mC.drawBitmap(bm, x, y, null);
    
public voiddrawBytes(byte[] data, int offset, int length, int x, int y)

        drawString(new String(data, offset, length), x, y);
    
public voiddrawChars(char[] data, int offset, int length, int x, int y)

        mC.drawText(data, offset, length, x, y, mP);
    
public voiddrawGlyphVector(java.awt.font.GlyphVector g, float x, float y)

        // TODO draw at x, y
        // draw(g.getOutline());
        /*
        Matrix matrix = new Matrix();
        matrix.setTranslate(x, y);
        Path pth = getPath(g.getOutline());
        pth.transform(matrix);
        draw(pth);
        */
        Path path = new Path();
        char[] c = ((AndroidGlyphVector)g).getGlyphs();
        mP.getTextPath(c, 0, c.length, x, y, path);
        mC.drawPath(path, mP);
    
public booleandrawImage(java.awt.Image image, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver imageObserver)


        if(image == null) {
            return true;
        }

        boolean done = false;
        boolean somebits = false;
        Surface srcSurf = null;
        if(image instanceof OffscreenImage){
            OffscreenImage oi = (OffscreenImage) image;
            if((oi.getState() & ImageObserver.ERROR) != 0) {
                return false;
            }
            done = oi.prepareImage(imageObserver);
            somebits = (oi.getState() & ImageObserver.SOMEBITS) != 0;
            srcSurf = oi.getImageSurface();
        }else{
            done = true;
            srcSurf = Surface.getImageSurface(image);
        }

        if(done || somebits) {
            int w = srcSurf.getWidth();
            int h = srcSurf.getHeight();
            
            blitter.blit(0, 0, srcSurf, x, y, dstSurf, w, h, (AffineTransform) transform.clone(),
                    composite, bgcolor, clip);
        }
        return done;
    
public booleandrawImage(java.awt.Image image, int x, int y, java.awt.image.ImageObserver imageObserver)

        return drawImage(image, x, y, null, imageObserver);
    
public booleandrawImage(java.awt.Image image, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver imageObserver)


        if(image == null) {
            return true;
        }
        if(width == 0 || height == 0) {
            return true;
        }

        boolean done = false;
        boolean somebits = false;
        Surface srcSurf = null;

        if(image instanceof OffscreenImage){
            OffscreenImage oi = (OffscreenImage) image;
            if((oi.getState() & ImageObserver.ERROR) != 0) {
                return false;
            }
            done = oi.prepareImage(imageObserver);
            somebits = (oi.getState() & ImageObserver.SOMEBITS) != 0;
            srcSurf = oi.getImageSurface();
        }else{
            done = true;
            srcSurf = Surface.getImageSurface(image);
        }

        if(done || somebits) {
            int w = srcSurf.getWidth();
            int h = srcSurf.getHeight();
            if(w == width && h == height){
                blitter.blit(0, 0, srcSurf, x, y, dstSurf, w, h,
                        (AffineTransform) transform.clone(),
                        composite, bgcolor, clip);
            }else{
                AffineTransform xform = new AffineTransform();
                xform.setToScale((float)width / w, (float)height / h);
                blitter.blit(0, 0, srcSurf, x, y, dstSurf, w, h,
                        (AffineTransform) transform.clone(),
                        xform, composite, bgcolor, clip);
            }
        }
        return done;
    
public booleandrawImage(java.awt.Image image, int x, int y, int width, int height, java.awt.image.ImageObserver imageObserver)

        return drawImage(image, x, y, width, height, null, imageObserver);
    
public booleandrawImage(java.awt.Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver imageObserver)


        if(image == null) {
            return true;
        }
        if(dx1 == dx2 || dy1 == dy2 || sx1 == sx2 || sy1 == sy2) {
            return true;
        }

        boolean done = false;
        boolean somebits = false;
        Surface srcSurf = null;
        if(image instanceof OffscreenImage){
            OffscreenImage oi = (OffscreenImage) image;
            if((oi.getState() & ImageObserver.ERROR) != 0) {
                return false;
            }
            done = oi.prepareImage(imageObserver);
            somebits = (oi.getState() & ImageObserver.SOMEBITS) != 0;
            srcSurf = oi.getImageSurface();
        }else{
            done = true;
            srcSurf = Surface.getImageSurface(image);
        }

        if(done || somebits) {

            int dstX = dx1;
            int dstY = dy1;
            int srcX = sx1;
            int srcY = sy1;

            int dstW = dx2 - dx1;
            int dstH = dy2 - dy1;
            int srcW = sx2 - sx1;
            int srcH = sy2 - sy1;

            if(srcW == dstW && srcH == dstH){
                blitter.blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, srcW, srcH,
                        (AffineTransform) transform.clone(),
                        composite, bgcolor, clip);
            }else{
                AffineTransform xform = new AffineTransform();
                xform.setToScale((float)dstW / srcW, (float)dstH / srcH);
                blitter.blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, srcW, srcH,
                        (AffineTransform) transform.clone(),
                        xform, composite, bgcolor, clip);
            }
        }
        return done;
    
public booleandrawImage(java.awt.Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver imageObserver)


        return drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null,
                imageObserver);
     
public voiddrawImage(java.awt.image.BufferedImage bufImage, java.awt.image.BufferedImageOp op, int x, int y)


        if(bufImage == null) {
            return;
        }

        if(op == null) {
            drawImage(bufImage, x, y, null);
        } else if(op instanceof AffineTransformOp){
            AffineTransformOp atop = (AffineTransformOp) op;
            AffineTransform xform = atop.getTransform();
            Surface srcSurf = Surface.getImageSurface(bufImage);
            int w = srcSurf.getWidth();
            int h = srcSurf.getHeight();
            blitter.blit(0, 0, srcSurf, x, y, dstSurf, w, h,
                    (AffineTransform) transform.clone(), xform,
                    composite, null, clip);
        } else {
            bufImage = op.filter(bufImage, null);
            Surface srcSurf = Surface.getImageSurface(bufImage);
            int w = srcSurf.getWidth();
            int h = srcSurf.getHeight();
            blitter.blit(0, 0, srcSurf, x, y, dstSurf, w, h,
                    (AffineTransform) transform.clone(),
                    composite, null, clip);
        }
    
public booleandrawImage(java.awt.Image image, java.awt.geom.AffineTransform trans, java.awt.image.ImageObserver imageObserver)


        if(image == null) {
            return true;
        }
        if(trans == null || trans.isIdentity()) {
            return drawImage(image, 0, 0, imageObserver);
        }

        boolean done = false;
        boolean somebits = false;
        Surface srcSurf = null;
        if(image instanceof OffscreenImage){
            OffscreenImage oi = (OffscreenImage) image;
            if((oi.getState() & ImageObserver.ERROR) != 0) {
                return false;
            }
            done = oi.prepareImage(imageObserver);
            somebits = (oi.getState() & ImageObserver.SOMEBITS) != 0;
            srcSurf = oi.getImageSurface();
        }else{
            done = true;
            srcSurf = Surface.getImageSurface(image);
        }

        if(done || somebits) {
            int w = srcSurf.getWidth();
            int h = srcSurf.getHeight();
            AffineTransform xform = (AffineTransform) transform.clone();
            xform.concatenate(trans);
            blitter.blit(0, 0, srcSurf, 0, 0, dstSurf, w, h, xform, composite,
                    null, clip);
        }
        return done;
    
public voiddrawLine(int x1, int y1, int x2, int y2)

        if (mP == null) {
            mP = new Paint();
        }
            mC.drawLine(x1, y1, x2, y2, mP);
    
public voiddrawOval(int x, int y, int width, int height)

            if (mP == null) {
                mP = new Paint();
            }
            mP.setStyle(Paint.Style.STROKE);
            mC.drawOval(new RectF(x, y, x + width, y + height), mP);
    
public voiddrawPolygon(int[] xpoints, int[] ypoints, int npoints)

            if (mP == null) {
                mP = new Paint();
            }
            mC.drawLine(xpoints[npoints - 1], ypoints[npoints - 1], xpoints[0],
                    ypoints[0], mP);
            for (int i = 0; i < npoints - 1; i++) {
                mC.drawLine(xpoints[i], ypoints[i], xpoints[i + 1],
                        ypoints[i + 1], mP);
            }
    
public voiddrawPolygon(java.awt.Polygon p)

        drawPolygon(p.xpoints, p.ypoints, p.npoints);
    
public voiddrawPolyline(int[] xpoints, int[] ypoints, int npoints)

        for (int i = 0; i < npoints - 1; i++) {
            drawLine(xpoints[i], ypoints[i], xpoints[i + 1], ypoints[i + 1]);
        }

    
public voiddrawRect(int x, int y, int width, int height)

        int[] xpoints = { x, x, x + width, x + width };
        int[] ypoints = { y, y + height, y + height, y };
        drawPolygon(xpoints, ypoints, 4);
    
public voiddrawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)

        throw new RuntimeException("Not implemented!");
    
public voiddrawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)

        throw new RuntimeException("Not implemented!");
    
public voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

            if (mP == null) {
                mP = new Paint();
            }
            mC.drawRoundRect(new RectF(x, y, width, height), arcWidth,
                    arcHeight, mP);
    
public voiddrawString(java.text.AttributedCharacterIterator iterator, float x, float y)

        throw new RuntimeException("AttributedCharacterIterator not supported!");

    
public voiddrawString(java.text.AttributedCharacterIterator iterator, int x, int y)

        throw new RuntimeException("AttributedCharacterIterator not supported!");

    
public voiddrawString(java.lang.String s, float x, float y)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();

            mP.setStyle(Paint.Style.FILL);
            Path pth = new Path();
            mP.getTextPath(s, 0, s.length(), x, y, pth);
            mC.drawPath(pth, mP);
            mP.setStyle(tmp);
    
public voiddrawString(java.lang.String str, int x, int y)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();
            mP.setStrokeWidth(0);

            mC.drawText(str.toCharArray(), 0, str.toCharArray().length, x, y,
                    mP);
            mP.setStyle(tmp);
    
public voidfill(java.awt.Shape s)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();
            mP.setStyle(Paint.Style.FILL);
            mC.drawPath(getPath(s), mP);
            mP.setStyle(tmp);
    
public voidfill3DRect(int x, int y, int width, int height, boolean raised)

        Color color = getColor();
        Color colorUp, colorDown;
        if (raised) {
            colorUp = color.brighter();
            colorDown = color.darker();
            setColor(color);
        } else {
            colorUp = color.darker();
            colorDown = color.brighter();
            setColor(colorUp);
        }

        width--;
        height--;
        fillRect(x+1, y+1, width-1, height-1);

        setColor(colorUp);
        fillRect(x, y, width, 1);
        fillRect(x, y+1, 1, height);

        setColor(colorDown);
        fillRect(x+width, y, 1, height);
        fillRect(x+1, y+height, width, 1);
    
public voidfillArc(int x, int y, int width, int height, int sa, int ea)

            if (mP == null) {
                mP = new Paint();
            }
            
            Paint.Style tmp = mP.getStyle();
            mP.setStyle(Paint.Style.FILL_AND_STROKE);
            mC.drawArc(new RectF(x, y, x + width, y + height), 360 - (sa + ea),
                    ea, true, mP);
            
            mP.setStyle(tmp);
    
public voidfillOval(int x, int y, int width, int height)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();
            mP.setStyle(Paint.Style.FILL);
            mC.drawOval(new RectF(x, y, x + width, y + height), mP);
            mP.setStyle(tmp);
    
public voidfillPolygon(int[] xpoints, int[] ypoints, int npoints)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();
            mC.save(Canvas.CLIP_SAVE_FLAG);

            mP.setStyle(Paint.Style.FILL);

            GeneralPath filledPolygon = new GeneralPath(
                    GeneralPath.WIND_EVEN_ODD, npoints);
            filledPolygon.moveTo(xpoints[0], ypoints[0]);
            for (int index = 1; index < xpoints.length; index++) {
                filledPolygon.lineTo(xpoints[index], ypoints[index]);
            }
            filledPolygon.closePath();
            Path path = getPath(filledPolygon);
            mC.clipPath(path);
            mC.drawPath(path, mP);

            mP.setStyle(tmp);
            mC.restore();
    
public voidfillPolygon(java.awt.Polygon p)

        fillPolygon(p.xpoints, p.ypoints, p.npoints);
    
public voidfillRect(int x, int y, int width, int height)

            if (mP == null) {
                mP = new Paint();
            }
            Paint.Style tmp = mP.getStyle();
            mP.setStyle(Paint.Style.FILL);
            mC.drawRect(new Rect(x, y, x + width, y + height), mP);
            mP.setStyle(tmp);
    
public voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

            if (mP == null) {
                mP = new Paint();
            }
            mP.setStyle(Paint.Style.FILL);
            mC.drawRoundRect(new RectF(x, y, x + width, y + height), arcWidth,
                    arcHeight, mP);
    
public static android.graphics.CanvasgetAndroidCanvas()

        return mC;
    
public static android.graphics.PaintgetAndroidPaint()

        return mP;
    
public java.awt.ColorgetBackground()

        return mBc;
    
public java.awt.ShapegetClip()

        return mCurrClip;
    
public java.awt.RectanglegetClipBounds()

            Rect r = mC.getClipBounds();
            return new Rectangle(r.left, r.top, r.width(), r.height());
    
public java.awt.RectanglegetClipBounds(java.awt.Rectangle r)

        Shape clip = getClip();
        if (clip != null) {
            Rectangle b = clip.getBounds();
            r.x = b.x;
            r.y = b.y;
            r.width = b.width;
            r.height = b.height;
        }
        return r;
    
public java.awt.ColorgetColor()

        if (mP != null) {
            return new Color(mP.getColor());
        }
        return null;
    
public java.awt.CompositegetComposite()

        throw new RuntimeException("Composite not implemented!");
    
private voidgetCurrentSegment(java.awt.geom.PathIterator pi, android.graphics.Path path)

        float[] coordinates = new float[6];
        int type = pi.currentSegment(coordinates);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            path.moveTo(coordinates[0], coordinates[1]);
            break;
        case PathIterator.SEG_LINETO:
            path.lineTo(coordinates[0], coordinates[1]);
            break;
        case PathIterator.SEG_QUADTO:
            path.quadTo(coordinates[0], coordinates[1], coordinates[2],
                    coordinates[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            path.cubicTo(coordinates[0], coordinates[1], coordinates[2],
                    coordinates[3], coordinates[4], coordinates[5]);
            break;
        case PathIterator.SEG_CLOSE:
            path.close();
            break;
        default:
            break;
        }
    
public static floatgetDegree(float radian)

        return (float) ((180 / Math.PI) * radian);
    
public java.awt.GraphicsConfigurationgetDeviceConfiguration()

        return new AndroidGraphicsConfiguration();
    
public static floatgetEllipsisX(float degree, float princAxis)

        return (float) Math.cos(degree) * princAxis;
    
public static floatgetEllipsisY(float degree, float conAxis)

        return (float) Math.sin(degree) * conAxis;
    
public java.awt.FontgetFont()

        return mFnt;
    
public java.awt.FontMetricsgetFontMetrics(java.awt.Font font)

        mFm = new FontMetricsImpl(font);
        return mFm;
    
public java.awt.font.FontRenderContextgetFontRenderContext()

        return new FontRenderContext(getTransform(), mP.isAntiAlias(), true);
    
public static com.android.internal.awt.AndroidGraphics2DgetInstance()



        
        if (mAg == null) {
            throw new RuntimeException("AndroidGraphics2D not instantiated!");
        }
        return mAg;
    
public static com.android.internal.awt.AndroidGraphics2DgetInstance(android.content.Context ctx, android.graphics.Canvas c, android.graphics.Paint p)

        if (c == null || ctx == null) {
            throw new RuntimeException(
                    "Illegal argument, Canvas cannot be null!");
        }
        mAg = new AndroidGraphics2D(ctx, c, p);
        return mAg;
    
public float[]getInverseMatrix()

return
a Matrix in Android format

        AffineTransform af = new AffineTransform(createAWTMatrix(getMatrix()));
        try {
            af = af.createInverse();
        } catch (NoninvertibleTransformException e) {
        }
        return createMatrix(af);
    
public float[]getMatrix()

        float[] f = new float[9];
        mC.getMatrix().getValues(f);
        return f;
    
public java.awt.PaintgetPaint()

        throw new RuntimeException("AWT Paint not implemented in Android!");
    
private android.graphics.PathgetPath(java.awt.Shape s)

        Path path = new Path();
        PathIterator pi = s.getPathIterator(null);
        while (pi.isDone() == false) {
            getCurrentSegment(pi, path);
            pi.next();
        }
        return path;
    
public static floatgetRadian(float degree)

        return (float) ((Math.PI / 180) * degree);
    
public java.lang.ObjectgetRenderingHint(java.awt.RenderingHints$Key key)

        if (mRh == null) {
            return null;
        }
        return mRh.get(key);
    
public java.awt.RenderingHintsgetRenderingHints()

        return mRh;
    
private java.awt.ShapegetShape()

        return null;
    
public java.awt.StrokegetStroke()

        if (mP != null) {
            return new BasicStroke(mP.getStrokeWidth(), mP.getStrokeCap()
                    .ordinal(), mP.getStrokeJoin().ordinal());
        }
        return null;
    
public java.awt.geom.AffineTransformgetTransform()

        return new AffineTransform(createAWTMatrix(getMatrix()));
    
public booleanhit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)

        // ???AWT TODO check if on stroke
        return s.intersects(rect.getX(), rect.getY(), rect.getWidth(), rect
                .getHeight());
    
public booleanhitClip(int x, int y, int width, int height)

        return getClipBounds().intersects(new Rectangle(x, y, width, height));
    
public voidrotate(double theta)

        mM.preRotate((float) AndroidGraphics2D
                .getDegree((float) (RAD_360 - theta)));
        mC.concat(mM);
    
public voidrotate(double theta, double x, double y)

        mM.preRotate((float) AndroidGraphics2D.getDegree((float) theta),
                (float) x, (float) y);
        mC.concat(mM);
    
public voidscale(double sx, double sy)

        mM.setScale((float) sx, (float) sy);
        mC.concat(mM);
    
public voidsetBackground(java.awt.Color color)

        mBc = color;
        mC.clipRect(new Rect(0, 0, mC.getWidth(), mC.getHeight()));
        // TODO don't limit to current clip
        mC.drawARGB(color.getAlpha(), color.getRed(), color.getGreen(), color
                .getBlue());
    
public voidsetCanvas(android.graphics.Canvas c)

        mC = c;
    
public voidsetClip(int x, int y, int width, int height)

        int cl[] = {-1, x, y, -2, x, y + width, -2, x + height, y + width, -2, x + height, y};
        mCurrClip = new Area(createShape(cl));
        mC.clipRect(x, y, x + width, y + height, Region.Op.REPLACE);

    
public voidsetClip(java.awt.Shape clip)

        mCurrClip = new Area(clip);
        mC.clipPath(getPath(clip), Region.Op.REPLACE);
    
public voidsetColor(java.awt.Color c)

        if (mP == null) {
            mP = new Paint();
        }
        mP.setColor(c.getRGB());
    
public voidsetComposite(java.awt.Composite comp)

        throw new RuntimeException("Composite not implemented!");
    
public voidsetFont(java.awt.Font font)
Font mapping: Family: Android AWT ------------------------------------- serif Serif / TimesRoman sans-serif SansSerif / Helvetica monospace Monospaced / Courier Style: Android AWT ------------------------------------- normal Plain bold bold italic italic

        if (font == null) {
            return;
        }
        if (mP == null) {
            mP = new Paint();
        }

        mFnt = font;
        Typeface tf = null;
        int sty = font.getStyle();
        String nam = font.getName();
        String aF = "";
        if (nam != null) {
            if (nam.equalsIgnoreCase("Serif")
                    || nam.equalsIgnoreCase("TimesRoman")) {
                aF = "serif";
            } else if (nam.equalsIgnoreCase("SansSerif")
                    || nam.equalsIgnoreCase("Helvetica")) {
                aF = "sans-serif";
            } else if (nam.equalsIgnoreCase("Monospaced")
                    || nam.equalsIgnoreCase("Courier")) {
                aF = "monospace";
            }
        }

        switch (sty) {
        case Font.PLAIN:
            tf = Typeface.create(aF, Typeface.NORMAL);
            break;
        case Font.BOLD:
            tf = Typeface.create(aF, Typeface.BOLD);
            break;
        case Font.ITALIC:
            tf = Typeface.create(aF, Typeface.ITALIC);
            break;
        case Font.BOLD | Font.ITALIC:
            tf = Typeface.create(aF, Typeface.BOLD_ITALIC);
            break;
        default:
            tf = Typeface.DEFAULT;
        }

        mP.setTextSize(font.getSize());
        mP.setTypeface(tf);
    
public voidsetPaint(java.awt.Paint paint)

        setColor((Color)paint);
    
public voidsetPaintMode()

        if (mP == null) {
            mP = new Paint();
        }
        mP.setXfermode(null);
    
public voidsetRenderingHint(java.awt.RenderingHints$Key hintKey, java.lang.Object hintValue)

        if (mRh == null) {
            mRh = new RenderingHints(hintKey, hintValue);
        } else {
            mRh.put(hintKey, hintValue);
        }
        applyHints();
    
public voidsetRenderingHints(java.util.Map hints)

        mRh = (RenderingHints) hints;
        applyHints();
    
public voidsetSpaint(android.graphics.Paint paint)

        mP = paint;
    
public voidsetStroke(java.awt.Stroke s)

        if (mP == null) {
            mP = new Paint();
        }
        BasicStroke bs = (BasicStroke) s;
        mP.setStyle(Paint.Style.STROKE);
        mP.setStrokeWidth(bs.getLineWidth());

        int cap = bs.getEndCap();
        if (cap == 0) {
            mP.setStrokeCap(Paint.Cap.BUTT);
        } else if (cap == 1) {
            mP.setStrokeCap(Paint.Cap.ROUND);
        } else if (cap == 2) {
            mP.setStrokeCap(Paint.Cap.SQUARE);
        }

        int join = bs.getLineJoin();
        if (join == 0) {
            mP.setStrokeJoin(Paint.Join.MITER);
        } else if (join == 1) {
            mP.setStrokeJoin(Paint.Join.ROUND);
        } else if (join == 2) {
            mP.setStrokeJoin(Paint.Join.BEVEL);
        }
    
public voidsetTransform(java.awt.geom.AffineTransform Tx)

        mM.reset();
        /*
         * if(Tx.isIdentity()) { mM = new Matrix(); }
         */
        mM.setValues(createMatrix(Tx));
        Matrix m = new Matrix();
        m.setValues(getInverseMatrix());
        mC.concat(m);
        mC.concat(mM);
    
public voidsetXORMode(java.awt.Color color)

        if (mP == null) {
            mP = new Paint();
        }
        mP.setXfermode(new PixelXorXfermode(color.getRGB()));
    
public voidshear(double shx, double shy)

        mM.setSkew((float) shx, (float) shy);
        mC.concat(mM);
    
public voidtransform(java.awt.geom.AffineTransform Tx)

        Matrix m = new Matrix();
        m.setValues(createMatrix(Tx));
        mC.concat(m);
    
public voidtranslate(double tx, double ty)

        mM.setTranslate((float) tx, (float) ty);
        mC.concat(mM);
    
public voidtranslate(int x, int y)

        mM.setTranslate((float) x, (float) y);
        mC.concat(mM);