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

see #15229 - move CoordinateFormat code out of LatLon class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.