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

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

Add licence in headers for GPL compliance.

  • Property svn:eol-style set to native
File size: 4.3 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.awt.GridBagLayout;
7import java.awt.event.ActionEvent;
8import java.util.ArrayList;
9
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
53 p.add(labelSectionNewLocation, GBC.eol());
54 p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
55 p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
56 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
57 private static final long serialVersionUID = 1L;
58
59 @Override
60 public void selectInitialValue() {
61 inputTown.requestFocusInWindow();
62 inputTown.selectAll();
63 }
64 };
65 pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
66 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
67 return null;
68
69 WMSLayer wmsLayer = null;
70 if (!inputTown.getText().equals("")) {
71 location = inputTown.getText().toUpperCase();
72 resetCookie = true;
73 Main.pref.put("cadastrewms.location", location);
74 Main.pref.put("cadastrewms.codeCommune", codeCommune);
75 if (Main.map != null) {
76 for (Layer l : Main.map.mapView.getAllLayers()) {
77 if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
78 return null;
79 }
80 }
81 }
82 // add the layer if it doesn't exist
83 if (Main.proj instanceof LambertCC9Zones)
84 wmsLayer = new WMSLayer(location, codeCommune, LambertCC9Zones.layoutZone);
85 else
86 wmsLayer = new WMSLayer(location, codeCommune, Lambert.layoutZone);
87 Main.main.addLayer(wmsLayer);
88 System.out.println("Add new layer with Location:" + inputTown.getText());
89 } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
90 wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
91 resetCookie = true;
92 }
93
94 if (resetCookie)
95 CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
96 return wmsLayer;
97 //}
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.