Changeset 9494 in osm for applications/viewer/jmapviewer/src/org/openstreetmap
- Timestamp:
- 2008-08-06T14:04:13+02:00 (16 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 4 added
- 8 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java
r9421 r9494 47 47 } 48 48 49 public void mouseMoved(MouseEvent e) {50 }51 52 49 public void mouseClicked(MouseEvent e) { 53 50 if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 54 51 map.zoomIn(e.getPoint()); 55 }56 57 public void mouseEntered(MouseEvent e) {58 }59 60 public void mouseExited(MouseEvent e) {61 52 } 62 53 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r9289 r9494 13 13 import javax.swing.JPanel; 14 14 15 15 16 /** 16 17 * … … 26 27 setSize(400, 400); 27 28 final JMapViewer map = new JMapViewer(); 29 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); 30 // map.setTileLoader(new OsmFileCacheTileLoader(map,OsmTileLoader.MAP_MAPNIK)); 31 new DefaultMapController(map); 28 32 setLayout(new BorderLayout()); 29 33 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); … … 87 91 */ 88 92 public static void main(String[] args) { 93 // Properties systemProperties = System.getProperties(); 94 // systemProperties.setProperty("http.proxyHost","localhost"); 95 // systemProperties.setProperty("http.proxyPort","8008"); 89 96 new Demo().setVisible(true); 90 97 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapController.java
r9421 r9494 26 26 public JMapController(JMapViewer map) { 27 27 this.map = map; 28 map.addMouseListener( (MouseListener)this);29 map.addMouseWheelListener( (MouseWheelListener)this);30 map.addMouseMotionListener( (MouseMotionListener)this);28 map.addMouseListener(this); 29 map.addMouseWheelListener(this); 30 map.addMouseMotionListener(this); 31 31 } 32 32 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r9421 r9494 12 12 import java.awt.geom.Point2D; 13 13 import java.awt.image.BufferedImage; 14 import java.io.InputStream;15 import java.net.HttpURLConnection;16 import java.net.URL;17 14 import java.util.LinkedList; 18 15 import java.util.List; … … 27 24 28 25 import org.openstreetmap.gui.jmapviewer.JobDispatcher.JobThread; 26 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 27 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 28 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; 29 29 30 30 /** … … 49 49 public static final int MIN_ZOOM = 0; 50 50 51 protected TileLoader tileLoader; 51 52 protected TileCache tileCache; 52 53 protected List<MapMarker> mapMarkerList; … … 90 91 public JMapViewer(TileCache tileCache, int downloadThreadCount) { 91 92 super(); 93 tileLoader = new OsmTileLoader(this); 92 94 this.tileCache = tileCache; 93 95 jobDispatcher = new JobDispatcher(downloadThreadCount); … … 442 444 } 443 445 if (!tile.isLoaded()) { 444 jobDispatcher.addJob(new Job() { 445 446 InputStream input = null; 447 448 public void run() { 449 Tile tile = tileCache.getTile(tilex, tiley, zoom); 450 if (tile == null || tile.isLoaded()) 451 return; 452 try { 453 // Thread.sleep(500); 454 URL url; 455 url = new URL("http://tile.openstreetmap.org/" + tile.getKey() + ".png"); 456 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 457 urlConn.setReadTimeout(30000); // 30 seconds read 458 // timeout 459 input = urlConn.getInputStream(); 460 tile.setImage(ImageIO.read(input)); 461 tile.setLoaded(true); 462 repaint(); 463 input.close(); 464 input = null; 465 } catch (Exception e) { 466 if (input == null /* || !input.isStopped() */) 467 System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley 468 + " " + e.getMessage()); 469 } 470 } 471 472 /** 473 * Terminating all transfers that are currently in progress 474 */ 475 public void stop() { 476 477 try { 478 // if (input != null) 479 // input.stop(); 480 } catch (Exception e) { 481 } 482 } 483 }); 446 tileLoader.addLoadRequest(tilex, tiley, zoom); 484 447 } 485 448 return tile; … … 538 501 } 539 502 503 public TileLoader getTileLoader() { 504 return tileLoader; 505 } 506 507 public void setTileLoader(TileLoader tileLoader) { 508 this.tileLoader = tileLoader; 509 } 510 540 511 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java
r9288 r9494 5 5 import java.util.concurrent.BlockingQueue; 6 6 import java.util.concurrent.LinkedBlockingQueue; 7 8 import org.openstreetmap.gui.jmapviewer.interfaces.Job; 7 9 8 10 /** … … 55 57 public JobThread(int threadId) { 56 58 super("OSMJobThread " + threadId); 59 setDaemon(true); 57 60 job = null; 58 61 start(); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapMarkerDot.java
r9095 r9494 6 6 import java.awt.Graphics; 7 7 import java.awt.Point; 8 9 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 8 10 9 11 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java
r9288 r9494 5 5 import java.util.Hashtable; 6 6 import java.util.logging.Logger; 7 8 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 7 9 8 10 /** … … 15 17 public class MemoryTileCache implements TileCache { 16 18 17 pr ivatestatic final Logger log = Logger.getLogger(MemoryTileCache.class.getName());19 protected static final Logger log = Logger.getLogger(MemoryTileCache.class.getName()); 18 20 19 21 /** … … 35 37 36 38 public void addTile(Tile tile) { 37 CacheEntry entry = newCacheEntry(tile);39 CacheEntry entry = createCacheEntry(tile); 38 40 hashtable.put(tile.getKey(), entry); 39 41 lruTiles.addFirst(entry); 40 42 if (hashtable.size() > cacheSize) 41 removeOld Tiles();43 removeOldEntries(); 42 44 } 43 45 … … 56 58 * Removes the least recently used tiles 57 59 */ 58 protected void removeOld Tiles() {60 protected void removeOldEntries() { 59 61 synchronized (lruTiles) { 60 62 try { 61 63 while (lruTiles.getElementCount() > cacheSize) { 62 CacheEntry entry = lruTiles.getLastElement(); 63 hashtable.remove(entry.tile.getKey()); 64 lruTiles.removeEntry(entry); 64 removeEntry(lruTiles.getLastElement()); 65 65 } 66 66 } catch (Exception e) { … … 68 68 } 69 69 } 70 } 71 72 protected void removeEntry(CacheEntry entry) { 73 hashtable.remove(entry.tile.getKey()); 74 lruTiles.removeEntry(entry); 75 } 76 77 protected CacheEntry createCacheEntry(Tile tile) { 78 return new CacheEntry(tile); 70 79 } 71 80 … … 87 96 this.cacheSize = cacheSize; 88 97 if (hashtable.size() > cacheSize) 89 removeOld Tiles();98 removeOldEntries(); 90 99 } 91 100 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r9288 r9494 7 7 import java.awt.geom.AffineTransform; 8 8 import java.awt.image.BufferedImage; 9 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 9 11 10 12 /** … … 22 24 protected String key; 23 25 protected boolean loaded = false; 26 protected boolean loading = false; 24 27 public static final int WIDTH = 256; 25 28 public static final int HEIGHT = 256; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/Job.java
r9288 r9494 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.interfaces; 2 2 3 3 //License: GPL. Copyright 2008 by Jan Peter Stotz -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/MapMarker.java
r9095 r9494 1 package org.openstreetmap.gui.jmapviewer ;1 package org.openstreetmap.gui.jmapviewer.interfaces; 2 2 3 3 //License: GPL. Copyright 2008 by Jan Peter Stotz … … 5 5 import java.awt.Graphics; 6 6 import java.awt.Point; 7 8 import org.openstreetmap.gui.jmapviewer.JMapViewer; 7 9 8 10 /** -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileCache.java
r9288 r9494 1 package org.openstreetmap.gui.jmapviewer; 1 package org.openstreetmap.gui.jmapviewer.interfaces; 2 3 import org.openstreetmap.gui.jmapviewer.JMapViewer; 4 import org.openstreetmap.gui.jmapviewer.Tile; 2 5 3 6 //License: GPL. Copyright 2008 by Jan Peter Stotz
Note:
See TracChangeset
for help on using the changeset viewer.