1622 lines · 63.6 KB · Java
RawDownload
     * @param       dy2 the <i>y</i> coordinate of the second corner of the     *                    destination rectangle.     * @param       sx1 the <i>x</i> coordinate of the first corner of the     *                    source rectangle.     * @param       sy1 the <i>y</i> coordinate of the first corner of the     *                    source rectangle.     * @param       sx2 the <i>x</i> coordinate of the second corner of the     *                    source rectangle.     * @param       sy2 the <i>y</i> coordinate of the second corner of the     *                    source rectangle.     * @param       observer object to be notified as more of the image is     *                    scaled and converted.     * @see         java.awt.Image     * @see         java.awt.image.ImageObserver     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)     * @since       JDK1.1     */    public boolean drawImage(Image img,                                      int dx1, int dy1, int dx2, int dy2,                                      int sx1, int sy1, int sx2, int sy2,                                      ImageObserver observer) {        return mGraphics.drawImage(img, dx1, dy1, dx2, dy2,                                   sx1, sy1, sx2, sy2,                                   observer);    }     /**     * Draws as much of the specified area of the specified image as is     * currently available, scaling it on the fly to fit inside the     * specified area of the destination drawable surface.     * <p>     * Transparent pixels are drawn in the specified background color.     * This operation is equivalent to filling a rectangle of the     * width and height of the specified image with the given color and then     * drawing the image on top of it, but possibly more efficient.     * <p>     * This method returns immediately in all cases, even if the     * image area to be drawn has not yet been scaled, dithered, and converted     * for the current output device.     * If the current output representation is not yet complete then     * <code>drawImage</code> returns <code>false</code>. As more of     * the image becomes available, the process that draws the image notifies     * the specified image observer.     * <p>     * This method always uses the unscaled version of the image     * to render the scaled rectangle and performs the required     * scaling on the fly. It does not use a cached, scaled version     * of the image for this operation. Scaling of the image from source     * to destination is performed such that the first coordinate     * of the source rectangle is mapped to the first coordinate of     * the destination rectangle, and the second source coordinate is     * mapped to the second destination coordinate. The subimage is     * scaled and flipped as needed to preserve those mappings.     * @param       img the specified image to be drawn     * @param       dx1 the <i>x</i> coordinate of the first corner of the     *                    destination rectangle.     * @param       dy1 the <i>y</i> coordinate of the first corner of the     *                    destination rectangle.     * @param       dx2 the <i>x</i> coordinate of the second corner of the     *                    destination rectangle.     * @param       dy2 the <i>y</i> coordinate of the second corner of the     *                    destination rectangle.     * @param       sx1 the <i>x</i> coordinate of the first corner of the     *                    source rectangle.     * @param       sy1 the <i>y</i> coordinate of the first corner of the     *                    source rectangle.     * @param       sx2 the <i>x</i> coordinate of the second corner of the     *                    source rectangle.     * @param       sy2 the <i>y</i> coordinate of the second corner of the     *                    source rectangle.     * @param       bgcolor the background color to paint under the     *                    non-opaque portions of the image.     * @param       observer object to be notified as more of the image is     *                    scaled and converted.     * @see         java.awt.Image     * @see         java.awt.image.ImageObserver     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)     * @since       JDK1.1     */    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;        }         boolean result;        if (needToCopyBgColorImage(img)) {            BufferedImage imageCopy = getBufferedImageCopy(img, bgcolor);            result = mGraphics.drawImage(imageCopy,                                         dx1, dy1, dx2, dy2,                                         sy1, sy1, sx2, sy2,                                         null);        } else {            result = mGraphics.drawImage(img,                                         dx1, dy1, dx2, dy2,                                         sy1, sy1, sx2, sy2,                                         bgcolor,                                         observer);        }         return result;    }     /**     * Return true if drawing <code>img</code> will     * invoke a Java2D bug (#4258675). The bug in question     * occurs when a draw image call with a background color     * parameter tries to render a sheared     * or rotated image. The portions of the bounding     * rectangle not covered by the sheared image     * are incorrectly drawn with the background color.     */    private boolean needToCopyBgColorImage(Image img) {         boolean needToCopy;         AffineTransform transform = getTransform();         return (transform.getType()                & (AffineTransform.TYPE_GENERAL_ROTATION                   | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0;    }     /**     * Return a new <code>BufferedImage</code>     * that contains a copy of the provided     * <code>Image</code> where its     * transparent pixels have been replaced by     * <code>bgcolor</code>. If the new     * <code>BufferedImage</code> can not be created,     * probably because the original image has not     * finished loading, then <code>null</code> is     * returned.     */    private BufferedImage getBufferedImageCopy(Image img, Color bgcolor) {         BufferedImage imageCopy = null;         int width = img.getWidth(null);        int height = img.getHeight(null);         if (width > 0 && height > 0) {             int imageType;             /* Try to minimize the depth of the BufferedImage             * we are about to create by, if possible, making             * it the same depth as the original image.             */            if (img instanceof BufferedImage) {                BufferedImage bufImage = (BufferedImage) img;                imageType = bufImage.getType();            } else {                imageType = BufferedImage.TYPE_INT_ARGB;            }             imageCopy = new BufferedImage(width, height, imageType);             /* Copy the original image into the new buffer             * without any transformations.             * This will replace the transparent pixels             * in the original with background color.             */            Graphics g = imageCopy.createGraphics();            g.drawImage(img, 0, 0, bgcolor, null);            g.dispose();         /* We couldn't get the width or height of the image         * so just return null.         */        } else {            imageCopy = null;        }         return imageCopy;    }     /**     * Draws 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,     * and composite attributes. Note that the result is     * undefined, if the given transform is noninvertible.     * @param img The image to be drawn.     * @param xform The transformation from image space into user space.     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public void drawRenderedImage(RenderedImage img,                                  AffineTransform xform) {        mGraphics.drawRenderedImage(img, xform);    }       public void drawRenderableImage(RenderableImage img,                                    AffineTransform xform) {         if (img == null) {            return;        }         AffineTransform pipeTransform = getTransform();        AffineTransform concatTransform = new AffineTransform(xform);        concatTransform.concatenate(pipeTransform);        AffineTransform reverseTransform;         RenderContext rc = new RenderContext(concatTransform);         try {            reverseTransform = pipeTransform.createInverse();        } catch (NoninvertibleTransformException nte) {            rc = new RenderContext(pipeTransform);            reverseTransform = new AffineTransform();        }         RenderedImage rendering = img.createRendering(rc);        drawRenderedImage(rendering,reverseTransform);    }     /**     * Disposes of this graphics context and releases     * any system resources that it is using.     * A <code>Graphics</code> object cannot be used after     * <code>dispose</code>has been called.     * <p>     * When a Java program runs, a large number of <code>Graphics</code>     * objects can be created within a short time frame.     * Although the finalization process of the garbage collector     * also disposes of the same system resources, it is preferable     * to manually free the associated resources by calling this     * method rather than to rely on a finalization process which     * may not run to completion for a long period of time.     * <p>     * Graphics objects which are provided as arguments to the     * <code>paint</code> and <code>update</code> methods     * of components are automatically released by the system when     * those methods return. For efficiency, programmers should     * call <code>dispose</code> when finished using     * a <code>Graphics</code> object only if it was created     * directly from a component or another <code>Graphics</code> object.     * @see         java.awt.Graphics#finalize     * @see         java.awt.Component#paint     * @see         java.awt.Component#update     * @see         java.awt.Component#getGraphics     * @see         java.awt.Graphics#create     * @since       JDK1.0     */    public void dispose() {        mGraphics.dispose();    }     /**     * Empty finalizer as no clean up needed here.     */    public void finalize() {    }  /* The Delegated Graphics2D Methods */     /**     * Strokes the outline of a Shape using the settings of the current     * graphics state.  The rendering attributes applied include the     * clip, transform, paint or color, composite and stroke attributes.     * @param s The shape to be drawn.     * @see #setStroke     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see #transform     * @see #setTransform     * @see #clip     * @see #setClip     * @see #setComposite     */    public void draw(Shape s) {        mGraphics.draw(s);    }     /**     * Draws 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,     * and composite attributes. Note that the result is     * undefined, if the given transform is noninvertible.     * @param img The image to be drawn.     * @param xform The transformation from image space into user space.     * @param obs The image observer to be notified as more of the image     * is converted.     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public boolean drawImage(Image img,                             AffineTransform xform,                             ImageObserver obs) {         return mGraphics.drawImage(img, xform, obs);    }     /**     * Draws a BufferedImage that is filtered with a BufferedImageOp.     * The rendering attributes applied include the clip, transform     * and composite attributes.  This is equivalent to:     * <pre>     * img1 = op.filter(img, null);     * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);     * </pre>     * @param op The filter to be applied to the image before drawing.     * @param img The BufferedImage to be drawn.     * @param x,y The location in user space where the image should be drawn.     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public void drawImage(BufferedImage img,                          BufferedImageOp op,                          int x,                          int y) {         mGraphics.drawImage(img, op, x, y);    }      /**     * Draws a string of text.     * The rendering attributes applied include the clip, transform,     * paint or color, font and composite attributes.     * @param s The string to be drawn.     * @param x,y The coordinates where the string should be drawn.     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see java.awt.Graphics#setFont     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public void drawString(String str,                           float x,                           float y) {        mGraphics.drawString(str, x, y);    }     /**     * Draws a GlyphVector.     * The rendering attributes applied include the clip, transform,     * paint or color, and composite attributes.  The GlyphVector specifies     * individual glyphs from a Font.     * @param g The GlyphVector to be drawn.     * @param x,y The coordinates where the glyphs should be drawn.     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public void drawGlyphVector(GlyphVector g,                                float x,                                float y) {        mGraphics.drawGlyphVector(g, x, y);    }     /**     * Fills the interior of a Shape using the settings of the current     * graphics state. The rendering attributes applied include the     * clip, transform, paint or color, and composite.     * @see #setPaint     * @see java.awt.Graphics#setColor     * @see #transform     * @see #setTransform     * @see #setComposite     * @see #clip     * @see #setClip     */    public void fill(Shape s) {        mGraphics.fill(s);    }     /**     * Checks to see if the outline of a Shape intersects the specified     * Rectangle in device space.     * The rendering attributes taken into account include the     * clip, transform, and stroke attributes.     * @param rect The area in device space to check for a hit.     * @param s The shape to check for a hit.     * @param onStroke Flag to choose between testing the stroked or     * the filled shape.     * @return True if there is a hit, false otherwise.     * @see #setStroke     * @see #fill     * @see #draw     * @see #transform     * @see #setTransform     * @see #clip     * @see #setClip     */    public boolean hit(Rectangle rect,                       Shape s,                       boolean onStroke) {         return mGraphics.hit(rect, s, onStroke);    }     /**     * Sets the Composite in the current graphics state. Composite is used     * in all drawing methods such as drawImage, drawString, draw,     * and fill.  It specifies how new pixels are to be combined with     * the existing pixels on the graphics device in the rendering process.     * @param comp The Composite object to be used for drawing.     * @see java.awt.Graphics#setXORMode     * @see java.awt.Graphics#setPaintMode     * @see AlphaComposite     */    public void setComposite(Composite comp) {        mGraphics.setComposite(comp);    }      /**     * Sets the Paint in the current graphics state.     * @param paint The Paint object to be used to generate color in     * the rendering process.     * @see java.awt.Graphics#setColor     * @see GradientPaint     * @see TexturePaint     */    public void setPaint(Paint paint) {        mGraphics.setPaint(paint);    }     /**     * Sets the Stroke in the current graphics state.     * @param s The Stroke object to be used to stroke a Shape in     * the rendering process.     * @see BasicStroke     */    public void setStroke(Stroke s) {        mGraphics.setStroke(s);    }     /**     * Sets the preferences for the rendering algorithms.     * Hint categories include controls for rendering quality and     * overall time/quality trade-off in the rendering process.     * @param hintCategory The category of hint to be set.     * @param hintValue The value indicating preferences for the specified     * hint category.     * @see RenderingHints     */    public void setRenderingHint(Key hintCategory, Object hintValue) {        mGraphics.setRenderingHint(hintCategory, hintValue);    }     /**     * Returns the preferences for the rendering algorithms.     * @param hintCategory The category of hint to be set.     * @return The preferences for rendering algorithms.     * @see RenderingHings     */    public Object getRenderingHint(Key hintCategory) {        return mGraphics.getRenderingHint(hintCategory);    }     /**     * Sets the preferences for the rendering algorithms.     * Hint categories include controls for rendering quality and     * overall time/quality trade-off in the rendering process.     * @param hints The rendering hints to be set     * @see RenderingHints     */    public void setRenderingHints(Map<?,?> hints) {        mGraphics.setRenderingHints(hints);    }     /**     * Adds a number of preferences for the rendering algorithms.     * Hint categories include controls for rendering quality and

Lines 1001–1500 of 1622. Previous lines