001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.preferences.projection;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.util.Collection;
007import java.util.Collections;
008
009import org.openstreetmap.josm.tools.Utils;
010
011/**
012 * ProjectionChoice for PUWG 1992 (EPSG:2180) and PUWG 2000 for Poland (Zone 5-8, EPSG:2176-2179).
013 * <p>
014 * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_1992">PUWG 1992</a>
015 * @see <a href="https://pl.wikipedia.org/wiki/Uk%C5%82ad_wsp%C3%B3%C5%82rz%C4%99dnych_2000">PUWG 2000</a>
016 */
017public class PuwgProjectionChoice extends ListProjectionChoice {
018
019    private static final String[] CODES = {
020        "EPSG:2180",
021        "EPSG:2176",
022        "EPSG:2177",
023        "EPSG:2178",
024        "EPSG:2179"
025    };
026
027    private static final String[] NAMES = {
028        tr("PUWG 1992 (Poland)"),
029        tr("PUWG 2000 Zone {0} (Poland)", 5),
030        tr("PUWG 2000 Zone {0} (Poland)", 6),
031        tr("PUWG 2000 Zone {0} (Poland)", 7),
032        tr("PUWG 2000 Zone {0} (Poland)", 8)
033    };
034
035    /**
036     * Constructs a new {@code PuwgProjectionChoice}.
037     */
038    public PuwgProjectionChoice() {
039        super(tr("PUWG (Poland)"), /* NO-ICON */ "core:puwg", NAMES, tr("PUWG Zone"));
040    }
041
042    @Override
043    public String getCurrentCode() {
044        return CODES[index];
045    }
046
047    @Override
048    public String getProjectionName() {
049        return NAMES[index];
050    }
051
052    @Override
053    public String[] allCodes() {
054        return Utils.copyArray(CODES);
055    }
056
057    @Override
058    public Collection<String> getPreferencesFromCode(String code) {
059        for (String code2 : CODES) {
060            if (code.equals(code2))
061                return Collections.singleton(code2);
062        }
063        return null;
064    }
065
066    @Override
067    protected String indexToZone(int index) {
068        return CODES[index];
069    }
070
071    @Override
072    protected int zoneToIndex(String zone) {
073        for (int i = 0; i < CODES.length; i++) {
074            if (zone.equals(CODES[i])) {
075                return i;
076            }
077        }
078        return defaultIndex;
079    }
080}