jview
Class ImageCache

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by jview.ImageCache
All Implemented Interfaces:
Cloneable, ConditionalRefreshing, Initializable, LocalizedSupplying, PropertySupplying, Refreshing, ResourceSupplying
Direct Known Subclasses:
CloudsCache

public class ImageCache
extends PropertyBundles
implements ConditionalRefreshing

A class to monitor an URL for a sequence of images. Two important times have to be distinguished: The main web-site refresh interval, i.e. the time at which the content of the URL is updated to show a new image, and the recording interval of the cache, which is at least as long as the web update interval. If you have a website that delivers an hourly update of an image, but you are only interested in the daily changes, leave the #KEY_WEBUPDATE interval at 3600 000ms, and set the #KEY_CACHEUPDATE to 86400 000ms. Subclasses may load specific images and allow some image-manipulation.

See Also:
Clouds

Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  SortedMap<Date,BufferedImage> cache
          The mapping of retrieval dates to images.
private static int DEFCACHESIZE
          Defaults to zero meaning unlimited cache size.
static String KEY_CACHEREFRESH
          Forced to be at least the web refresh interval, determines image seq.
static String KEY_CACHESIZE
          The maximum cache size.
static String KEY_IMAGEURL
          URL to read the cloud image from.
static String KEY_WEBREFRESH
          The web refresh interval, the time the URL is updated.
private  Date last
          The date of the last successful invokation.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
ImageCache(Map<String,String> prop)
          Defaults only the cache size.
 
Method Summary
protected  BufferedImage downloadImage(URL address, Date called)
          The default implementation simply downloads the image and adjusts the time stamp of the image retrieveal to additionally reflect the time it took for downloading.
protected  List<URL> getDownloadURL()
          In the default implementation we simply return the URL given by the KEY_IMAGEURL.
 Date getLastDate()
          Returns the last date in the cache.
 BufferedImage getLastImage()
          Returns the last buffered image in the cache.
 long getRefreshInterval()
          The refresh interval is our cache intervall, not the web refresh.
 void init()
          We throw an illegal argument if no download url has been given.
 boolean isFixedRate()
          We act like a cron, thus return true;
 boolean isRefreshNeeded()
          We return true if we request a new image.
 void refresh()
          On refresh, we download the image from the net and store it in the cache if successful.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_IMAGEURL

public static final String KEY_IMAGEURL
URL to read the cloud image from.

See Also:
Constant Field Values

KEY_WEBREFRESH

public static final String KEY_WEBREFRESH
The web refresh interval, the time the URL is updated.

See Also:
Constant Field Values

KEY_CACHEREFRESH

public static final String KEY_CACHEREFRESH
Forced to be at least the web refresh interval, determines image seq.

See Also:
Constant Field Values

KEY_CACHESIZE

public static final String KEY_CACHESIZE
The maximum cache size. Defaults to zero, meaning unlimited cache.

See Also:
Constant Field Values

DEFCACHESIZE

private static final int DEFCACHESIZE
Defaults to zero meaning unlimited cache size.

See Also:
Constant Field Values

cache

private SortedMap<Date,BufferedImage> cache
The mapping of retrieval dates to images.


last

private Date last
The date of the last successful invokation.

Constructor Detail

ImageCache

public ImageCache(Map<String,String> prop)
Defaults only the cache size.

Method Detail

init

public void init()
We throw an illegal argument if no download url has been given. We check the refresh rates to be compatible and create the cache.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

refresh

public void refresh()
On refresh, we download the image from the net and store it in the cache if successful.

Specified by:
refresh in interface Refreshing

isRefreshNeeded

public boolean isRefreshNeeded()
We return true if we request a new image.

Specified by:
isRefreshNeeded in interface ConditionalRefreshing

getRefreshInterval

public long getRefreshInterval()
The refresh interval is our cache intervall, not the web refresh.

Specified by:
getRefreshInterval in interface Refreshing

isFixedRate

public boolean isFixedRate()
We act like a cron, thus return true;

Specified by:
isFixedRate in interface Refreshing
See Also:
Timer

getLastImage

public BufferedImage getLastImage()
Returns the last buffered image in the cache. If used together with getLastDate() consider synchronizing in multithreaded environments.


getLastDate

public Date getLastDate()
Returns the last date in the cache.


getDownloadURL

protected List<URL> getDownloadURL()
In the default implementation we simply return the URL given by the KEY_IMAGEURL.


downloadImage

protected BufferedImage downloadImage(URL address,
                                      Date called)
                               throws IOException
The default implementation simply downloads the image and adjusts the time stamp of the image retrieveal to additionally reflect the time it took for downloading.

Throws:
IOException