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 | public class LambertProjectionChoice extends ListProjectionChoice {
|
---|
18 |
|
---|
19 | private static final String[] lambert4zones = {
|
---|
20 | tr("{0} ({1} to {2} degrees)", 1,"51.30","48.15"),
|
---|
21 | tr("{0} ({1} to {2} degrees)", 2,"48.15","45.45"),
|
---|
22 | tr("{0} ({1} to {2} degrees)", 3,"45.45","42.76"),
|
---|
23 | tr("{0} (Corsica)", 4)
|
---|
24 | };
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructs a new {@code LambertProjectionChoice}.
|
---|
28 | */
|
---|
29 | public LambertProjectionChoice() {
|
---|
30 | super(tr("Lambert 4 Zones (France)"), /* NO-ICON */ "core:lambert", lambert4zones, tr("Lambert CC Zone"));
|
---|
31 | }
|
---|
32 |
|
---|
33 | private class LambertCBPanel extends CBPanel {
|
---|
34 | public LambertCBPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
|
---|
35 | super(entries, initialIndex, label, listener);
|
---|
36 | this.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
37 | this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public JPanel getPreferencePanel(ActionListener listener) {
|
---|
43 | return new LambertCBPanel(entries, index, label, listener);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public String getCurrentCode() {
|
---|
48 | return "EPSG:" + Integer.toString(27561+index);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public String getProjectionName() {
|
---|
53 | return tr("Lambert 4 Zones (France)");
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public String[] allCodes() {
|
---|
58 | String[] codes = new String[4];
|
---|
59 | for (int zone = 0; zone < 4; zone++) {
|
---|
60 | codes[zone] = "EPSG:"+(27561+zone);
|
---|
61 | }
|
---|
62 | return codes;
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public Collection<String> getPreferencesFromCode(String code) {
|
---|
67 | if (code.startsWith("EPSG:2756") && code.length() == 10) {
|
---|
68 | try {
|
---|
69 | String zonestring = code.substring(9);
|
---|
70 | int zoneval = Integer.parseInt(zonestring);
|
---|
71 | if(zoneval >= 1 && zoneval <= 4)
|
---|
72 | return Collections.singleton(zonestring);
|
---|
73 | } catch(NumberFormatException e) {
|
---|
74 | Main.warn(e);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | protected String indexToZone(int idx) {
|
---|
82 | return Integer.toString(idx + 1);
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | protected int zoneToIndex(String zone) {
|
---|
87 | try {
|
---|
88 | return Integer.parseInt(zone) - 1;
|
---|
89 | } catch(NumberFormatException e) {
|
---|
90 | Main.warn(e);
|
---|
91 | }
|
---|
92 | return defaultIndex;
|
---|
93 | }
|
---|
94 | }
|
---|