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

Last change on this file since 18207 was 18207, checked in by pieren, 16 years ago

Use the new cadastre projection LambertCC9Zones

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1package cadastre_fr;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.awt.event.ActionEvent;
7import java.util.ArrayList;
8
9import javax.swing.JComboBox;
10import javax.swing.JLabel;
11import javax.swing.JOptionPane;
12import javax.swing.JPanel;
13import javax.swing.JTextField;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.actions.JosmAction;
17import org.openstreetmap.josm.data.projection.Lambert;
18import org.openstreetmap.josm.data.projection.LambertCC9Zones;
19import org.openstreetmap.josm.gui.layer.Layer;
20import org.openstreetmap.josm.tools.GBC;
21
22public class MenuActionNewLocation extends JosmAction {
23
24 private static final long serialVersionUID = 1L;
25
26 public MenuActionNewLocation() {
27 super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false);
28 }
29
30 public void actionPerformed(ActionEvent e) {
31 WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
32 if (wmsLayer != null)
33 DownloadWMSVectorImage.download(wmsLayer);
34 }
35
36 public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
37 /*if (Main.map == null) {
38 JOptionPane.showMessageDialog(Main.parent,
39 tr("Open a layer first (GPX, OSM, cache)"));
40 return null;
41 } else {*/
42 String location = "";
43 String codeDepartement = "";
44 String codeCommune = "";
45 boolean resetCookie = false;
46 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
47 JPanel p = new JPanel(new GridBagLayout());
48 JLabel labelLocation = new JLabel(tr("Location"));
49 final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
50 inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
51 + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
52 JComboBox inputWMSList = null;
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 if (Main.proj instanceof LambertCC9Zones)
85 wmsLayer = new WMSLayer(location, codeCommune, LambertCC9Zones.layoutZone);
86 else
87 wmsLayer = new WMSLayer(location, codeCommune, Lambert.layoutZone);
88 Main.main.addLayer(wmsLayer);
89 System.out.println("Add new layer with Location:" + inputTown.getText());
90 } else if (existingLayers != null && existingLayers.size() > 0 && inputWMSList.getSelectedIndex() > 0) {
91 wmsLayer = existingLayers.get(inputWMSList.getSelectedIndex()-1);
92 resetCookie = true;
93 }
94
95 if (resetCookie)
96 CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
97 return wmsLayer;
98 //}
99 }
100
101}
Note: See TracBrowser for help on using the repository browser.