001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.coor.conversion;
003
004import static org.openstreetmap.josm.tools.I18n.trc;
005
006import java.text.DecimalFormat;
007import java.text.NumberFormat;
008import java.util.Locale;
009
010/**
011 * Abstract base class for {@link ICoordinateFormat} implementations.
012 * @since 12735
013 */
014public abstract class AbstractCoordinateFormat implements ICoordinateFormat {
015
016    protected final String id;
017    protected final String displayName;
018
019    /**
020     * The normal number format for server precision coordinates
021     */
022    protected static final DecimalFormat cDdFormatter;
023    static {
024        // Don't use the localized decimal separator. This way we can present
025        // a comma separated list of coordinates.
026        cDdFormatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK);
027        cDdFormatter.applyPattern("###0.0######");
028    }
029
030    /** Character denoting South, as string */
031    protected static final String SOUTH = trc("compass", "S");
032    /** Character denoting North, as string */
033    protected static final String NORTH = trc("compass", "N");
034    /** Character denoting West, as string */
035    protected static final String WEST = trc("compass", "W");
036    /** Character denoting East, as string */
037    protected static final String EAST = trc("compass", "E");
038
039    protected AbstractCoordinateFormat(String id, String displayName) {
040        this.id = id;
041        this.displayName = displayName;
042    }
043
044    @Override
045    public String getId() {
046        return id;
047    }
048
049    @Override
050    public String getDisplayName() {
051        return displayName;
052    }
053
054    @Override
055    public String toString() {
056        return getDisplayName();
057    }
058}