Ignore:
Timestamp:
2017-09-05T17:58:01+02:00 (2 years ago)
Author:
bastiK
Message:

see #15229 - move CoordinateFormat code out of LatLon class

Location:
trunk/src/org/openstreetmap/josm/data/coor
Files:
8 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/CoordinateFormat.java

    r11489 r12735  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
     7import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat;
     8import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;
     9import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
     10import org.openstreetmap.josm.data.coor.conversion.NauticalCoordinateFormat;
     11import org.openstreetmap.josm.data.coor.conversion.ProjectedCoordinateFormat;
     12
    613/**
    714 * An enumeration  of coordinate formats
    815 * @since 1990
     16 * @deprecated use {@link CoordinateFormatManager}
    917 */
     18@Deprecated
    1019public enum CoordinateFormat {
    1120
     
    1322     * the decimal format 999.999
    1423     */
    15     DECIMAL_DEGREES(tr("Decimal Degrees")),
     24    DECIMAL_DEGREES(tr("Decimal Degrees"), DecimalDegreesCoordinateFormat.INSTANCE),
    1625
    1726    /**
    1827     * the degrees/minutes/seconds format 9 deg 99 min 99 sec
    1928     */
    20     DEGREES_MINUTES_SECONDS(tr("deg\u00B0 min'' sec\"")),
     29    DEGREES_MINUTES_SECONDS(tr("deg\u00B0 min'' sec\""), DMSCoordinateFormat.INSTANCE),
    2130
    2231    /**
    2332     * the nautical format
    2433     */
    25     NAUTICAL(tr("deg\u00B0 min'' (Nautical)")),
     34    NAUTICAL(tr("deg\u00B0 min'' (Nautical)"), NauticalCoordinateFormat.INSTANCE),
    2635
    2736    /**
    2837     * coordinates East/North
    2938     */
    30     EAST_NORTH(tr("Projected Coordinates"));
     39    EAST_NORTH(tr("Projected Coordinates"), ProjectedCoordinateFormat.INSTANCE);
    3140
    3241    private final String displayName;
     42    private final ICoordinateFormat migration;
    3343
    34     CoordinateFormat(String displayName) {
     44    CoordinateFormat(String displayName, ICoordinateFormat migration) {
    3545        this.displayName = displayName;
     46        this.migration = migration;
    3647    }
    3748
     
    4354    public String getDisplayName() {
    4455        return displayName;
     56    }
     57
     58    /**
     59     * Returns the corresponding {@link ICoordinateFormat} instance for
     60     * migration.
     61     * @return the corresponding {@link ICoordinateFormat} instance for
     62     * migration
     63     */
     64    public ICoordinateFormat getICoordinateFormat() {
     65        return migration;
    4566    }
    4667
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r12725 r12735  
    2525import org.openstreetmap.josm.Main;
    2626import org.openstreetmap.josm.data.Bounds;
     27import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat;
     28import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;
     29import org.openstreetmap.josm.data.coor.conversion.NauticalCoordinateFormat;
    2730import org.openstreetmap.josm.tools.Logging;
    2831import org.openstreetmap.josm.tools.Utils;
     
    6972    public static final LatLon SOUTH_POLE = new LatLon(-90, 0);
    7073
    71     private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00");
    72     private static DecimalFormat cDmsSecondFormatter = new DecimalFormat(
    73             Main.pref == null ? "00.0" : Main.pref.get("latlon.dms.decimal-format", "00.0"));
    74     private static DecimalFormat cDmMinuteFormatter = new DecimalFormat(
    75             Main.pref == null ? "00.000" : Main.pref.get("latlon.dm.decimal-format", "00.000"));
    7674    /**
    7775     * The normal number format for server precision coordinates
     
    9088        cDdHighPecisionFormatter.applyPattern("###0.0##########");
    9189    }
    92 
    93     private static final String cDms60 = cDmsSecondFormatter.format(60.0);
    94     private static final String cDms00 = cDmsSecondFormatter.format(0.0);
    95     private static final String cDm60 = cDmMinuteFormatter.format(60.0);
    96     private static final String cDm00 = cDmMinuteFormatter.format(0.0);
    9790
    9891    /** Character denoting South, as string */
     
    217210     * @return The coordinate in degrees/minutes/seconds format
    218211     * @since 12561
    219      */
     212     * @deprecated use {@link DMSCoordinateFormat#degreesMinutesSeconds(double)}
     213     */
     214    @Deprecated
    220215    public static String degreesMinutesSeconds(double pCoordinate) {
    221 
    222         double tAbsCoord = Math.abs(pCoordinate);
    223         int tDegree = (int) tAbsCoord;
    224         double tTmpMinutes = (tAbsCoord - tDegree) * 60;
    225         int tMinutes = (int) tTmpMinutes;
    226         double tSeconds = (tTmpMinutes - tMinutes) * 60;
    227 
    228         String sDegrees = Integer.toString(tDegree);
    229         String sMinutes = cDmsMinuteFormatter.format(tMinutes);
    230         String sSeconds = cDmsSecondFormatter.format(tSeconds);
    231 
    232         if (cDms60.equals(sSeconds)) {
    233             sSeconds = cDms00;
    234             sMinutes = cDmsMinuteFormatter.format(tMinutes+1L);
    235         }
    236         if ("60".equals(sMinutes)) {
    237             sMinutes = "00";
    238             sDegrees = Integer.toString(tDegree+1);
    239         }
    240 
    241         return sDegrees + '\u00B0' + sMinutes + '\'' + sSeconds + '\"';
     216        return DMSCoordinateFormat.degreesMinutesSeconds(pCoordinate);
    242217    }
    243218
     
    247222     * @return The coordinate in degrees/minutes format
    248223     * @since 12537
    249      */
     224     * @deprecated use {@link NauticalCoordinateFormat#degreesMinutes(double)}
     225     */
     226    @Deprecated
    250227    public static String degreesMinutes(double pCoordinate) {
    251 
    252         double tAbsCoord = Math.abs(pCoordinate);
    253         int tDegree = (int) tAbsCoord;
    254         double tMinutes = (tAbsCoord - tDegree) * 60;
    255 
    256         String sDegrees = Integer.toString(tDegree);
    257         String sMinutes = cDmMinuteFormatter.format(tMinutes);
    258 
    259         if (sMinutes.equals(cDm60)) {
    260             sMinutes = cDm00;
    261             sDegrees = Integer.toString(tDegree+1);
    262         }
    263 
    264         return sDegrees + '\u00B0' + sMinutes + '\'';
     228        return NauticalCoordinateFormat.degreesMinutes(pCoordinate);
    265229    }
    266230
     
    302266     * @param d the coordinate format to use
    303267     * @return the formatted latitude
    304      */
     268     * @deprecated use {@link org.openstreetmap.josm.data.coor.format.ICoordinateFormat#latToString(ILatLon)
     269     */
     270    @Deprecated
    305271    public String latToString(CoordinateFormat d) {
    306         switch(d) {
    307         case DECIMAL_DEGREES: return cDdFormatter.format(y);
    308         case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(y) + ((y < 0) ? SOUTH : NORTH);
    309         case NAUTICAL: return degreesMinutes(y) + ((y < 0) ? SOUTH : NORTH);
    310         case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).north());
    311         default: return "ERR";
    312         }
     272        return d.getICoordinateFormat().latToString(this);
    313273    }
    314274
     
    322282     * @param d the coordinate format to use
    323283     * @return the formatted longitude
    324      */
     284     * @deprecated use {@link org.openstreetmap.josm.data.coor.format.ICoordinateFormat#lonToString(ILatLon)
     285     */
     286    @Deprecated
    325287    public String lonToString(CoordinateFormat d) {
    326         switch(d) {
    327         case DECIMAL_DEGREES: return cDdFormatter.format(x);
    328         case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(x) + ((x < 0) ? WEST : EAST);
    329         case NAUTICAL: return degreesMinutes(x) + ((x < 0) ? WEST : EAST);
    330         case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).east());
    331         default: return "ERR";
    332         }
     288        return d.getICoordinateFormat().lonToString(this);
    333289    }
    334290
     
    469425    public String toStringCSV(String separator) {
    470426        return Utils.join(separator, Arrays.asList(
    471                 latToString(CoordinateFormat.DECIMAL_DEGREES),
    472                 lonToString(CoordinateFormat.DECIMAL_DEGREES)
     427                DecimalDegreesCoordinateFormat.INSTANCE.latToString(this),
     428                DecimalDegreesCoordinateFormat.INSTANCE.lonToString(this)
    473429        ));
    474430    }
Note: See TracChangeset for help on using the changeset viewer.