source: josm/trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java@ 2593

Last change on this file since 2593 was 2593, checked in by bastiK, 14 years ago

forgot to add

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. See LICENSE file for details.
2
3package org.openstreetmap.josm.gui.layer.geoimage;
4
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.MediaTracker;
8import java.awt.Graphics2D;
9import java.awt.Image;
10import java.awt.Toolkit;
11import java.awt.image.BufferedImage;
12import java.io.File;
13import java.util.List;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.ImageEntry;
17
18public class ThumbsLoader implements Runnable {
19 List<ImageEntry> data;
20 public ThumbsLoader(List<ImageEntry> data) {
21 this.data = data;
22 }
23
24 public void run() {
25 System.err.println("Load Thumbnails");
26 MediaTracker tracker = new MediaTracker(Main.map.mapView);
27 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;
51 if (Main.map != null && Main.map.mapView != null) {
52 Main.map.mapView.repaint();
53 }
54 }
55 (new Thread() {
56 public void run() {
57 try {
58 Thread.sleep(200);
59 }
60 catch (InterruptedException ie) {}
61 System.gc();
62 }
63 }).start();
64
65// boolean error = tracker.isErrorID(1);
66// if (img != null && (img.getWidth(null) == 0 || img.getHeight(null) == 0)) {
67// error = true;
68// }
69
70
71 }
72
73 }
Note: See TracBrowser for help on using the repository browser.