source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/projection/AbstractProjectionChoice.java@ 7864

Last change on this file since 7864 was 7864, checked in by Don-vip, 9 years ago

global cleanup of IllegalArgumentExceptions thrown by JOSM

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.projection;
3
4import org.openstreetmap.josm.data.projection.CustomProjection;
5import org.openstreetmap.josm.data.projection.Projection;
6import org.openstreetmap.josm.data.projection.Projections;
7
8public abstract class AbstractProjectionChoice implements ProjectionChoice {
9
10 protected String name;
11 protected String id;
12 protected String cacheDir;
13
14 /**
15 * Constructs a new {@code AbstractProjectionChoice}.
16 *
17 * @param name short name of the projection choice as shown in the GUI
18 * @param id unique identifier for the projection choice
19 * @param cacheDir a cache directory name
20 */
21 public AbstractProjectionChoice(String name, String id, String cacheDir) {
22 this.name = name;
23 this.id = id;
24 this.cacheDir = cacheDir;
25 }
26
27 /**
28 * Constructs a new {@code AbstractProjectionChoice}.
29 *
30 * Only for core projection choices, where chacheDir is the same as
31 * the second part of the id.
32 * @param name short name of the projection choice as shown in the GUI
33 * @param id unique identifier for the projection choice
34 */
35 public AbstractProjectionChoice(String name, String id) {
36 this(name, id, null);
37 if (!id.startsWith("core:")) throw new IllegalArgumentException(id+" does not start with core:");
38 this.cacheDir = id.substring(5);
39 }
40
41 @Override
42 public String getId() {
43 return id;
44 }
45
46 public String getCacheDir() {
47 return cacheDir;
48 }
49
50 @Override
51 public String toString() {
52 return name;
53 }
54
55 public abstract String getCurrentCode();
56
57 public abstract String getProjectionName();
58
59 @Override
60 public Projection getProjection() {
61 String code = getCurrentCode();
62 String pref = Projections.getInit(code);
63 if (pref == null)
64 throw new AssertionError("Error: Unknown projection code");
65 return new CustomProjection(getProjectionName(), code, pref, getCacheDir());
66 }
67}
Note: See TracBrowser for help on using the repository browser.