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.Logging; 010 011/** 012 * ProjectionChoice for various French overseas territories (EPSG:2969,2970,2972,2973,2975). 013 * <p> 014 * @see <a href="https://fr.wikipedia.org/wiki/Système_de_coordonnées_(cartographie)#Dans_les_d.C3.A9partements_d.27Outre-mer">DOM</a> 015 */ 016public class UTMFranceDOMProjectionChoice extends ListProjectionChoice { 017 018 private static final String FORT_MARIGOT_NAME = tr("Guadeloupe Fort-Marigot 1949"); 019 private static final String SAINTE_ANNE_NAME = tr("Guadeloupe Ste-Anne 1948"); 020 private static final String MARTINIQUE_NAME = tr("Martinique Fort Desaix 1952"); 021 private static final String REUNION_92_NAME = tr("Reunion RGR92"); 022 private static final String GUYANE_92_NAME = tr("Guyane RGFG95"); 023 private static final String[] UTM_GEODESIC_NAMES = {FORT_MARIGOT_NAME, SAINTE_ANNE_NAME, MARTINIQUE_NAME, REUNION_92_NAME, GUYANE_92_NAME}; 024 025 private static final Integer FORT_MARIGOT_EPSG = 2969; 026 private static final Integer SAINTE_ANNE_EPSG = 2970; 027 private static final Integer MARTINIQUE_EPSG = 2973; 028 private static final Integer REUNION_EPSG = 2975; 029 private static final Integer GUYANE_EPSG = 2972; 030 private static final Integer[] UTM_EPSGS = {FORT_MARIGOT_EPSG, SAINTE_ANNE_EPSG, MARTINIQUE_EPSG, REUNION_EPSG, GUYANE_EPSG }; 031 032 /** 033 * Constructs a new {@code UTMFranceDOMProjectionChoice}. 034 */ 035 public UTMFranceDOMProjectionChoice() { 036 super(tr("UTM France (DOM)"), /* NO-ICON */ "core:utmfrancedom", UTM_GEODESIC_NAMES, tr("UTM Geodesic system")); 037 } 038 039 @Override 040 protected String indexToZone(int index) { 041 return Integer.toString(index + 1); 042 } 043 044 @Override 045 protected int zoneToIndex(String zone) { 046 try { 047 return Integer.parseInt(zone) - 1; 048 } catch (NumberFormatException e) { 049 Logging.warn(e); 050 } 051 return defaultIndex; 052 } 053 054 @Override 055 public String getProjectionName() { 056 return UTM_GEODESIC_NAMES[index]; 057 } 058 059 @Override 060 public String getCurrentCode() { 061 return "EPSG:" + UTM_EPSGS[index]; 062 } 063 064 @Override 065 public String[] allCodes() { 066 String[] res = new String[UTM_EPSGS.length]; 067 for (int i = 0; i < UTM_EPSGS.length; ++i) { 068 res[i] = "EPSG:" + UTM_EPSGS[i]; 069 } 070 return res; 071 } 072 073 @Override 074 public Collection<String> getPreferencesFromCode(String code) { 075 for (int i = 0; i < UTM_EPSGS.length; i++) { 076 if (("EPSG:" + UTM_EPSGS[i]).equals(code)) 077 return Collections.singleton(Integer.toString(i+1)); 078 } 079 return null; 080 } 081}