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 LambertCC9ZonesProjectionChoice extends ListProjectionChoice {
|
---|
18 |
|
---|
19 | private static String[] lambert9zones = {
|
---|
20 | tr("{0} ({1} to {2} degrees)", 1,41,43),
|
---|
21 | tr("{0} ({1} to {2} degrees)", 2,42,44),
|
---|
22 | tr("{0} ({1} to {2} degrees)", 3,43,45),
|
---|
23 | tr("{0} ({1} to {2} degrees)", 4,44,46),
|
---|
24 | tr("{0} ({1} to {2} degrees)", 5,45,47),
|
---|
25 | tr("{0} ({1} to {2} degrees)", 6,46,48),
|
---|
26 | tr("{0} ({1} to {2} degrees)", 7,47,49),
|
---|
27 | tr("{0} ({1} to {2} degrees)", 8,48,50),
|
---|
28 | tr("{0} ({1} to {2} degrees)", 9,49,51)
|
---|
29 | };
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructs a new {@code LambertCC9ZonesProjectionChoice}.
|
---|
33 | */
|
---|
34 | public LambertCC9ZonesProjectionChoice() {
|
---|
35 | super(tr("Lambert CC9 Zone (France)"), "core:lambertcc9", lambert9zones, tr("Lambert CC Zone"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | private class LambertCC9CBPanel extends CBPanel {
|
---|
39 | public LambertCC9CBPanel(Object[] entries, int initialIndex, String label, ActionListener listener) {
|
---|
40 | super(entries, initialIndex, label, listener);
|
---|
41 | this.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), 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 LambertCC9CBPanel(entries, index, label, listener);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public String getCurrentCode() {
|
---|
53 | return "EPSG:" + Integer.toString(3942+index); //CC42 is EPSG:3942 (up to EPSG:3950 for CC50)
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public String getProjectionName() {
|
---|
58 | return tr("Lambert CC9 Zone (France)");
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String[] allCodes() {
|
---|
63 | String[] codes = new String[9];
|
---|
64 | for (int zone = 0; zone < 9; zone++) {
|
---|
65 | codes[zone] = "EPSG:" + (3942 + zone);
|
---|
66 | }
|
---|
67 | return codes;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public Collection<String> getPreferencesFromCode(String code) {
|
---|
72 | //zone 1=CC42=EPSG:3942 up to zone 9=CC50=EPSG:3950
|
---|
73 | if (code.startsWith("EPSG:39") && code.length() == 9) {
|
---|
74 | try {
|
---|
75 | String zonestring = code.substring(5,9);
|
---|
76 | int zoneval = Integer.parseInt(zonestring)-3942;
|
---|
77 | if(zoneval >= 0 && zoneval <= 8)
|
---|
78 | return Collections.singleton(String.valueOf(zoneval+1));
|
---|
79 | } catch(NumberFormatException ex) {
|
---|
80 | Main.warn(ex);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | return null;
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | protected String indexToZone(int index) {
|
---|
88 | return Integer.toString(index + 1);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | protected int zoneToIndex(String zone) {
|
---|
93 | try {
|
---|
94 | return Integer.parseInt(zone) - 1;
|
---|
95 | } catch(NumberFormatException e) {
|
---|
96 | Main.warn(e);
|
---|
97 | }
|
---|
98 | return defaultIndex;
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|