jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26001 jdk/src/share/classes/javax/swing/ImageIcon.java@991e1be0b235
parent 25859 jdk/src/share/classes/javax/swing/ImageIcon.java@3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21257
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1843
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.ConstructorProperties;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    30
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.reflect.Field;
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
    43
import java.security.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * An implementation of the Icon interface that paints Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * from Images. Images that are created from a URL, filename or byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * are preloaded using MediaTracker to monitor the loaded state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * For further information and examples of using image icons, see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 9850
diff changeset
    53
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html">How to Use Icons</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    62
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author Lynn Monsanto
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    68
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21257
diff changeset
    70
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class ImageIcon implements Icon, Serializable, Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /* Keep references to the filename and location so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * alternate persistence schemes have the option to archive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * images symbolically rather than including the image data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * in the archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    transient private String filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    transient private URL location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    transient Image image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    transient int loadStatus = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    ImageObserver imageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    String description = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
21257
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    85
    /**
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    86
     * Do not use this shared component, which is used to track image loading.
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    87
     * It is left for backward compatibility only.
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    88
     * @deprecated since 1.8
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    89
     */
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    90
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected final static Component component;
21257
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    92
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    93
    /**
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    94
     * Do not use this shared media tracker, which is used to load images.
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    95
     * It is left for backward compatibility only.
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    96
     * @deprecated since 1.8
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    97
     */
