001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.data.projection; 003 004 import java.util.Collection; 005 import java.util.HashMap; 006 import java.util.Map; 007 008 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 009 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 010 011 public class ProjectionInfo { 012 private static Map<String, ProjectionChoice> allCodesPC = new HashMap<String, ProjectionChoice>(); 013 private static Map<String, Projection> allCodes = new HashMap<String, Projection>(); 014 015 static { 016 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 017 for (String code : pc.allCodes()) { 018 allCodesPC.put(code, pc); 019 } 020 } 021 } 022 023 public static Projection getProjectionByCode(String code) { 024 Projection p = allCodes.get(code); 025 if (p != null) return p; 026 ProjectionChoice pc = allCodesPC.get(code); 027 if (pc == null) return null; 028 Collection<String> pref = pc.getPreferencesFromCode(code); 029 pc.setPreferences(pref); 030 p = pc.getProjection(); 031 allCodes.put(code, p); 032 return p; 033 } 034 }