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

Last change on this file since 20390 was 20390, checked in by pieren, 14 years ago

Many small fixes and improvements

  • Property svn:eol-style set to native
File size: 4.2 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, false);
35 }
36
37 public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
38 String location = "";
39 String codeDepartement = "";
40 String codeCommune = "";
41 boolean changeInterface = false;
42 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
43 JPanel p = new JPanel(new GridBagLayout());
44 JLabel labelLocation = new JLabel(tr("Location"));
45 final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
46 inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
47 + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
48
49 p.add(labelSectionNewLocation, GBC.eol());
50 p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
51 p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
52 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
53 private static final long serialVersionUID = 1L;
54
55 @Override
56 public void selectInitialValue() {
57 inputTown.requestFocusInWindow();
58 inputTown.selectAll();
59 }
60 };
61 pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
62 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
63 return null;
64
65 WMSLayer wmsLayer = null;
66 if (!inputTown.getText().equals("")) {
67 location = inputTown.getText().toUpperCase();
68 changeInterface = true;
69 Main.pref.put("cadastrewms.location", location);
70 Main.pref.put("cadastrewms.codeCommune", codeCommune);
71 if (Main.map != null) {
72 for (Layer l : Main.map.mapView.getAllLayers()) {
73 if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
74 return null;
75 }
76 }
77 }
78 // add the layer if it doesn't exist
79 int zone = -1;
80 if (Main.proj instanceof LambertCC9Zones)
81 zone = ((LambertCC9Zones)Main.proj).getLayoutZone();
82 else if (Main.proj instanceof Lambert)
83 zone = ((Lambert)Main.proj).getLayoutZone();
84 else if (Main.proj instanceof UTM_20N_France_DOM)
85 zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();
86 wmsLayer = new WMSLayer(location, codeCommune, zone);
87 CadastrePlugin.addWMSLayer(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 changeInterface = true;
92 }
93
94 if (changeInterface)
95 CadastrePlugin.cadastreGrabber.getWmsInterface().resetInterfaceRefIfNewLayer(wmsLayer.getName());
96 return wmsLayer;
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.