1 |
14 |
jlechner |
/* Image.java -- superclass for images
|
2 |
|
|
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package java.awt;
|
40 |
|
|
|
41 |
|
|
import java.awt.image.AreaAveragingScaleFilter;
|
42 |
|
|
import java.awt.image.FilteredImageSource;
|
43 |
|
|
import java.awt.image.ImageFilter;
|
44 |
|
|
import java.awt.image.ImageObserver;
|
45 |
|
|
import java.awt.image.ImageProducer;
|
46 |
|
|
import java.awt.image.ReplicateScaleFilter;
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
|
|
* This is the abstract superclass of all image objects in Java.
|
50 |
|
|
*
|
51 |
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
52 |
|
|
* @since 1.0
|
53 |
|
|
* @status updated to 1.4
|
54 |
|
|
*/
|
55 |
|
|
public abstract class Image
|
56 |
|
|
{
|
57 |
|
|
/**
|
58 |
|
|
* This variable is returned whenever a property that is not defined
|
59 |
|
|
* is requested.
|
60 |
|
|
*/
|
61 |
|
|
// For debug purposes, this might as well be a unique string.
|
62 |
|
|
public static final Object UndefinedProperty
|
63 |
|
|
= new String("undefined property");
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Constant indicating that the default scaling algorithm should be used.
|
67 |
|
|
*
|
68 |
|
|
* @since 1.1
|
69 |
|
|
*/
|
70 |
|
|
public static final int SCALE_DEFAULT = 1;
|
71 |
|
|
|
72 |
|
|
/**
|
73 |
|
|
* Constant indicating that a fast scaling algorithm should be used.
|
74 |
|
|
*
|
75 |
|
|
* @since 1.1
|
76 |
|
|
*/
|
77 |
|
|
public static final int SCALE_FAST = 2;
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Constant indicating that a smooth scaling algorithm should be used.
|
81 |
|
|
*
|
82 |
|
|
* @since 1.1
|
83 |
|
|
*/
|
84 |
|
|
public static final int SCALE_SMOOTH = 4;
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Constant indicating that the <code>ReplicateScaleFilter</code> class
|
88 |
|
|
* algorithm should be used for scaling.
|
89 |
|
|
*
|
90 |
|
|
* @see ReplicateScaleFilter
|
91 |
|
|
* @since 1.1
|
92 |
|
|
*/
|
93 |
|
|
public static final int SCALE_REPLICATE = 8;
|
94 |
|
|
|
95 |
|
|
/**
|
96 |
|
|
* Constant indicating that the area averaging scaling algorithm should be
|
97 |
|
|
* used.
|
98 |
|
|
*
|
99 |
|
|
* @see java.awt.image.AreaAveragingScaleFilter
|
100 |
|
|
* @since 1.1
|
101 |
|
|
*/
|
102 |
|
|
public static final int SCALE_AREA_AVERAGING = 16;
|
103 |
|
|
|
104 |
|
|
/**
|
105 |
|
|
* A default constructor for subclasses.
|
106 |
|
|
*/
|
107 |
|
|
public Image()
|
108 |
|
|
{
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Returns the width of the image, or -1 if it is unknown. If the
|
113 |
|
|
* image width is unknown, the observer object will be notified when
|
114 |
|
|
* the value is known.
|
115 |
|
|
*
|
116 |
|
|
* @param observer the image observer for this object
|
117 |
|
|
* @return the width in pixels
|
118 |
|
|
* @see #getHeight(ImageObserver)
|
119 |
|
|
*/
|
120 |
|
|
public abstract int getWidth(ImageObserver observer);
|
121 |
|
|
|
122 |
|
|
/**
|
123 |
|
|
* Returns the height of the image, or -1 if it is unknown. If the
|
124 |
|
|
* image height is unknown, the observer object will be notified when
|
125 |
|
|
* the value is known.
|
126 |
|
|
*
|
127 |
|
|
* @param observer the image observer for this object
|
128 |
|
|
* @return the height in pixels
|
129 |
|
|
* @see #getWidth(ImageObserver)
|
130 |
|
|
*/
|
131 |
|
|
public abstract int getHeight(ImageObserver observer);
|
132 |
|
|
|
133 |
|
|
/**
|
134 |
|
|
* Returns the image producer object for this object. The producer is the
|
135 |
|
|
* object which generates pixels for this image.
|
136 |
|
|
*
|
137 |
|
|
* @return the image producer for this object
|
138 |
|
|
*/
|
139 |
|
|
public abstract ImageProducer getSource();
|
140 |
|
|
|
141 |
|
|
/**
|
142 |
|
|
* Returns a graphics context object for drawing an off-screen object.
|
143 |
|
|
* This method is only valid for off-screen objects.
|
144 |
|
|
*
|
145 |
|
|
* @return a graphics context object for an off-screen object
|
146 |
|
|
*/
|
147 |
|
|
public abstract Graphics getGraphics();
|
148 |
|
|
|
149 |
|
|
/**
|
150 |
|
|
* This method requests a named property for an object. The value of the
|
151 |
|
|
* property is returned. The value <code>UndefinedProperty</code> is
|
152 |
|
|
* returned if there is no property with the specified name. The value
|
153 |
|
|
* <code>null</code> is returned if the properties for the object are
|
154 |
|
|
* not yet known. In this case, the specified image observer is notified
|
155 |
|
|
* when the properties are known.
|
156 |
|
|
*
|
157 |
|
|
* @param name the requested property name
|
158 |
|
|
* @param observer the image observer for this object
|
159 |
|
|
* @return the named property, if available
|
160 |
|
|
* @see #UndefinedProperty
|
161 |
|
|
*/
|
162 |
|
|
public abstract Object getProperty(String name, ImageObserver observer);
|
163 |
|
|
|
164 |
|
|
/**
|
165 |
|
|
* Scales the image to the requested dimension. A new Image with asynchronous
|
166 |
|
|
* loading will be produced according to the hints of the algorithm
|
167 |
|
|
* requested. If either the width or height is non-positive, it is adjusted
|
168 |
|
|
* to preserve the original aspect ratio.
|
169 |
|
|
*
|
170 |
|
|
* @param width the width of the scaled image
|
171 |
|
|
* @param height the height of the scaled image
|
172 |
|
|
* @param flags a value indicating the algorithm to use
|
173 |
|
|
* @return the scaled <code>Image</code> object
|
174 |
|
|
* @see #SCALE_DEFAULT
|
175 |
|
|
* @see #SCALE_FAST
|
176 |
|
|
* @see #SCALE_SMOOTH
|
177 |
|
|
* @see #SCALE_REPLICATE
|
178 |
|
|
* @see #SCALE_AREA_AVERAGING
|
179 |
|
|
* @since 1.1
|
180 |
|
|
*/
|
181 |
|
|
public Image getScaledInstance(int width, int height, int flags)
|
182 |
|
|
{
|
183 |
|
|
ImageFilter filter;
|
184 |
|
|
switch (flags)
|
185 |
|
|
{
|
186 |
|
|
case SCALE_DEFAULT:
|
187 |
|
|
case SCALE_FAST:
|
188 |
|
|
case SCALE_REPLICATE:
|
189 |
|
|
filter = new ReplicateScaleFilter(width, height);
|
190 |
|
|
break;
|
191 |
|
|
case SCALE_AREA_AVERAGING:
|
192 |
|
|
filter = new AreaAveragingScaleFilter(width, height);
|
193 |
|
|
break;
|
194 |
|
|
case SCALE_SMOOTH:
|
195 |
|
|
throw new Error("SCALE_SMOOTH: not implemented");
|
196 |
|
|
default:
|
197 |
|
|
throw new Error("Unknown flag or not implemented: " + flags);
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
ImageProducer producer = new FilteredImageSource(getSource(), filter);
|
201 |
|
|
return Toolkit.getDefaultToolkit().createImage(producer);
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/**
|
205 |
|
|
* Flushes (that is, destroys) any resources used for this image. This
|
206 |
|
|
* includes the actual image data.
|
207 |
|
|
*/
|
208 |
|
|
public abstract void flush();
|
209 |
|
|
} // class Image
|