1 | // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
|
---|
2 | package cadastre_fr;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.util.ArrayList;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JOptionPane;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JTextField;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
17 | import org.openstreetmap.josm.data.projection.Lambert;
|
---|
18 | import org.openstreetmap.josm.data.projection.LambertCC9Zones;
|
---|
19 | import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
|
---|
20 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
21 | import org.openstreetmap.josm.tools.GBC;
|
---|
22 |
|
---|
23 | public class MenuActionNewLocation extends JosmAction {
|
---|
24 |
|
---|
25 | private static final long serialVersionUID = 1L;
|
---|
26 |
|
---|
27 | public MenuActionNewLocation() {
|
---|
28 | super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void actionPerformed(ActionEvent e) {
|
---|
32 | WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
|
---|
33 | if (wmsLayer != null)
|
---|
34 | DownloadWMSVectorImage.download(wmsLayer);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
|
---|
38 | /*if (Main.map == null) {
|
---|
39 | JOptionPane.showMessageDialog(Main.parent,
|
---|
40 | tr("Open a layer first (GPX, OSM, cache)"));
|
---|
41 | return null;
|
---|
42 | } else {*/
|
---|
43 | String location = "";
|
---|
44 | String codeDepartement = "";
|
---|
45 | String codeCommune = "";
|
---|
46 | boolean resetCookie = false;
|
---|
47 | JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
|
---|
48 | JPanel p = new JPanel(new GridBagLayout());
|
---|
49 | JLabel labelLocation = new JLabel(tr("Location"));
|
---|
50 | final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
|
---|
51 | inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
|
---|
52 | + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
|
---|
53 |
|
---|
54 | p.add(labelSectionNewLocation, GBC.eol());
|
---|
55 | p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
|
---|
56 | p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
57 | JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
|
---|
58 | private static final long serialVersionUID = 1L;
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public void selectInitialValue() {
|
---|
62 | inputTown.requestFocusInWindow();
|
---|
63 | inputTown.selectAll();
|
---|
64 | }
|
---|
65 | };
|
---|
66 | pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
|
---|
67 | if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
|
---|
68 | return null;
|
---|
69 |
|
---|
70 | WMSLayer wmsLayer = null;
|
---|
71 | if (!inputTown.getText().equals("")) {
|
---|
72 | location = inputTown.getText().toUpperCase();
|
---|
73 | resetCookie = true;
|
---|
74 | Main.pref.put("cadastrewms.location", location);
|
---|
75 | Main.pref.put("cadastrewms.codeCommune", codeCommune);
|
---|
76 | if (Main.map != null) {
|
---|
77 | for (Layer l : Main.map.mapView.getAllLayers()) {
|
---|
78 | if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
|
---|
79 | return null;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | // add the layer if it doesn't exist
|
---|
84 | int zone = -1;
|
---|
85 | if (Main.proj instanceof LambertCC9Zones)
|
---|
86 | zone = ((LambertCC9Zones)Main.proj).getLayoutZone();
|
---|
87 | else if (Main.proj instanceof Lambert)
|
---|
88 | zone = ((Lambert)Main.proj).getLayoutZone();
|
---|
89 | else if (Main.proj instanceof UTM_20N_France_DOM)
|
---|
90 | zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();
|
---|
91 | wmsLayer = new WMSLayer(location, codeCommune, zone);
|
---|
92 | Main.main.addLayer(wmsLayer);
|
---|
93 | System.out.println("Add new layer with Location:" + inputTown.getText());
|
---|
94 | } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
|
---|
95 | wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
|
---|
96 | resetCookie = true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (resetCookie)
|
---|
100 | CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
|
---|
101 | return wmsLayer;
|
---|
102 | //}
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|