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

Last change on this file since 18743 was 18720, checked in by pieren, 15 years ago

Add subprojection handling

  • Property svn:eol-style set to native
File size: 4.6 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.data.projection.UTM_20N_France_DOM;
20import org.openstreetmap.josm.gui.layer.Layer;
21import org.openstreetmap.josm.tools.GBC;
22
23public 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}
Note: See TracBrowser for help on using the repository browser.