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.Main;
010
011public class UTMFranceDOMProjectionChoice extends ListProjectionChoice {
012
013    private static final String FortMarigotName = tr("Guadeloupe Fort-Marigot 1949");
014    private static final String SainteAnneName = tr("Guadeloupe Ste-Anne 1948");
015    private static final String MartiniqueName = tr("Martinique Fort Desaix 1952");
016    private static final String Reunion92Name = tr("Reunion RGR92");
017    private static final String Guyane92Name = tr("Guyane RGFG95");
018    private static final String[] utmGeodesicsNames = {FortMarigotName, SainteAnneName, MartiniqueName, Reunion92Name, Guyane92Name};
019
020    private static final Integer FortMarigotEPSG = 2969;
021    private static final Integer SainteAnneEPSG = 2970;
022    private static final Integer MartiniqueEPSG = 2973;
023    private static final Integer ReunionEPSG = 2975;
024    private static final Integer GuyaneEPSG = 2972;
025    private static final Integer[] utmEPSGs = {FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG };
026
027    /**
028     * Constructs a new {@code UTMFranceDOMProjectionChoice}.
029     */
030    public UTMFranceDOMProjectionChoice() {
031        super(tr("UTM France (DOM)"), /* NO-ICON */ "core:utmfrancedom", utmGeodesicsNames, tr("UTM Geodesic system"));
032    }
033
034    @Override
035    protected String indexToZone(int index) {
036        return Integer.toString(index + 1);
037    }
038
039    @Override
040    protected int zoneToIndex(String zone) {
041        try {
042            return Integer.parseInt(zone) - 1;
043        } catch (NumberFormatException e) {
044            Main.warn(e);
045        }
046        return defaultIndex;
047    }
048
049    @Override
050    public String getProjectionName() {
051        return utmGeodesicsNames[index];
052    }
053
054    @Override
055    public String getCurrentCode() {
056        return "EPSG:" + utmEPSGs[index];
057    }
058
059    @Override
060    public String[] allCodes() {
061        String[] res = new String[utmEPSGs.length];
062        for (int i = 0; i < utmEPSGs.length; ++i) {
063            res[i] = "EPSG:" + utmEPSGs[i];
064        }
065        return res;
066    }
067
068    @Override
069    public Collection<String> getPreferencesFromCode(String code) {
070        for (int i = 0; i < utmEPSGs.length; i++) {
071            if (("EPSG:" + utmEPSGs[i]).equals(code))
072                return Collections.singleton(Integer.toString(i+1));
073        }
074        return null;
075    }
076}