Class ImageCache

java.lang.Object
org.graphstream.ui.swing_viewer.util.ImageCache

public class ImageCache extends Object
A simple cache for images to avoid reloading them constantly and to allow sharing. TODO have a policy to release images if they have not been used for a given time.
  • Field Details

    • imageCache

      protected final Map<String,Image> imageCache
      The image cache.
    • dummy

      protected final Image dummy
      The dummy image used to mark a not found image (and avoid trying to reload it again and again).
    • defaultImageCache

      protected static ImageCache defaultImageCache
      The default singleton image cache instance.
  • Constructor Details

    • ImageCache

      public ImageCache()
      New empty image cache.
  • Method Details

    • defaultImageCache

      public static ImageCache defaultImageCache()
      Default singleton image cache instance that can be shared. This method and singleton must be used only in the Swing thread.
      Returns:
      The default singleton image cache instance.
    • getImage

      public Image getImage(String fileNameOrUrl)
      Lookup an image based on its name, if found return it, else try to load it. If an image is not found once, the cache remembers it and will not try to reload it again if the same image is requested anew. Therefore using getImage() is fast and smooth.
      Parameters:
      fileNameOrUrl - A file name or an URL pointing at the image.
      Returns:
      An image or null if the image cannot be found.
    • getImage

      public Image getImage(String fileNameOrUrl, boolean forceTryReload)
      The same as getImage(String) but you can force the cache to try to reload an image that where not found before.
      Parameters:
      fileNameOrUrl - A file name or an URL pointing at the image.
      forceTryReload - If true, try to reload an image that where not found before.
      Returns:
      An image or null if the image cannot be found.
    • getDummyImage

      public Image getDummyImage()
      A dummy 16x16 image.
      Returns:
      An image.