001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.gui.preferences.projection; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import java.util.Collection; 007 import java.util.Collections; 008 009 import org.openstreetmap.josm.data.projection.GaussKrueger; 010 import org.openstreetmap.josm.data.projection.Projection; 011 012 public class GaussKruegerProjectionChoice extends ListProjectionChoice implements Alias { 013 014 private static String[] zones = { "2", "3", "4", "5" }; 015 016 public GaussKruegerProjectionChoice() { 017 super("core:gauss-krueger", tr("Gau\u00DF-Kr\u00FCger"), zones, tr("GK Zone")); 018 } 019 020 @Override 021 public Projection getProjection() { 022 return new GaussKrueger(index + 2); 023 } 024 025 @Override 026 protected String indexToZone(int index) { 027 return Integer.toString(index + 2); 028 } 029 030 @Override 031 protected int zoneToIndex(String zone) { 032 try { 033 return Integer.parseInt(zone) - 2; 034 } catch(NumberFormatException e) {} 035 return defaultIndex; 036 } 037 038 @Override 039 public String[] allCodes() { 040 String[] codes = new String[4]; 041 for (int zone = 2; zone <= 5; zone++) { 042 codes[zone-2] = "EPSG:" + (31464 + zone); 043 } 044 return codes; 045 } 046 047 @Override 048 public Collection<String> getPreferencesFromCode(String code) 049 { 050 //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469 051 for (int zone = 2; zone <= 5; zone++) { 052 String epsg = "EPSG:" + (31464 + zone); 053 if (epsg.equals(code)) 054 return Collections.singleton(String.valueOf(zone)); 055 } 056 return null; 057 } 058 059 @Override 060 public String getAlias() { 061 return GaussKrueger.class.getName(); 062 } 063 064 }