1 | // License: GPL. See LICENSE file for details.
|
---|
2 |
|
---|
3 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
4 |
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.MediaTracker;
|
---|
8 | import java.awt.Graphics2D;
|
---|
9 | import java.awt.Image;
|
---|
10 | import java.awt.Toolkit;
|
---|
11 | import java.awt.image.BufferedImage;
|
---|
12 | import java.io.File;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.ImageEntry;
|
---|
17 |
|
---|
18 | public 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 | }
|
---|