Changeset 12786 in josm
- Timestamp:
- 2017-09-08T19:25:12+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r12778 r12786 14 14 import java.util.Map; 15 15 import java.util.Set; 16 import java.util.function.Supplier; 16 17 import java.util.regex.Matcher; 17 18 import java.util.regex.Pattern; … … 42 43 import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator; 43 44 import org.openstreetmap.josm.data.projection.proj.TransverseMercator; 44 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;45 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;46 45 import org.openstreetmap.josm.io.CachedFile; 47 46 import org.openstreetmap.josm.tools.JosmRuntimeException; … … 78 77 79 78 private static final Set<String> allCodes = new HashSet<>(); 80 private static final Map<String, Projection Choice> allProjectionChoicesByCode = new HashMap<>();79 private static final Map<String, Supplier<Projection>> projectionSuppliersByCode = new HashMap<>(); 81 80 private static final Map<String, Projection> projectionsByCode_cache = new HashMap<>(); 82 81 … … 157 156 throw new JosmRuntimeException(ex); 158 157 } 159 160 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {161 for (String code : pc.allCodes()) {162 allProjectionChoicesByCode.put(code, pc);163 }164 }165 158 allCodes.addAll(inits.keySet()); 166 allCodes.addAll(allProjectionChoicesByCode.keySet());167 159 } 168 160 … … 242 234 public static void registerBaseProjection(String id, Class<? extends Proj> projClass, String origin) { 243 235 registerBaseProjection(id, new ClassProjFactory(projClass), origin); 236 } 237 238 /** 239 * Register a projection supplier, that is, a factory class for projections. 240 * @param code the code of the projection that will be returned 241 * @param supplier a supplier to return a projection with given code 242 * @since 12786 243 */ 244 public static void registerProjectionSupplier(String code, Supplier<Projection> supplier) { 245 projectionSuppliersByCode.put(code, supplier); 246 allCodes.add(code); 244 247 } 245 248 … … 351 354 Projection proj = projectionsByCode_cache.get(code); 352 355 if (proj != null) return proj; 353 ProjectionChoice pc = allProjectionChoicesByCode.get(code); 354 if (pc != null) { 355 Collection<String> pref = pc.getPreferencesFromCode(code); 356 pc.setPreferences(pref); 357 try { 358 proj = pc.getProjection(); 359 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { 360 Logging.log(Logging.LEVEL_WARN, "Unable to get projection "+code+" with "+pc+':', e); 356 357 ProjectionDefinition pd = inits.get(code); 358 if (pd != null) { 359 proj = new CustomProjection(pd.name, code, pd.definition); 360 } 361 if (proj == null) { 362 Supplier<Projection> ps = projectionSuppliersByCode.get(code); 363 if (ps != null) { 364 proj = ps.get(); 361 365 } 362 366 } 363 if (proj == null) { 364 ProjectionDefinition pd = inits.get(code); 365 if (pd == null) return null; 366 proj = new CustomProjection(pd.name, code, pd.definition); 367 } 368 projectionsByCode_cache.put(code, proj); 367 if (proj != null) { 368 projectionsByCode_cache.put(code, proj); 369 } 369 370 return proj; 370 371 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r12735 r12786 32 32 import org.openstreetmap.josm.data.projection.CustomProjection; 33 33 import org.openstreetmap.josm.data.projection.Projection; 34 import org.openstreetmap.josm.data.projection.Projections; 34 35 import org.openstreetmap.josm.gui.ExtendedDialog; 35 36 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 42 43 import org.openstreetmap.josm.tools.GBC; 43 44 import org.openstreetmap.josm.tools.JosmRuntimeException; 45 import org.openstreetmap.josm.tools.Logging; 44 46 45 47 /** … … 255 257 projectionChoices.add(c); 256 258 projectionChoicesById.put(c.getId(), c); 259 for (String code : c.allCodes()) { 260 Projections.registerProjectionSupplier(code, () -> { 261 Collection<String> pref = c.getPreferencesFromCode(code); 262 c.setPreferences(pref); 263 try { 264 return c.getProjection(); 265 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { 266 Logging.log(Logging.LEVEL_WARN, "Unable to get projection "+code+" with "+c+':', e); 267 return null; 268 } 269 }); 270 } 257 271 } 258 272
Note:
See TracChangeset
for help on using the changeset viewer.