2
|
1 |
/*
|
|
2 |
* Copyright 1997-2007 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package javax.swing;
|
|
26 |
|
|
27 |
import java.awt.*;
|
|
28 |
import java.awt.image.*;
|
|
29 |
import java.beans.ConstructorProperties;
|
|
30 |
import java.net.URL;
|
|
31 |
|
|
32 |
import java.io.Serializable;
|
|
33 |
import java.io.ObjectOutputStream;
|
|
34 |
import java.io.ObjectInputStream;
|
|
35 |
import java.io.IOException;
|
|
36 |
|
|
37 |
import java.util.Locale;
|
|
38 |
import javax.accessibility.*;
|
|
39 |
|
|
40 |
import sun.awt.AppContext;
|
|
41 |
import java.lang.reflect.Field;
|
|
42 |
import java.security.PrivilegedAction;
|
|
43 |
import java.security.AccessController;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* An implementation of the Icon interface that paints Icons
|
|
47 |
* from Images. Images that are created from a URL, filename or byte array
|
|
48 |
* are preloaded using MediaTracker to monitor the loaded state
|
|
49 |
* of the image.
|
|
50 |
*
|
|
51 |
* <p>
|
|
52 |
* For further information and examples of using image icons, see
|
|
53 |
* <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html">How to Use Icons</a>
|
|
54 |
* in <em>The Java Tutorial.</em>
|
|
55 |
*
|
|
56 |
* <p>
|
|
57 |
* <strong>Warning:</strong>
|
|
58 |
* Serialized objects of this class will not be compatible with
|
|
59 |
* future Swing releases. The current serialization support is
|
|
60 |
* appropriate for short term storage or RMI between applications running
|
|
61 |
* the same version of Swing. As of 1.4, support for long term storage
|
|
62 |
* of all JavaBeans<sup><font size="-2">TM</font></sup>
|
|
63 |
* has been added to the <code>java.beans</code> package.
|
|
64 |
* Please see {@link java.beans.XMLEncoder}.
|
|
65 |
*
|
|
66 |
* @author Jeff Dinkins
|
|
67 |
* @author Lynn Monsanto
|
|
68 |
*/
|
|
69 |
public class ImageIcon implements Icon, Serializable, Accessible {
|
|
70 |
/* Keep references to the filename and location so that
|
|
71 |
* alternate persistence schemes have the option to archive
|
|
72 |
* images symbolically rather than including the image data
|
|
73 |
* in the archive.
|
|
74 |
*/
|
|
75 |
transient private String filename;
|
|
76 |
transient private URL location;
|
|
77 |
|
|
78 |
transient Image image;
|
|
79 |
transient int loadStatus = 0;
|
|
80 |
ImageObserver imageObserver;
|
|
81 |
String description = null;
|
|
82 |
|
|
83 |
protected final static Component component;
|
|
84 |
protected final static MediaTracker tracker;
|
|
85 |
|
|
86 |
static {
|
|
87 |
component = new Component() {};
|
|
88 |
AccessController.doPrivileged(new PrivilegedAction() {
|
|
89 |
public Object run() {
|
|
90 |
try {
|
|
91 |
// 6482575 - clear the appContext field so as not to leak it
|
|
92 |
Field appContextField =
|
|
93 |
Component.class.getDeclaredField("appContext");
|
|
94 |
appContextField.setAccessible(true);
|
|
95 |
appContextField.set(component, null);
|
|
96 |
}
|
|
97 |
catch (NoSuchFieldException e) {
|
|
98 |
e.printStackTrace();
|
|
99 |
}
|
|
100 |
catch (IllegalAccessException e) {
|
|
101 |
e.printStackTrace();
|
|
102 |
}
|
|
103 |
return null;
|
|
104 |
}
|
|
105 |
});
|
|
106 |
tracker = new MediaTracker(component);
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Id used in loading images from MediaTracker.
|
|
111 |
*/
|
|
112 |
private static int mediaTrackerID;
|
|
113 |
|
|
114 |
private final static Object TRACKER_KEY = new StringBuilder("TRACKER_KEY");
|
|
115 |
|
|
116 |
int width = -1;
|
|
117 |
int height = -1;
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Creates an ImageIcon from the specified file. The image will
|
|
121 |
* be preloaded by using MediaTracker to monitor the loading state
|
|
122 |
* of the image.
|
|
123 |
* @param filename the name of the file containing the image
|
|
124 |
* @param description a brief textual description of the image
|
|
125 |
* @see #ImageIcon(String)
|
|
126 |
*/
|
|
127 |
public ImageIcon(String filename, String description) {
|
|
128 |
image = Toolkit.getDefaultToolkit().getImage(filename);
|
|
129 |
if (image == null) {
|
|
130 |
return;
|
|
131 |
}
|
|
132 |
this.filename = filename;
|
|
133 |
this.description = description;
|
|
134 |
loadImage(image);
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Creates an ImageIcon from the specified file. The image will
|
|
139 |
* be preloaded by using MediaTracker to monitor the loading state
|
|
140 |
* of the image. The specified String can be a file name or a
|
|
141 |
* file path. When specifying a path, use the Internet-standard
|
|
142 |
* forward-slash ("/") as a separator.
|
|
143 |
* (The string is converted to an URL, so the forward-slash works
|
|
144 |
* on all systems.)
|
|
145 |
* For example, specify:
|
|
146 |
* <pre>
|
|
147 |
* new ImageIcon("images/myImage.gif") </pre>
|
|
148 |
* The description is initialized to the <code>filename</code> string.
|
|
149 |
*
|
|
150 |
* @param filename a String specifying a filename or path
|
|
151 |
* @see #getDescription
|
|
152 |
*/
|
|
153 |
@ConstructorProperties({"description"})
|
|
154 |
public ImageIcon (String filename) {
|
|
155 |
this(filename, filename);
|
|
156 |
}
|
|
157 |
|
|
158 |
/**
|
|
159 |
* Creates an ImageIcon from the specified URL. The image will
|
|
160 |
* be preloaded by using MediaTracker to monitor the loaded state
|
|
161 |
* of the image.
|
|
162 |
* @param location the URL for the image
|
|
163 |
* @param description a brief textual description of the image
|
|
164 |
* @see #ImageIcon(String)
|
|
165 |
*/
|
|
166 |
public ImageIcon(URL location, String description) {
|
|
167 |
image = Toolkit.getDefaultToolkit().getImage(location);
|
|
168 |
if (image == null) {
|
|
169 |
return;
|
|
170 |
}
|
|
171 |
this.location = location;
|
|
172 |
this.description = description;
|
|
173 |
loadImage(image);
|
|
174 |
}
|
|
175 |
|
|
176 |
/**
|
|
177 |
* Creates an ImageIcon from the specified URL. The image will
|
|
178 |
* be preloaded by using MediaTracker to monitor the loaded state
|
|
179 |
* of the image.
|
|
180 |
* The icon's description is initialized to be
|
|
181 |
* a string representation of the URL.
|
|
182 |
* @param location the URL for the image
|
|
183 |
* @see #getDescription
|
|
184 |
*/
|
|
185 |
public ImageIcon (URL location) {
|
|
186 |
this(location, location.toExternalForm());
|
|
187 |
}
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Creates an ImageIcon from the image.
|
|
191 |
* @param image the image
|
|
192 |
* @param description a brief textual description of the image
|
|
193 |
*/
|
|
194 |
public ImageIcon(Image image, String description) {
|
|
195 |
this(image);
|
|
196 |
this.description = description;
|
|
197 |
}
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Creates an ImageIcon from an image object.
|
|
201 |
* If the image has a "comment" property that is a string,
|
|
202 |
* then the string is used as the description of this icon.
|
|
203 |
* @param image the image
|
|
204 |
* @see #getDescription
|
|
205 |
* @see java.awt.Image#getProperty
|
|
206 |
*/
|
|
207 |
public ImageIcon (Image image) {
|
|
208 |
this.image = image;
|
|
209 |
Object o = image.getProperty("comment", imageObserver);
|
|
210 |
if (o instanceof String) {
|
|
211 |
description = (String) o;
|
|
212 |
}
|
|
213 |
loadImage(image);
|
|
214 |
}
|
|
215 |
|
|
216 |
/**
|
|
217 |
* Creates an ImageIcon from an array of bytes which were
|
|
218 |
* read from an image file containing a supported image format,
|
|
219 |
* such as GIF, JPEG, or (as of 1.3) PNG.
|
|
220 |
* Normally this array is created
|
|
221 |
* by reading an image using Class.getResourceAsStream(), but
|
|
222 |
* the byte array may also be statically stored in a class.
|
|
223 |
*
|
|
224 |
* @param imageData an array of pixels in an image format supported
|
|
225 |
* by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
|
|
226 |
* @param description a brief textual description of the image
|
|
227 |
* @see java.awt.Toolkit#createImage
|
|
228 |
*/
|
|
229 |
public ImageIcon (byte[] imageData, String description) {
|
|
230 |
this.image = Toolkit.getDefaultToolkit().createImage(imageData);
|
|
231 |
if (image == null) {
|
|
232 |
return;
|
|
233 |
}
|
|
234 |
this.description = description;
|
|
235 |
loadImage(image);
|
|
236 |
}
|
|
237 |
|
|
238 |
/**
|
|
239 |
* Creates an ImageIcon from an array of bytes which were
|
|
240 |
* read from an image file containing a supported image format,
|
|
241 |
* such as GIF, JPEG, or (as of 1.3) PNG.
|
|
242 |
* Normally this array is created
|
|
243 |
* by reading an image using Class.getResourceAsStream(), but
|
|
244 |
* the byte array may also be statically stored in a class.
|
|
245 |
* If the resulting image has a "comment" property that is a string,
|
|
246 |
* then the string is used as the description of this icon.
|
|
247 |
*
|
|
248 |
* @param imageData an array of pixels in an image format supported by
|
|
249 |
* the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
|
|
250 |
* @see java.awt.Toolkit#createImage
|
|
251 |
* @see #getDescription
|
|
252 |
* @see java.awt.Image#getProperty
|
|
253 |
*/
|
|
254 |
public ImageIcon (byte[] imageData) {
|
|
255 |
this.image = Toolkit.getDefaultToolkit().createImage(imageData);
|
|
256 |
if (image == null) {
|
|
257 |
return;
|
|
258 |
}
|
|
259 |
Object o = image.getProperty("comment", imageObserver);
|
|
260 |
if (o instanceof String) {
|
|
261 |
description = (String) o;
|
|
262 |
}
|
|
263 |
loadImage(image);
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
* Creates an uninitialized image icon.
|
|
268 |
*/
|
|
269 |
public ImageIcon() {
|
|
270 |
}
|
|
271 |
|
|
272 |
/**
|
|
273 |
* Loads the image, returning only when the image is loaded.
|
|
274 |
* @param image the image
|
|
275 |
*/
|
|
276 |
protected void loadImage(Image image) {
|
|
277 |
MediaTracker mTracker = getTracker();
|
|
278 |
synchronized(mTracker) {
|
|
279 |
int id = getNextID();
|
|
280 |
|
|
281 |
mTracker.addImage(image, id);
|
|
282 |
try {
|
|
283 |
mTracker.waitForID(id, 0);
|
|
284 |
} catch (InterruptedException e) {
|
|
285 |
System.out.println("INTERRUPTED while loading Image");
|
|
286 |
}
|
|
287 |
loadStatus = mTracker.statusID(id, false);
|
|
288 |
mTracker.removeImage(image, id);
|
|
289 |
|
|
290 |
width = image.getWidth(imageObserver);
|
|
291 |
height = image.getHeight(imageObserver);
|
|
292 |
}
|
|
293 |
}
|
|
294 |
|
|
295 |
/**
|
|
296 |
* Returns an ID to use with the MediaTracker in loading an image.
|
|
297 |
*/
|
|
298 |
private int getNextID() {
|
|
299 |
synchronized(getTracker()) {
|
|
300 |
return ++mediaTrackerID;
|
|
301 |
}
|
|
302 |
}
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Returns the MediaTracker for the current AppContext, creating a new
|
|
306 |
* MediaTracker if necessary.
|
|
307 |
*/
|
|
308 |
private MediaTracker getTracker() {
|
|
309 |
Object trackerObj;
|
|
310 |
AppContext ac = AppContext.getAppContext();
|
|
311 |
// Opt: Only synchronize if trackerObj comes back null?
|
|
312 |
// If null, synchronize, re-check for null, and put new tracker
|
|
313 |
synchronized(ac) {
|
|
314 |
trackerObj = ac.get(TRACKER_KEY);
|
|
315 |
if (trackerObj == null) {
|
|
316 |
Component comp = new Component() {};
|
|
317 |
trackerObj = new MediaTracker(comp);
|
|
318 |
ac.put(TRACKER_KEY, trackerObj);
|
|
319 |
}
|
|
320 |
}
|
|
321 |
return (MediaTracker) trackerObj;
|
|
322 |
}
|
|
323 |
|
|
324 |
/**
|
|
325 |
* Returns the status of the image loading operation.
|
|
326 |
* @return the loading status as defined by java.awt.MediaTracker
|
|
327 |
* @see java.awt.MediaTracker#ABORTED
|
|
328 |
* @see java.awt.MediaTracker#ERRORED
|
|
329 |
* @see java.awt.MediaTracker#COMPLETE
|
|
330 |
*/
|
|
331 |
public int getImageLoadStatus() {
|
|
332 |
return loadStatus;
|
|
333 |
}
|
|
334 |
|
|
335 |
/**
|
|
336 |
* Returns this icon's <code>Image</code>.
|
|
337 |
* @return the <code>Image</code> object for this <code>ImageIcon</code>
|
|
338 |
*/
|
|
339 |
public Image getImage() {
|
|
340 |
return image;
|
|
341 |
}
|
|
342 |
|
|
343 |
/**
|
|
344 |
* Sets the image displayed by this icon.
|
|
345 |
* @param image the image
|
|
346 |
*/
|
|
347 |
public void setImage(Image image) {
|
|
348 |
this.image = image;
|
|
349 |
loadImage(image);
|
|
350 |
}
|
|
351 |
|
|
352 |
/**
|
|
353 |
* Gets the description of the image. This is meant to be a brief
|
|
354 |
* textual description of the object. For example, it might be
|
|
355 |
* presented to a blind user to give an indication of the purpose
|
|
356 |
* of the image.
|
|
357 |
* The description may be null.
|
|
358 |
*
|
|
359 |
* @return a brief textual description of the image
|
|
360 |
*/
|
|
361 |
public String getDescription() {
|
|
362 |
return description;
|
|
363 |
}
|
|
364 |
|
|
365 |
/**
|
|
366 |
* Sets the description of the image. This is meant to be a brief
|
|
367 |
* textual description of the object. For example, it might be
|
|
368 |
* presented to a blind user to give an indication of the purpose
|
|
369 |
* of the image.
|
|
370 |
* @param description a brief textual description of the image
|
|
371 |
*/
|
|
372 |
public void setDescription(String description) {
|
|
373 |
this.description = description;
|
|
374 |
}
|
|
375 |
|
|
376 |
/**
|
|
377 |
* Paints the icon.
|
|
378 |
* The top-left corner of the icon is drawn at
|
|
379 |
* the point (<code>x</code>, <code>y</code>)
|
|
380 |
* in the coordinate space of the graphics context <code>g</code>.
|
|
381 |
* If this icon has no image observer,
|
|
382 |
* this method uses the <code>c</code> component
|
|
383 |
* as the observer.
|
|
384 |
*
|
|
385 |
* @param c the component to be used as the observer
|
|
386 |
* if this icon has no image observer
|
|
387 |
* @param g the graphics context
|
|
388 |
* @param x the X coordinate of the icon's top-left corner
|
|
389 |
* @param y the Y coordinate of the icon's top-left corner
|
|
390 |
*/
|
|
391 |
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
|
|
392 |
if(imageObserver == null) {
|
|
393 |
g.drawImage(image, x, y, c);
|
|
394 |
} else {
|
|
395 |
g.drawImage(image, x, y, imageObserver);
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
/**
|
|
400 |
* Gets the width of the icon.
|
|
401 |
*
|
|
402 |
* @return the width in pixels of this icon
|
|
403 |
*/
|
|
404 |
public int getIconWidth() {
|
|
405 |
return width;
|
|
406 |
}
|
|
407 |
|
|
408 |
/**
|
|
409 |
* Gets the height of the icon.
|
|
410 |
*
|
|
411 |
* @return the height in pixels of this icon
|
|
412 |
*/
|
|
413 |
public int getIconHeight() {
|
|
414 |
return height;
|
|
415 |
}
|
|
416 |
|
|
417 |
/**
|
|
418 |
* Sets the image observer for the image. Set this
|
|
419 |
* property if the ImageIcon contains an animated GIF, so
|
|
420 |
* the observer is notified to update its display.
|
|
421 |
* For example:
|
|
422 |
* <pre>
|
|
423 |
* icon = new ImageIcon(...)
|
|
424 |
* button.setIcon(icon);
|
|
425 |
* icon.setImageObserver(button);
|
|
426 |
* </pre>
|
|
427 |
*
|
|
428 |
* @param observer the image observer
|
|
429 |
*/
|
|
430 |
public void setImageObserver(ImageObserver observer) {
|
|
431 |
imageObserver = observer;
|
|
432 |
}
|
|
433 |
|
|
434 |
/**
|
|
435 |
* Returns the image observer for the image.
|
|
436 |
*
|
|
437 |
* @return the image observer, which may be null
|
|
438 |
*/
|
|
439 |
public ImageObserver getImageObserver() {
|
|
440 |
return imageObserver;
|
|
441 |
}
|
|
442 |
|
|
443 |
/**
|
|
444 |
* Returns a string representation of this image.
|
|
445 |
*
|
|
446 |
* @return a string representing this image
|
|
447 |
*/
|
|
448 |
public String toString() {
|
|
449 |
if (description != null) {
|
|
450 |
return description;
|
|
451 |
}
|
|
452 |
return super.toString();
|
|
453 |
}
|
|
454 |
|
|
455 |
private void readObject(ObjectInputStream s)
|
|
456 |
throws ClassNotFoundException, IOException
|
|
457 |
{
|
|
458 |
s.defaultReadObject();
|
|
459 |
|
|
460 |
int w = s.readInt();
|
|
461 |
int h = s.readInt();
|
|
462 |
int[] pixels = (int[])(s.readObject());
|
|
463 |
|
|
464 |
if (pixels != null) {
|
|
465 |
Toolkit tk = Toolkit.getDefaultToolkit();
|
|
466 |
ColorModel cm = ColorModel.getRGBdefault();
|
|
467 |
image = tk.createImage(new MemoryImageSource(w, h, cm, pixels, 0, w));
|
|
468 |
loadImage(image);
|
|
469 |
}
|
|
470 |
}
|
|
471 |
|
|
472 |
|
|
473 |
private void writeObject(ObjectOutputStream s)
|
|
474 |
throws IOException
|
|
475 |
{
|
|
476 |
s.defaultWriteObject();
|
|
477 |
|
|
478 |
int w = getIconWidth();
|
|
479 |
int h = getIconHeight();
|
|
480 |
int[] pixels = image != null? new int[w * h] : null;
|
|
481 |
|
|
482 |
if (image != null) {
|
|
483 |
try {
|
|
484 |
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
|
|
485 |
pg.grabPixels();
|
|
486 |
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
|
|
487 |
throw new IOException("failed to load image contents");
|
|
488 |
}
|
|
489 |
}
|
|
490 |
catch (InterruptedException e) {
|
|
491 |
throw new IOException("image load interrupted");
|
|
492 |
}
|
|
493 |
}
|
|
494 |
|
|
495 |
s.writeInt(w);
|
|
496 |
s.writeInt(h);
|
|
497 |
s.writeObject(pixels);
|
|
498 |
}
|
|
499 |
|
|
500 |
/**
|
|
501 |
* --- Accessibility Support ---
|
|
502 |
*/
|
|
503 |
|
|
504 |
private AccessibleImageIcon accessibleContext = null;
|
|
505 |
|
|
506 |
/**
|
|
507 |
* Gets the AccessibleContext associated with this ImageIcon.
|
|
508 |
* For image icons, the AccessibleContext takes the form of an
|
|
509 |
* AccessibleImageIcon.
|
|
510 |
* A new AccessibleImageIcon instance is created if necessary.
|
|
511 |
*
|
|
512 |
* @return an AccessibleImageIcon that serves as the
|
|
513 |
* AccessibleContext of this ImageIcon
|
|
514 |
* @beaninfo
|
|
515 |
* expert: true
|
|
516 |
* description: The AccessibleContext associated with this ImageIcon.
|
|
517 |
* @since 1.3
|
|
518 |
*/
|
|
519 |
public AccessibleContext getAccessibleContext() {
|
|
520 |
if (accessibleContext == null) {
|
|
521 |
accessibleContext = new AccessibleImageIcon();
|
|
522 |
}
|
|
523 |
return accessibleContext;
|
|
524 |
}
|
|
525 |
|
|
526 |
/**
|
|
527 |
* This class implements accessibility support for the
|
|
528 |
* <code>ImageIcon</code> class. It provides an implementation of the
|
|
529 |
* Java Accessibility API appropriate to image icon user-interface
|
|
530 |
* elements.
|
|
531 |
* <p>
|
|
532 |
* <strong>Warning:</strong>
|
|
533 |
* Serialized objects of this class will not be compatible with
|
|
534 |
* future Swing releases. The current serialization support is
|
|
535 |
* appropriate for short term storage or RMI between applications running
|
|
536 |
* the same version of Swing. As of 1.4, support for long term storage
|
|
537 |
* of all JavaBeans<sup><font size="-2">TM</font></sup>
|
|
538 |
* has been added to the <code>java.beans</code> package.
|
|
539 |
* Please see {@link java.beans.XMLEncoder}.
|
|
540 |
* @since 1.3
|
|
541 |
*/
|
|
542 |
protected class AccessibleImageIcon extends AccessibleContext
|
|
543 |
implements AccessibleIcon, Serializable {
|
|
544 |
|
|
545 |
/*
|
|
546 |
* AccessibleContest implementation -----------------
|
|
547 |
*/
|
|
548 |
|
|
549 |
/**
|
|
550 |
* Gets the role of this object.
|
|
551 |
*
|
|
552 |
* @return an instance of AccessibleRole describing the role of the
|
|
553 |
* object
|
|
554 |
* @see AccessibleRole
|
|
555 |
*/
|
|
556 |
public AccessibleRole getAccessibleRole() {
|
|
557 |
return AccessibleRole.ICON;
|
|
558 |
}
|
|
559 |
|
|
560 |
/**
|
|
561 |
* Gets the state of this object.
|
|
562 |
*
|
|
563 |
* @return an instance of AccessibleStateSet containing the current
|
|
564 |
* state set of the object
|
|
565 |
* @see AccessibleState
|
|
566 |
*/
|
|
567 |
public AccessibleStateSet getAccessibleStateSet() {
|
|
568 |
return null;
|
|
569 |
}
|
|
570 |
|
|
571 |
/**
|
|
572 |
* Gets the Accessible parent of this object. If the parent of this
|
|
573 |
* object implements Accessible, this method should simply return
|
|
574 |
* getParent().
|
|
575 |
*
|
|
576 |
* @return the Accessible parent of this object -- can be null if this
|
|
577 |
* object does not have an Accessible parent
|
|
578 |
*/
|
|
579 |
public Accessible getAccessibleParent() {
|
|
580 |
return null;
|
|
581 |
}
|
|
582 |
|
|
583 |
/**
|
|
584 |
* Gets the index of this object in its accessible parent.
|
|
585 |
*
|
|
586 |
* @return the index of this object in its parent; -1 if this
|
|
587 |
* object does not have an accessible parent.
|
|
588 |
* @see #getAccessibleParent
|
|
589 |
*/
|
|
590 |
public int getAccessibleIndexInParent() {
|
|
591 |
return -1;
|
|
592 |
}
|
|
593 |
|
|
594 |
/**
|
|
595 |
* Returns the number of accessible children in the object. If all
|
|
596 |
* of the children of this object implement Accessible, than this
|
|
597 |
* method should return the number of children of this object.
|
|
598 |
*
|
|
599 |
* @return the number of accessible children in the object.
|
|
600 |
*/
|
|
601 |
public int getAccessibleChildrenCount() {
|
|
602 |
return 0;
|
|
603 |
}
|
|
604 |
|
|
605 |
/**
|
|
606 |
* Returns the nth Accessible child of the object.
|
|
607 |
*
|
|
608 |
* @param i zero-based index of child
|
|
609 |
* @return the nth Accessible child of the object
|
|
610 |
*/
|
|
611 |
public Accessible getAccessibleChild(int i) {
|
|
612 |
return null;
|
|
613 |
}
|
|
614 |
|
|
615 |
/**
|
|
616 |
* Returns the locale of this object.
|
|
617 |
*
|
|
618 |
* @return the locale of this object
|
|
619 |
*/
|
|
620 |
public Locale getLocale() throws IllegalComponentStateException {
|
|
621 |
return null;
|
|
622 |
}
|
|
623 |
|
|
624 |
/*
|
|
625 |
* AccessibleIcon implementation -----------------
|
|
626 |
*/
|
|
627 |
|
|
628 |
/**
|
|
629 |
* Gets the description of the icon. This is meant to be a brief
|
|
630 |
* textual description of the object. For example, it might be
|
|
631 |
* presented to a blind user to give an indication of the purpose
|
|
632 |
* of the icon.
|
|
633 |
*
|
|
634 |
* @return the description of the icon
|
|
635 |
*/
|
|
636 |
public String getAccessibleIconDescription() {
|
|
637 |
return ImageIcon.this.getDescription();
|
|
638 |
}
|
|
639 |
|
|
640 |
/**
|
|
641 |
* Sets the description of the icon. This is meant to be a brief
|
|
642 |
* textual description of the object. For example, it might be
|
|
643 |
* presented to a blind user to give an indication of the purpose
|
|
644 |
* of the icon.
|
|
645 |
*
|
|
646 |
* @param description the description of the icon
|
|
647 |
*/
|
|
648 |
public void setAccessibleIconDescription(String description) {
|
|
649 |
ImageIcon.this.setDescription(description);
|
|
650 |
}
|
|
651 |
|
|
652 |
/**
|
|
653 |
* Gets the height of the icon.
|
|
654 |
*
|
|
655 |
* @return the height of the icon
|
|
656 |
*/
|
|
657 |
public int getAccessibleIconHeight() {
|
|
658 |
return ImageIcon.this.height;
|
|
659 |
}
|
|
660 |
|
|
661 |
/**
|
|
662 |
* Gets the width of the icon.
|
|
663 |
*
|
|
664 |
* @return the width of the icon
|
|
665 |
*/
|
|
666 |
public int getAccessibleIconWidth() {
|
|
667 |
return ImageIcon.this.width;
|
|
668 |
}
|
|
669 |
|
|
670 |
private void readObject(ObjectInputStream s)
|
|
671 |
throws ClassNotFoundException, IOException
|
|
672 |
{
|
|
673 |
s.defaultReadObject();
|
|
674 |
}
|
|
675 |
|
|
676 |
private void writeObject(ObjectOutputStream s)
|
|
677 |
throws IOException
|
|
678 |
{
|
|
679 |
s.defaultWriteObject();
|
|
680 |
}
|
|
681 |
} // AccessibleImageIcon
|
|
682 |
}
|