source: josm/trunk/src/org/openstreetmap/josm/data/coor/conversion/NauticalCoordinateFormat.java@ 13224

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

see #15229 - use Config.getPref() wherever possible

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor.conversion;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.text.DecimalFormat;
7
8import org.openstreetmap.josm.data.coor.ILatLon;
9import org.openstreetmap.josm.spi.preferences.Config;
10
11/**
12 * Coordinate format that converts a coordinate to degrees and minutes (nautical format).
13 * @since 12735
14 */
15public class NauticalCoordinateFormat extends AbstractCoordinateFormat {
16 private static final DecimalFormat DM_MINUTE_FORMATTER = new DecimalFormat(
17 Config.getPref() == null ? "00.000" : Config.getPref().get("latlon.dm.decimal-format", "00.000"));
18 private static final String DM60 = DM_MINUTE_FORMATTER.format(60.0);
19 private static final String DM00 = DM_MINUTE_FORMATTER.format(0.0);
20
21 /**
22 * The unique instance.
23 */
24 public static final NauticalCoordinateFormat INSTANCE = new NauticalCoordinateFormat();
25
26 protected NauticalCoordinateFormat() {
27 super("NAUTICAL", tr("deg\u00B0 min'' (Nautical)"));
28 }
29
30 @Override
31 public String latToString(ILatLon ll) {
32 return degreesMinutes(ll.lat()) + ((ll.lat() < 0) ? SOUTH : NORTH);
33 }
34
35 @Override
36 public String lonToString(ILatLon ll) {
37 return degreesMinutes(ll.lon()) + ((ll.lon() < 0) ? WEST : EAST);
38 }
39
40 /**
41 * Replies the coordinate in degrees/minutes format
42 * @param pCoordinate The coordinate to convert
43 * @return The coordinate in degrees/minutes format
44 * @since 12537
45 */
46 public static String degreesMinutes(double pCoordinate) {
47
48 double tAbsCoord = Math.abs(pCoordinate);
49 int tDegree = (int) tAbsCoord;
50 double tMinutes = (tAbsCoord - tDegree) * 60;
51
52 String sDegrees = Integer.toString(tDegree);
53 String sMinutes = DM_MINUTE_FORMATTER.format(tMinutes);
54
55 if (sMinutes.equals(DM60)) {
56 sMinutes = DM00;
57 sDegrees = Integer.toString(tDegree+1);
58 }
59
60 return sDegrees + '\u00B0' + sMinutes + '\'';
61 }
62}
Note: See TracBrowser for help on using the repository browser.