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

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

see #15229 - fix javadoc warnings

File size: 2.4 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 final class CoordinateFormatManager {
15
16 private static final 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 private CoordinateFormatManager() {
26 // hide constructor
27 }
28
29 /**
30 * Register a coordinate format.
31 * <p>
32 * It will be available as a choice in the preferences.
33 * @param format the coordinate format
34 */
35 public static void registerCoordinateFormat(ICoordinateFormat format) {
36 formats.add(format);
37 }
38
39 /**
40 * Get the list of all registered coordinate formats.
41 * @return the list of all registered coordinate formats
42 */
43 public static List<ICoordinateFormat> getCoordinateFormats() {
44 return Collections.unmodifiableList(formats);
45 }
46
47 private static volatile ICoordinateFormat defaultCoordinateFormat = DecimalDegreesCoordinateFormat.INSTANCE;
48
49 /**
50 * Replies the default coordinate format to be use
51 *
52 * @return the default coordinate format
53 */
54 public static ICoordinateFormat getDefaultFormat() {
55 return defaultCoordinateFormat;
56 }
57
58 /**
59 * Sets the default coordinate format
60 *
61 * @param format the default coordinate format
62 */
63 public static void setCoordinateFormat(ICoordinateFormat format) {
64 if (format != null) {
65 defaultCoordinateFormat = format;
66 }
67 }
68
69 /**
70 * Get registered coordinate format by id
71 *
72 * @param id id of the coordinate format to get
73 * @return the registered {@link ICoordinateFormat} with given id, or <code>null</code>
74 * if no match is found
75 */
76 public static ICoordinateFormat getCoordinateFormat(String id) {
77 CheckParameterUtil.ensureParameterNotNull(id, "id");
78 return formats.stream().filter(format -> id.equals(format.getId())).findFirst().orElse(null);
79 }
80}
Note: See TracBrowser for help on using the repository browser.