3310 lines · 121.6 KB · Java
RawDownload
        } finally {            surfaceData.markDirty();        }    }     /**     * Draws an image scaled to x,y,w,h in nonblocking mode with a     * solid background color and a callback object.     */    public boolean drawImage(Image img, int x, int y, int width, int height,                             Color bg, ImageObserver observer) {         if (img == null) {            return true;        }         if ((width == 0) || (height == 0)) {            return true;        }        if (width == img.getWidth(null) && height == img.getHeight(null)) {            return copyImage(img, x, y, 0, 0, width, height, bg, observer);        }         try {            return imagepipe.scaleImage(this, img, x, y, width, height,                                        bg, observer);        } catch (InvalidPipeException e) {            revalidateAll();            try {                return imagepipe.scaleImage(this, img, x, y, width, height,                                            bg, observer);            } catch (InvalidPipeException e2) {                // Still catching the exception; we are not yet ready to                // validate the surfaceData correctly.  Fail for now and                // try again next time around.                return false;            }        } finally {            surfaceData.markDirty();        }    }     /**     * Draws an image at x,y in nonblocking mode.     */    public boolean drawImage(Image img, int x, int y, ImageObserver observer) {        return drawImage(img, x, y, null, observer);    }     /**     * Draws an image at x,y in nonblocking mode with a solid background     * color and a callback object.     */    public boolean drawImage(Image img, int x, int y, Color bg,                             ImageObserver observer) {         if (img == null) {            return true;        }         try {            return imagepipe.copyImage(this, img, x, y, bg, observer);        } catch (InvalidPipeException e) {            revalidateAll();            try {                return imagepipe.copyImage(this, img, x, y, bg, observer);            } catch (InvalidPipeException e2) {                // Still catching the exception; we are not yet ready to                // validate the surfaceData correctly.  Fail for now and                // try again next time around.                return false;            }        } finally {            surfaceData.markDirty();        }    }     /**     * Draws a subrectangle of an image scaled to a destination rectangle     * in nonblocking mode with a callback object.     */    public boolean drawImage(Image img,                             int dx1, int dy1, int dx2, int dy2,                             int sx1, int sy1, int sx2, int sy2,                             ImageObserver observer) {        return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null,                         observer);    }     /**     * Draws a subrectangle of an image scaled to a destination rectangle in     * nonblocking mode with a solid background color and a callback object.     */    public boolean drawImage(Image img,                             int dx1, int dy1, int dx2, int dy2,                             int sx1, int sy1, int sx2, int sy2,                             Color bgcolor, ImageObserver observer) {         if (img == null) {            return true;        }         if (dx1 == dx2 || dy1 == dy2 ||            sx1 == sx2 || sy1 == sy2)        {            return true;        }         if (((sx2 - sx1) == (dx2 - dx1)) &&            ((sy2 - sy1) == (dy2 - dy1)))        {            // Not a scale - forward it to a copy routine            int srcX, srcY, dstX, dstY, width, height;            if (sx2 > sx1) {                width = sx2 - sx1;                srcX = sx1;                dstX = dx1;            } else {                width = sx1 - sx2;                srcX = sx2;                dstX = dx2;            }            if (sy2 > sy1) {                height = sy2-sy1;                srcY = sy1;                dstY = dy1;            } else {                height = sy1-sy2;                srcY = sy2;                dstY = dy2;            }            return copyImage(img, dstX, dstY, srcX, srcY,                             width, height, bgcolor, observer);        }         try {            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2,                                          sx1, sy1, sx2, sy2, bgcolor,                                          observer);        } catch (InvalidPipeException e) {            revalidateAll();            try {                return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2,                                              sx1, sy1, sx2, sy2, bgcolor,                                              observer);            } catch (InvalidPipeException e2) {                // Still catching the exception; we are not yet ready to                // validate the surfaceData correctly.  Fail for now and                // try again next time around.                return false;            }        } finally {            surfaceData.markDirty();        }    }     /**     * Draw an image, applying a transform from image space into user space     * before drawing.     * The transformation from user space into device space is done with     * the current transform in the Graphics2D.     * The given transformation is applied to the image before the     * transform attribute in the Graphics2D state is applied.     * The rendering attributes applied include the clip, transform,     * paint or color and composite attributes. Note that the result is     * undefined, if the given transform is non-invertible.     * @param img The image to be drawn.     * @param xform The transformation from image space into user space.     * @param observer The image observer to be notified on the image producing     * progress.     * @see #transform     * @see #setComposite     * @see #setClip     */    public boolean drawImage(Image img,                             AffineTransform xform,                             ImageObserver observer) {         if (img == null) {            return true;        }         if (xform == null || xform.isIdentity()) {            return drawImage(img, 0, 0, null, observer);        }         try {            return imagepipe.transformImage(this, img, xform, observer);        } catch (InvalidPipeException e) {            revalidateAll();            try {                return imagepipe.transformImage(this, img, xform, observer);            } catch (InvalidPipeException e2) {                // Still catching the exception; we are not yet ready to                // validate the surfaceData correctly.  Fail for now and                // try again next time around.                return false;            }        } finally {            surfaceData.markDirty();        }    }     public void drawImage(BufferedImage bImg,                          BufferedImageOp op,                          int x,                          int y)  {         if (bImg == null) {            return;        }         try {            imagepipe.transformImage(this, bImg, op, x, y);        } catch (InvalidPipeException e) {            revalidateAll();            try {                imagepipe.transformImage(this, bImg, op, x, y);            } catch (InvalidPipeException e2) {                // Still catching the exception; we are not yet ready to                // validate the surfaceData correctly.  Fail for now and                // try again next time around.            }        } finally {            surfaceData.markDirty();        }    }     /**    * Get the rendering context of the font    * within this Graphics2D context.    */    public FontRenderContext getFontRenderContext() {        if (cachedFRC == null) {            int aahint = textAntialiasHint;            if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT &&                antialiasHint == SunHints.INTVAL_ANTIALIAS_ON) {                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;            }            // Translation components should be excluded from the FRC transform            AffineTransform tx = null;            if (transformState >= TRANSFORM_TRANSLATESCALE) {                if (transform.getTranslateX() == 0 &&                    transform.getTranslateY() == 0) {                    tx = transform;                } else {                    tx = new AffineTransform(transform.getScaleX(),                                             transform.getShearY(),                                             transform.getShearX(),                                             transform.getScaleY(),                                             0, 0);                }            }            cachedFRC = new FontRenderContext(tx,             SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING, aahint),             SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS,                                fractionalMetricsHint));        }        return cachedFRC;    }    private FontRenderContext cachedFRC;     /**     * This object has no resources to dispose of per se, but the     * doc comments for the base method in java.awt.Graphics imply     * that this object will not be useable after it is disposed.     * So, we sabotage the object to prevent further use to prevent     * developers from relying on behavior that may not work on     * other, less forgiving, VMs that really need to dispose of     * resources.     */    public void dispose() {        surfaceData = NullSurfaceData.theInstance;        invalidatePipe();    }     /**     * Graphics has a finalize method that automatically calls dispose()     * for subclasses.  For SunGraphics2D we do not need to be finalized     * so that method simply causes us to be enqueued on the Finalizer     * queues for no good reason.  Unfortunately, that method and     * implementation are now considered part of the public contract     * of that base class so we can not remove or gut the method.     * We override it here with an empty method and the VM is smart     * enough to know that if our override is empty then it should not     * mark us as finalizeable.     */    public void finalize() {        // DO NOT REMOVE THIS METHOD    }     /**     * Returns destination that this Graphics renders to.  This could be     * either an Image or a Component; subclasses of SurfaceData are     * responsible for returning the appropriate object.     */    public Object getDestination() {        return surfaceData.getDestination();    }     /**     * {@inheritDoc}     *     * @see sun.java2d.DestSurfaceProvider#getDestSurface     */    @Override    public Surface getDestSurface() {        return surfaceData;    }}

Lines 3001–3310 of 3310. Previous lines