Class ImageCache

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

public class ImageCache
extends java.lang.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.
  • Constructor Summary

    Constructors 
    Constructor Description
    ImageCache()
    New empty image cache.
  • Method Summary

    Modifier and Type Method Description
    static ImageCache defaultImageCache()
    Default singleton image cache instance that can be shared.
    java.awt.Image getDummyImage()
    A dummy 16x16 image.
    java.awt.Image getImage​(java.lang.String fileNameOrUrl)
    Lookup an image based on its name, if found return it, else try to load it.
    java.awt.Image getImage​(java.lang.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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 java.awt.Image getImage​(java.lang.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 java.awt.Image getImage​(java.lang.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 java.awt.Image getDummyImage()
      A dummy 16x16 image.
      Returns:
      An image.