Changeset 8598 in josm
- Timestamp:
- 2015-07-12T23:55:18+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java
r8510 r8598 235 235 private void addWMSLayer(String title, String url) { 236 236 WMSLayer layer = new WMSLayer(new ImageryInfo(title, url)); 237 layer.checkGrabberType();238 237 Main.main.addLayer(layer); 239 238 } -
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r8514 r8598 15 15 import org.apache.commons.jcs.access.CacheAccess; 16 16 import org.apache.commons.jcs.auxiliary.AuxiliaryCache; 17 import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCache; 17 import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory; 18 import org.apache.commons.jcs.auxiliary.disk.behavior.IDiskCacheAttributes; 18 19 import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes; 19 20 import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory; … … 35 36 */ 36 37 public final class JCSCacheManager { 37 private static final Logger log= FeatureAdapter.getLogger(JCSCacheManager.class.getCanonicalName());38 private static final Logger LOG = FeatureAdapter.getLogger(JCSCacheManager.class.getCanonicalName()); 38 39 39 40 private static volatile CompositeCacheManager cacheManager = null; 40 41 private static long maxObjectTTL = Long.MAX_VALUE; 41 42 private static final String PREFERENCE_PREFIX = "jcs.cache"; 42 private static final IndexedDiskCacheFactory diskCacheFactory = new IndexedDiskCacheFactory();43 private static final AuxiliaryCacheFactory diskCacheFactory = new IndexedDiskCacheFactory(); 43 44 private static FileLock cacheDirLock = null; 44 45 … … 61 62 File cacheDirLockPath = new File(cacheDir, ".lock"); 62 63 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 63 log.log(Level.WARNING, "Cannot create cache dir lock file");64 LOG.log(Level.WARNING, "Cannot create cache dir lock file"); 64 65 } 65 66 cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock(); 66 67 67 68 if (cacheDirLock == null) 68 log.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache");69 LOG.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache"); 69 70 70 71 // raising logging level gives ~500x performance gain 71 72 // http://westsworld.dk/blog/2008/01/jcs-and-performance/ 72 Logger jcsLog = Logger.getLogger("org.apache.commons.jcs");73 final Logger jcsLog = Logger.getLogger("org.apache.commons.jcs"); 73 74 jcsLog.setLevel(Level.INFO); 74 75 jcsLog.setUseParentHandlers(false); … … 92 93 @Override 93 94 public void flush() { 95 // nothing to be done on flush 94 96 } 95 97 96 98 @Override 97 99 public void close() { 100 // nothing to be done on close 98 101 } 99 102 }); … … 131 134 * @param cacheName region name 132 135 * @param maxMemoryObjects number of objects to keep in memory 133 * @param maxDiskObjects number of objects to keep on disk (if cachePath provided)136 * @param maxDiskObjects maximum size of the objects stored on disk in kB 134 137 * @param cachePath path to disk cache. if null, no disk cache will be created 135 138 * @return cache access object … … 153 156 154 157 if (cachePath != null && cacheDirLock != null) { 155 I ndexedDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath);158 IDiskCacheAttributes diskAttributes = getDiskCacheAttributes(maxDiskObjects, cachePath); 156 159 diskAttributes.setCacheName(cacheName); 157 IndexedDiskCache<K, V> diskCache = diskCacheFactory.createCache(diskAttributes, cacheManager, null, new StandardSerializer()); 158 159 cc.setAuxCaches(new AuxiliaryCache[]{diskCache}); 160 try { 161 if (cc.getAuxCaches().length == 0) { 162 AuxiliaryCache<K, V> diskCache = diskCacheFactory.createCache(diskAttributes, cacheManager, null, new StandardSerializer()); 163 cc.setAuxCaches(new AuxiliaryCache[]{diskCache}); 164 } 165 } catch (Exception e) { 166 throw new RuntimeException(e); 167 } 160 168 } 161 169 return new CacheAccess<K, V>(cc); … … 173 181 } 174 182 175 private static I ndexedDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath) {183 private static IDiskCacheAttributes getDiskCacheAttributes(int maxDiskObjects, String cachePath) { 176 184 IndexedDiskCacheAttributes ret = new IndexedDiskCacheAttributes(); 185 ret.setDiskLimitType(IDiskCacheAttributes.DiskLimitType.SIZE); 177 186 ret.setMaxKeySize(maxDiskObjects); 178 187 if (cachePath != null) { 179 188 File path = new File(cachePath); 180 189 if (!path.exists() && !path.mkdirs()) { 181 log.log(Level.WARNING, "Failed to create cache path: {0}", cachePath);190 LOG.log(Level.WARNING, "Failed to create cache path: {0}", cachePath); 182 191 } else { 183 192 ret.setDiskPath(path); -
trunk/src/org/openstreetmap/josm/data/imagery/CachedTileLoaderFactory.java
r8530 r8598 3 3 4 4 import java.io.File; 5 import java. io.IOException;6 import java. util.HashMap;5 import java.lang.reflect.Constructor; 6 import java.lang.reflect.InvocationTargetException; 7 7 import java.util.Map; 8 import java.util.concurrent.ConcurrentHashMap; 8 9 10 import org.apache.commons.jcs.access.behavior.ICacheAccess; 9 11 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 10 12 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 11 13 import org.openstreetmap.josm.Main; 12 14 import org.openstreetmap.josm.data.Version; 15 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 13 16 import org.openstreetmap.josm.data.preferences.StringProperty; 14 17 … … 19 22 * @since 8526 20 23 */ 21 public abstractclass CachedTileLoaderFactory implements TileLoaderFactory {24 public class CachedTileLoaderFactory implements TileLoaderFactory { 22 25 /** 23 26 * Keeps the cache directory where 24 27 */ 25 28 public static final StringProperty PROP_TILECACHE_DIR = getTileCacheDir(); 26 private String cacheName; 29 private ICacheAccess<String, BufferedImageCacheEntry> cache; 30 private Constructor<? extends TileLoader> tileLoaderConstructor; 27 31 28 32 /** 29 * @param cacheName name of the cache region, that the created loader will use 33 * @param cache cache instance which will be used by tile loaders created by this tile loader 34 * @param tileLoaderClass tile loader class that will be created 35 * 30 36 */ 31 public CachedTileLoaderFactory(String cacheName) { 32 this.cacheName = cacheName; 37 public CachedTileLoaderFactory(ICacheAccess<String, BufferedImageCacheEntry> cache, Class<? extends TileLoader> tileLoaderClass) { 38 this.cache = cache; 39 try { 40 tileLoaderConstructor = tileLoaderClass.getConstructor( 41 TileLoaderListener.class, 42 ICacheAccess.class, 43 int.class, 44 int.class, 45 Map.class); 46 } catch (NoSuchMethodException | SecurityException e) { 47 Main.warn(e); 48 throw new RuntimeException(e); 49 } 33 50 } 34 51 … … 50 67 @Override 51 68 public TileLoader makeTileLoader(TileLoaderListener listener, Map<String, String> inputHeaders) { 52 Map<String, String> headers = new HashMap<>();69 Map<String, String> headers = new ConcurrentHashMap<>(); 53 70 headers.put("User-Agent", Version.getInstance().getFullAgentString()); 54 71 headers.put("Accept", "text/html, image/png, image/jpeg, image/gif, */*"); … … 56 73 headers.putAll(inputHeaders); 57 74 58 try { 59 return getLoader(listener, cacheName, 60 Main.pref.getInteger("socket.timeout.connect", 15) * 1000, 61 Main.pref.getInteger("socket.timeout.read", 30) * 1000, 62 headers, 63 PROP_TILECACHE_DIR.get()); 64 } catch (IOException e) { 65 Main.warn(e); 66 } 67 return null; 75 return getLoader(listener, cache, 76 Main.pref.getInteger("socket.timeout.connect", 15) * 1000, 77 Main.pref.getInteger("socket.timeout.read", 30) * 1000, 78 headers); 68 79 } 69 80 70 protected abstract TileLoader getLoader(TileLoaderListener listener, String cacheName, int connectTimeout, int readTimeout, 71 Map<String, String> headers, String cacheDir) throws IOException; 81 protected TileLoader getLoader(TileLoaderListener listener, ICacheAccess<String, BufferedImageCacheEntry> cache, 82 int connectTimeout, int readTimeout, Map<String, String> headers) { 83 try { 84 return tileLoaderConstructor.newInstance( 85 listener, 86 cache, 87 connectTimeout, 88 readTimeout, 89 headers); 90 } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 91 Main.warn(e); 92 throw new RuntimeException(e); 93 } 94 } 72 95 } -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java
r8530 r8598 17 17 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 18 18 import org.openstreetmap.josm.data.cache.HostLimitQueue; 19 import org.openstreetmap.josm.data.cache.JCSCacheManager;20 19 import org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob; 21 20 import org.openstreetmap.josm.data.preferences.IntegerProperty; … … 34 33 protected final Map<String, String> headers; 35 34 protected final TileLoaderListener listener; 36 private static final String PREFERENCE_PREFIX = "imagery.tms.cache.";37 38 /**39 * how many object on disk should be stored for TMS region. Average tile size is about 20kb. 25000 is around 500MB under this assumption40 */41 public static final IntegerProperty MAX_OBJECTS_ON_DISK = new IntegerProperty(PREFERENCE_PREFIX + "max_objects_disk", 25000);42 35 43 36 /** 44 37 * overrides the THREAD_LIMIT in superclass, as we want to have separate limit and pool for TMS 45 38 */ 39 46 40 public static final IntegerProperty THREAD_LIMIT = new IntegerProperty("imagery.tms.tmsloader.maxjobs", 25); 47 41 … … 51 45 public static final IntegerProperty HOST_LIMIT = new IntegerProperty("imagery.tms.tmsloader.maxjobsperhost", 6); 52 46 47 53 48 /** 54 49 * separate from JCS thread pool for TMS loader, so we can have different thread pools for default JCS … … 57 52 private static ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER = getNewThreadPoolExecutor("TMS downloader"); 58 53 54 59 55 private ThreadPoolExecutor downloadExecutor = DEFAULT_DOWNLOAD_JOB_DISPATCHER; 60 56 … … 62 58 * Constructor 63 59 * @param listener called when tile loading has finished 64 * @param name of the cache60 * @param cache of the cache 65 61 * @param connectTimeout to remote resource 66 62 * @param readTimeout to remote resource 67 63 * @param headers HTTP headers to be sent along with request 68 * @param cacheDir where cache file shall reside69 64 * @throws IOException when cache initialization fails 70 65 */ 71 public TMSCachedTileLoader(TileLoaderListener listener, String name, int connectTimeout, int readTimeout, 72 Map<String, String> headers, String cacheDir) throws IOException { 73 this.cache = JCSCacheManager.getCache(name, 74 200, // use fairly small memory cache, as cached objects are quite big, as they contain BufferedImages 75 MAX_OBJECTS_ON_DISK.get(), 76 cacheDir); 66 public TMSCachedTileLoader(TileLoaderListener listener, ICacheAccess<String, BufferedImageCacheEntry> cache, 67 int connectTimeout, int readTimeout, Map<String, String> headers) throws IOException { 68 this.cache = cache; 77 69 this.connectTimeout = connectTimeout; 78 70 this.readTimeout = readTimeout; … … 113 105 @Override 114 106 public void clearCache(TileSource source) { 115 this.cache. clear();107 this.cache.remove(source.getName() + ":"); 116 108 } 117 109 -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r8510 r8598 85 85 @Override 86 86 public String getCacheKey() { 87 if (tile != null) 88 return tile.getKey(); 87 if (tile != null) { 88 TileSource tileSource = tile.getTileSource(); 89 String tsName = tileSource.getName(); 90 if (tsName == null) { 91 tsName = ""; 92 } 93 return tsName.replace(":", "_") + ":" + tileSource.getTileId(tile.getZoom(), tile.getXtile(), tile.getYtile()); 94 } 89 95 return null; 90 96 } … … 128 134 } 129 135 130 private boolean isNoTileAtZoom() {131 if (attributes == null) {132 LOG.warning("Cache attributes are null");133 }134 return attributes != null && attributes.isNoTileAtZoom();135 }136 137 136 @Override 138 137 protected boolean isResponseLoadable(Map<String, List<String>> headers, int statusCode, byte[] content) { … … 148 147 protected boolean cacheAsEmpty() { 149 148 return isNoTileAtZoom() || super.cacheAsEmpty(); 150 }151 152 private boolean handleNoTileAtZoom() {153 if (isNoTileAtZoom()) {154 LOG.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);155 tile.setError("No tile at this zoom level");156 tile.putValue("tile-info", "no-tile");157 return true;158 }159 return false;160 149 } 161 150 … … 231 220 232 221 /** 222 * For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers) 223 * 224 * @return base URL of TMS or server url as defined in super class 225 */ 226 @Override 227 protected String getServerKey() { 228 TileSource ts = tile.getSource(); 229 if (ts instanceof AbstractTMSTileSource) { 230 return ((AbstractTMSTileSource) ts).getBaseUrl(); 231 } 232 return super.getServerKey(); 233 } 234 235 @Override 236 protected BufferedImageCacheEntry createCacheEntry(byte[] content) { 237 return new BufferedImageCacheEntry(content); 238 } 239 240 @Override 241 public void submit() { 242 submit(false); 243 } 244 245 @Override 246 protected CacheEntryAttributes parseHeaders(URLConnection urlConn) { 247 CacheEntryAttributes ret = super.parseHeaders(urlConn); 248 // keep the expiration time between MINIMUM_EXPIRES and MAXIMUM_EXPIRES, so we will cache the tiles 249 // at least for some short period of time, but not too long 250 if (ret.getExpirationTime() < MINIMUM_EXPIRES) { 251 ret.setExpirationTime(now + MINIMUM_EXPIRES); 252 } 253 if (ret.getExpirationTime() > MAXIMUM_EXPIRES) { 254 ret.setExpirationTime(now + MAXIMUM_EXPIRES); 255 } 256 return ret; 257 } 258 259 /** 233 260 * Method for getting the tile from cache only, without trying to reach remote resource 234 261 * @return tile or null, if nothing (useful) was found in cache … … 272 299 } 273 300 274 /** 275 * For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers) 276 * 277 * @return base URL of TMS or server url as defined in super class 278 */ 279 @Override 280 protected String getServerKey() { 281 TileSource ts = tile.getSource(); 282 if (ts instanceof AbstractTMSTileSource) { 283 return ((AbstractTMSTileSource) ts).getBaseUrl(); 284 } 285 return super.getServerKey(); 286 } 287 288 @Override 289 protected BufferedImageCacheEntry createCacheEntry(byte[] content) { 290 return new BufferedImageCacheEntry(content); 291 } 292 293 @Override 294 public void submit() { 295 submit(false); 296 } 297 298 @Override 299 protected CacheEntryAttributes parseHeaders(URLConnection urlConn) { 300 CacheEntryAttributes ret = super.parseHeaders(urlConn); 301 // keep the expiration time between MINIMUM_EXPIRES and MAXIMUM_EXPIRES, so we will cache the tiles 302 // at least for some short period of time, but not too long 303 if (ret.getExpirationTime() < MINIMUM_EXPIRES) { 304 ret.setExpirationTime(now + MINIMUM_EXPIRES); 305 } 306 if (ret.getExpirationTime() > MAXIMUM_EXPIRES) { 307 ret.setExpirationTime(now + MAXIMUM_EXPIRES); 308 } 309 return ret; 310 } 301 private boolean handleNoTileAtZoom() { 302 if (isNoTileAtZoom()) { 303 LOG.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile); 304 tile.setError("No tile at this zoom level"); 305 tile.putValue("tile-info", "no-tile"); 306 return true; 307 } 308 return false; 309 } 310 311 private boolean isNoTileAtZoom() { 312 if (attributes == null) { 313 LOG.warning("Cache attributes are null"); 314 } 315 return attributes != null && attributes.isNoTileAtZoom(); 316 } 317 318 311 319 } -
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r8584 r8598 5 5 6 6 import java.awt.Point; 7 import java.io.IOException;8 7 import java.text.DecimalFormat; 9 8 import java.text.DecimalFormatSymbols; 10 9 import java.text.NumberFormat; 11 import java.util.HashMap;12 10 import java.util.List; 13 11 import java.util.Locale; 14 12 import java.util.Map; 13 import java.util.concurrent.ConcurrentHashMap; 15 14 import java.util.regex.Matcher; 16 15 import java.util.regex.Pattern; … … 37 36 */ 38 37 public class TemplatedWMSTileSource extends TMSTileSource implements TemplatedTileSource { 39 private Map<String, String> headers = new HashMap<>();40 private List<String> serverProjections;38 private Map<String, String> headers = new ConcurrentHashMap<>(); 39 private final List<String> serverProjections; 41 40 private EastNorth topLeftCorner; 42 41 43 private static final String COOKIE_HEADER = "Cookie";44 42 private static final String PATTERN_HEADER = "\\{header\\(([^,]+),([^}]+)\\)\\}"; 45 43 private static final String PATTERN_PROJ = "\\{proj(\\([^})]+\\))?\\}"; … … 69 67 } 70 68 69 /** 70 * Initializes class with current projection in JOSM. This call is needed every time projection changes. 71 */ 71 72 public void initProjection() { 72 73 initProjection(Main.getProjection()); 73 74 } 74 75 76 /** 77 * Initializes class with projection in JOSM. This call is needed every time projection changes. 78 * @param proj new projection that shall be used for computations 79 */ 75 80 public void initProjection(Projection proj) { 76 81 Bounds bounds = proj.getWorldBoundsLatLon(); … … 93 98 94 99 @Override 95 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException{100 public String getTileUrl(int zoom, int tilex, int tiley) { 96 101 String myProjCode = Main.getProjection().toCode(); 97 102 … … 225 230 @Override 226 231 public int getTileXMax(int zoom) { 227 return getTileXMax(zoom, Main.getProjection()); 232 Projection proj = Main.getProjection(); 233 double scale = getDegreesPerTile(zoom); 234 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 235 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 236 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 237 return (int) Math.ceil(Math.abs(max.getX() - min.getX()) / scale); 228 238 } 229 239 … … 233 243 } 234 244 235 //TODO: cache this method with projection code as the key236 245 @Override 237 246 public int getTileYMax(int zoom) { 238 return getTileYMax(zoom, Main.getProjection()); 247 Projection proj = Main.getProjection(); 248 double scale = getDegreesPerTile(zoom); 249 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 250 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 251 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 252 return (int) Math.ceil(Math.abs(max.getY() - min.getY()) / scale); 239 253 } 240 254 … … 347 361 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 348 362 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 349 int tilesPerZoom = (int) Math.pow(2, zoom );350 double ret =Math.max(363 int tilesPerZoom = (int) Math.pow(2, zoom - 1); 364 return Math.max( 351 365 Math.abs(max.getY() - min.getY()) / tilesPerZoom, 352 366 Math.abs(max.getX() - min.getX()) / tilesPerZoom 353 367 ); 354 355 return ret; 356 } 357 358 private int getTileYMax(int zoom, Projection proj) { 359 double scale = getDegreesPerTile(zoom); 360 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 361 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 362 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 363 return (int) Math.ceil(Math.abs(max.getY() - min.getY()) / scale); 364 } 365 366 private int getTileXMax(int zoom, Projection proj) { 367 double scale = getDegreesPerTile(zoom); 368 Bounds bounds = Main.getProjection().getWorldBoundsLatLon(); 369 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 370 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 371 return (int) Math.ceil(Math.abs(max.getX() - min.getX()) / scale); 368 } 369 370 @Override 371 public String getTileId(int zoom, int tilex, int tiley) { 372 return getTileUrl(zoom, tilex, tiley); 372 373 } 373 374 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMSCachedTileLoader.java
r8530 r8598 5 5 import java.util.Map; 6 6 7 import org.apache.commons.jcs.access.behavior.ICacheAccess; 7 8 import org.openstreetmap.gui.jmapviewer.Tile; 8 9 import org.openstreetmap.gui.jmapviewer.interfaces.TileJob; 9 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 10 import org.openstreetmap.josm.data. preferences.IntegerProperty;11 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 11 12 12 13 /** … … 19 20 public class WMSCachedTileLoader extends TMSCachedTileLoader { 20 21 21 /** limit of concurrent connections to WMS tile source (per source) */22 public static final IntegerProperty THREAD_LIMIT = new IntegerProperty("imagery.wms.simultaneousConnections", 3);23 24 22 /** 25 23 * Creates a TileLoader with separate WMS downloader. 26 24 * 27 25 * @param listener that will be notified when tile is loaded 28 * @param name name of the cache region26 * @param cache reference 29 27 * @param connectTimeout to tile source 30 28 * @param readTimeout from tile source 31 29 * @param headers to be sent with requests 32 * @param cacheDir place to store the cache33 30 * @throws IOException when there is a problem creating cache repository 34 31 */ 35 public WMSCachedTileLoader(TileLoaderListener listener, String name, int connectTimeout, int readTimeout,36 Map<String, String> headers, String cacheDir) throws IOException {32 public WMSCachedTileLoader(TileLoaderListener listener, ICacheAccess<String, BufferedImageCacheEntry> cache, 33 int connectTimeout, int readTimeout, Map<String, String> headers) throws IOException { 37 34 38 super(listener, name, connectTimeout, readTimeout, headers, cacheDir);35 super(listener, cache, connectTimeout, readTimeout, headers); 39 36 setDownloadExecutor(TMSCachedTileLoader.getNewThreadPoolExecutor("WMS downloader", THREAD_LIMIT.get())); 40 37 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMSCachedTileLoaderJob.java
r8530 r8598 40 40 String key = super.getCacheKey(); 41 41 if (key != null) { 42 return Main.getProjection().toCode() + key;42 return key + Main.getProjection().toCode(); 43 43 } 44 44 return null; -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r8586 r8598 15 15 import java.util.Collection; 16 16 import java.util.Comparator; 17 import java.util.HashMap;18 17 import java.util.Map; 19 18 import java.util.Set; … … 27 26 import javax.swing.JPanel; 28 27 import javax.swing.ListSelectionModel; 28 import javax.xml.XMLConstants; 29 29 import javax.xml.namespace.QName; 30 30 import javax.xml.parsers.DocumentBuilder; 31 31 import javax.xml.parsers.DocumentBuilderFactory; 32 import javax.xml.parsers.ParserConfigurationException; 32 33 import javax.xml.xpath.XPath; 33 34 import javax.xml.xpath.XPathConstants; … … 43 44 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 44 45 import org.openstreetmap.josm.Main; 45 import org.openstreetmap.josm.data.Bounds;46 46 import org.openstreetmap.josm.data.coor.EastNorth; 47 47 import org.openstreetmap.josm.data.coor.LatLon; … … 53 53 import org.openstreetmap.josm.tools.GBC; 54 54 import org.openstreetmap.josm.tools.Utils; 55 import org.w3c.dom.DOMException;56 55 import org.w3c.dom.Document; 57 56 import org.w3c.dom.Node; … … 75 74 76 75 private static class TileMatrix { 77 String identifier;78 double scaleDenominator;79 EastNorth topLeftCorner;80 int tileWidth;81 int tileHeight;82 p ublicint matrixWidth = -1;83 p ublicint matrixHeight = -1;76 private String identifier; 77 private double scaleDenominator; 78 private EastNorth topLeftCorner; 79 private int tileWidth; 80 private int tileHeight; 81 private int matrixWidth = -1; 82 private int matrixHeight = -1; 84 83 } 85 84 … … 92 91 } 93 92 }); // sorted by zoom level 94 String crs;95 String identifier;93 private String crs; 94 private String identifier; 96 95 } 97 96 98 97 private static class Layer { 99 String format;100 String name;101 Map<String, TileMatrixSet> tileMatrixSetByCRS = new ConcurrentHashMap<>();102 p ublicString baseUrl;103 p ublicString style;98 private String format; 99 private String name; 100 private Map<String, TileMatrixSet> tileMatrixSetByCRS = new ConcurrentHashMap<>(); 101 private String baseUrl; 102 private String style; 104 103 } 105 104 … … 129 128 130 129 private static final class SelectLayerDialog extends ExtendedDialog { 131 private Layer[] layers;132 private JList<String> list;133 134 p rivateSelectLayerDialog(Collection<Layer> layers) {130 private final Layer[] layers; 131 private final JList<String> list; 132 133 public SelectLayerDialog(Collection<Layer> layers) { 135 134 super(Main.parent, tr("Select WMTS layer"), new String[]{tr("Add layers"), tr("Cancel")}); 136 135 this.layers = layers.toArray(new Layer[]{}); … … 143 142 } 144 143 145 private String[] getLayerNames(Collection<Layer> layers) {144 private static final String[] getLayerNames(Collection<Layer> layers) { 146 145 Collection<String> ret = new ArrayList<>(); 147 146 for (Layer layer: layers) { … … 160 159 } 161 160 162 private Map<String, String> headers = newHashMap<>();161 private final Map<String, String> headers = new ConcurrentHashMap<>(); 163 162 private Collection<Layer> layers; 164 163 private Layer currentLayer; … … 177 176 this.layers = getCapabilities(); 178 177 if (layers.size() > 1) { 179 SelectLayerDialog layerSelection = new SelectLayerDialog(layers);178 final SelectLayerDialog layerSelection = new SelectLayerDialog(layers); 180 179 if (layerSelection.showDialog().getValue() == 1) { 181 180 this.currentLayer = layerSelection.getSelectedLayer(); 182 // TODO: save layer information into ImageryInfo / ImageryPreferences 181 // TODO: save layer information into ImageryInfo / ImageryPreferences? 183 182 } else { 184 183 throw new IllegalArgumentException(); //user canceled operation … … 205 204 } 206 205 207 private Collection<Layer> getCapabilities() throws IOException 206 private Collection<Layer> getCapabilities() throws IOException { 208 207 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 209 208 builderFactory.setValidating(false); 210 209 builderFactory.setNamespaceAware(false); 210 try { 211 builderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); 212 } catch (ParserConfigurationException e) { 213 //this should not happen 214 throw new IllegalArgumentException(e); 215 } 211 216 DocumentBuilder builder = null; 212 217 InputStream in = new CachedFile(baseUrl). … … 266 271 } 267 272 268 private Map<String, TileMatrixSet> parseMatrices(NodeList nodeList) throws DOMException,XPathExpressionException {273 private Map<String, TileMatrixSet> parseMatrices(NodeList nodeList) throws XPathExpressionException { 269 274 Map<String, TileMatrixSet> ret = new ConcurrentHashMap<>(); 270 275 for (int matrixSetId = 0; matrixSetId < nodeList.getLength(); matrixSetId++) { … … 314 319 } 315 320 316 private int getOptionalIntegerByXpath(Node document, String xpathQuery) throws XPathExpressionException {321 private static int getOptionalIntegerByXpath(Node document, String xpathQuery) throws XPathExpressionException { 317 322 String ret = getStringByXpath(document, xpathQuery); 318 323 if (ret == null || "".equals(ret)) { … … 374 379 375 380 @Override 376 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException{381 public String getTileUrl(int zoom, int tilex, int tiley) { 377 382 String url; 378 383 switch (transferMode) { … … 471 476 @Override 472 477 public TileXY latLonToTileXY(double lat, double lon, int zoom) { 473 Projection proj = Main.getProjection();474 EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon));475 478 TileMatrix matrix = getTileMatrix(zoom); 476 479 if (matrix == null) { 477 480 return new TileXY(0, 0); 478 481 } 482 483 Projection proj = Main.getProjection(); 484 EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon)); 479 485 double scale = matrix.scaleDenominator * this.crsScale; 480 486 return new TileXY( … … 576 582 return 0; 577 583 } 584 585 @Override 586 public String getTileId(int zoom, int tilex, int tiley) { 587 return getTileUrl(zoom, tilex, tiley); 588 } 589 578 590 579 591 /** … … 617 629 618 630 double scale = matrix.scaleDenominator * this.crsScale; 619 Bounds bounds = proj.getWorldBoundsLatLon(); 620 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 621 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 631 EastNorth min = matrix.topLeftCorner; 632 EastNorth max = proj.latlon2eastNorth(proj.getWorldBoundsLatLon().getMax()); 622 633 return (int) Math.ceil(Math.abs(max.north() - min.north()) / scale); 623 634 } … … 633 644 634 645 double scale = matrix.scaleDenominator * this.crsScale; 635 Bounds bounds = proj.getWorldBoundsLatLon(); 636 EastNorth min = proj.latlon2eastNorth(bounds.getMin()); 637 EastNorth max = proj.latlon2eastNorth(bounds.getMax()); 646 EastNorth min = matrix.topLeftCorner; 647 EastNorth max = proj.latlon2eastNorth(proj.getWorldBoundsLatLon().getMax()); 638 648 return (int) Math.ceil(Math.abs(max.east() - min.east()) / scale); 639 649 } -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r8526 r8598 40 40 import org.openstreetmap.josm.data.imagery.ImageryInfo; 41 41 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 42 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 42 43 import org.openstreetmap.josm.data.preferences.StringProperty; 44 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; 43 45 import org.openstreetmap.josm.gui.layer.TMSLayer; 44 46 … … 139 141 headers.put("User-Agent", Version.getInstance().getFullAgentString()); 140 142 141 cachedLoader = TMSLayer.loaderFactory.makeTileLoader(this,headers);143 cachedLoader = AbstractCachedTileSourceLayer.getTileLoaderFactory("TMS", TMSCachedTileLoader.class).makeTileLoader(this, headers); 142 144 143 145 uncachedLoader = new OsmTileLoader(this); -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r8571 r8598 206 206 */ 207 207 public void clearTileCache(ProgressMonitor monitor) { 208 tileCache.clear();209 208 if (tileLoader instanceof CachedTileLoader) { 210 209 ((CachedTileLoader) tileLoader).clearCache(tileSource); 211 210 } 211 // if we use TMSCachedTileLoader, we already cleared by tile source, this is needed 212 // to prevent removal of additional objects 213 if (!(tileLoader instanceof TMSCachedTileLoader)) { 214 tileCache.clear(); 215 } 216 212 217 } 213 218 … … 1409 1414 } 1410 1415 } 1416 1417 if (zoom < getMinZoomLvl() && (ts.insane() || ts.tooLarge())) { 1418 myDrawString(g, tr("zoom in to load any tiles"), 120, 120); 1419 } 1420 1411 1421 if (noTilesAtZoom) { 1412 1422 myDrawString(g, tr("No tiles at this zoom level"), 120, 120); -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r8568 r8598 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 7 import java.util.Map; 8 6 import org.apache.commons.jcs.access.CacheAccess; 9 7 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;11 8 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 12 9 import org.openstreetmap.gui.jmapviewer.tilesources.ScanexTileSource; 13 10 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 14 11 import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource; 12 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 15 13 import org.openstreetmap.josm.data.imagery.CachedAttributionBingAerialTileSource; 16 import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;17 14 import org.openstreetmap.josm.data.imagery.ImageryInfo; 18 15 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 19 16 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 20 import org.openstreetmap.josm.data.imagery.TileLoaderFactory;21 17 import org.openstreetmap.josm.data.preferences.BooleanProperty; 22 18 import org.openstreetmap.josm.data.preferences.IntegerProperty; … … 32 28 * 33 29 */ 34 public class TMSLayer extends AbstractTileSourceLayer { 30 public class TMSLayer extends AbstractCachedTileSourceLayer { 31 private static final String CACHE_REGION_NAME = "TMS"; 32 35 33 private static final String PREFERENCE_PREFIX = "imagery.tms"; 36 34 … … 45 43 true); 46 44 47 /** loader factory responsible for loading tiles for this layer */48 public static TileLoaderFactory loaderFactory = new CachedTileLoaderFactory("TMS"){49 50 @Override51 protected TileLoader getLoader(TileLoaderListener listener, String cacheName, int connectTimeout,52 int readTimeout, Map<String, String> headers, String cacheDir) throws IOException {53 return new TMSCachedTileLoader(listener, cacheName, connectTimeout, readTimeout, headers, cacheDir);54 }55 56 };57 58 45 /** 59 46 * Create a layer based on ImageryInfo … … 64 51 } 65 52 66 /**67 * Plugins that wish to set custom tile loader should call this method68 * @param newLoaderFactory that will be used to load tiles69 */70 71 public static void setTileLoaderFactory(TileLoaderFactory newLoaderFactory) {72 loaderFactory = newLoaderFactory;73 }74 75 @Override76 protected TileLoaderFactory getTileLoaderFactory() {77 return loaderFactory;78 }79 53 80 54 /** … … 136 110 } 137 111 112 @Override 113 protected Class<? extends TileLoader> getTileLoaderClass() { 114 return TMSCachedTileLoader.class; 115 } 138 116 117 @Override 118 protected String getCacheName() { 119 return CACHE_REGION_NAME; 120 } 121 122 /** 123 * @return cache for TMS region 124 */ 125 public static CacheAccess<String, BufferedImageCacheEntry> getCache() { 126 return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME); 127 } 139 128 140 129 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r8557 r8598 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.io.IOException;8 7 import java.util.ArrayList; 9 8 import java.util.Arrays; 10 9 import java.util.List; 11 10 import java.util.Map; 11 import java.util.Set; 12 import java.util.TreeSet; 12 13 13 14 import javax.swing.AbstractAction; 14 15 import javax.swing.Action; 15 16 17 import org.apache.commons.jcs.access.CacheAccess; 16 18 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 17 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;18 19 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 19 20 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.data. imagery.CachedTileLoaderFactory;21 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 21 22 import org.openstreetmap.josm.data.imagery.ImageryInfo; 22 23 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 23 24 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 24 25 import org.openstreetmap.josm.data.imagery.TemplatedWMSTileSource; 25 import org.openstreetmap.josm.data.imagery.TileLoaderFactory;26 26 import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader; 27 27 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 34 34 * 35 35 */ 36 public class WMSLayer extends AbstractTileSourceLayer { 36 public class WMSLayer extends AbstractCachedTileSourceLayer { 37 private static final String PREFERENCE_PREFIX = "imagery.wms."; 38 37 39 /** default tile size for WMS Layer */ 38 public static final IntegerProperty PROP_IMAGE_SIZE = new IntegerProperty("imagery.wms.imageSize", 512); 40 public static final IntegerProperty PROP_IMAGE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + "imageSize", 512); 41 39 42 /** should WMS layer autozoom in default mode */ 40 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty("imagery.wms.default_autozoom", true); 41 private List<String> supportedProjections; 43 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty(PREFERENCE_PREFIX + "default_autozoom", true); 44 45 /** limit of concurrent connections to WMS tile source (per source) */ 46 public static final IntegerProperty THREAD_LIMIT = new IntegerProperty(PREFERENCE_PREFIX + "simultaneousConnections", 3); 47 48 private static final String CACHE_REGION_NAME = "WMS"; 49 50 private Set<String> supportedProjections; 42 51 43 52 /** … … 47 56 public WMSLayer(ImageryInfo info) { 48 57 super(info); 49 this.supportedProjections = info.getServerProjections(); 58 this.supportedProjections = new TreeSet<>(info.getServerProjections()); 59 this.autoZoom = PROP_DEFAULT_AUTOZOOM.get(); 60 50 61 } 51 62 … … 62 73 63 74 @Override 64 protected TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException{75 protected TileSource getTileSource(ImageryInfo info) { 65 76 if (info.getImageryType() == ImageryType.WMS && info.getUrl() != null) { 66 77 TemplatedWMSTileSource.checkUrl(info.getUrl()); … … 89 100 ImageryLayerInfo.addLayer(new ImageryInfo(info)); 90 101 } 91 }92 93 /**94 * Checks that WMS layer is a grabber-compatible one (HTML or WMS).95 * @throws IllegalStateException if imagery time is neither HTML nor WMS96 * @since 806897 */98 public void checkGrabberType() {99 }100 101 private static TileLoaderFactory loaderFactory = new CachedTileLoaderFactory("WMS") {102 @Override103 protected TileLoader getLoader(TileLoaderListener listener, String cacheName, int connectTimeout,104 int readTimeout, Map<String, String> headers, String cacheDir) throws IOException {105 return new WMSCachedTileLoader(listener, cacheName, connectTimeout, readTimeout, headers, cacheDir);106 }107 108 };109 110 @Override111 protected TileLoaderFactory getTileLoaderFactory() {112 return loaderFactory;113 102 } 114 103 … … 149 138 } 150 139 } 140 141 /** 142 * Checks that WMS layer is a grabber-compatible one (HTML or WMS). 143 * @throws IllegalStateException if imagery time is neither HTML nor WMS 144 * @since 8068 145 * @deprecated not implemented anymore 146 */ 147 @Deprecated 148 public void checkGrabberType() { 149 // not implemented 150 } 151 152 @Override 153 protected Class<? extends TileLoader> getTileLoaderClass() { 154 return WMSCachedTileLoader.class; 155 } 156 157 @Override 158 protected String getCacheName() { 159 return CACHE_REGION_NAME; 160 } 161 162 /** 163 * @return cache region for WMS layer 164 */ 165 public static CacheAccess<String, BufferedImageCacheEntry> getCache() { 166 return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME); 167 } 151 168 } -
trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java
r8586 r8598 3 3 4 4 import java.io.IOException; 5 import java.util.Map;6 5 6 import org.apache.commons.jcs.access.CacheAccess; 7 7 import org.openstreetmap.gui.jmapviewer.TileXY; 8 8 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 9 9 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;11 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 12 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;15 14 import org.openstreetmap.josm.data.imagery.ImageryInfo; 16 15 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 17 import org.openstreetmap.josm.data.imagery.TileLoaderFactory;18 16 import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader; 19 17 import org.openstreetmap.josm.data.imagery.WMTSTileSource; … … 32 30 * 33 31 */ 34 public class WMTSLayer extends Abstract TileSourceLayer {32 public class WMTSLayer extends AbstractCachedTileSourceLayer { 35 33 /** 36 34 * default setting of autozoom per layer 37 35 */ 38 36 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty("imagery.wmts.default_autozoom", true); 37 private static final String CACHE_REGION_NAME = "WMTS"; 39 38 40 39 … … 45 44 public WMTSLayer(ImageryInfo info) { 46 45 super(info); 47 } 48 49 private static TileLoaderFactory loaderFactory = new CachedTileLoaderFactory("WMTS") { 50 @Override 51 protected TileLoader getLoader(TileLoaderListener listener, String cacheName, int connectTimeout, 52 int readTimeout, Map<String, String> headers, String cacheDir) throws IOException { 53 return new WMSCachedTileLoader(listener, cacheName, connectTimeout, readTimeout, headers, cacheDir); 54 } 55 56 }; 57 58 @Override 59 protected TileLoaderFactory getTileLoaderFactory() { 60 return loaderFactory; 46 autoZoom = PROP_DEFAULT_AUTOZOOM.get(); 61 47 } 62 48 … … 126 112 ((WMTSTileSource) tileSource).initProjection(newValue); 127 113 } 114 115 @Override 116 protected Class<? extends TileLoader> getTileLoaderClass() { 117 return WMSCachedTileLoader.class; 118 } 119 120 @Override 121 protected String getCacheName() { 122 return CACHE_REGION_NAME; 123 } 124 125 /** 126 * @return cache region for WMTS layer 127 */ 128 public static CacheAccess<String, BufferedImageCacheEntry> getCache() { 129 return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME); 130 } 128 131 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java
r7937 r8598 15 15 import javax.swing.JPanel; 16 16 import javax.swing.JSlider; 17 import javax.swing.JSpinner; 18 import javax.swing.SpinnerNumberModel; 17 19 20 import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory; 21 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; 18 22 import org.openstreetmap.josm.gui.layer.ImageryLayer; 19 23 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 24 import org.openstreetmap.josm.gui.widgets.JosmTextField; 20 25 import org.openstreetmap.josm.tools.ColorHelper; 21 26 import org.openstreetmap.josm.tools.GBC; … … 31 36 private final JSlider fadeAmount = new JSlider(0, 100); 32 37 private final JosmComboBox<String> sharpen; 38 private final JosmTextField tilecacheDir = new JosmTextField(); 39 private final JSpinner maxElementsOnDisk; 40 private final JSpinner maxElementsInRam; 41 33 42 34 43 /** … … 37 46 public CommonSettingsPanel() { 38 47 super(new GridBagLayout()); 39 48 49 this.maxElementsInRam = new JSpinner(new SpinnerNumberModel( 50 AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get().intValue(), 0, Integer.MAX_VALUE, 1)); 51 this.maxElementsOnDisk = new JSpinner(new SpinnerNumberModel( 52 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().intValue(), 0, Integer.MAX_VALUE, 1)); 53 54 40 55 this.btnFadeColor = new JButton(); 41 56 … … 72 87 add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 73 88 add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL)); 89 90 add(new JLabel(tr("Tile cache directory: ")), GBC.std()); 91 add(GBC.glue(5, 0), GBC.std()); 92 add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL)); 93 94 add(new JLabel(tr("Maximum size of disk cache (per imagery) in MB: ")), GBC.std()); 95 add(GBC.glue(5, 0), GBC.std()); 96 add(this.maxElementsOnDisk, GBC.eol()); 97 98 add(new JLabel(tr("Maximum number of objects in memory cache: ")), GBC.std()); 99 add(GBC.glue(5, 0), GBC.std()); 100 add(this.maxElementsInRam, GBC.eol()); 74 101 } 75 102 76 103 /** 77 104 * Loads the common settings. … … 83 110 this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get()); 84 111 this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get()))); 112 this.tilecacheDir.setText(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get()); 113 this.maxElementsOnDisk.setValue(AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get()); 114 this.maxElementsInRam.setValue(AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get()); 115 85 116 } 86 117 87 118 /** 88 119 * Saves the common settings. … … 93 124 ImageryLayer.PROP_FADE_COLOR.put(this.btnFadeColor.getBackground()); 94 125 ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex()); 95 return false; 126 boolean restartRequired = false; 127 if (!AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().equals(this.maxElementsOnDisk.getValue())) { 128 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.put((Integer) this.maxElementsOnDisk.getValue()); 129 restartRequired = true; 130 } 131 132 133 if (!CachedTileLoaderFactory.PROP_TILECACHE_DIR.get().equals(this.tilecacheDir.getText())) { 134 restartRequired = true; 135 CachedTileLoaderFactory.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText()); 136 } 137 138 if (!AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get().equals(this.maxElementsInRam.getValue())) { 139 AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.put((Integer) this.maxElementsInRam.getValue()); 140 } 141 142 143 return restartRequired; 96 144 } 97 145 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r8568 r8598 73 73 public final class ImageryPreference extends DefaultTabPreferenceSetting { 74 74 75 private ImageryProvidersPanel imageryProviders; 76 private ImageryLayerInfo layerInfo; 77 78 private CommonSettingsPanel commonSettings; 79 private WMSSettingsPanel wmsSettings; 80 private TMSSettingsPanel tmsSettings; 81 75 82 /** 76 83 * Factory used to create a new {@code ImageryPreference}. … … 87 94 false, new JTabbedPane()); 88 95 } 89 90 private ImageryProvidersPanel imageryProviders;91 private ImageryLayerInfo layerInfo;92 93 private CommonSettingsPanel commonSettings;94 private WMSSettingsPanel wmsSettings;95 private TMSSettingsPanel tmsSettings;96 96 97 97 private void addSettingsSection(final JPanel p, String name, JPanel section) { … … 131 131 pane.addTab(tr("Settings"), buildSettingsPanel()); 132 132 pane.addTab(tr("Offset bookmarks"), new OffsetBookmarksPanel(gui)); 133 pane.addTab(tr("Cache contents") , new CacheContentsPanel()); 133 134 loadSettings(); 134 135 p.add(pane, GBC.std().fill(GBC.BOTH)); -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java
r8540 r8598 12 12 import javax.swing.SpinnerNumberModel; 13 13 14 import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;15 14 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 16 15 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob; 17 16 import org.openstreetmap.josm.gui.layer.TMSLayer; 18 import org.openstreetmap.josm.gui.widgets.JosmTextField;19 17 import org.openstreetmap.josm.tools.GBC; 20 18 … … 31 29 private final JSpinner maxZoomLvl; 32 30 private final JCheckBox addToSlippyMapChosser = new JCheckBox(); 33 private final JosmTextField tilecacheDir = new JosmTextField(); 34 private final JSpinner maxElementsOnDisk; 31 35 32 private final JSpinner maxConcurrentDownloads; 36 33 private final JSpinner maxDownloadsPerHost; … … 46 43 maxZoomLvl = new JSpinner(new SpinnerNumberModel( 47 44 TMSLayer.PROP_MAX_ZOOM_LVL.get().intValue(), TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1)); 48 maxElementsOnDisk = new JSpinner(new SpinnerNumberModel(49 TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get().intValue(), 0, Integer.MAX_VALUE, 1));50 45 maxConcurrentDownloads = new JSpinner(new SpinnerNumberModel( 51 46 TMSCachedTileLoaderJob.THREAD_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1)); 52 47 maxDownloadsPerHost = new JSpinner(new SpinnerNumberModel( 53 48 TMSCachedTileLoader.HOST_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1)); 49 54 50 55 51 add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); … … 73 69 add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL)); 74 70 75 add(new JLabel(tr("Tile cache directory: ")), GBC.std());76 add(GBC.glue(5, 0), GBC.std());77 add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL));78 79 71 add(new JLabel(tr("Maximum concurrent downloads: ")), GBC.std()); 80 72 add(GBC.glue(5, 0), GBC.std()); … … 84 76 add(GBC.glue(5, 0), GBC.std()); 85 77 add(maxDownloadsPerHost, GBC.eol()); 86 87 88 add(new JLabel(tr("Maximum elements in disk cache: ")), GBC.std());89 add(GBC.glue(5, 0), GBC.std());90 add(this.maxElementsOnDisk, GBC.eol());91 78 92 79 } … … 101 88 this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null)); 102 89 this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null)); 103 this.tilecacheDir.setText(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get());104 this.maxElementsOnDisk.setValue(TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get());105 90 this.maxConcurrentDownloads.setValue(TMSCachedTileLoaderJob.THREAD_LIMIT.get()); 106 91 this.maxDownloadsPerHost.setValue(TMSCachedTileLoader.HOST_LIMIT.get()); … … 114 99 boolean restartRequired = false; 115 100 116 if ( TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get() != this.addToSlippyMapChosser.isSelected()) {101 if (!TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get().equals(this.addToSlippyMapChosser.isSelected())) { 117 102 restartRequired = true; 118 103 } … … 122 107 TMSLayer.setMaxZoomLvl((Integer) this.maxZoomLvl.getValue()); 123 108 TMSLayer.setMinZoomLvl((Integer) this.minZoomLvl.getValue()); 124 125 if (!TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get().equals(this.maxElementsOnDisk.getValue())) {126 TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.put((Integer) this.maxElementsOnDisk.getValue());127 restartRequired = true;128 }129 109 130 110 if (!TMSCachedTileLoader.THREAD_LIMIT.get().equals(this.maxConcurrentDownloads.getValue())) { … … 138 118 } 139 119 140 if (!CachedTileLoaderFactory.PROP_TILECACHE_DIR.get().equals(this.tilecacheDir.getText())) {141 restartRequired = true;142 CachedTileLoaderFactory.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText());143 }144 145 120 return restartRequired; 146 121 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r8586 r8598 89 89 verifyBounds(wallonieBounds, testSource, 6, 1063, 1219); 90 90 verifyBounds(wallonieBounds, testSource, 11, 17724, 20324); 91 LatLon ll = new LatLon(testSource.tileXYToLatLon(1063, 1219, 6)); 92 91 } 92 93 @Test 94 public void testWALLONIENoMatrixDimension() throws MalformedURLException, IOException { 95 Main.setProjection(Projections.getProjectionByCode("EPSG:31370")); 96 WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml")); 97 Bounds wallonieBounds = new Bounds( 98 new LatLon(49.485372459967245, 2.840548314430268), 99 new LatLon(50.820959517561256, 6.427849693016202) 100 ); 101 102 verifyBounds(wallonieBounds, testSource, 6, 1063, 1219); 103 verifyBounds(wallonieBounds, testSource, 11, 17724, 20324); 93 104 } 94 105
Note:
See TracChangeset
for help on using the changeset viewer.