summaryrefslogtreecommitdiffstats
path: root/awt/java/awt/image/VolatileImage.java
blob: f24e866bdb13512bf4f01da9b890293d152417ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Alexey A. Petrenko
 * @version $Revision$
 */

package java.awt.image;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.ImageCapabilities;
import java.awt.Transparency;

/**
 * The VolatileImage abstract class represents an image which can lose its
 * contents at any point. VolatileImage objects are device specific. This class
 * provides methods for checking if operation of this image are compatible for
 * the GraphicsConfiguration.
 * 
 * @since Android 1.0
 */
public abstract class VolatileImage extends Image
// Volatile image implements Transparency since 1.5
        implements Transparency {

    /**
     * The Constant IMAGE_INCOMPATIBLE indicates that this VolatileImage is not
     * applicable for the GraphicsConfiguration object.
     */
    public static final int IMAGE_INCOMPATIBLE = 2;

    /**
     * The Constant IMAGE_OK indicates that VolatileImage is ready for using.
     */
    public static final int IMAGE_OK = 0;

    /**
     * The Constant IMAGE_RESTORED indicates that VolatileImage will be ready to
     * use after restoring.
     */
    public static final int IMAGE_RESTORED = 1;

    /**
     * The transparency value of this image.
     */
    protected int transparency = OPAQUE;

    /**
     * Instantiates a new VolatileImage object.
     */
    public VolatileImage() {
        super();
    }

    /**
     * Returns true if rendering data is lost during validating. This method
     * should be called after rendering operation of image.
     * 
     * @return true, if contents lost during validating, false otherwise.
     */

    public abstract boolean contentsLost();

    /**
     * Creates a Graphics2D used to draw in this VolatileImage.
     * 
     * @return the Graphics2D object.
     */
    public abstract Graphics2D createGraphics();

    /**
     * Gets the ImageCapabilities of this VolatileImage.
     * 
     * @return the ImageCapabilities of this VolatileImage.
     */
    public abstract ImageCapabilities getCapabilities();

    /**
     * Gets the height of this VolatileImage.
     * 
     * @return the height of this VolatileImage.
     */
    public abstract int getHeight();

    /**
     * Gets a BufferedImage representation of current VolatileImage that won't
     * be affected by any changes to this VolatileImage.
     * 
     * @return a BufferedImage representation of current VolatileImage.
     */
    public abstract BufferedImage getSnapshot();

    /**
     * Gets the width of this VolatileImage.
     * 
     * @return the width of this VolatileImage.
     */
    public abstract int getWidth();

    /**
     * Validates the drawing surface of the image if the surface had been lost
     * and if the specified GraphicsConfiguration object is applicable to this
     * image.
     * 
     * @param gc
     *            the GraphicsConfiguration object.
     * @return one of the image status constants: IMAGE_OK, IMAGE_RESTORED or
     *         IMAGE_INCOMPATIBLE.
     */
    public abstract int validate(GraphicsConfiguration gc);

    @Override
    public void flush() {
    }

    @Override
    public Graphics getGraphics() {
        return createGraphics();
    }

    @Override
    public ImageProducer getSource() {
        return getSnapshot().getSource();
    }

    public int getTransparency() {
        return transparency;
    }
}