| 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.util.Arrays;
|
|---|
| 7 | import java.util.Collection;
|
|---|
| 8 | import java.util.Collections;
|
|---|
| 9 | import java.util.stream.IntStream;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.tools.Utils;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * ProjectionChoice for PUWG 1992 (EPSG:2180) and PUWG 2000 for Poland (Zone 5-8, EPSG:2176-2179).
|
|---|
| 15 | * <p>
|
|---|
| 16 | * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_1992">PUWG 1992</a>
|
|---|
| 17 | * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_2000">PUWG 2000</a>
|
|---|
| 18 | */
|
|---|
| 19 | public class PuwgProjectionChoice extends ListProjectionChoice {
|
|---|
| 20 |
|
|---|
| 21 | private static final String[] CODES = {
|
|---|
| 22 | "EPSG:2180",
|
|---|
| 23 | "EPSG:2176",
|
|---|
| 24 | "EPSG:2177",
|
|---|
| 25 | "EPSG:2178",
|
|---|
| 26 | "EPSG:2179"
|
|---|
| 27 | };
|
|---|
| 28 |
|
|---|
| 29 | private static final String[] NAMES = {
|
|---|
| 30 | tr("PUWG 1992 (Poland)"),
|
|---|
| 31 | tr("PUWG 2000 Zone {0} (Poland)", 5),
|
|---|
| 32 | tr("PUWG 2000 Zone {0} (Poland)", 6),
|
|---|
| 33 | tr("PUWG 2000 Zone {0} (Poland)", 7),
|
|---|
| 34 | tr("PUWG 2000 Zone {0} (Poland)", 8)
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Constructs a new {@code PuwgProjectionChoice}.
|
|---|
| 39 | */
|
|---|
| 40 | public PuwgProjectionChoice() {
|
|---|
| 41 | super(tr("PUWG (Poland)"), /* NO-ICON */ "core:puwg", NAMES, tr("PUWG Zone"));
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | @Override
|
|---|
| 45 | public String getCurrentCode() {
|
|---|
| 46 | return CODES[index];
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | @Override
|
|---|
| 50 | public String getProjectionName() {
|
|---|
| 51 | return NAMES[index];
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | @Override
|
|---|
| 55 | public String[] allCodes() {
|
|---|
| 56 | return Utils.copyArray(CODES);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | @Override
|
|---|
| 60 | public Collection<String> getPreferencesFromCode(String code) {
|
|---|
| 61 | return Arrays.stream(CODES).filter(code::equals).findFirst().map(Collections::singleton).orElse(null);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | @Override
|
|---|
| 65 | protected String indexToZone(int index) {
|
|---|
| 66 | return CODES[index];
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | @Override
|
|---|
| 70 | protected int zoneToIndex(String zone) {
|
|---|
| 71 | return IntStream.range(0, CODES.length)
|
|---|
| 72 | .filter(i -> zone.equals(CODES[i]))
|
|---|
| 73 | .findFirst().orElse(defaultIndex);
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|