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 String
DEFAULT_IMAGE_DIR
the default path for images/icons.static String
EMPTY_ICON
the empty icon name.static String
KEY_IMAGES_DIRECTORY
the property in the GUIHelper.props with the default images dir.static String
KEY_THEME_IMAGES_DIRECTORY
the property in the GUIHelper.props with the theme images dir.protected static Map<String,BufferedImage>
m_BufferedImageCache
maps filename to buffered image.protected static Map<String,ImageIcon>
m_IconCache
maps filename to icon.protected static List<String>
m_ImageDirs
the directories to look for files.protected static Map<String,String>
m_NameCache
maps icon name to filename.
-
Constructor Summary
Constructors Constructor Description ImageManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
checkImageFilename(String dir, String name)
Checks whether an image with the given name is present in the specified directory.static ImageIcon
getEmptyIcon()
Returns the ImageIcon for the empty icon.static ImageIcon
getExternalIcon(String filename)
Returns an ImageIcon from the given name.static BufferedImage
getExternalImage(String filename)
Returns a BufferedImage from the given filename.static ImageIcon
getIcon(Class cls)
Returns an ImageIcon for the given class.static ImageIcon
getIcon(String name)
Returns an ImageIcon from the given name.static BufferedImage
getImage(String name)
Returns a BufferedImage from the given name.static String
getImageFilename(String name)
Tries to find an image with the specified name in one of the defined image directories.static ImageIcon
getLogoIcon()
Returns an ImageIcon of the logo (icon sized image).static ImageIcon
getLogoImage()
Returns an ImageIcon of the logo (large image).static boolean
hasImageFile(String name)
Checks whether the image is available.protected static void
initImageDirs()
Initializes the directories to look for images.protected static String
removeExtension(String name)
Removes the gif/png/jpg extension from the name, if any.static BufferedImage
toBufferedImage(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
-
-