[18544] | 1 | // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
|
---|
[13497] | 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.JLabel;
|
---|
| 11 | import javax.swing.JOptionPane;
|
---|
| 12 | import javax.swing.JPanel;
|
---|
| 13 | import javax.swing.JTextField;
|
---|
| 14 |
|
---|
| 15 | import org.openstreetmap.josm.Main;
|
---|
| 16 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
| 17 | import org.openstreetmap.josm.data.projection.Lambert;
|
---|
[18207] | 18 | import org.openstreetmap.josm.data.projection.LambertCC9Zones;
|
---|
[18720] | 19 | import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
|
---|
[13497] | 20 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
| 21 | import org.openstreetmap.josm.tools.GBC;
|
---|
| 22 |
|
---|
| 23 | public class MenuActionNewLocation extends JosmAction {
|
---|
| 24 |
|
---|
[15961] | 25 | private static final long serialVersionUID = 1L;
|
---|
[13497] | 26 |
|
---|
[15961] | 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) {
|
---|
[13497] | 32 | WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
|
---|
| 33 | if (wmsLayer != null)
|
---|
[20390] | 34 | DownloadWMSVectorImage.download(wmsLayer, false);
|
---|
[13497] | 35 | }
|
---|
[15961] | 36 |
|
---|
| 37 | public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
|
---|
[18838] | 38 | String location = "";
|
---|
| 39 | String codeDepartement = "";
|
---|
| 40 | String codeCommune = "";
|
---|
[19267] | 41 | boolean changeInterface = false;
|
---|
[18838] | 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>"));
|
---|
[13497] | 48 |
|
---|
[18838] | 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;
|
---|
[13497] | 54 |
|
---|
[18838] | 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;
|
---|
[13497] | 64 |
|
---|
[18838] | 65 | WMSLayer wmsLayer = null;
|
---|
| 66 | if (!inputTown.getText().equals("")) {
|
---|
| 67 | location = inputTown.getText().toUpperCase();
|
---|
[19267] | 68 | changeInterface = true;
|
---|
[18838] | 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;
|
---|
[13497] | 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
[18838] | 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);
|
---|
[19928] | 87 | CadastrePlugin.addWMSLayer(wmsLayer);
|
---|
[18838] | 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();
|
---|
[19267] | 91 | changeInterface = true;
|
---|
[18838] | 92 | }
|
---|
[13497] | 93 |
|
---|
[19267] | 94 | if (changeInterface)
|
---|
| 95 | CadastrePlugin.cadastreGrabber.getWmsInterface().resetInterfaceRefIfNewLayer(wmsLayer.getName());
|
---|
[18838] | 96 | return wmsLayer;
|
---|
[13497] | 97 | }
|
---|
[15961] | 98 |
|
---|
[13497] | 99 | }
|
---|