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

Last change on this file since 21516 was 21493, checked in by pieren, 15 years ago

Improve renaming after municipality selection

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