source: josm/trunk/src/org/openstreetmap/josm/data/coor/conversion/AbstractCoordinateFormat.java@ 17787

Last change on this file since 17787 was 14203, checked in by Don-vip, 6 years ago

fix #15696, see #16688 - Don't use the localized decimal separator for coordinates

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.trc;
5
6import java.text.DecimalFormat;
7import java.text.NumberFormat;
8import java.util.Locale;
9
10/**
11 * Abstract base class for {@link ICoordinateFormat} implementations.
12 * @since 12735
13 */
14public abstract class AbstractCoordinateFormat implements ICoordinateFormat {
15
16 protected final String id;
17 protected final String displayName;
18
19 /** The normal number format for server precision coordinates */
20 protected static final DecimalFormat cDdFormatter = newUnlocalizedDecimalFormat("###0.0######");
21 /** Character denoting South, as string */
22 protected static final String SOUTH = trc("compass", "S");
23 /** Character denoting North, as string */
24 protected static final String NORTH = trc("compass", "N");
25 /** Character denoting West, as string */
26 protected static final String WEST = trc("compass", "W");
27 /** Character denoting East, as string */
28 protected static final String EAST = trc("compass", "E");
29
30 protected AbstractCoordinateFormat(String id, String displayName) {
31 this.id = id;
32 this.displayName = displayName;
33 }
34
35 /**
36 * Creates a new unlocalized {@link DecimalFormat}.
37 * By not using the localized decimal separator, we can present a comma separated list of coordinates.
38 * @param pattern decimal format pattern
39 * @return {@code DecimalFormat} using dot as decimal separator
40 * @see DecimalFormat#applyPattern
41 * @since 14203
42 */
43 public static DecimalFormat newUnlocalizedDecimalFormat(String pattern) {
44 DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.UK);
45 format.applyPattern(pattern);
46 return format;
47 }
48
49 @Override
50 public String getId() {
51 return id;
52 }
53
54 @Override
55 public String getDisplayName() {
56 return displayName;
57 }
58
59 @Override
60 public String toString() {
61 return getDisplayName();
62 }
63}
Note: See TracBrowser for help on using the repository browser.