ImageIcon.java revision 2362
4028N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * An implementation of the Icon interface that paints Icons 0N/A * from Images. Images that are created from a URL, filename or byte array 0N/A * are preloaded using MediaTracker to monitor the loaded state 0N/A * For further information and examples of using image icons, see 0N/A * in <em>The Java Tutorial.</em> 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * @author Jeff Dinkins 0N/A * @author Lynn Monsanto 0N/A /* Keep references to the filename and location so that 0N/A * alternate persistence schemes have the option to archive 0N/A * images symbolically rather than including the image data 0N/A // 6482575 - clear the appContext field so as not to leak it 0N/A * Id used in loading images from MediaTracker. 0N/A * Creates an ImageIcon from the specified file. The image will 0N/A * be preloaded by using MediaTracker to monitor the loading state 0N/A * @param filename the name of the file containing the image 0N/A * @param description a brief textual description of the image 0N/A * @see #ImageIcon(String) 0N/A * Creates an ImageIcon from the specified file. The image will 0N/A * be preloaded by using MediaTracker to monitor the loading state 0N/A * of the image. The specified String can be a file name or a 0N/A * file path. When specifying a path, use the Internet-standard 0N/A * forward-slash ("/") as a separator. 0N/A * (The string is converted to an URL, so the forward-slash works 0N/A * For example, specify: 0N/A * The description is initialized to the <code>filename</code> string. 0N/A * @param filename a String specifying a filename or path 0N/A * @see #getDescription 0N/A * Creates an ImageIcon from the specified URL. The image will 0N/A * be preloaded by using MediaTracker to monitor the loaded state 0N/A * @param location the URL for the image 0N/A * @param description a brief textual description of the image 0N/A * @see #ImageIcon(String) 0N/A * Creates an ImageIcon from the specified URL. The image will 0N/A * be preloaded by using MediaTracker to monitor the loaded state 0N/A * The icon's description is initialized to be 0N/A * a string representation of the URL. 0N/A * @param location the URL for the image 0N/A * @see #getDescription 0N/A * Creates an ImageIcon from the image. 0N/A * @param image the image 0N/A * @param description a brief textual description of the image 0N/A * Creates an ImageIcon from an image object. 0N/A * If the image has a "comment" property that is a string, 0N/A * then the string is used as the description of this icon. 0N/A * @param image the image 0N/A * @see #getDescription 0N/A * @see java.awt.Image#getProperty 0N/A * Creates an ImageIcon from an array of bytes which were 0N/A * read from an image file containing a supported image format, 0N/A * such as GIF, JPEG, or (as of 1.3) PNG. 0N/A * Normally this array is created 0N/A * by reading an image using Class.getResourceAsStream(), but 0N/A * the byte array may also be statically stored in a class. 0N/A * @param imageData an array of pixels in an image format supported 0N/A * by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG 0N/A * @param description a brief textual description of the image 0N/A * @see java.awt.Toolkit#createImage 0N/A * Creates an ImageIcon from an array of bytes which were 0N/A * read from an image file containing a supported image format, 0N/A * such as GIF, JPEG, or (as of 1.3) PNG. 0N/A * Normally this array is created 0N/A * by reading an image using Class.getResourceAsStream(), but 0N/A * the byte array may also be statically stored in a class. 0N/A * If the resulting image has a "comment" property that is a string, 0N/A * then the string is used as the description of this icon. 0N/A * @param imageData an array of pixels in an image format supported by 0N/A * the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG 0N/A * @see java.awt.Toolkit#createImage 0N/A * @see #getDescription 0N/A * @see java.awt.Image#getProperty 0N/A * Creates an uninitialized image icon. 0N/A * Loads the image, returning only when the image is loaded. 0N/A * @param image the image 0N/A * Returns an ID to use with the MediaTracker in loading an image. 0N/A * Returns the MediaTracker for the current AppContext, creating a new 0N/A * MediaTracker if necessary. 0N/A // Opt: Only synchronize if trackerObj comes back null? 0N/A // If null, synchronize, re-check for null, and put new tracker 0N/A * Returns the status of the image loading operation. 0N/A * @return the loading status as defined by java.awt.MediaTracker 0N/A * @see java.awt.MediaTracker#ABORTED 0N/A * @see java.awt.MediaTracker#ERRORED 0N/A * @see java.awt.MediaTracker#COMPLETE 0N/A * Returns this icon's <code>Image</code>. 0N/A * @return the <code>Image</code> object for this <code>ImageIcon</code> 0N/A * Sets the image displayed by this icon. 0N/A * @param image the image 0N/A * Gets the description of the image. This is meant to be a brief 0N/A * textual description of the object. For example, it might be 0N/A * presented to a blind user to give an indication of the purpose 0N/A * The description may be null. 0N/A * @return a brief textual description of the image 0N/A * Sets the description of the image. This is meant to be a brief 0N/A * textual description of the object. For example, it might be 0N/A * presented to a blind user to give an indication of the purpose 0N/A * @param description a brief textual description of the image 1644N/A * The top-left corner of the icon is drawn at 1644N/A * the point (<code>x</code>, <code>y</code>) 1644N/A * in the coordinate space of the graphics context <code>g</code>. 1644N/A * If this icon has no image observer, 0N/A * this method uses the <code>c</code> component 0N/A * @param c the component to be used as the observer 0N/A * if this icon has no image observer 0N/A * @param g the graphics context 0N/A * @param x the X coordinate of the icon's top-left corner 0N/A * @param y the Y coordinate of the icon's top-left corner 0N/A * Gets the width of the icon. 0N/A * @return the width in pixels of this icon 0N/A * Gets the height of the icon. 0N/A * @return the height in pixels of this icon 0N/A * Sets the image observer for the image. Set this 0N/A * property if the ImageIcon contains an animated GIF, so 0N/A * the observer is notified to update its display. 0N/A * icon = new ImageIcon(...) 0N/A * button.setIcon(icon); 0N/A * icon.setImageObserver(button); 0N/A * @param observer the image observer 0N/A * Returns the image observer for the image. 0N/A * @return the image observer, which may be null 0N/A * Returns a string representation of this image. 0N/A * @return a string representing this image 0N/A * --- Accessibility Support --- 0N/A * Gets the AccessibleContext associated with this ImageIcon. 0N/A * For image icons, the AccessibleContext takes the form of an 0N/A * AccessibleImageIcon. 0N/A * A new AccessibleImageIcon instance is created if necessary. 0N/A * @return an AccessibleImageIcon that serves as the 0N/A * AccessibleContext of this ImageIcon 0N/A * description: The AccessibleContext associated with this ImageIcon. 0N/A * This class implements accessibility support for the 0N/A * <code>ImageIcon</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to image icon user-interface 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * AccessibleContest implementation ----------------- 0N/A * Gets the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * @see AccessibleRole 0N/A * Gets the state of this object. 0N/A * @return an instance of AccessibleStateSet containing the current 0N/A * state set of the object 0N/A * @see AccessibleState 0N/A * Gets the Accessible parent of this object. If the parent of this 0N/A * object implements Accessible, this method should simply return 0N/A * @return the Accessible parent of this object -- can be null if this 0N/A * object does not have an Accessible parent 0N/A * Gets the index of this object in its accessible parent. 0N/A * @return the index of this object in its parent; -1 if this 0N/A * object does not have an accessible parent. 0N/A * @see #getAccessibleParent 0N/A * Returns the number of accessible children in the object. If all 0N/A * of the children of this object implement Accessible, than this 183N/A * method should return the number of children of this object. 183N/A * @return the number of accessible children in the object. 183N/A * Returns the nth Accessible child of the object. 183N/A * @param i zero-based index of child 183N/A * @return the nth Accessible child of the object 183N/A * Returns the locale of this object. 183N/A * @return the locale of this object 183N/A * AccessibleIcon implementation ----------------- 183N/A * Gets the description of the icon. This is meant to be a brief 183N/A * textual description of the object. For example, it might be 183N/A * presented to a blind user to give an indication of the purpose 183N/A * @return the description of the icon 183N/A * Sets the description of the icon. This is meant to be a brief 183N/A * textual description of the object. For example, it might be 183N/A * presented to a blind user to give an indication of the purpose 183N/A * @param description the description of the icon 183N/A * Gets the height of the icon. 183N/A * @return the height of the icon 183N/A * Gets the width of the icon. 183N/A * @return the width of the icon 0N/A }
// AccessibleImageIcon