Home | History | Annotate | Download | only in image
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Alexey A. Petrenko
     19  * @version $Revision$
     20  */
     21 
     22 package java.awt.image;
     23 
     24 import java.awt.Graphics;
     25 import java.awt.Graphics2D;
     26 import java.awt.GraphicsConfiguration;
     27 import java.awt.Image;
     28 import java.awt.ImageCapabilities;
     29 import java.awt.Transparency;
     30 
     31 /**
     32  * The VolatileImage abstract class represents an image which can lose its
     33  * contents at any point. VolatileImage objects are device specific. This class
     34  * provides methods for checking if operation of this image are compatible for
     35  * the GraphicsConfiguration.
     36  *
     37  * @since Android 1.0
     38  */
     39 public abstract class VolatileImage extends Image
     40 // Volatile image implements Transparency since 1.5
     41         implements Transparency {
     42 
     43     /**
     44      * The Constant IMAGE_INCOMPATIBLE indicates that this VolatileImage is not
     45      * applicable for the GraphicsConfiguration object.
     46      */
     47     public static final int IMAGE_INCOMPATIBLE = 2;
     48 
     49     /**
     50      * The Constant IMAGE_OK indicates that VolatileImage is ready for using.
     51      */
     52     public static final int IMAGE_OK = 0;
     53 
     54     /**
     55      * The Constant IMAGE_RESTORED indicates that VolatileImage will be ready to
     56      * use after restoring.
     57      */
     58     public static final int IMAGE_RESTORED = 1;
     59 
     60     /**
     61      * The transparency value of this image.
     62      */
     63     protected int transparency = OPAQUE;
     64 
     65     /**
     66      * Instantiates a new VolatileImage object.
     67      */
     68     public VolatileImage() {
     69         super();
     70     }
     71 
     72     /**
     73      * Returns true if rendering data is lost during validating. This method
     74      * should be called after rendering operation of image.
     75      *
     76      * @return true, if contents lost during validating, false otherwise.
     77      */
     78 
     79     public abstract boolean contentsLost();
     80 
     81     /**
     82      * Creates a Graphics2D used to draw in this VolatileImage.
     83      *
     84      * @return the Graphics2D object.
     85      */
     86     public abstract Graphics2D createGraphics();
     87 
     88     /**
     89      * Gets the ImageCapabilities of this VolatileImage.
     90      *
     91      * @return the ImageCapabilities of this VolatileImage.
     92      */
     93     public abstract ImageCapabilities getCapabilities();
     94 
     95     /**
     96      * Gets the height of this VolatileImage.
     97      *
     98      * @return the height of this VolatileImage.
     99      */
    100     public abstract int getHeight();
    101 
    102     /**
    103      * Gets a BufferedImage representation of current VolatileImage that won't
    104      * be affected by any changes to this VolatileImage.
    105      *
    106      * @return a BufferedImage representation of current VolatileImage.
    107      */
    108     public abstract BufferedImage getSnapshot();
    109 
    110     /**
    111      * Gets the width of this VolatileImage.
    112      *
    113      * @return the width of this VolatileImage.
    114      */
    115     public abstract int getWidth();
    116 
    117     /**
    118      * Validates the drawing surface of the image if the surface had been lost
    119      * and if the specified GraphicsConfiguration object is applicable to this
    120      * image.
    121      *
    122      * @param gc
    123      *            the GraphicsConfiguration object.
    124      * @return one of the image status constants: IMAGE_OK, IMAGE_RESTORED or
    125      *         IMAGE_INCOMPATIBLE.
    126      */
    127     public abstract int validate(GraphicsConfiguration gc);
    128 
    129     @Override
    130     public void flush() {
    131     }
    132 
    133     @Override
    134     public Graphics getGraphics() {
    135         return createGraphics();
    136     }
    137 
    138     @Override
    139     public ImageProducer getSource() {
    140         return getSnapshot().getSource();
    141     }
    142 
    143     public int getTransparency() {
    144         return transparency;
    145     }
    146 }
    147