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.JComboBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JOptionPane;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.JTextField;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
18 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
19 | import org.openstreetmap.josm.tools.GBC;
|
---|
20 |
|
---|
21 | public class MenuActionNewLocation extends JosmAction {
|
---|
22 |
|
---|
23 | private static final long serialVersionUID = 1L;
|
---|
24 |
|
---|
25 | private static final String departements[] = {
|
---|
26 | "", tr("(optional)"),
|
---|
27 | "001", "01 - Ain", "002", "02 - Aisne", "003", "03 - Allier", "004", "04 - Alpes de Haute-Provence", "005", "05 - Hautes-Alpes",
|
---|
28 | "006", "06 - Alpes-Maritimes", "007", "07 - Ard\u00eache", "008", "08 - Ardennes", "009", "09 - Ari\u00e8ge", "010", "10 - Aube",
|
---|
29 | "011", "11 - Aude", "012", "12 - Aveyron", "013", "13 - Bouches-du-Rh\u00f4ne", "014", "14 - Calvados", "015", "15 - Cantal",
|
---|
30 | "016", "16 - Charente", "017", "17 - Charente-Maritime", "018", "18 - Cher", "019", "19 - Corr\u00e8ze",
|
---|
31 | "02A", "2A - Corse-du-Sud", "02B", "2B - Haute-Corse",
|
---|
32 | "021", "21 - C\u00f4te-d'Or", "022", "22 - C\u00f4tes d'Armor", "023", "23 - Creuse", "024", "24 - Dordogne", "025", "25 - Doubs",
|
---|
33 | "026", "26 - Dr\u00f4me", "027", "27 - Eure", "028", "28 - Eure-et-Loir", "029", "29 - Finist\u00e8re", "030", "30 - Gard",
|
---|
34 | "031", "31 - Haute-Garonne", "032", "32 - Gers", "033", "33 - Gironde", "034", "34 - H\u00e9rault", "035", "35 - Ille-et-Vilaine",
|
---|
35 | "036", "36 - Indre", "037", "37 - Indre-et-Loire", "038", "38 - Is\u00e8re", "039", "39 - Jura", "040", "40 - Landes",
|
---|
36 | "041", "41 - Loir-et-Cher", "042", "42 - Loire", "043", "43 - Haute-Loire", "044", "44 - Loire-Atlantique", "045", "45 - Loiret",
|
---|
37 | "046", "46 - Lot", "047", "47 - Lot-et-Garonne", "048", "48 - Loz\u00e8re", "049", "49 - Maine-et-Loire", "050", "50 - Manche",
|
---|
38 | "051", "51 - Marne", "052", "52 - Haute-Marne", "053", "53 - Mayenne", "054", "54 - Meurthe-et-Moselle", "055", "55 - Meuse",
|
---|
39 | "056", "56 - Morbihan", "057", "57 - Moselle", "058", "58 - Ni\u00e8vre", "059", "59 - Nord", "060", "60 - Oise",
|
---|
40 | "061", "61 - Orne", "062", "62 - Pas-de-Calais", "063", "63 - Puy-de-D\u00f4me", "064", "64 - Pyr\u00e9n\u00e9es-Atlantiques", "065", "65 - Hautes-Pyr\u00e9n\u00e9es",
|
---|
41 | "066", "66 - Pyr\u00e9n\u00e9es-Orientales", "067", "67 - Bas-Rhin", "068", "68 - Haut-Rhin", "069", "69 - Rh\u00f4ne", "070", "70 - Haute-Sa\u00f4ne",
|
---|
42 | "071", "71 - Sa\u00f4ne-et-Loire", "072", "72 - Sarthe", "073", "73 - Savoie", "074", "74 - Haute-Savoie", "075", "75 - Paris",
|
---|
43 | "076", "76 - Seine-Maritime", "077", "77 - Seine-et-Marne", "078", "78 - Yvelines", "079", "79 - Deux-S\u00e8vres", "080", "80 - Somme",
|
---|
44 | "081", "81 - Tarn", "082", "82 - Tarn-et-Garonne", "083", "83 - Var", "084", "84 - Vaucluse", "085", "85 - Vend\u00e9e",
|
---|
45 | "086", "86 - Vienne", "087", "87 - Haute-Vienne", "088", "88 - Vosges", "089", "89 - Yonne", "090", "90 - Territoire de Belfort",
|
---|
46 | "091", "91 - Essonne", "092", "92 - Hauts-de-Seine", "093", "93 - Seine-Saint-Denis", "094", "94 - Val-de-Marne", "095", "95 - Val-d'Oise",
|
---|
47 | "971", "971 - Guadeloupe", "972", "972 - Martinique", "973", "973 - Guyane", "974", "974 - R\u00e9union"
|
---|
48 | };
|
---|
49 |
|
---|
50 | public MenuActionNewLocation() {
|
---|
51 | super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false, "cadastrefr/newlocation", true);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public void actionPerformed(ActionEvent e) {
|
---|
56 | WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
|
---|
57 | if (wmsLayer != null)
|
---|
58 | DownloadWMSVectorImage.download(wmsLayer);
|
---|
59 | }
|
---|
60 |
|
---|
61 | public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
|
---|
62 | String location = "";
|
---|
63 | String codeDepartement = "";
|
---|
64 | String codeCommune = "";
|
---|
65 | JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality layer"));
|
---|
66 | JPanel p = new JPanel(new GridBagLayout());
|
---|
67 | JLabel labelLocation = new JLabel(tr("Commune"));
|
---|
68 | final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
|
---|
69 | inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
|
---|
70 | + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
|
---|
71 | JLabel labelDepartement = new JLabel(tr("Departement"));
|
---|
72 | final JComboBox<String> inputDepartement = new JComboBox<>();
|
---|
73 | for (int i=1; i<departements.length; i+=2) {
|
---|
74 | inputDepartement.addItem(departements[i]);
|
---|
75 | }
|
---|
76 | inputDepartement.setToolTipText(tr("<html>Departement number (optional)</html>"));
|
---|
77 | if (!Main.pref.get("cadastrewms.codeDepartement").equals("")) {
|
---|
78 | for (int i=0; i < departements.length; i=i+2)
|
---|
79 | if (departements[i].equals(Main.pref.get("cadastrewms.codeDepartement")))
|
---|
80 | inputDepartement.setSelectedIndex(i/2);
|
---|
81 | }
|
---|
82 | p.add(labelSectionNewLocation, GBC.eol());
|
---|
83 | p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
|
---|
84 | p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
85 | p.add(labelDepartement, GBC.std().insets(10, 0, 0, 0));
|
---|
86 | p.add(inputDepartement, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
87 | JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
|
---|
88 | private static final long serialVersionUID = 1L;
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | public void selectInitialValue() {
|
---|
92 | inputTown.requestFocusInWindow();
|
---|
93 | inputTown.selectAll();
|
---|
94 | }
|
---|
95 | };
|
---|
96 | pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
|
---|
97 | if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
|
---|
98 | return null;
|
---|
99 |
|
---|
100 | WMSLayer wmsLayer = null;
|
---|
101 | if (!inputTown.getText().equals("")) {
|
---|
102 | location = inputTown.getText().toUpperCase();
|
---|
103 | codeDepartement = departements[inputDepartement.getSelectedIndex()*2];
|
---|
104 | Main.pref.put("cadastrewms.location", location);
|
---|
105 | Main.pref.put("cadastrewms.codeCommune", codeCommune);
|
---|
106 | Main.pref.put("cadastrewms.codeDepartement", codeDepartement);
|
---|
107 | if (Main.map != null) {
|
---|
108 | for (Layer l : Main.getLayerManager().getLayers()) {
|
---|
109 | if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location)) {
|
---|
110 | return null;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 | // add the layer if it doesn't exist
|
---|
115 | int zone = CadastrePlugin.getCadastreProjectionLayoutZone();
|
---|
116 | wmsLayer = new WMSLayer(location, codeCommune, zone);
|
---|
117 | wmsLayer.setDepartement(codeDepartement);
|
---|
118 | CadastrePlugin.addWMSLayer(wmsLayer);
|
---|
119 | Main.info("Add new layer with Location:" + inputTown.getText());
|
---|
120 | } else if (existingLayers != null && existingLayers.size() > 0 && Main.getLayerManager().getActiveLayer() instanceof WMSLayer) {
|
---|
121 | wmsLayer = (WMSLayer)Main.getLayerManager().getActiveLayer();
|
---|
122 | }
|
---|
123 |
|
---|
124 | return wmsLayer;
|
---|
125 | }
|
---|
126 | }
|
---|