1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.projection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionListener;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.tools.GBC;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * ProjectionChoice for 4 zone Lambert (1920, EPSG:27561-27564).
|
---|
19 | * <p>
|
---|
20 | * @see <a href="https://fr.wikipedia.org/wiki/Projection_conique_conforme_de_Lambert#Lambert_zone">Lambert zone</a>
|
---|
21 | */
|
---|
22 | public class LambertProjectionChoice extends ListProjectionChoice {
|
---|
23 |
|
---|
24 | private static final String[] LAMBERT_4_ZONES = {
|
---|
25 | tr("{0} ({1} to {2} degrees)", 1, "51.30", "48.15"),
|
---|
26 | tr("{0} ({1} to {2} degrees)", 2, "48.15", "45.45"),
|
---|
27 | tr("{0} ({1} to {2} degrees)", 3, "45.45", "42.76"),
|
---|
28 | tr("{0} (Corsica)", 4)
|
---|
29 | };
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructs a new {@code LambertProjectionChoice}.
|
---|
33 | */
|
---|
34 | public LambertProjectionChoice() {
|
---|
35 | super(tr("Lambert 4 Zones (France)"), /* NO-ICON */ "core:lambert", LAMBERT_4_ZONES, tr("Lambert CC Zone"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | private static class LambertCBPanel extends CBPanel {
|
---|
39 | LambertCBPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
|
---|
40 | super(entries, initialIndex, label, listener);
|
---|
41 | this.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones")), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
42 | this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public JPanel getPreferencePanel(ActionListener listener) {
|
---|
48 | return new LambertCBPanel(entries, index, label, listener);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public String getCurrentCode() {
|
---|
53 | return "EPSG:" + Integer.toString(27561+index);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public String getProjectionName() {
|
---|
58 | return tr("Lambert 4 Zones (France)");
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String[] allCodes() {
|
---|
63 | String[] codes = new String[4];
|
---|
64 | for (int zone = 0; zone < 4; zone++) {
|
---|
65 | codes[zone] = "EPSG:"+(27561+zone);
|
---|
66 | }
|
---|
67 | return codes;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public Collection<String> getPreferencesFromCode(String code) {
|
---|
72 | if (code.startsWith("EPSG:2756") && code.length() == 10) {
|
---|
73 | try {
|
---|
74 | String zonestring = code.substring(9);
|
---|
75 | int zoneval = Integer.parseInt(zonestring);
|
---|
76 | if (zoneval >= 1 && zoneval <= 4)
|
---|
77 | return Collections.singleton(zonestring);
|
---|
78 | } catch (NumberFormatException e) {
|
---|
79 | Main.warn(e);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | return null;
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | protected String indexToZone(int idx) {
|
---|
87 | return Integer.toString(idx + 1);
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | protected int zoneToIndex(String zone) {
|
---|
92 | try {
|
---|
93 | return Integer.parseInt(zone) - 1;
|
---|
94 | } catch (NumberFormatException e) {
|
---|
95 | Main.warn(e);
|
---|
96 | }
|
---|
97 | return defaultIndex;
|
---|
98 | }
|
---|
99 | }
|
---|