001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.plugins.streetside.cache; 003 004import java.net.URL; 005import java.util.HashMap; 006 007import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 008import org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob; 009import org.openstreetmap.josm.data.imagery.TileJobOptions; 010import org.openstreetmap.josm.plugins.streetside.utils.StreetsideURL.VirtualEarth; 011 012/** 013 * Stores the downloaded pictures locally. 014 * 015 * @author nokutu 016 * 017 */ 018public class StreetsideCache extends JCSCachedTileLoaderJob<String, BufferedImageCacheEntry> { 019 020 private final URL url; 021 private final String id; 022 023 /** 024 * Types of images. 025 * 026 * @author nokutu 027 */ 028 public enum Type { 029 /** Full quality image */ 030 FULL_IMAGE, 031 /** Low quality image */ 032 THUMBNAIL, 033 /** cubemap faces */ 034 // TODO: one class per cache/load required? really?! 035 CUBEMAP/*, 036 CUBEMAP_FRONT, 037 CUBEMAP_RIGHT, 038 CUBEMAP_BACK, 039 CUBEMAP_LEFT, 040 CUBEMAP_UP, 041 CUBEMAP_DOWN*/ 042 } 043 044 /** 045 * Main constructor. 046 * 047 * @param id 048 * The id of the image. 049 * @param type 050 * The type of image that must be downloaded (THUMBNAIL or 051 * FULL_IMAGE). 052 */ 053 public StreetsideCache(final String id, final Type type) { 054 //ICacheAccess<String,BufferedImageCacheEntry>,TileJobOptions,ThreadPoolExecutor 055 // TODO: StreetsideCache.java:53: error: no suitable constructor found for JCSCachedTileLoaderJob(CacheAccess<String,BufferedImageCacheEntry>,int,int,HashMap<String,String>) 056// [javac] super(Caches.ImageCache.getInstance().getCache(), 50000, 50000, new HashMap<String,String>()); 057// [javac] ^ 058// [javac] constructor JCSCachedTileLoaderJob.JCSCachedTileLoaderJob(ICacheAccess<String,BufferedImageCacheEntry>,TileJobOptions,ThreadPoolExecutor) is not applicable 059// [javac] (actual and formal argument lists differ in length) 060// [javac] constructor JCSCachedTileLoaderJob.JCSCachedTileLoaderJob(ICacheAccess<String,BufferedImageCacheEntry>,TileJobOptions) is not applicable 061// [javac] (actual and formal argument lists differ in length) 062 063 //super(Caches.ImageCache.getInstance().getCache(), 50000, 50000, new HashMap<String,String>()); 064 //super(Caches.ImageCache.getInstance().getCache(),TileJobOptions,ThreadpoolExecutor) 065 //TileJobOptions tjo = ; 066 super(Caches.ImageCache.getInstance().getCache(),new TileJobOptions(50000, 50000, new HashMap<String,String>(),50000l)); 067 068 if (id == null || type == null) { 069 this.id = null; 070 url = null; 071 } else { 072 //this.id = id + (type == Type.FULL_IMAGE ? ".FULL_IMAGE" : ".THUMBNAIL"); 073 // Add an "01" to the Streetside imageId in order to get a frontal thumbnail image for the display 074 this.id = id; 075 url = VirtualEarth.streetsideTile(id, type == Type.THUMBNAIL); 076 } 077 } 078 079 @Override 080 public String getCacheKey() { 081 return id; 082 } 083 084 @Override 085 public URL getUrl() { 086 return url; 087 } 088 089 @Override 090 protected BufferedImageCacheEntry createCacheEntry(byte[] content) { 091 return new BufferedImageCacheEntry(content); 092 } 093 094 @Override 095 protected boolean isObjectLoadable() { 096 if (cacheData == null) { 097 return false; 098 } 099 final byte[] content = cacheData.getContent(); 100 return content != null && content.length > 0; 101 } 102}