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

Last change on this file since 33335 was 33047, checked in by donvip, 9 years ago

findbugs

File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package cadastre_fr;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.util.ArrayList;
9
10import javax.swing.JOptionPane;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.actions.JosmAction;
14
15public class MenuActionGrabPlanImage extends JosmAction implements Runnable {
16
17 /**
18 * Action calling the wms grabber for non georeferenced images called "plan image"
19 */
20 private static final long serialVersionUID = 1L;
21
22 public static final String NAME = marktr("Georeference an image");
23
24 private DownloadWMSPlanImage downloadWMSPlanImage;
25 private WMSLayer wmsLayer;
26 private RasterImageGeoreferencer rasterImageGeoreferencer;
27
28 /**
29 * Constructs a new {@code MenuActionGrabPlanImage}.
30 */
31 public MenuActionGrabPlanImage() {
32 super(tr(NAME), "cadastre_small", tr("Grab non-georeferenced image"), null, false, "cadastrefr/grabplanimage", true);
33 rasterImageGeoreferencer = new RasterImageGeoreferencer();
34 }
35
36 @Override
37 protected void updateEnabledState() {
38 if (wmsLayer == null || Main.map == null || Main.map.mapView == null) return;
39 if (!rasterImageGeoreferencer.isRunning()) return;
40 if (Main.getLayerManager().containsLayer(wmsLayer))
41 return;
42 JOptionPane.showMessageDialog(Main.parent, tr("Georeferencing interrupted"));
43 rasterImageGeoreferencer.actionInterrupted();
44 }
45
46 @Override
47 public void actionPerformed(ActionEvent ae) {
48 if (Main.map != null) {
49 if (CadastrePlugin.isCadastreProjection()) {
50 wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList<WMSLayer>());
51 if (wmsLayer == null) return;
52 downloadWMSPlanImage = new DownloadWMSPlanImage();
53 downloadWMSPlanImage.download(wmsLayer);
54 // download sub-images of the cadastre scan and join them into one single
55 Main.worker.execute(this);
56 } else {
57 CadastrePlugin.askToChangeProjection();
58 }
59 }
60 }
61
62 @Override
63 public void run() {
64 // wait until plan image is fully loaded and joined into one single image
65 boolean loadedFromCache = downloadWMSPlanImage.waitFinished();
66 if (loadedFromCache) {
67 Main.map.repaint();
68 } else if (wmsLayer.getImages().size() == 0) {
69 // action canceled or image loaded from cache (and already georeferenced)
70 rasterImageGeoreferencer.actionInterrupted();
71 } else {
72 int reply = JOptionPane.CANCEL_OPTION;
73 if (wmsLayer.isAlreadyGeoreferenced()) {
74 reply = JOptionPane.showConfirmDialog(null,
75 tr("This image contains georeference data.\n"+
76 "Do you want to use them ?"),
77 null,
78 JOptionPane.YES_NO_OPTION);
79 }
80 if (reply == JOptionPane.OK_OPTION) {
81 rasterImageGeoreferencer.transformGeoreferencedImg();
82 } else {
83 rasterImageGeoreferencer.addListener();
84 if (Main.pref.getBoolean("cadastrewms.noImageCropping", false) == false)
85 rasterImageGeoreferencer.startCropping(wmsLayer);
86 else
87 rasterImageGeoreferencer.startGeoreferencing(wmsLayer);
88 }
89 }
90 }
91}
Note: See TracBrowser for help on using the repository browser.