57214b6e9c3e 7035495: javax.swing.ImageIcon spec should be clarified
malenkov
parents: 20458
diff changeset
    98
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected final static MediaTracker tracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static {
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   102
        component = AccessController.doPrivileged(new PrivilegedAction<Component>() {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   103
            public Component run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                try {
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   105
                    final Component component = createNoPermsComponent();
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    // 6482575 - clear the appContext field so as not to leak it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    Field appContextField =
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   109
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   110
                            Component.class.getDeclaredField("appContext");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    appContextField.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    appContextField.set(component, null);
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   113
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   114
                    return component;
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   115
                } catch (Throwable e) {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   116
                    // We don't care about component.
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   117
                    // So don't prevent class initialisation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    e.printStackTrace();
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   119
                    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        tracker = new MediaTracker(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
9850
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   126
    private static Component createNoPermsComponent() {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   127
        // 7020198 - set acc field to no permissions and no subject
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   128
        // Note, will have appContext set.
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   129
        return AccessController.doPrivileged(
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   130
                new PrivilegedAction<Component>() {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   131
                    public Component run() {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   132
                        return new Component() {
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   133
                        };
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   134
                    }
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   135
                },
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   136
                new AccessControlContext(new ProtectionDomain[]{
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   137
                        new ProtectionDomain(null, null)
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   138
                })
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   139
        );
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   140
    }
2689977af15b 7020198: ImageIcon creates Component with null acc
alexp
parents: 5506
diff changeset
   141
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Id used in loading images from MediaTracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static int mediaTrackerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private final static Object TRACKER_KEY = new StringBuilder("TRACKER_KEY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    int width = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    int height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Creates an ImageIcon from the specified file. The image will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * be preloaded by using MediaTracker to monitor the loading state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param filename the name of the file containing the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param description a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @see #ImageIcon(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public ImageIcon(String filename, String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        image = Toolkit.getDefaultToolkit().getImage(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.filename = filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Creates an ImageIcon from the specified file. The image will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * be preloaded by using MediaTracker to monitor the loading state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * of the image. The specified String can be a file name or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * file path. When specifying a path, use the Internet-standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * forward-slash ("/") as a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * (The string is converted to an URL, so the forward-slash works
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * on all systems.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * For example, specify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *    new ImageIcon("images/myImage.gif") </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * The description is initialized to the <code>filename</code> string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param filename a String specifying a filename or path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see #getDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    @ConstructorProperties({"description"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public ImageIcon (String filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this(filename, filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Creates an ImageIcon from the specified URL. The image will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * be preloaded by using MediaTracker to monitor the loaded state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param location the URL for the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param description a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see #ImageIcon(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public ImageIcon(URL location, String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        image = Toolkit.getDefaultToolkit().getImage(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Creates an ImageIcon from the specified URL. The image will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * be preloaded by using MediaTracker to monitor the loaded state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The icon's description is initialized to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * a string representation of the URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param location the URL for the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see #getDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public ImageIcon (URL location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        this(location, location.toExternalForm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Creates an ImageIcon from the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param image the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param description a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public ImageIcon(Image image, String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        this(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Creates an ImageIcon from an image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * If the image has a "comment" property that is a string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * then the string is used as the description of this icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param image the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see #getDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see java.awt.Image#getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public ImageIcon (Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        this.image = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Object o = image.getProperty("comment", imageObserver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (o instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            description = (String) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Creates an ImageIcon from an array of bytes which were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * read from an image file containing a supported image format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * such as GIF, JPEG, or (as of 1.3) PNG.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Normally this array is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * by reading an image using Class.getResourceAsStream(), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the byte array may also be statically stored in a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param  imageData an array of pixels in an image format supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *         by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param  description a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see    java.awt.Toolkit#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public ImageIcon (byte[] imageData, String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        this.image = Toolkit.getDefaultToolkit().createImage(imageData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Creates an ImageIcon from an array of bytes which were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * read from an image file containing a supported image format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * such as GIF, JPEG, or (as of 1.3) PNG.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Normally this array is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * by reading an image using Class.getResourceAsStream(), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * the byte array may also be statically stored in a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * If the resulting image has a "comment" property that is a string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * then the string is used as the description of this icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param  imageData an array of pixels in an image format supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *             the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see    java.awt.Toolkit#createImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see #getDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see java.awt.Image#getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public ImageIcon (byte[] imageData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        this.image = Toolkit.getDefaultToolkit().createImage(imageData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        Object o = image.getProperty("comment", imageObserver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (o instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            description = (String) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Creates an uninitialized image icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public ImageIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Loads the image, returning only when the image is loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param image the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    protected void loadImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        MediaTracker mTracker = getTracker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        synchronized(mTracker) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            int id = getNextID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            mTracker.addImage(image, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                mTracker.waitForID(id, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                System.out.println("INTERRUPTED while loading Image");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            loadStatus = mTracker.statusID(id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            mTracker.removeImage(image, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            width = image.getWidth(imageObserver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            height = image.getHeight(imageObserver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Returns an ID to use with the MediaTracker in loading an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    private int getNextID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        synchronized(getTracker()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return ++mediaTrackerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Returns the MediaTracker for the current AppContext, creating a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * MediaTracker if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    private MediaTracker getTracker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        Object trackerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        AppContext ac = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // Opt: Only synchronize if trackerObj comes back null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // If null, synchronize, re-check for null, and put new tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        synchronized(ac) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            trackerObj = ac.get(TRACKER_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (trackerObj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                Component comp = new Component() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                trackerObj = new MediaTracker(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                ac.put(TRACKER_KEY, trackerObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return (MediaTracker) trackerObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Returns the status of the image loading operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return the loading status as defined by java.awt.MediaTracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see java.awt.MediaTracker#ABORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see java.awt.MediaTracker#ERRORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see java.awt.MediaTracker#COMPLETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public int getImageLoadStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return loadStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns this icon's <code>Image</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return the <code>Image</code> object for this <code>ImageIcon</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   372
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public Image getImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Sets the image displayed by this icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @param image the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public void setImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        this.image = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Gets the description of the image.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * The description may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @return a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Sets the description of the image.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @param description a brief textual description of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public void setDescription(String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Paints the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * The top-left corner of the icon is drawn at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * the point (<code>x</code>, <code>y</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * in the coordinate space of the graphics context <code>g</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * If this icon has no image observer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * this method uses the <code>c</code> component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * as the observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param c the component to be used as the observer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *          if this icon has no image observer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param g the graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @param x the X coordinate of the icon's top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @param y the Y coordinate of the icon's top-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if(imageObserver == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
           g.drawImage(image, x, y, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
           g.drawImage(image, x, y, imageObserver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Gets the width of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @return the width in pixels of this icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Gets the height of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return the height in pixels of this icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Sets the image observer for the image.  Set this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * property if the ImageIcon contains an animated GIF, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * the observer is notified to update its display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *     icon = new ImageIcon(...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *     button.setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *     icon.setImageObserver(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param observer the image observer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public void setImageObserver(ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        imageObserver = observer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Returns the image observer for the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the image observer, which may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   473
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public ImageObserver getImageObserver() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return imageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Returns a string representation of this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @return a string representing this image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (description != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return super.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   493
        ObjectInputStream.GetField f = s.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   494
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   495
        imageObserver = (ImageObserver) f.get("imageObserver", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   496
        description = (String) f.get("description", null);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   497
        width = f.get("width", -1);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   498
        height = f.get("height", -1);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   499
        accessibleContext = (AccessibleImageIcon) f.get("accessibleContext", null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int w = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        int h = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        int[] pixels = (int[])(s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   505
        if (pixels == null && (w != -1 || h != -1)) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   506
            throw new IllegalStateException("Inconsistent width and height"
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   507
                    + " for null image [" + w + ", " + h + "]");
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   508
        }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   509
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   510
        if (pixels != null && (w < 0 || h < 0)) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   511
            throw new IllegalStateException("Inconsistent width and height"
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   512
                    + " for image [" + w + ", " + h + "]");
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   513
        }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   514
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   515
        if (w != getIconWidth() || h != getIconHeight()) {
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   516
            throw new IllegalStateException("Inconsistent width and height"
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   517
                    + " for image [" + w + ", " + h + "]");
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   518
        }
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25201
diff changeset
   519
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (pixels != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            ColorModel cm = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            image = tk.createImage(new MemoryImageSource(w, h, cm, pixels, 0, w));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            loadImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        int w = getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        int h = getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        int[] pixels = image != null? new int[w * h] : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                pg.grabPixels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    throw new IOException("failed to load image contents");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                throw new IOException("image load interrupted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        s.writeInt(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        s.writeInt(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        s.writeObject(pixels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    private AccessibleImageIcon accessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Gets the AccessibleContext associated with this ImageIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * For image icons, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * AccessibleImageIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * A new AccessibleImageIcon instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @return an AccessibleImageIcon that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *         AccessibleContext of this ImageIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *  description: The AccessibleContext associated with this ImageIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            accessibleContext = new AccessibleImageIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <code>ImageIcon</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Java Accessibility API appropriate to image icon user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   593
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21257
diff changeset
   598
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    protected class AccessibleImageIcon extends AccessibleContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        implements AccessibleIcon, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         * AccessibleContest implementation -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return AccessibleRole.ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         * Gets the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * Gets the Accessible parent of this object.  If the parent of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         * object implements Accessible, this method should simply return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * getParent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * @return the Accessible parent of this object -- can be null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         * object does not have an Accessible parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        public Accessible getAccessibleParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
         * Gets the index of this object in its accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         * @return the index of this object in its parent; -1 if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * object does not have an accessible parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * @see #getAccessibleParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        public int getAccessibleIndexInParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * Returns the number of accessible children in the object.  If all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         * of the children of this object implement Accessible, than this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * method should return the number of children of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         * @return the number of accessible children in the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * Returns the nth Accessible child of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         * @return the nth Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * Returns the locale of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
         * @return the locale of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        public Locale getLocale() throws IllegalComponentStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         * AccessibleIcon implementation -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         * Gets the description of the icon.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         * of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * @return the description of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        public String getAccessibleIconDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            return ImageIcon.this.getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         * Sets the description of the icon.  This is meant to be a brief
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         * textual description of the object.  For example, it might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
         * presented to a blind user to give an indication of the purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         * of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         * @param description the description of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        public void setAccessibleIconDescription(String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            ImageIcon.this.setDescription(description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
         * Gets the height of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * @return the height of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        public int getAccessibleIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            return ImageIcon.this.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
         * Gets the width of the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
         * @return the width of the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        public int getAccessibleIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return ImageIcon.this.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }  // AccessibleImageIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
}