Changeset 5560 in josm for trunk/src/org


Ignore:
Timestamp:
2012-11-03T23:59:14+01:00 (11 years ago)
Author:
Don-vip
Message:

see #8153 - Add area units to systems of measurement

File:
1 edited

Legend:

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

    r5549 r5560  
    44import static org.openstreetmap.josm.tools.I18n.marktr;
    55
    6 import java.awt.Color;
    76import java.awt.Cursor;
    87import java.awt.Graphics;
     
    133132    }
    134133
     134    /**
     135     * Returns the text describing the given distance in the current system of measurement.
     136     * @param dist The distance in metres.
     137     * @return the text describing the given distance in the current system of measurement.
     138     * @since 3406
     139     */
    135140    public static String getDistText(double dist) {
    136141        return getSystemOfMeasurement().getDistText(dist);
     142    }
     143
     144    /**
     145     * Returns the text describing the given area in the current system of measurement.
     146     * @param area The distance in square metres.
     147     * @return the text describing the given area in the current system of measurement.
     148     * @since 5560
     149     */
     150    public static String getAreaText(double area) {
     151        return getSystemOfMeasurement().getAreaText(area);
    137152    }
    138153
     
    11711186    }
    11721187
     1188    /**
     1189     * Returns the current system of measurement.
     1190     * @return The current system of measurement (metric system by default).
     1191     * @since 3490
     1192     */
    11731193    public static SystemOfMeasurement getSystemOfMeasurement() {
    11741194        SystemOfMeasurement som = SYSTEMS_OF_MEASUREMENT.get(ProjectionPreference.PROP_SYSTEM_OF_MEASUREMENT.get());
     
    11781198    }
    11791199
     1200    /**
     1201     * A system of units used to express length and area measurements.
     1202     * @since 3406
     1203     */
    11801204    public static class SystemOfMeasurement {
    11811205        public final double aValue;
     
    11851209
    11861210        /**
    1187          * System of measurement. Currently covers only length units.
     1211         * System of measurement. Currently covers only length (and area) units.
    11881212         *
    11891213         * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as
     
    11971221        }
    11981222
     1223        /**
     1224         * Returns the text describing the given distance in this system of measurement.
     1225         * @param dist The distance in metres
     1226         * @return The text describing the given distance in this system of measurement.
     1227         */
    11991228        public String getDistText(double dist) {
    12001229            double a = dist / aValue;
     
    12071236                return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s", a, aName);
    12081237        }
    1209     }
    1210 
     1238
     1239        /**
     1240         * Returns the text describing the given area in this system of measurement.
     1241         * @param area The area in square metres
     1242         * @return The text describing the given area in this system of measurement.
     1243         * @since 5560
     1244         */
     1245        public String getAreaText(double area) {
     1246            return getDistText(area)+"\u00b2"; // square
     1247        }
     1248    }
     1249
     1250    /**
     1251     * Metric system (international standard).
     1252     * @since 3406
     1253     */
    12111254    public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km");
     1255   
     1256    /**
     1257     * Chinese system.
     1258     * @since 3406
     1259     */
    12121260    public static final SystemOfMeasurement CHINESE_SOM = new SystemOfMeasurement(1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */);
     1261   
     1262    /**
     1263     * Imperial system (British Commonwealth and former British Empire).
     1264     * @since 3406
     1265     */
    12131266    public static final SystemOfMeasurement IMPERIAL_SOM = new SystemOfMeasurement(0.3048, "ft", 1609.344, "mi");
     1267   
     1268    /**
     1269     * Nautical mile system (navigation, polar exploration).
     1270     * @since 5549
     1271     */
    12141272    public static final SystemOfMeasurement NAUTICAL_MILE_SOM = new SystemOfMeasurement(185.2, "kbl", 1852, "NM");
    12151273
     1274    /**
     1275     * Known systems of measurement.
     1276     * @since 3406
     1277     */
    12161278    public static final Map<String, SystemOfMeasurement> SYSTEMS_OF_MEASUREMENT;
    12171279    static {
Note: See TracChangeset for help on using the changeset viewer.