Changeset 10175 in josm


Ignore:
Timestamp:
2016-05-10T17:56:23+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #12813 - adapt GPX color scale bar to system of measurement for HDOP and velocity

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r8846 r10175  
    3939     * @since 3406
    4040     */
    41     public static final SystemOfMeasurement METRIC = new SystemOfMeasurement(1, "m", 1000, "km", 10000, "ha");
     41    public static final SystemOfMeasurement METRIC = new SystemOfMeasurement(1, "m", 1000, "km", "km/h", 3.6, 10000, "ha");
    4242
    4343    /**
    4444     * Chinese system.
    45      * @since 3406
    46      */
    47     public static final SystemOfMeasurement CHINESE = new SystemOfMeasurement(1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */);
     45     * See <a href="https://en.wikipedia.org/wiki/Chinese_units_of_measurement#Chinese_length_units_effective_in_1930">length units</a>,
     46     * <a href="https://en.wikipedia.org/wiki/Chinese_units_of_measurement#Chinese_area_units_effective_in_1930">area units</a>
     47     * @since 3406
     48     */
     49    public static final SystemOfMeasurement CHINESE = new SystemOfMeasurement(1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */,
     50            "km/h", 3.6, 666.0 + 2.0/3.0, "\u4ea9" /* mu */);
    4851
    4952    /**
     
    5154     * @since 3406
    5255     */
    53     public static final SystemOfMeasurement IMPERIAL = new SystemOfMeasurement(0.3048, "ft", 1609.344, "mi", 4046.86, "ac");
     56    public static final SystemOfMeasurement IMPERIAL = new SystemOfMeasurement(0.3048, "ft", 1609.344, "mi", "mph", 2.23694, 4046.86, "ac");
    5457
    5558    /**
     
    5760     * @since 5549
    5861     */
    59     public static final SystemOfMeasurement NAUTICAL_MILE = new SystemOfMeasurement(185.2, "kbl", 1852, "NM");
     62    public static final SystemOfMeasurement NAUTICAL_MILE = new SystemOfMeasurement(185.2, "kbl", 1852, "NM", "kn", 1.94384);
    6063
    6164    /**
     
    138141    /** Second unit used to format text. */
    139142    public final String bName;
     143    /** Speed value for the most common speed symbol, in meters per second
     144     *  @since 10175 */
     145    public final double speedValue;
     146    /** Most common speed symbol (kmh/h, mph, kn, etc.)
     147     *  @since 10175 */
     148    public final String speedName;
    140149    /** Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}. Set to {@code -1} if not used.
    141150     *  @since 5870 */
     
    155164     * @param bValue Second value, in meters, used to translate unit according to above formula.
    156165     * @param bName Second unit used to format text.
    157      */
    158     public SystemOfMeasurement(double aValue, String aName, double bValue, String bName) {
    159         this(aValue, aName, bValue, bName, -1, null);
     166     * @param speedName the most common speed symbol (kmh/h, mph, kn, etc.)
     167     * @param speedValue the speed value for the most common speed symbol, for 1 meter per second
     168     * @since 10175
     169     */
     170    public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, String speedName, double speedValue) {
     171        this(aValue, aName, bValue, bName, speedName, speedValue, -1, null);
    160172    }
    161173
     
    170182     * @param bValue Second value, in meters, used to translate unit according to above formula.
    171183     * @param bName Second unit used to format text.
     184     * @param speedName the most common speed symbol (kmh/h, mph, kn, etc.)
     185     * @param speedValue the speed value for the most common speed symbol, for 1 meter per second
    172186     * @param areaCustomValue Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}.
    173187     *                        Set to {@code -1} if not used.
    174188     * @param areaCustomName Specific optional area unit. Set to {@code null} if not used.
    175189     *
    176      * @since 5870
    177      */
    178     public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, double areaCustomValue, String areaCustomName) {
     190     * @since 10175
     191     */
     192    public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, String speedName, double speedValue,
     193            double areaCustomValue, String areaCustomName) {
    179194        this.aValue = aValue;
    180195        this.aName = aName;
    181196        this.bValue = bValue;
    182197        this.bName = bName;
     198        this.speedValue = speedValue;
     199        this.speedName = speedName;
    183200        this.areaCustomValue = areaCustomValue;
    184201        this.areaCustomName = areaCustomName;
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r10059 r10175  
    9090        data = d;
    9191        drawHelper = new GpxDrawHelper(data);
     92        SystemOfMeasurement.addSoMChangeListener(drawHelper);
    9293        ensureTrackVisibilityLength();
    9394        setName(name);
     
    390391        return LayerPositionStrategy.AFTER_LAST_DATA_LAYER;
    391392    }
     393
     394    @Override
     395    public void destroy() {
     396        SystemOfMeasurement.removeSoMChangeListener(drawHelper);
     397    }
    392398}
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r9796 r10175  
    1919
    2020import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.data.SystemOfMeasurement;
     22import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener;
    2123import org.openstreetmap.josm.data.coor.LatLon;
    2224import org.openstreetmap.josm.data.gpx.GpxConstants;
     
    3032 * @since 7319
    3133 */
    32 public class GpxDrawHelper {
     34public class GpxDrawHelper implements SoMChangeListener {
    3335    private final GpxData data;
    3436
     
    9799    private void setupColors() {
    98100        hdopAlpha = Main.pref.getInteger("hdop.color.alpha", -1);
    99         velocityScale = ColorScale.createHSBScale(256).addTitle(tr("Velocity, km/h"));
     101        velocityScale = ColorScale.createHSBScale(256);
    100102        /** Colors (without custom alpha channel, if given) for HDOP painting. **/
    101         hdopScale = ColorScale.createHSBScale(256).makeReversed().addTitle(tr("HDOP, m"));
     103        hdopScale = ColorScale.createHSBScale(256).makeReversed();
    102104        dateScale = ColorScale.createHSBScale(256).addTitle(tr("Time"));
    103105        directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4).addTitle(tr("Direction"));
     106        systemOfMeasurementChanged(null, null);
     107    }
     108
     109    @Override
     110    public void systemOfMeasurementChanged(String oldSoM, String newSoM) {
     111        SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement();
     112        velocityScale.addTitle(tr("Velocity, {0}", som.speedName));
     113        hdopScale.addTitle(tr("HDOP, {0}", som.aName));
     114        if (Main.isDisplayingMapView() && oldSoM != null && newSoM != null) {
     115            Main.map.mapView.repaint();
     116        }
    104117    }
    105118
     
    554567    public void drawColorBar(Graphics2D g, MapView mv) {
    555568        int w = mv.getWidth();
     569        SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement();
    556570        if (colored == ColorMode.HDOP) {
    557             hdopScale.drawColorBar(g, w-30, 50, 20, 100, 1.0);
     571            hdopScale.drawColorBar(g, w-30, 50, 20, 100, som.aValue);
    558572        } else if (colored == ColorMode.VELOCITY) {
    559             velocityScale.drawColorBar(g, w-30, 50, 20, 100, 3.6);
     573            velocityScale.drawColorBar(g, w-30, 50, 20, 100, som.speedValue);
    560574        } else if (colored == ColorMode.DIRECTION) {
    561575            directionScale.drawColorBar(g, w-30, 50, 20, 100, 180.0/Math.PI);
Note: See TracChangeset for help on using the changeset viewer.