Class CachedImageModel<Q,V>

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
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, io.clogr.Clogged, ImageModel, Model, PendingImageModel

public class CachedImageModel<Q,V> extends DefaultImageModel implements PendingImageModel, io.clogr.Clogged
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 
    A listener that changes the image URI when the an image is fetched into the cache.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The cached image query bound property.
    static final String
    The cached image URI bound property.

    Fields inherited from class com.globalmentor.beans.BoundPropertyObject

    NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS

    Fields inherited from interface io.guise.framework.model.ImageModel

    IMAGE_URI_PROPERTY

    Fields inherited from interface io.guise.framework.model.PendingImageModel

    IMAGE_PENDING_PROPERTY
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    com.globalmentor.cache.Cache<Q,V>
     
     
     
    boolean
     
    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(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
    Initiates pending by both a cached image key and cached image URI are available.

    Methods inherited from class io.guise.framework.model.DefaultImageModel

    getImageURI, setImageURI

    Methods inherited from class io.guise.framework.model.AbstractModel

    getEventListenerManager, getPlainText

    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 io.clogr.Clogged

    getLogger

    Methods inherited from interface io.guise.framework.model.ImageModel

    getImageURI, setImageURI

    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 Details

    • CACHED_IMAGE_QUERY_PROPERTY

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

      public static final String CACHED_IMAGE_URI_PROPERTY
      The cached image URI bound property.
  • Constructor Details

    • CachedImageModel

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

      public CachedImageModel(com.globalmentor.cache.Cache<Q,V> cache, 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:
      NullPointerException - if the given cache is null.
  • Method Details

    • getCache

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

      public 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(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:
      IllegalStateException - if the cached image URI is changed while the current image is pending.
      See Also:
    • 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:
      IllegalStateException - if the cached image query is changed while the current image is pending.
      See Also:
    • 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:
    • updatePending

      protected void updatePending()
      Initiates pending by both a cached image key and cached image URI are available.
      See Also: