Package io.guise.framework.model
Class CachedImageModel<Q,V>
- java.lang.Object
-
- com.globalmentor.beans.BoundPropertyObject
-
- io.guise.framework.model.AbstractModel
-
- io.guise.framework.model.DefaultImageModel
-
- io.guise.framework.model.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 usingDefaultImageModel.setImageURI(URI)
and the cached image key is set usingsetCachedImageQuery(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.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CACHED_IMAGE_QUERY_PROPERTY
The cached image query bound property.static java.lang.String
CACHED_IMAGE_URI_PROPERTY
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, 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, ornull
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 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.guise.framework.model.ImageModel
getImageURI, setImageURI
-
-
-
-
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 isnull
.
-
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, ornull
if there is no cached image URI.- Throws:
java.lang.NullPointerException
- if the given cache isnull
.
-
-
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, ornull
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, ornull
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 interfacePendingImageModel
- 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 typeBoolean
.- Parameters:
newImagePending
-true
if the current image is a transitional image that is expected to change.- See Also:
PendingImageModel.IMAGE_PENDING_PROPERTY
-
updatePending
protected void updatePending()
Initiates pending by both a cached image key and cached image URI are available.- See Also:
getCachedImageURI()
,getCachedImageURI()
-
-