Class ImageLoader

java.lang.Object
jmt.framework.gui.image.ImageLoader
Direct Known Subclasses:
ImageLoaderImpl

public abstract class ImageLoader extends Object

Name: ImageLoader

Description: A class used to load images. Each subclass must implement the getImageURL method to retrieve URL of resource to be loaded. This class holds a cache of loaded images. Cache size can be adjusted using the maxCache field.

Date: 23/gen/07 Time: 15:09:14

Version:
1.0
Author:
Bertoli Marco
  • Field Details

    • MODIFIER_MIRROR

      public static final String MODIFIER_MIRROR
      Modifier to be used for mirror images (rotated on y axis)
      See Also:
    • MODIFIER_ROTATE

      public static final String MODIFIER_ROTATE
      Modifier to be used for rotating images (rotated on y axis)
      See Also:
    • MODIFIER_MIRROR_AND_ROTATE

      public static final String MODIFIER_MIRROR_AND_ROTATE
      Modifier to be used for mirror images and rotating images (rotated on y axis)
      See Also:
    • MODIFIER_PRESSED

      public static final String MODIFIER_PRESSED
      Modifier to be used for pressed button images
      See Also:
    • MODIFIER_ROLLOVER

      public static final String MODIFIER_ROLLOVER
      Modifier to be used for rollover button images
      See Also:
    • MODIFIER_SELECTED

      public static final String MODIFIER_SELECTED
      Modifier to be used for selected (toggled) button images
      See Also:
    • maxCache

      protected int maxCache
      Maximum number of cached elements
    • iconCache

      protected HashMap<String, ImageIcon> iconCache
      Internal caching data structure
  • Constructor Details

    • ImageLoader

      public ImageLoader()
  • Method Details

    • getImageURL

      protected abstract URL getImageURL(String resourceName)
      Returns the url of a given resource
      Parameters:
      resourceName - name of the resource to be retrieved
      Returns:
      url of the resource or null if it was not found
    • loadIcon

      public ImageIcon loadIcon(String iconName)
      Loads an icon with specified name, and caches it.
      Parameters:
      iconName - name of the icon to be loaded
      Returns:
      icon if found, null otherwise
    • loadIcon

      public ImageIcon loadIcon(String iconName, String modifier)
      Loads an icon with specified name and modifier, and caches it.
      Parameters:
      iconName - name of the icon to be loaded
      modifier - modifier to be applied
      Returns:
      icon if found, null otherwise
    • loadIcon

      public ImageIcon loadIcon(String iconName, Dimension size)
      Loads an icon with specified name and size, caches it and then resizes it.
      Parameters:
      iconName - name of the icon to be loaded
      size - target dimension of image
      Returns:
      icon if found, null otherwise
    • loadIcon

      public ImageIcon loadIcon(String iconName, String modifier, Dimension size)
      Loads an icon with specified name, modifier and size, caches it and then resizes it.
      Parameters:
      iconName - name of the icon to be loaded
      modifier - modifier to be applied
      size - target dimension of image
      Returns:
      icon if found, null otherwise
    • loadIcon

      public ImageIcon loadIcon(String iconName, String modifier, Double angle)
      Loads an icon with specified name, modifier and size, caches it and then resizes it.
      Parameters:
      iconName - name of the icon to be loaded
      modifier - modifier to be applied
      angle - rotation angle of the image in degrees
      Returns:
      icon if found, null otherwise
    • deriveIconName

      public static String deriveIconName(String iconName, String modifier)
      Derives an icon name to apply suffixes before extension
      Parameters:
      iconName - name of the icon to be derived
      modifier - suffix to be appended
      Returns:
      derived name
    • applyModifier

      protected ImageIcon applyModifier(ImageIcon base, String modifier)
      Apply known modifiers to given image
      Parameters:
      base - base image to be modified
      modifier - modifier to be applied
      Returns:
      modified image
    • applyModifier

      protected ImageIcon applyModifier(ImageIcon base, String modifier, Double angle)
      Apply known modifiers to given image
      Parameters:
      base - base image to be modified
      modifier - modifier to be applied
      angle - rotation angle in degrees
      Returns:
      modified image
    • mergeIcons

      protected ImageIcon mergeIcons(ImageIcon background, ImageIcon overlay, Point cropMin, Point cropMax, Point move)
      Merge two icons together. Output icon dimension is the same as background one.
      Parameters:
      background - background icon
      overlay - overlay icon, needs to be transparent (will be moved and cropped)
      cropMin - minimum crop point for overlay icon (0,0 for no crop)
      cropMax - maximum crop point for overlay icon (width and height for no crop)
      move - upper left corner where cropped overlay image should be positioned on background image
      Returns:
      merged icon
    • mirrorImage

      protected ImageIcon mirrorImage(ImageIcon base)
      Rotates image on y axis
      Parameters:
      base - image to be modified
      Returns:
      mirrored image
    • rotate

      protected ImageIcon rotate(ImageIcon base, Double angle)
      Rotates image on y axis
      Parameters:
      base - image to be modified
      angle - rotation angle in degrees
      Returns:
      rotated image