source: josm/trunk/src/org/openstreetmap/josm/data/coor/conversion/CoordinateFormatManager.java@ 12735

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

see #15229 - move CoordinateFormat code out of LatLon class

File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor.conversion;
3
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7
8import org.openstreetmap.josm.tools.CheckParameterUtil;
9
10/**
11 * Class that manages the available coordinate formats.
12 * @since 12735
13 */
14public class CoordinateFormatManager {
15
16 private final static List<ICoordinateFormat> formats = new ArrayList<>();
17
18 static {
19 registerCoordinateFormat(DecimalDegreesCoordinateFormat.INSTANCE);
20 registerCoordinateFormat(DMSCoordinateFormat.INSTANCE);
21 registerCoordinateFormat(NauticalCoordinateFormat.INSTANCE);
22 registerCoordinateFormat(ProjectedCoordinateFormat.INSTANCE);
23 }
24
25 /**
26 * Register a coordinate format.
27 * <p>
28 * It will be available as a choice in the preferences.
29 * @param format the coordinate format
30 */
31 public static void registerCoordinateFormat(ICoordinateFormat format) {
32 formats.add(format);
33 }
34
35 /**
36 * Get the list of all registered coordinate formats.
37 * @return the list of all registered coordinate formats
38 */
39 public static List<ICoordinateFormat> getCoordinateFormats() {
40 return Collections.unmodifiableList(formats);
41 }
42
43 private static volatile ICoordinateFormat defaultCoordinateFormat = DecimalDegreesCoordinateFormat.INSTANCE;
44
45 /**
46 * Replies the default coordinate format to be use
47 *
48 * @return the default coordinate format
49 */
50 public static ICoordinateFormat getDefaultFormat() {
51 return defaultCoordinateFormat;
52 }
53
54 /**
55 * Sets the default coordinate format
56 *
57 * @param format the default coordinate format
58 */
59 public static void setCoordinateFormat(ICoordinateFormat format) {
60 if (format != null) {
61 defaultCoordinateFormat = format;
62 }
63 }
64
65 /**
66 * Get registered coordinate format by id
67 *
68 * @param id id of the coordinate format to get
69 * @return the registered {@link ICoordinateFormat} with given id, or <code>null</code>
70 * if no match is found
71 */
72 public static ICoordinateFormat getCoordinateFormat(String id) {
73 CheckParameterUtil.ensureParameterNotNull(id, "id");
74 return formats.stream().filter(format -> id.equals(format.getId())).findFirst().orElse(null);
75 }
76}
Note: See TracBrowser for help on using the repository browser.