Ignore:
Timestamp:
2012-03-26T18:20:51+02:00 (12 years ago)
Author:
oliverw
Message:
  • Bugfix #7549: Plugin crashes, when importing TCX files
  • Some minor refactorings
Location:
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java

    r27426 r28149  
    4646                        eleMode = new ElevationMapMode("Elevation profile", Main.map);
    4747                        eleModeButton = new IconToggleButton(eleMode);
    48                         eleModeButton.setAutoHideDisabledButton(true);
    4948                } catch (Exception e1) {
    5049                        System.err.println("Init of ElevationProfilePlugin failed: " + e1);
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java

    r26509 r28149  
    3535import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    3636import org.openstreetmap.josm.plugins.elevation.WayPointHelper;
     37import org.openstreetmap.josm.tools.CheckParameterUtil;
    3738
    3839/**
     
    133134                        MapView mv, WayPoint wpt, ElevationWayPointKind kind) {
    134135
    135                 if (mv == null || profile == null || wpt == null) {
     136                CheckParameterUtil.ensureParameterNotNull(g, "graphics");
     137                CheckParameterUtil.ensureParameterNotNull(profile, "profile");
     138                CheckParameterUtil.ensureParameterNotNull(mv, "map view");
     139                               
     140                if (wpt == null) {
    136141                        System.err.println(String.format(
    137                                         "Cannot paint: mv=%s, prof=%s, wpt=%s", mv, profile, wpt));
    138                         if (wpt == null) {
    139                                 throw new RuntimeException("WPT must not be null, profile " + profile);
    140                         }
     142                                        "Cannot paint: mv=%s, prof=%s, wpt=%s", mv, profile, wpt));                     
    141143                        return;
    142144                }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java

    r26817 r28149  
    4343public class ElevationProfileLayer extends
    4444org.openstreetmap.josm.gui.layer.Layer implements IElevationProfileSelectionListener {
     45        private static final double Level_Factor = 100.0;
    4546        private IElevationProfile profile;
    4647        private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer();
     
    159160                renderer.beginRendering();
    160161                if (profile != null) {                 
     162                        // paint way points one by one
    161163                        for (WayPoint wpt : profile.getWayPoints()) {
    162164                                int ele = (int) WayPointHelper.getElevation(wpt);
    163165
    164166                                if (lastWpt != null) {
    165                                         /*
    166                                         int h1 = WayPointHelper.getHourOfWayPoint(wpt);
    167                                         int h2 = WayPointHelper.getHourOfWayPoint(lastWpt);
    168                                         */
    169                                         int ele1 = (int)(ele / 100.0);
    170                                         int ele2 = (int)(lastEle / 100.0);
     167                                        // normalize to levels
     168                                        int ele1 = (int)(ele / Level_Factor);
     169                                        int ele2 = (int)(lastEle / Level_Factor);
    171170                                       
    172                                         // Check, if we passed an elevation level
     171                                        // plain way point by default
     172                                        ElevationWayPointKind kind = ElevationWayPointKind.Plain;
     173                                        // check, if we passed an elevation level
     174                                        // We assume, that we cannot pass more than one levels between two way points ;-)
    173175                                        if (ele1 != ele2 && Math.abs(ele1 - ele2) == 1) {
    174176                                                if (ele1 > ele2) { // we went down?
    175                                                         renderer.renderWayPoint(g, profile, mv, wpt,
    176                                                                 ElevationWayPointKind.ElevationLevelGain);
     177                                                        kind =ElevationWayPointKind.ElevationLevelGain;
    177178                                                } else {
    178                                                         renderer.renderWayPoint(g, profile, mv, wpt,
    179                                                                         ElevationWayPointKind.ElevationLevelLoss);
     179                                                        kind =ElevationWayPointKind.ElevationLevelLoss;
    180180                                                }
    181181                                        } else { // check for elevation gain or loss
    182182                                                if (ele > lastEle) { // we went down?
    183                                                         renderer.renderWayPoint(g, profile, mv, wpt,
    184                                                                         ElevationWayPointKind.ElevationGain);
     183                                                        kind =ElevationWayPointKind.ElevationGain;
    185184                                                } else {
    186                                                         renderer.renderWayPoint(g, profile, mv, wpt,
    187                                                                         ElevationWayPointKind.ElevationLoss);
     185                                                        kind =ElevationWayPointKind.ElevationLoss;
    188186                                                }
    189187                                        }
     188                                       
     189                                        // render way point
     190                                        renderer.renderWayPoint(g, profile, mv, wpt, kind);
    190191                                }
    191192
     
    194195                                lastWpt = wpt;
    195196                        }
    196 
     197                       
     198                        // now we paint special way points in emphasized style
     199                       
    197200                        // paint selected way point, if available
    198201                        if (selWayPoint != null) {
Note: See TracChangeset for help on using the changeset viewer.