Package adams.gui.core
Class ImageManager
- java.lang.Object
-
- adams.gui.core.ImageManager
-
public class ImageManager extends Object
Manages images and icons.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_IMAGE_DIRthe default path for images/icons.static StringEMPTY_ICONthe empty icon name.static StringKEY_IMAGES_DIRECTORYthe property in the GUIHelper.props with the default images dir.static StringKEY_THEME_IMAGES_DIRECTORYthe property in the GUIHelper.props with the theme images dir.protected static Map<String,BufferedImage>m_BufferedImageCachemaps filename to buffered image.protected static Map<String,ImageIcon>m_IconCachemaps filename to icon.protected static List<String>m_ImageDirsthe directories to look for files.protected static Map<String,String>m_NameCachemaps icon name to filename.
-
Constructor Summary
Constructors Constructor Description ImageManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcheckImageFilename(String dir, String name)Checks whether an image with the given name is present in the specified directory.static ImageIcongetEmptyIcon()Returns the ImageIcon for the empty icon.static ImageIcongetExternalIcon(String filename)Returns an ImageIcon from the given name.static BufferedImagegetExternalImage(String filename)Returns a BufferedImage from the given filename.static ImageIcongetIcon(Class cls)Returns an ImageIcon for the given class.static ImageIcongetIcon(String name)Returns an ImageIcon from the given name.static BufferedImagegetImage(String name)Returns a BufferedImage from the given name.static StringgetImageFilename(String name)Tries to find an image with the specified name in one of the defined image directories.static ImageIcongetLogoIcon()Returns an ImageIcon of the logo (icon sized image).static ImageIcongetLogoImage()Returns an ImageIcon of the logo (large image).static booleanhasImageFile(String name)Checks whether the image is available.protected static voidinitImageDirs()Initializes the directories to look for images.protected static StringremoveExtension(String name)Removes the gif/png/jpg extension from the name, if any.static BufferedImagetoBufferedImage(RenderedImage image)Converts a RenderedImage into a BufferedImage.
-
-
-
Field Detail
-
EMPTY_ICON
public static final String EMPTY_ICON
the empty icon name.- See Also:
- Constant Field Values
-
DEFAULT_IMAGE_DIR
public static final String DEFAULT_IMAGE_DIR
the default path for images/icons.- See Also:
- Constant Field Values
-
KEY_IMAGES_DIRECTORY
public static final String KEY_IMAGES_DIRECTORY
the property in the GUIHelper.props with the default images dir.- See Also:
- Constant Field Values
-
KEY_THEME_IMAGES_DIRECTORY
public static final String KEY_THEME_IMAGES_DIRECTORY
the property in the GUIHelper.props with the theme images dir.- See Also:
- Constant Field Values
-
m_BufferedImageCache
protected static Map<String,BufferedImage> m_BufferedImageCache
maps filename to buffered image.
-
-
Method Detail
-
hasImageFile
public static boolean hasImageFile(String name)
Checks whether the image is available.- Parameters:
name- the name of the image (filename without path but with extension)- Returns:
- true if image exists
-
checkImageFilename
public static String checkImageFilename(String dir, String name)
Checks whether an image with the given name is present in the specified directory.- Parameters:
dir- the directory to look for imagename- the name of the image to look for- Returns:
- the full path of the image if present, otherwise null
-
removeExtension
protected static String removeExtension(String name)
Removes the gif/png/jpg extension from the name, if any.- Parameters:
name- the name to process- Returns:
- the processed name
-
initImageDirs
protected static void initImageDirs()
Initializes the directories to look for images.
-
getImageFilename
public static String getImageFilename(String name)
Tries to find an image with the specified name in one of the defined image directories. Automatically checks for .gif/.png/.jpg, therefore does not require an extension in the name.- Parameters:
name- the name of the image to add the path to- Returns:
- the full path of the image
-
getIcon
public static ImageIcon getIcon(Class cls)
Returns an ImageIcon for the given class.- Parameters:
cls- the class to get the icon for (gif, png or jpg)- Returns:
- the ImageIcon or null if none found
-
getIcon
public static ImageIcon getIcon(String name)
Returns an ImageIcon from the given name.- Parameters:
name- the filename without path- Returns:
- the ImageIcon or null if not available
-
getExternalIcon
public static ImageIcon getExternalIcon(String filename)
Returns an ImageIcon from the given name.- Parameters:
filename- the filename- Returns:
- the ImageIcon or null if not available
-
getEmptyIcon
public static ImageIcon getEmptyIcon()
Returns the ImageIcon for the empty icon.- Returns:
- the ImageIcon
-
getImage
public static BufferedImage getImage(String name)
Returns a BufferedImage from the given name.- Parameters:
name- the filename without path- Returns:
- the BufferedImage or null if not available/failed to load
-
getExternalImage
public static BufferedImage getExternalImage(String filename)
Returns a BufferedImage from the given filename.- Parameters:
filename- the full filename- Returns:
- the BufferedImage or null if not available/failed to load
-
getLogoImage
public static ImageIcon getLogoImage()
Returns an ImageIcon of the logo (large image).- Returns:
- the logo or null if none available
-
getLogoIcon
public static ImageIcon getLogoIcon()
Returns an ImageIcon of the logo (icon sized image).- Returns:
- the logo or null if none available
-
toBufferedImage
public static BufferedImage toBufferedImage(RenderedImage image)
Converts a RenderedImage into a BufferedImage.- Parameters:
image- the image to convert- Returns:
- the converted image
-
-