jas.util
Class JASIcon

java.lang.Object
  extended by javax.swing.ImageIcon
      extended by jas.util.JASIcon
All Implemented Interfaces:
Serializable, Accessible, Icon

public class JASIcon
extends ImageIcon

A convenience class for creating small icons where the source file is stored in the CLASSPATH of the application, typically in the same JAR file as the class creating the image

Author:
Tony Johnson
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
 
Field Summary
 
Fields inherited from class javax.swing.ImageIcon
component, tracker
 
Constructor Summary
JASIcon(Class c)
          Create a JASIcon without specifing the source
JASIcon(Class c, String file)
          Create a JASIcon from the CLASSPATH.
JASIcon(Object obj, String file)
          Create a JASIcon from the CLASSPATH.
 
Method Summary
static JASIcon create(Class c, String file)
          Create a JASIcon but do not throw an exception if the source cannot be found (just displays a "broken" icon instead) //TODO: Should create return a cached version of the JASIcon, instead of a cached // version of the image with a new JASIcon object?
static JASIcon create(Object obj, String file)
          Create a JASIcon but do not throw an exception if the source cannot be found (just displays a "broken" icon instead)
 boolean equals(Object in)
          Override Objects equals method.
 int hashCode()
          Override Objects hashCode method
 void setImage(String file)
          This method sets the image of the JASIcon to be that referenced by file.
 
Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getIconHeight, getIconWidth, getImage, getImageLoadStatus, getImageObserver, loadImage, paintIcon, setDescription, setImage, setImageObserver, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JASIcon

public JASIcon(Object obj,
               String file)
        throws ImageException
Create a JASIcon from the CLASSPATH.

Parameters:
obj - The object used as the root of the file path
file - The path to the image source file, relative to obj
Throws:
ImageException - Thrown if the image source file can not be found
See Also:
create(Object obj, String file)

JASIcon

public JASIcon(Class c,
               String file)
        throws ImageException
Create a JASIcon from the CLASSPATH.

Parameters:
c - The class used as the root of the file path
file - The path to the image source file, relative to the root class
Throws:
ImageException - Thrown if the image source file can not be found
See Also:
create(Object c, String file)

JASIcon

public JASIcon(Class c)
Create a JASIcon without specifing the source

Parameters:
Class - c The class used as the root of the file path when setImage is called
See Also:
setImage(String file)
Method Detail

setImage

public void setImage(String file)
This method sets the image of the JASIcon to be that referenced by file. The image will display as "broken" if the file can not be found, no exception is thrown

Parameters:
file - The path to the image source file, relative to the root class

hashCode

public int hashCode()
Override Objects hashCode method

Overrides:
hashCode in class Object

equals

public boolean equals(Object in)
Override Objects equals method. Two images are considered equal if they have the same class and file.

Overrides:
equals in class Object

create

public static JASIcon create(Object obj,
                             String file)
Create a JASIcon but do not throw an exception if the source cannot be found (just displays a "broken" icon instead)

Parameters:
obj - The object used as the root of the file path
file - The path to the image source file, relative to obj
Returns:
The resulting JASIcon

create

public static JASIcon create(Class c,
                             String file)
Create a JASIcon but do not throw an exception if the source cannot be found (just displays a "broken" icon instead) //TODO: Should create return a cached version of the JASIcon, instead of a cached // version of the image with a new JASIcon object?

Parameters:
obj - The class used as the root of the file path
file - The path to the image source file, relative to obj
Returns:
The resulting JASIcon


Copyright © 2000-2009 FreeHEP. All Rights Reserved.