Class CachedImageModel<Q,​V>

  • Type Parameters:
    Q - The type of query used to request data from the cache.
    V - The type of value stored in the cache. Cache checking and possible fetching is initiated when both the image URI is set using DefaultImageModel.setImageURI(URI) and the cached image key is set using setCachedImageQuery(Object). The image URI is set automatically when the image is determined to have been fetched into the cache.
    All Implemented Interfaces:
    com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, ImageModel, Model, PendingImageModel

    public class CachedImageModel<Q,​V>
    extends DefaultImageModel
    implements PendingImageModel
    An image model that can initiate retrieval of an image from a cache and update the image when fetching succeeds.
    Author:
    Garret Wilson
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  CachedImageModel.CachedImageListener
      A listener that changes the image URI when the an image is fetched into the cache.
    • Constructor Summary

      Constructors 
      Constructor Description
      CachedImageModel​(com.globalmentor.cache.Cache<Q,​V> cache)
      Cache constructor.
      CachedImageModel​(com.globalmentor.cache.Cache<Q,​V> cache, java.net.URI cachedImageURI)
      Cached image URI constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.globalmentor.cache.Cache<Q,​V> getCache()  
      Q getCachedImageQuery()  
      java.net.URI getCachedImageURI()  
      boolean isImagePending()  
      void setCachedImageQuery​(Q newCachedImageQuery)
      The query to request an image from the cache, or null if the image should not be looked up from the cache.
      void setCachedImageURI​(java.net.URI newCachedImageURI)
      Sets the URI of the image.
      protected void setImagePending​(boolean newImagePending)
      Sets whether the current image is in the process of transitioning to some other value.
      protected void updatePending()
      Initiates pending by both a cached image key and cached image URI are available.
      • Methods inherited from class com.globalmentor.beans.BoundPropertyObject

        addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.globalmentor.beans.PropertyBindable

        addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
      • Methods inherited from interface com.globalmentor.beans.PropertyConstrainable

        addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
    • Field Detail

      • CACHED_IMAGE_QUERY_PROPERTY

        public static final java.lang.String CACHED_IMAGE_QUERY_PROPERTY
        The cached image query bound property.
      • CACHED_IMAGE_URI_PROPERTY

        public static final java.lang.String CACHED_IMAGE_URI_PROPERTY
        The cached image URI bound property.
    • Constructor Detail

      • CachedImageModel

        public CachedImageModel​(com.globalmentor.cache.Cache<Q,​V> cache)
        Cache constructor.
        Parameters:
        cache - The cache from which the image will be retrieved.
        Throws:
        java.lang.NullPointerException - if the given cache is null.
      • CachedImageModel

        public CachedImageModel​(com.globalmentor.cache.Cache<Q,​V> cache,
                                java.net.URI cachedImageURI)
        Cached image URI constructor.
        Parameters:
        cache - The cache from which the image will be retrieved.
        cachedImageURI - The cached image URI, which may be a resource URI, or null if there is no cached image URI.
        Throws:
        java.lang.NullPointerException - if the given cache is null.
    • Method Detail

      • getCache

        public com.globalmentor.cache.Cache<Q,​V> getCache()
        Returns:
        The cache from which images will be retrieved.
      • getCachedImageURI

        public java.net.URI getCachedImageURI()
        Returns:
        The cached image URI, which may be a resource URI, or null if there is no cached image URI.
      • setCachedImageURI

        public void setCachedImageURI​(java.net.URI newCachedImageURI)
        Sets the URI of the image. This is a bound property.
        Parameters:
        newCachedImageURI - The new URI of the image, which may be a resource URI.
        Throws:
        java.lang.IllegalStateException - if the cached image URI is changed while the current image is pending.
        See Also:
        CACHED_IMAGE_URI_PROPERTY
      • getCachedImageQuery

        public Q getCachedImageQuery()
        Returns:
        The query to request an image from the cache, or null if the image should not be looked up from the cache.
      • setCachedImageQuery

        public void setCachedImageQuery​(Q newCachedImageQuery)
        The query to request an image from the cache, or null if the image should not be looked up from the cache. Chaging the cached image query initiates a deferred retrieval of the image from the cache. This is a bound property.
        Parameters:
        newCachedImageQuery - The new query to request an image from the cache, or null if the image should not be looked up from the cache.
        Throws:
        java.lang.IllegalStateException - if the cached image query is changed while the current image is pending.
        See Also:
        CACHED_IMAGE_QUERY_PROPERTY
      • isImagePending

        public boolean isImagePending()
        Specified by:
        isImagePending in interface PendingImageModel
        Returns:
        Whether the current image is in the process of transitioning to some other value.
      • setImagePending

        protected void setImagePending​(boolean newImagePending)
        Sets whether the current image is in the process of transitioning to some other value. This is a bound property of type Boolean.
        Parameters:
        newImagePending - true if the current image is a transitional image that is expected to change.
        See Also:
        PendingImageModel.IMAGE_PENDING_PROPERTY