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

Last change on this file since 12216 was 12216, checked in by bastiK, 7 years ago

deprecate unused methods

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.projection;
3
4import java.util.Optional;
5
6import org.openstreetmap.josm.data.projection.CustomProjection;
7import org.openstreetmap.josm.data.projection.Projection;
8import org.openstreetmap.josm.data.projection.Projections;
9
10/**
11 * Super class for ProjectionChoice implementations.
12 * <p>
13 * Handles common parameters <code>name</code>, <code>id</code> and <code>cacheDir</code>.
14 */
15public abstract class AbstractProjectionChoice implements ProjectionChoice {
16
17 protected String name;
18 protected String id;
19 protected String cacheDir;
20
21 /**
22 * Constructs a new {@code AbstractProjectionChoice}.
23 *
24 * @param name short name of the projection choice as shown in the GUI
25 * @param id unique identifier for the projection choice
26 * @param cacheDir a cache directory name
27 */
28 public AbstractProjectionChoice(String name, String id, String cacheDir) {
29 this.name = name;
30 this.id = id;
31 this.cacheDir = cacheDir;
32 }
33
34 /**
35 * Constructs a new {@code AbstractProjectionChoice}.
36 *
37 * Only for core projection choices, where chacheDir is the same as
38 * the second part of the id.
39 * @param name short name of the projection choice as shown in the GUI
40 * @param id unique identifier for the projection choice
41 */
42 public AbstractProjectionChoice(String name, String id) {
43 this(name, id, null);
44 if (!id.startsWith("core:")) throw new IllegalArgumentException(id+" does not start with core:");
45 this.cacheDir = id.substring(5);
46 }
47
48 @Override
49 public String getId() {
50 return id;
51 }
52
53 /**
54 * Get the cache directory name.
55 * @return the cache directory name (base name)
56 * @deprecated unused - remove in 2017-07
57 */
58 @Deprecated
59 public String getCacheDir() {
60 return cacheDir;
61 }
62
63 @Override
64 public String toString() {
65 return name;
66 }
67
68 public abstract String getCurrentCode();
69
70 public abstract String getProjectionName();
71
72 @Override
73 public Projection getProjection() {
74 String code = getCurrentCode();
75 return new CustomProjection(getProjectionName(), code, Optional.ofNullable(Projections.getInit(code))
76 .orElseThrow(() -> new AssertionError("Error: Unknown projection code: " + code)), getCacheDir());
77 }
78}
Note: See TracBrowser for help on using the repository browser.