|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.metamatrix.toolbox.ui.widget.util.IconFactory
public class IconFactory
IconFactory is a static class for generating ImageIcon objects from graphics files located either inside a jar file or on the file system. IconFactory first tries to locate the file in the JVM's classpath by searching the fullLocationPath. If it is not found, IconFactory then searches the file system via the relativeLocationPath from the application's current default directory. This design allows for software developers to run the application outside a jar file pulling image resources from their file system with the same code as would be obtaining resources from a jar archive in production.
IconFactory is designed to be set upon application startup and used throughout the application. The following is an example of it's use:
// initialize the factory paths IconFactory.setFullLocationPath("/com/metamatrix/modeler/images/"); IconFactory.setRelativeLocationPath("../images/"); ... // use the factory ImageIcon imageIcon = IconFactory.getIconForImageFile("splash.jpg"); JLabel imageLabel = new JLabel(imageIcon);
IconFactory was designed assuming all images for an application would be located in a single directory. If images are in multiple locations, you could set one location as the default, then for other locations use the getIconForImageFile( ) method where the full and relative paths are specified explicitly.
Usage Note: Graphics file names are case sensitive in jar files, but may not be case sensitive on the file system. Always use case sensitive file names.
Constructor Summary | |
---|---|
IconFactory()
|
Method Summary | |
---|---|
static javax.swing.ImageIcon |
getIconForImageFile(java.lang.String fileName)
Generate an ImageIcon from the specified graphics file in the default locations. |
static javax.swing.ImageIcon |
getIconForImageFile(java.lang.String fileName,
java.lang.String jarPath,
java.lang.String relativePath)
Generate an ImageIcon from the specified graphics file. |
static void |
setDefaultJarPath(java.lang.String path)
Set the default path for the images resources as located within a jar. |
static void |
setDefaultRelativePath(java.lang.String path)
Set the default path for the images resources as located on the file system. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IconFactory()
Method Detail |
---|
public static void setDefaultJarPath(java.lang.String path)
Set the default path for the images resources as located within a jar. Example:
IconFactory.setDefaultJarPath("/com/metamatrix/modeler/images/");
public static void setDefaultRelativePath(java.lang.String path)
Set the default path for the images resources as located on the file system. Example:
IconFactory.setDefaultRelativePath("../images/");
path
- relative path string. Default value is "."public static javax.swing.ImageIcon getIconForImageFile(java.lang.String fileName)
fileName
- the name of the graphics file to be found either in the specified resource location or relative
path on the file system.
java.lang.RuntimeException
- if both defaultJarPath and defaultRelativePath properties are null for this
static class.public static javax.swing.ImageIcon getIconForImageFile(java.lang.String fileName, java.lang.String jarPath, java.lang.String relativePath)
fileName
- the name of the graphics file - case sensitive.jarPath
- the full path of the image resources. Example: /com/metamatrix/modeler/images/
relativePath
- the path on the file system relative to the current directory. Example: ../images/
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |