- Timestamp:
- 2009-12-10T19:25:38+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r2592 r2606 644 644 645 645 if (yLayer.loadThumbs) { 646 Thread tl = new Thread(new ThumbsLoader(yLayer.data)); 647 tl.setPriority(Thread.MIN_PRIORITY); 648 tl.start(); 646 yLayer.thumbsloader = new ThumbsLoader(yLayer.data); 647 Thread t = new Thread(yLayer.thumbsloader); 648 t.setPriority(Thread.MIN_PRIORITY); 649 t.start(); 649 650 } 650 651 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r2592 r2606 72 72 73 73 boolean loadThumbs; 74 ThumbsLoader thumbsloader; 74 75 75 76 /* … … 542 543 543 544 ImageViewerDialog d = ImageViewerDialog.getInstance(); 544 // System.err.println(d.isDialogShowing());545 546 545 547 546 for (int i = data.size() - 1; i >= 0; --i) { … … 586 585 }); 587 586 } 587 588 @Override 589 public void destroy() { 590 if (thumbsloader != null) { 591 thumbsloader.stop = true; 592 } 593 } 588 594 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java
r2593 r2606 11 11 import java.awt.image.BufferedImage; 12 12 import java.io.File; 13 import java.util.ArrayList; 13 14 import java.util.List; 14 15 16 import org.openstreetmap.josm.io.CacheFiles; 15 17 import org.openstreetmap.josm.Main; 16 18 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.ImageEntry; 17 19 18 20 public class ThumbsLoader implements Runnable { 21 volatile boolean stop = false; 19 22 List<ImageEntry> data; 23 MediaTracker tracker; 24 CacheFiles cache; 25 boolean cacheOff = Main.pref.getBoolean("geoimage.noThumbnailCache", false); 26 20 27 public ThumbsLoader(List<ImageEntry> data) { 21 this.data = data; 28 this.data = new ArrayList<ImageEntry>(data); 29 if (!cacheOff) { 30 cache = new CacheFiles("geoimage-thumbnails", false); 31 cache.setExpire(CacheFiles.EXPIRE_NEVER, false); 32 cache.setMaxSize(120, false); 33 } 22 34 } 23 35 24 36 public void run() { 25 37 System.err.println("Load Thumbnails"); 26 MediaTrackertracker = new MediaTracker(Main.map.mapView);38 tracker = new MediaTracker(Main.map.mapView); 27 39 for (int i = 0; i < data.size(); i++) { 28 System.err.println("getImg "+i); 29 String path; 30 path = data.get(i).file.getPath(); 31 Image img = Toolkit.getDefaultToolkit().createImage(path); 32 tracker.addImage(img, 0); 33 try { 34 tracker.waitForID(0); 35 } catch (InterruptedException e) { 36 System.err.println("InterruptedException"); 37 return; // FIXME 38 } 39 BufferedImage scaledBI = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); 40 Graphics2D g = scaledBI.createGraphics(); 41 while (!g.drawImage(img, 0, 0, 16, 16, null)) 42 { 43 try { 44 Thread.sleep(10); 45 } catch(InterruptedException ie) {} 46 } 47 g.dispose(); 48 tracker.removeImage(img); 49 50 data.get(i).thumbnail = scaledBI; 40 if (stop) return; 41 System.err.print("fetching image "+i); 42 data.get(i).thumbnail = loadThumb(data.get(i)); 51 43 if (Main.map != null && Main.map.mapView != null) { 52 44 Main.map.mapView.repaint(); … … 63 55 }).start(); 64 56 65 // boolean error = tracker.isErrorID(1); 66 // if (img != null && (img.getWidth(null) == 0 || img.getHeight(null) == 0)) { 67 // error = true; 68 // } 69 70 57 } 58 59 private BufferedImage loadThumb(ImageEntry entry) { 60 final int size = 16; 61 final String cacheIdent = entry.file.toString()+":"+size; 62 63 if (!cacheOff) { 64 BufferedImage cached = cache.getImg(cacheIdent); 65 if(cached != null) { 66 System.err.println(" from cache"); 67 return cached; 68 } 69 } 70 71 Image img = Toolkit.getDefaultToolkit().createImage(entry.file.getPath()); 72 tracker.addImage(img, 0); 73 try { 74 tracker.waitForID(0); 75 } catch (InterruptedException e) { 76 System.err.println(" InterruptedException"); 77 return null; 78 } 79 BufferedImage scaledBI = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); 80 Graphics2D g = scaledBI.createGraphics(); 81 while (!g.drawImage(img, 0, 0, 16, 16, null)) 82 { 83 try { 84 Thread.sleep(10); 85 } catch(InterruptedException ie) {} //FIXME: timeout? 86 } 87 g.dispose(); 88 tracker.removeImage(img); 89 90 if (!cacheOff && scaledBI != null && scaledBI.getWidth() > 0) { 91 cache.saveImg(cacheIdent, scaledBI); 92 } 93 94 System.err.println(""); 95 return scaledBI; 71 96 } 72 97 -
trunk/src/org/openstreetmap/josm/io/CacheFiles.java
r2512 r2606 55 55 */ 56 56 public CacheFiles(String ident) { 57 String pref = Main.pref.getPluginsDirFile().getPath(); 57 this(ident, true); 58 } 59 60 public CacheFiles(String ident, boolean isPlugin) { 61 String pref = isPlugin ? Main.pref.getPluginsDirFile().getPath() : Main.pref.getPreferencesDir(); 62 58 63 boolean dir_writeable; 59 64 this.ident = ident;
Note:
See TracChangeset
for help on using the changeset viewer.