source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java@ 18408

Last change on this file since 18408 was 18278, checked in by pieren, 15 years ago

fix some warnings and easier selection of WMSlayer in WMSAdjustAction

File size: 5.2 KB
Line 
1package cadastre_fr;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.io.IOException;
6import java.util.concurrent.Future;
7
8import javax.swing.JDialog;
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.Bounds;
13import org.openstreetmap.josm.gui.MapView;
14import org.openstreetmap.josm.gui.PleaseWaitRunnable;
15
16public class DownloadWMSPlanImage {
17
18 private Future<Task> task = null;
19 private WMSLayer wmsLayer;
20 private Bounds bounds;
21 private boolean dontGeoreference = false;
22
23 private class Task extends PleaseWaitRunnable {
24 private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
25 public Task(WMSLayer wmsLayer, Bounds bounds) {
26 super(tr("Downloading {0}", wmsLayer.getName()));
27 }
28
29 @Override
30 public void realRun() throws IOException {
31 progressMonitor.indeterminateSubTask(tr("Contacting cadastre WMS ..."));
32 try {
33 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
34 if (!wmsLayer.images.isEmpty()) {
35 //JOptionPane.showMessageDialog(Main.parent,tr("Image already loaded"));
36 JOptionPane pane = new JOptionPane(
37 tr("Image already loaded")
38 , JOptionPane.INFORMATION_MESSAGE);
39 // this below is a temporary workaround to fix the "always on top" issue
40 JDialog dialog = pane.createDialog(Main.parent, "");
41 CadastrePlugin.prepareDialog(dialog);
42 dialog.setVisible(true);
43 // till here
44 dontGeoreference = true;
45 } else if (grabber.getWmsInterface().downloadCancelled){
46 // do nothing
47 } else {
48 // first time we grab an image for this layer
49 if (CacheControl.cacheEnabled) {
50 if (wmsLayer.getCacheControl().loadCacheIfExist()) {
51 dontGeoreference = true;
52 Main.map.mapView.repaint();
53 return;
54 }
55 }
56 if (wmsLayer.isRaster()) {
57 // set raster image commune bounding box based on current view (before adjustment)
58 grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer);
59 wmsLayer.setRasterBounds(bounds);
60 // grab new images from wms server into active layer
61 wmsLayer.grab(grabber, bounds);
62 if (grabber.getWmsInterface().downloadCancelled) {
63 wmsLayer.images.clear();
64 Main.map.mapView.repaint();
65 } else {
66 // next steps follow in method finish() when download is terminated
67 wmsLayer.joinRasterImages();
68 }
69 } else {
70 /*JOptionPane.showMessageDialog(Main.parent,tr("Municipality vectorized !\n"+
71 "Use the normal Cadastre Grab menu."));*/
72 JOptionPane pane = new JOptionPane(
73 tr("Municipality vectorized !\nUse the normal Cadastre Grab menu.")
74 , JOptionPane.INFORMATION_MESSAGE);
75 // this below is a temporary workaround to fix the "always on top" issue
76 JDialog dialog = pane.createDialog(Main.parent, "");
77 CadastrePlugin.prepareDialog(dialog);
78 dialog.setVisible(true);
79 // till here
80 }
81 }
82 }
83 } catch (DuplicateLayerException e) {
84 // we tried to grab onto a duplicated layer (removed)
85 System.err.println("removed a duplicated layer");
86 }
87 }
88
89 @Override
90 protected void cancel() {
91 grabber.getWmsInterface().cancel();
92 dontGeoreference = true;
93 }
94
95 @Override
96 protected void finish() {
97 }
98 }
99
100 public void download(WMSLayer wmsLayer) {
101 MapView mv = Main.map.mapView;
102 Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
103
104 //Main.worker.execute(new DownloadWMSPlanImage(wmsLayer, bounds));
105 Task t = new Task(wmsLayer, bounds);
106 this.wmsLayer = wmsLayer;
107 this.bounds = bounds;
108 task = Main.worker.submit(t, t);
109 }
110
111 public boolean waitFinished() {
112 if (task != null) {
113 try {
114 task.get();
115 } catch (Exception e) {
116 e.printStackTrace();
117 }
118 }
119 return dontGeoreference;
120 }
121}
Note: See TracBrowser for help on using the repository browser.