< prev index next >

src/java.desktop/share/classes/java/awt/Component.java

Print this page
rev 57801 : XXXXXXX: Component.xxxImage cleanup
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


3616             if (isInc) {
3617                 rate = incRate;
3618                 if (rate < 0) {
3619                     rate = 0;
3620                 }
3621             }
3622         }
3623         if (rate >= 0) {
3624             repaint(rate, 0, 0, width, height);
3625         }
3626         return (infoflags & (ALLBITS|ABORT)) == 0;
3627     }
3628 
3629     /**
3630      * Creates an image from the specified image producer.
3631      * @param     producer  the image producer
3632      * @return    the image produced
3633      * @since     1.0
3634      */
3635     public Image createImage(ImageProducer producer) {
3636         ComponentPeer peer = this.peer;
3637         if ((peer != null) && ! (peer instanceof LightweightPeer)) {
3638             return peer.createImage(producer);
3639         }
3640         return getToolkit().createImage(producer);
3641     }
3642 
3643     /**
3644      * Creates an off-screen drawable image to be used for double buffering.
3645      *
3646      * @param  width the specified width
3647      * @param  height the specified height
3648      * @return an off-screen drawable image, which can be used for double
3649      *         buffering. The {@code null} value if the component is not
3650      *         displayable or {@code GraphicsEnvironment.isHeadless()} returns
3651      *         {@code true}.
3652      * @see #isDisplayable
3653      * @see GraphicsEnvironment#isHeadless
3654      * @since 1.0
3655      */
3656     public Image createImage(int width, int height) {
3657         ComponentPeer peer = this.peer;
3658         if (peer instanceof LightweightPeer) {
3659             if (parent != null) { return parent.createImage(width, height); }


3735     /**
3736      * Prepares an image for rendering on this component at the
3737      * specified width and height.
3738      * <p>
3739      * The image data is downloaded asynchronously in another thread,
3740      * and an appropriately scaled screen representation of the image is
3741      * generated.
3742      * @param     image    the instance of {@code Image}
3743      *            for which to prepare a screen representation
3744      * @param     width    the width of the desired screen representation
3745      * @param     height   the height of the desired screen representation
3746      * @param     observer   the {@code ImageObserver} object
3747      *            to be notified as the image is being prepared
3748      * @return    {@code true} if the image has already been fully
3749      *          prepared; {@code false} otherwise
3750      * @see       java.awt.image.ImageObserver
3751      * @since     1.0
3752      */
3753     public boolean prepareImage(Image image, int width, int height,
3754                                 ImageObserver observer) {
3755         ComponentPeer peer = this.peer;
3756         if (peer instanceof LightweightPeer) {
3757             return (parent != null)
3758                 ? parent.prepareImage(image, width, height, observer)
3759                 : getToolkit().prepareImage(image, width, height, observer);
3760         } else {
3761             return (peer != null)
3762                 ? peer.prepareImage(image, width, height, observer)
3763                 : getToolkit().prepareImage(image, width, height, observer);
3764         }
3765     }
3766 
3767     /**
3768      * Returns the status of the construction of a screen representation
3769      * of the specified image.
3770      * <p>
3771      * This method does not cause the image to begin loading. An
3772      * application must use the {@code prepareImage} method
3773      * to force the loading of an image.
3774      * <p>
3775      * Information on the flags returned by this method can be found
3776      * with the discussion of the {@code ImageObserver} interface.
3777      * @param     image   the {@code Image} object whose status
3778      *            is being checked
3779      * @param     observer   the {@code ImageObserver}
3780      *            object to be notified as the image is being prepared
3781      * @return  the bitwise inclusive <b>OR</b> of
3782      *            {@code ImageObserver} flags indicating what
3783      *            information about the image is currently available
3784      * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)


3807      * Information on the flags returned by this method can be found
3808      * with the discussion of the {@code ImageObserver} interface.
3809      * @param     image   the {@code Image} object whose status
3810      *                    is being checked
3811      * @param     width   the width of the scaled version
3812      *                    whose status is to be checked
3813      * @param     height  the height of the scaled version
3814      *                    whose status is to be checked
3815      * @param     observer   the {@code ImageObserver} object
3816      *                    to be notified as the image is being prepared
3817      * @return    the bitwise inclusive <b>OR</b> of
3818      *            {@code ImageObserver} flags indicating what
3819      *            information about the image is currently available
3820      * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
3821      * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
3822      * @see      java.awt.image.ImageObserver
3823      * @since    1.0
3824      */
3825     public int checkImage(Image image, int width, int height,
3826                           ImageObserver observer) {
3827         ComponentPeer peer = this.peer;
3828         if (peer instanceof LightweightPeer) {
3829             return (parent != null)
3830                 ? parent.checkImage(image, width, height, observer)
3831                 : getToolkit().checkImage(image, width, height, observer);
3832         } else {
3833             return (peer != null)
3834                 ? peer.checkImage(image, width, height, observer)
3835                 : getToolkit().checkImage(image, width, height, observer);
3836         }
3837     }
3838 
3839     /**
3840      * Creates a new strategy for multi-buffering on this component.
3841      * Multi-buffering is useful for rendering performance.  This method
3842      * attempts to create the best strategy available with the number of
3843      * buffers supplied.  It will always create a {@code BufferStrategy}
3844      * with that number of buffers.
3845      * A page-flipping strategy is attempted first, then a blitting strategy
3846      * using accelerated buffers.  Finally, an unaccelerated blitting
3847      * strategy is used.
3848      * <p>
3849      * Each time this method is called,
3850      * the existing buffer strategy for this component is discarded.
3851      * @param numBuffers number of buffers to create, including the front buffer
3852      * @exception IllegalArgumentException if numBuffers is less than 1.
3853      * @exception IllegalStateException if the component is not displayable
3854      * @see #isDisplayable
3855      * @see Window#getBufferStrategy()
3856      * @see Canvas#getBufferStrategy()


   1 /*
   2  * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


3616             if (isInc) {
3617                 rate = incRate;
3618                 if (rate < 0) {
3619                     rate = 0;
3620                 }
3621             }
3622         }
3623         if (rate >= 0) {
3624             repaint(rate, 0, 0, width, height);
3625         }
3626         return (infoflags & (ALLBITS|ABORT)) == 0;
3627     }
3628 
3629     /**
3630      * Creates an image from the specified image producer.
3631      * @param     producer  the image producer
3632      * @return    the image produced
3633      * @since     1.0
3634      */
3635     public Image createImage(ImageProducer producer) {




3636         return getToolkit().createImage(producer);
3637     }
3638 
3639     /**
3640      * Creates an off-screen drawable image to be used for double buffering.
3641      *
3642      * @param  width the specified width
3643      * @param  height the specified height
3644      * @return an off-screen drawable image, which can be used for double
3645      *         buffering. The {@code null} value if the component is not
3646      *         displayable or {@code GraphicsEnvironment.isHeadless()} returns
3647      *         {@code true}.
3648      * @see #isDisplayable
3649      * @see GraphicsEnvironment#isHeadless
3650      * @since 1.0
3651      */
3652     public Image createImage(int width, int height) {
3653         ComponentPeer peer = this.peer;
3654         if (peer instanceof LightweightPeer) {
3655             if (parent != null) { return parent.createImage(width, height); }


3731     /**
3732      * Prepares an image for rendering on this component at the
3733      * specified width and height.
3734      * <p>
3735      * The image data is downloaded asynchronously in another thread,
3736      * and an appropriately scaled screen representation of the image is
3737      * generated.
3738      * @param     image    the instance of {@code Image}
3739      *            for which to prepare a screen representation
3740      * @param     width    the width of the desired screen representation
3741      * @param     height   the height of the desired screen representation
3742      * @param     observer   the {@code ImageObserver} object
3743      *            to be notified as the image is being prepared
3744      * @return    {@code true} if the image has already been fully
3745      *          prepared; {@code false} otherwise
3746      * @see       java.awt.image.ImageObserver
3747      * @since     1.0
3748      */
3749     public boolean prepareImage(Image image, int width, int height,
3750                                 ImageObserver observer) {
3751         return getToolkit().prepareImage(image, width, height, observer);









3752     }
3753 
3754     /**
3755      * Returns the status of the construction of a screen representation
3756      * of the specified image.
3757      * <p>
3758      * This method does not cause the image to begin loading. An
3759      * application must use the {@code prepareImage} method
3760      * to force the loading of an image.
3761      * <p>
3762      * Information on the flags returned by this method can be found
3763      * with the discussion of the {@code ImageObserver} interface.
3764      * @param     image   the {@code Image} object whose status
3765      *            is being checked
3766      * @param     observer   the {@code ImageObserver}
3767      *            object to be notified as the image is being prepared
3768      * @return  the bitwise inclusive <b>OR</b> of
3769      *            {@code ImageObserver} flags indicating what
3770      *            information about the image is currently available
3771      * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)


3794      * Information on the flags returned by this method can be found
3795      * with the discussion of the {@code ImageObserver} interface.
3796      * @param     image   the {@code Image} object whose status
3797      *                    is being checked
3798      * @param     width   the width of the scaled version
3799      *                    whose status is to be checked
3800      * @param     height  the height of the scaled version
3801      *                    whose status is to be checked
3802      * @param     observer   the {@code ImageObserver} object
3803      *                    to be notified as the image is being prepared
3804      * @return    the bitwise inclusive <b>OR</b> of
3805      *            {@code ImageObserver} flags indicating what
3806      *            information about the image is currently available
3807      * @see      #prepareImage(Image, int, int, java.awt.image.ImageObserver)
3808      * @see      Toolkit#checkImage(Image, int, int, java.awt.image.ImageObserver)
3809      * @see      java.awt.image.ImageObserver
3810      * @since    1.0
3811      */
3812     public int checkImage(Image image, int width, int height,
3813                           ImageObserver observer) {
3814         return getToolkit().checkImage(image, width, height, observer);









3815     }
3816 
3817     /**
3818      * Creates a new strategy for multi-buffering on this component.
3819      * Multi-buffering is useful for rendering performance.  This method
3820      * attempts to create the best strategy available with the number of
3821      * buffers supplied.  It will always create a {@code BufferStrategy}
3822      * with that number of buffers.
3823      * A page-flipping strategy is attempted first, then a blitting strategy
3824      * using accelerated buffers.  Finally, an unaccelerated blitting
3825      * strategy is used.
3826      * <p>
3827      * Each time this method is called,
3828      * the existing buffer strategy for this component is discarded.
3829      * @param numBuffers number of buffers to create, including the front buffer
3830      * @exception IllegalArgumentException if numBuffers is less than 1.
3831      * @exception IllegalStateException if the component is not displayable
3832      * @see #isDisplayable
3833      * @see Window#getBufferStrategy()
3834      * @see Canvas#getBufferStrategy()


< prev index next >