Changeset 5870 in josm


Ignore:
Timestamp:
2013-04-15T21:41:07+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #8610 - Wrong display of areas (based on patch by Cobra)

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r5670 r5870  
    12361236     */
    12371237    public static class SystemOfMeasurement {
     1238       
     1239        /** First value, in meters, used to translate unit according to above formula. */
    12381240        public final double aValue;
     1241        /** Second value, in meters, used to translate unit according to above formula. */
    12391242        public final double bValue;
     1243        /** First unit used to format text. */
    12401244        public final String aName;
     1245        /** Second unit used to format text. */
    12411246        public final String bName;
     1247        /** Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}. Set to {@code -1} if not used.
     1248         *  @since 5870 */
     1249        public final double areaCustomValue;
     1250        /** Specific optional area unit. Set to {@code null} if not used.
     1251         *  @since 5870 */
     1252        public final String areaCustomName;
    12421253
    12431254        /**
     
    12461257         * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as
    12471258         * x_a == x_m / aValue
     1259         *
     1260         * @param aValue First value, in meters, used to translate unit according to above formula.
     1261         * @param aName First unit used to format text.
     1262         * @param bValue Second value, in meters, used to translate unit according to above formula.
     1263         * @param bName Second unit used to format text.
    12481264         */
    12491265        public SystemOfMeasurement(double aValue, String aName, double bValue, String bName) {
     1266            this(aValue, aName, bValue, bName, -1, null);
     1267        }
     1268       
     1269        /**
     1270         * System of measurement. Currently covers only length (and area) units.
     1271         *
     1272         * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as
     1273         * x_a == x_m / aValue
     1274         *
     1275         * @param aValue First value, in meters, used to translate unit according to above formula.
     1276         * @param aName First unit used to format text.
     1277         * @param bValue Second value, in meters, used to translate unit according to above formula.
     1278         * @param bName Second unit used to format text.
     1279         * @param areaCustomValue Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}.
     1280         *                        Set to {@code -1} if not used.
     1281         * @param areaCustomName Specific optional area unit. Set to {@code null} if not used.
     1282         *
     1283         * @since 5870
     1284         */
     1285        public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, double areaCustomValue, String areaCustomName) {
    12501286            this.aValue = aValue;
    12511287            this.aName = aName;
    12521288            this.bValue = bValue;
    12531289            this.bName = bName;
     1290            this.areaCustomValue = areaCustomValue;
     1291            this.areaCustomName = areaCustomName;
    12541292        }
    12551293
     
    12611299        public String getDistText(double dist) {
    12621300            double a = dist / aValue;
    1263             if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) {
    1264                 double b = dist / bValue;
    1265                 return String.format(Locale.US, "%." + (b<10 ? 2 : 1) + "f %s", b, bName);
    1266             } else if (a < 0.01)
     1301            if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue)
     1302                return formatText(dist / bValue, bName);
     1303            else if (a < 0.01)
    12671304                return "< 0.01 " + aName;
    12681305            else
    1269                 return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s", a, aName);
     1306                return formatText(a, aName);
    12701307        }
    12711308
     
    12781315        public String getAreaText(double area) {
    12791316            double a = area / (aValue*aValue);
    1280             if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) {
    1281                 double b = area / (bValue*bValue);
    1282                 return String.format(Locale.US, "%." + (b<10 ? 2 : 1) + "f %s", b, bName+"\u00b2");
    1283             } else if (a < 0.01)
    1284                 return "< 0.01 " + aName;
     1317            boolean lowerOnly = Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false);
     1318            if (!lowerOnly && areaCustomValue > 0 && a > areaCustomValue / aValue*aValue && a < bValue*bValue / aValue*aValue)
     1319                return formatText(area / areaCustomValue, areaCustomName);
     1320            else if (!lowerOnly && a >= bValue*bValue / aValue*aValue)
     1321                return formatText(area / (bValue*bValue), bName+"\u00b2");
     1322            else if (a < 0.01)
     1323                return "< 0.01 " + aName+"\u00b2";
    12851324            else
    1286                 return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s", a, aName+"\u00b2");
     1325                return formatText(a, aName+"\u00b2");
     1326        }
     1327       
     1328        private static String formatText(double v, String unit) {
     1329            return String.format(Locale.US, "%." + (v<9.999999 ? 2 : 1) + "f %s", v, unit);
    12871330        }
    12881331    }
     
    12921335     * @since 3406
    12931336     */
    1294     public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km");
     1337    public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km", 10000, "ha");
    12951338   
    12961339    /**
Note: See TracChangeset for help on using the changeset viewer.