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