Changeset 28505 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2012-07-23T19:28:26+02:00 (12 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r28427 r28505 661 661 /** 662 662 * Decreases the current zoom level by one 663 * 664 * @param mapPoint point to choose as center for new zoom level 663 665 */ 664 666 public void zoomOut(Point mapPoint) { … … 666 668 } 667 669 670 /** 671 * Set the zoom level and center point for display 672 * 673 * @param zoom new zoom level 674 * @param mapPoint point to choose as center for new zoom level 675 */ 668 676 public void setZoom(int zoom, Point mapPoint) { 669 677 if (zoom > tileController.getTileSource().getMaxZoom() || zoom < tileController.getTileSource().getMinZoom() … … 678 686 } 679 687 688 /** 689 * Set the zoom level 690 * 691 * @param zoom new zoom level 692 */ 680 693 public void setZoom(int zoom) { 681 694 setZoom(zoom, new Point(getWidth() / 2, getHeight() / 2)); … … 859 872 } 860 873 861 /* 862 * (non-Javadoc) 863 * 864 * @see 865 * org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener#getTileCache 866 * () 874 /** 875 * Return tile information caching class 876 * @see TileLoaderListener#getTileCache() 867 877 */ 868 878 public TileCache getTileCache() { … … 877 887 878 888 /** 879 * @param listener to set889 * @param listener listener to set 880 890 */ 881 891 public void addJMVListener(JMapViewerEventListener listener) { … … 884 894 885 895 /** 886 * @param listener to remove896 * @param listener listener to remove 887 897 */ 888 898 public void removeJMVListener(JMapViewerEventListener listener) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java
r19231 r28505 3 3 //License: GPL. Copyright 2008 by Jan Peter Stotz 4 4 5 import java.util.concurrent.Blocking Queue;6 import java.util.concurrent.LinkedBlocking Queue;5 import java.util.concurrent.BlockingDeque; 6 import java.util.concurrent.LinkedBlockingDeque; 7 7 import java.util.concurrent.TimeUnit; 8 9 import org.openstreetmap.gui.jmapviewer.interfaces.TileJob; 8 10 9 11 /** … … 31 33 } 32 34 33 protected Blocking Queue<Runnable> jobQueue = new LinkedBlockingQueue<Runnable>();35 protected BlockingDeque<TileJob> jobQueue = new LinkedBlockingDeque<TileJob>(); 34 36 35 37 public static int WORKER_THREAD_MAX_COUNT = 8; … … 42 44 */ 43 45 public static int WORKER_THREAD_TIMEOUT = 30; 46 47 /** 48 * Type of queue, FIFO if <code>false</code>, LIFO if <code>true</code> 49 */ 50 protected boolean modeLIFO = false; 44 51 45 52 /** … … 65 72 } 66 73 67 public void addJob(Runnable job) { 74 /** 75 * Function to set the maximum number of workers for tile loading. 76 */ 77 static public void setMaxWorkers(int workers) { 78 WORKER_THREAD_MAX_COUNT = workers; 79 } 80 81 /** 82 * Function to set the LIFO/FIFO mode for tile loading job. 83 * 84 * @param lifo <code>true</code> for LIFO mode, <code>false</code> for FIFO mode 85 */ 86 public void setLIFO(boolean lifo) { 87 modeLIFO = lifo; 88 } 89 90 /** 91 * Adds a job to the queue. 92 * Jobs for tiles already contained in the are ignored (using a <code>null</code> tile 93 * prevents skipping). 94 * 95 * @param job the the job to be added 96 */ 97 public void addJob(TileJob job) { 68 98 try { 99 if(job.getTile() != null) { 100 for(TileJob oldJob : jobQueue) { 101 if(oldJob.getTile() == job.getTile()) { 102 return; 103 } 104 } 105 } 69 106 jobQueue.put(job); 70 107 if (workerThreadIdleCount == 0 && workerThreadCount < WORKER_THREAD_MAX_COUNT) … … 108 145 workerThreadIdleCount++; 109 146 } 110 if (firstThread) 111 job = jobQueue.take(); 112 else 113 job = jobQueue.poll(WORKER_THREAD_TIMEOUT, TimeUnit.SECONDS); 147 if(modeLIFO) { 148 if (firstThread) 149 job = jobQueue.takeLast(); 150 else 151 job = jobQueue.pollLast(WORKER_THREAD_TIMEOUT, TimeUnit.SECONDS); 152 } else { 153 if (firstThread) 154 job = jobQueue.take(); 155 else 156 job = jobQueue.poll(WORKER_THREAD_TIMEOUT, TimeUnit.SECONDS); 157 } 114 158 } catch (InterruptedException e1) { 115 159 return; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java
r18772 r28505 163 163 * Add the element to the head of the list. 164 164 * 165 * @param new element to be added165 * @param element new element to be added 166 166 */ 167 167 public synchronized void addFirst(CacheEntry element) { … … 181 181 182 182 /** 183 * Removes the specified elem ntent form the list.183 * Removes the specified element from the list. 184 184 * 185 * @param element 186 * to be removed 185 * @param element element to be removed 187 186 */ 188 187 public synchronized void removeEntry(CacheEntry element) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r28254 r28505 27 27 import java.util.logging.Logger; 28 28 29 import org.openstreetmap.gui.jmapviewer.interfaces.Tile Cache;29 import org.openstreetmap.gui.jmapviewer.interfaces.TileJob; 30 30 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 31 31 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; … … 90 90 * Create a OSMFileCacheTileLoader with given cache directory. 91 91 * If cacheDir is not set or invalid, IOException will be thrown. 92 * @param map 93 * @param cacheDir 92 * @param map the listener checking for tile load events (usually the map for display) 93 * @param cacheDir directory to store cached tiles 94 94 */ 95 95 public OsmFileCacheTileLoader(TileLoaderListener map, File cacheDir) throws IOException { … … 106 106 * Create a OSMFileCacheTileLoader with system property temp dir. 107 107 * If not set an IOException will be thrown. 108 * @param map 108 * @param map the listener checking for tile load events (usually the map for display) 109 109 */ 110 110 public OsmFileCacheTileLoader(TileLoaderListener map) throws SecurityException, IOException { … … 113 113 114 114 @Override 115 public Runnable createTileLoaderJob(final TileSource source, final int tilex, final int tiley, final int zoom) {116 return new FileLoadJob( source, tilex, tiley, zoom);115 public TileJob createTileLoaderJob(final Tile tile) { 116 return new FileLoadJob(tile); 117 117 } 118 118 … … 128 128 } 129 129 130 protected class FileLoadJob implements Runnable{130 protected class FileLoadJob implements TileJob { 131 131 InputStream input = null; 132 132 133 int tilex, tiley, zoom;134 133 Tile tile; 135 TileSource source;136 134 File tileCacheDir; 137 135 File tileFile = null; … … 139 137 boolean fileTilePainted = false; 140 138 141 public FileLoadJob(TileSource source, int tilex, int tiley, int zoom) { 142 this.source = source; 143 this.tilex = tilex; 144 this.tiley = tiley; 145 this.zoom = zoom; 139 public FileLoadJob(Tile tile) { 140 this.tile = tile; 141 } 142 143 public Tile getTile() { 144 return tile; 146 145 } 147 146 148 147 public void run() { 149 TileCache cache = listener.getTileCache(); 150 synchronized (cache) { 151 tile = cache.getTile(source, tilex, tiley, zoom); 152 if (tile == null || (tile.isLoaded() && !tile.hasError()) || tile.loading) 148 synchronized (tile) { 149 if ((tile.isLoaded() && !tile.hasError()) || tile.isLoading()) 153 150 return; 154 151 tile.loaded = false; … … 156 153 tile.loading = true; 157 154 } 158 tileCacheDir = getSourceCacheDir( source);159 if (loadTileFromFile()) 155 tileCacheDir = getSourceCacheDir(tile.getSource()); 156 if (loadTileFromFile()) { 160 157 return; 158 } 161 159 if (fileTilePainted) { 162 Runnable job = new Runnable() {160 TileJob job = new TileJob() { 163 161 164 162 public void run() { 165 163 loadOrUpdateTile(); 164 } 165 public Tile getTile() { 166 return tile; 166 167 } 167 168 }; … … 174 175 protected void loadOrUpdateTile() { 175 176 try { 176 // log.finest("Loading tile from OSM: " + tile);177 177 URLConnection urlConn = loadTileFromOsm(tile); 178 178 if (tileFile != null) { 179 switch ( source.getTileUpdate()) {179 switch (tile.getSource().getTileUpdate()) { 180 180 case IfModifiedSince: 181 181 urlConn.setIfModifiedSince(fileAge); … … 191 191 } 192 192 } 193 if ( source.getTileUpdate() == TileUpdate.ETag || source.getTileUpdate() == TileUpdate.IfNoneMatch) {193 if (tile.getSource().getTileUpdate() == TileUpdate.ETag || tile.getSource().getTileUpdate() == TileUpdate.IfNoneMatch) { 194 194 String fileETag = tile.getValue("etag"); 195 195 if (fileETag != null) { 196 switch ( source.getTileUpdate()) {196 switch (tile.getSource().getTileUpdate()) { 197 197 case IfNoneMatch: 198 198 urlConn.addRequestProperty("If-None-Match", fileETag); … … 245 245 listener.tileLoadingFinished(tile, false); 246 246 if (input == null) { 247 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage()); 247 try { 248 System.err.println("Failed loading " + tile.getUrl() +": " + e.getMessage()); 249 } catch(IOException i) { 250 } 248 251 } 249 252 } finally { … … 325 328 * <code>LastModified</code> header: 326 329 * <ul> 327 * <li>{@link OsmTileLoader#MAP_OSMA} - supported</li>328 * <li>{@link OsmTileLoader#MAP_MAPNIK} - not supported</li>330 * <li>{@link tilesources.OsmTileSource.CycleMap} - supported</li> 331 * <li>{@link tilesources.OsmTileSource.Mapnik} - not supported</li> 329 332 * </ul> 330 333 * 331 * @param fileAge 334 * @param fileAge time of the 332 335 * @return <code>true</code> if the tile on the server is newer than the 333 336 * file … … 368 371 protected File getTileFile() { 369 372 return new File(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() + "_" + tile.getYtile() + "." 370 + source.getTileType());373 + tile.getSource().getTileType()); 371 374 } 372 375 … … 379 382 try { 380 383 FileOutputStream f = new FileOutputStream(tileCacheDir + "/" + tile.getZoom() + "_" + tile.getXtile() 381 + "_" + tile.getYtile() + "." + source.getTileType());384 + "_" + tile.getYtile() + "." + tile.getSource().getTileType()); 382 385 f.write(rawData); 383 386 f.close(); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java
r26701 r28505 29 29 * TILE_WIDTH where TILE_WIDTH is the width of a tile in pixels 30 30 * 31 * @param aZoomlevel 32 * @return 31 * @param aZoomlevel zoom level to request pixel data 32 * @return number of pixels 33 33 */ 34 34 public static int getMaxPixels(int aZoomlevel) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java
r26938 r28505 12 12 import java.util.HashMap; 13 13 14 import org.openstreetmap.gui.jmapviewer.interfaces.Tile Cache;14 import org.openstreetmap.gui.jmapviewer.interfaces.TileJob; 15 15 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 16 16 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; … … 39 39 } 40 40 41 public Runnable createTileLoaderJob(final TileSource source, final int tilex, final int tiley, final int zoom) {42 return new Runnable() {41 public TileJob createTileLoaderJob(final Tile tile) { 42 return new TileJob() { 43 43 44 44 InputStream input = null; 45 45 46 46 public void run() { 47 TileCache cache = listener.getTileCache(); 48 Tile tile; 49 synchronized (cache) { 50 tile = cache.getTile(source, tilex, tiley, zoom); 51 if (tile == null || (tile.isLoaded() && !tile.hasError()) || tile.loading) 47 synchronized (tile) { 48 if ((tile.isLoaded() && !tile.hasError()) || tile.isLoading()) 52 49 return; 53 50 tile.loaded = false; … … 56 53 } 57 54 try { 58 // Thread.sleep(500);59 55 URLConnection conn = loadTileFromOsm(tile); 60 56 loadTileMetadata(tile, conn); … … 73 69 listener.tileLoadingFinished(tile, false); 74 70 if (input == null) { 75 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage()); 71 try { 72 System.err.println("Failed loading " + tile.getUrl() +": " + e.getMessage()); 73 } catch(IOException i) { 74 } 76 75 } 77 76 } finally { … … 81 80 } 82 81 82 public Tile getTile() { 83 return tile; 84 } 83 85 }; 84 86 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileController.java
r25369 r28505 26 26 * a load job is added to the working queue of {@link JobThread}. 27 27 * 28 * @param tilex 29 * @param tiley 30 * @param zoom 28 * @param tilex the X position of the tile 29 * @param tiley the Y position of the tile 30 * @param zoom the zoom level of the tile 31 31 * @return specified tile from the cache or <code>null</code> if the tile 32 32 * was not found in the cache. … … 43 43 } 44 44 if (!tile.isLoaded()) { 45 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tile Source, tilex, tiley, zoom));45 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tile)); 46 46 } 47 47 return tile; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapRectangle.java
r18890 r28505 15 15 * @see JMapViewer#addMapRectangle(MapRectangle) 16 16 * @see JMapViewer#getMapRectangleList() 17 * @date 21.06.2009S18 17 */ 19 18 public interface MapRectangle { … … 33 32 * <code>bottomRight</code> are specifying the coordinates within <code>g</code> 34 33 * 35 * @param g 36 * @param position 34 * @param g graphics structure for painting 35 * @param topLeft lop left edge of painting region 36 * @param bottomRight bottom right edge of painting region 37 37 */ 38 38 public void paint(Graphics g, Point topLeft, Point bottomRight); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoader.java
r18772 r28505 2 2 3 3 //License: GPL. Copyright 2008 by Jan Peter Stotz 4 5 import org.openstreetmap.gui.jmapviewer.Tile; 4 6 5 7 /** … … 12 14 13 15 /** 14 * A typical {@link #createTileLoaderJob(int, int, int)} implementation 15 * should create and return a new {@link Job} instance that performs the 16 * load action. 16 * A typical implementation of this function should create and return a 17 * new {@link TileJob} instance that performs the load action. 17 18 * 18 * @param tileLayerSource 19 * @param tilex 20 * @param tiley 21 * @param zoom 22 * @returns {@link Runnable} implementation that performs the desired load 19 * @param tile the tile to be loaded 20 * @return {@link TileJob} implementation that performs the desired load 23 21 * action. 24 22 */ 25 public Runnable createTileLoaderJob(TileSource tileLayerSource, int tilex, int tiley, int zoom);23 public TileJob createTileLoaderJob(Tile tile); 26 24 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileLoaderListener.java
r18772 r28505 15 15 public void tileLoadingFinished(Tile tile, boolean success); 16 16 17 /** 18 * Return the {@link TileCache} class containing {@link Tile} 19 * data for requested and loaded tiles 20 * 21 * @return tile information caching class 22 */ 17 23 public TileCache getTileCache(); 18 24 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/package.html
r16960 r28505 1 1 <html> 2 <head><title>org.openstreetmap.gui.jmapviewer</title></head> 2 3 <body> 3 <h1>org.openstreetmap.gui.jmapviewer</h1>4 4 <p>This package and all sub-packages are belonging to the Java 5 5 component <a href="http://wiki.openstreetmap.org/wiki/JMapViewer">JMapViewer</a> … … 9 9 depends on other libraries or applications</b>. Only functions and methods 10 10 provided by the runtime library of Java 5 should be used.</p> 11 <h2>In particular, this concerns the developer of JOSM!</h2>12 <p>2009-08-10 Jan Peter Stotz jpstotz@gmx.de (maintainer of JMapViewer)</p>13 11 </body> 14 12 </html>
Note:
See TracChangeset
for help on using the changeset viewer.