Class ImageManager


  • public class ImageManager
    extends Object
    Manages images and icons.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • 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_NameCache

        protected static Map<String,​String> m_NameCache
        maps icon name to filename.
      • m_IconCache

        protected static Map<String,​ImageIcon> m_IconCache
        maps filename to icon.
      • m_BufferedImageCache

        protected static Map<String,​BufferedImage> m_BufferedImageCache
        maps filename to buffered image.
      • m_ImageDirs

        protected static List<String> m_ImageDirs
        the directories to look for files.
    • Constructor Detail

      • ImageManager

        public ImageManager()
    • 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 image
        name - 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