| 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 | import java.util.stream.IntStream;
|
|---|
| 10 |
|
|---|
| 11 | import javax.swing.JLabel;
|
|---|
| 12 | import javax.swing.JPanel;
|
|---|
| 13 |
|
|---|
| 14 | import org.openstreetmap.josm.tools.GBC;
|
|---|
| 15 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 16 | import org.openstreetmap.josm.tools.Logging;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * ProjectionChoice for Lambert CC (9 zones, EPSG:3942-3950).
|
|---|
| 20 | * <p>
|
|---|
| 21 | * @see <a href="https://fr.wikipedia.org/wiki/Projection_conique_conforme_de_Lambert#Lambert_zone_CC">Lambert CC</a>
|
|---|
| 22 | */
|
|---|
| 23 | public class LambertCC9ZonesProjectionChoice extends ListProjectionChoice {
|
|---|
| 24 |
|
|---|
| 25 | private static final String[] LAMBERT_9_ZONES = {
|
|---|
| 26 | tr("{0} ({1} to {2} degrees)", 1, 41, 43),
|
|---|
| 27 | tr("{0} ({1} to {2} degrees)", 2, 42, 44),
|
|---|
| 28 | tr("{0} ({1} to {2} degrees)", 3, 43, 45),
|
|---|
| 29 | tr("{0} ({1} to {2} degrees)", 4, 44, 46),
|
|---|
| 30 | tr("{0} ({1} to {2} degrees)", 5, 45, 47),
|
|---|
| 31 | tr("{0} ({1} to {2} degrees)", 6, 46, 48),
|
|---|
| 32 | tr("{0} ({1} to {2} degrees)", 7, 47, 49),
|
|---|
| 33 | tr("{0} ({1} to {2} degrees)", 8, 48, 50),
|
|---|
| 34 | tr("{0} ({1} to {2} degrees)", 9, 49, 51)
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Constructs a new {@code LambertCC9ZonesProjectionChoice}.
|
|---|
| 39 | */
|
|---|
| 40 | public LambertCC9ZonesProjectionChoice() {
|
|---|
| 41 | super(tr("Lambert CC9 Zone (France)"), /* NO-ICON */ "core:lambertcc9", LAMBERT_9_ZONES, tr("Lambert CC Zone"));
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | private static class LambertCC9CBPanel extends CBPanel {
|
|---|
| 45 | LambertCC9CBPanel(String[] entries, int initialIndex, String label, ActionListener listener) {
|
|---|
| 46 | super(entries, initialIndex, label, listener);
|
|---|
| 47 | this.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones")), GBC.eol().fill(GBC.HORIZONTAL));
|
|---|
| 48 | this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | @Override
|
|---|
| 53 | public JPanel getPreferencePanel(ActionListener listener) {
|
|---|
| 54 | return new LambertCC9CBPanel(entries, index, label, listener);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | @Override
|
|---|
| 58 | public String getCurrentCode() {
|
|---|
| 59 | return "EPSG:" + Integer.toString(3942+index); //CC42 is EPSG:3942 (up to EPSG:3950 for CC50)
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | @Override
|
|---|
| 63 | public String getProjectionName() {
|
|---|
| 64 | return tr("Lambert CC9 Zone (France)");
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | @Override
|
|---|
| 68 | public String[] allCodes() {
|
|---|
| 69 | return IntStream.range(0, 9).mapToObj(zone -> "EPSG:" + (3942 + zone)).toArray(String[]::new);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | @Override
|
|---|
| 73 | public Collection<String> getPreferencesFromCode(String code) {
|
|---|
| 74 | //zone 1=CC42=EPSG:3942 up to zone 9=CC50=EPSG:3950
|
|---|
| 75 | if (code.startsWith("EPSG:39") && code.length() == 9) {
|
|---|
| 76 | try {
|
|---|
| 77 | String zonestring = code.substring(5, 9);
|
|---|
| 78 | int zoneval = Integer.parseInt(zonestring)-3942;
|
|---|
| 79 | if (zoneval >= 0 && zoneval <= 8)
|
|---|
| 80 | return Collections.singleton(String.valueOf(zoneval+1));
|
|---|
| 81 | } catch (NumberFormatException ex) {
|
|---|
| 82 | Logging.warn(ex);
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | return null;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | @Override
|
|---|
| 89 | protected String indexToZone(int idx) {
|
|---|
| 90 | return Integer.toString(idx + 1);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | @Override
|
|---|
| 94 | protected int zoneToIndex(String zone) {
|
|---|
| 95 | try {
|
|---|
| 96 | return Integer.parseInt(zone) - 1;
|
|---|
| 97 | } catch (NumberFormatException e) {
|
|---|
| 98 | Logging.warn(e);
|
|---|
| 99 | }
|
|---|
| 100 | return defaultIndex;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | }
|
|---|