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 Gauß-Krüger coordinate system (zones 2-5, EPSG:31466-31469). 013 * <p> 014 * @see <a href="https://de.wikipedia.org/wiki/Gauß-Krüger-Koordinatensystem">Gauß-Krüger</a> 015 */ 016public class GaussKruegerProjectionChoice extends ListProjectionChoice { 017 018 private static String[] zones = {"2", "3", "4", "5"}; 019 020 /** 021 * Constructs a new {@code GaussKruegerProjectionChoice}. 022 */ 023 public GaussKruegerProjectionChoice() { 024 super(tr("Gau\u00DF-Kr\u00FCger"), /* NO-ICON */ "core:gauss-krueger", zones, tr("GK Zone")); 025 } 026 027 @Override 028 public String getCurrentCode() { 029 return "EPSG:"+Integer.toString(31466 + index); 030 } 031 032 @Override 033 protected String indexToZone(int index) { 034 return Integer.toString(index + 2); 035 } 036 037 @Override 038 protected int zoneToIndex(String zone) { 039 try { 040 return Integer.parseInt(zone) - 2; 041 } catch (NumberFormatException e) { 042 Logging.warn(e); 043 } 044 return defaultIndex; 045 } 046 047 @Override 048 public String[] allCodes() { 049 String[] codes = new String[4]; 050 for (int zone = 2; zone <= 5; zone++) { 051 codes[zone-2] = "EPSG:" + (31464 + zone); 052 } 053 return codes; 054 } 055 056 @Override 057 public Collection<String> getPreferencesFromCode(String code) { 058 //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469 059 for (int zone = 2; zone <= 5; zone++) { 060 String epsg = "EPSG:" + (31464 + zone); 061 if (epsg.equals(code)) 062 return Collections.singleton(String.valueOf(zone)); 063 } 064 return null; 065 } 066 067 @Override 068 public String getProjectionName() { 069 return tr("Gau\u00DF-Kr\u00FCger Zone {0}", index + 2); 070 } 071 072}