Ignore:
Timestamp:
2013-09-24T17:11:58+02:00 (11 years ago)
Author:
oliverw
Message:

[josm_elevationprofile]: Code cleanup, minor UI fixes

Location:
applications/editors/josm/plugins/ElevationProfile
Files:
1 added
1 deleted
15 edited
2 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/build.xml

    r29874 r29955  
    22<project name="ElevationProfile" default="dist" basedir=".">
    33    <!-- enter the SVN commit message -->
    4     <property name="commit.message" value=""/>
     4    <property name="commit.message" value="[josm_elevationprofile]"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    66    <property name="plugin.main.version" value="6162"/>
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationMapMode.java

    r29948 r29955  
    2121import org.openstreetmap.josm.actions.mapmode.MapMode;
    2222import org.openstreetmap.josm.gui.MapFrame;
    23 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    2423
    2524/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java

    r29921 r29955  
    4444                for (String location : Main.pref.getAllPossiblePreferenceDirs()) {                 
    4545                        String fullPath = new File(location + File.separator + "elevation", file).getPath();
    46                                  
    47                         System.out.println(fullPath);
    4846                        File f = new File(fullPath);
    4947                        if (f.exists()) {
    5048                            // found something: read HGT file...
    51                             ShortBuffer data = readHgtFile(fullPath);
    52                             System.out.println("Read SRTM data from " + fullPath + ", tag is '" + file + "'");
     49                            ShortBuffer data = readHgtFile(fullPath);                               
    5350                            // ... and store result in cache
    5451                            cache.put(file, data);
     
    109106       
    110107        if (sb == null) {
    111             System.out.println("readElevation: Buffer is null for tag '" + tag + "'");
    112108            return ElevationHelper.NO_ELEVATION;
    113109        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModel.java

    r29954 r29955  
    1 package org.openstreetmap.josm.plugins.elevation.gpx;
     1package org.openstreetmap.josm.plugins.elevation;
    22
    33import java.util.List;
    44
    5 import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
    65
    76public interface IElevationModel {
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModelListener.java

    r29948 r29955  
    1616
    1717import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
    18 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    1918
    2019/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationProfile.java

    r29954 r29955  
    1313 */
    1414
    15 package org.openstreetmap.josm.plugins.elevation.gpx;
     15package org.openstreetmap.josm.plugins.elevation;
    1616
    1717import java.util.Date;
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java

    r29948 r29955  
    2323import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    2424import org.openstreetmap.josm.data.gpx.WayPoint;
     25import org.openstreetmap.josm.plugins.elevation.IElevationModel;
    2526import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
     27import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    2628import org.openstreetmap.josm.tools.CheckParameterUtil;
    2729
     
    3739        private int trackCounter;
    3840        private GpxData gpxData;
    39 
     41        private String name;
    4042        private WayPointMap children = new WayPointMap();
    4143        private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>();
    4244        private List<WayPoint> buffer = new ArrayList<WayPoint>();
    4345        private int currentProfileIndex = 0;
    44        
     46        private ElevationProfileBase curProfile = null;
    4547
    4648        /**
     
    5961        public ElevationModel(String name, GpxData data) {
    6062                gpxData = data;
    61                
     63                this.name = name;
    6264                GpxIterator.visit(data, this);         
    6365        }
     
    135137                // we ignore the segment here
    136138                processWayPoint(wp);
     139               
    137140        }
    138141       
     
    146149
    147150        public void start() {
    148                 children.clear();               
     151                curProfile = new ElevationProfileBase(name);           
    149152        }
    150153
    151154        public void end() {
    152                 String trackName = "Track#" + trackCounter;
    153                 addTrackOrRoute(trackName);             
    154         }
    155        
     155                String trackName = name; //gpxData.getString(GpxData.META_NAME);// "Track#" + trackCounter;
     156               
     157                if (trackCounter > 0) {
     158                    trackName += "." + trackCounter;
     159                }
     160                addTrackOrRoute(trackName);     
     161                trackCounter++;
     162        }
     163       
     164
     165        @Override
     166        public void start(GpxTrack track) {
     167            curProfile = new ElevationProfileBase(name);           
     168        }
     169
     170        @Override
     171        public void end(GpxTrack track) {
     172            if (curProfile == null) throw new RuntimeException("Internal error: No elevation profile");
     173           
     174            curProfile.setDistance(track.length());
     175            addTrackOrRoute(name);         
     176        }
     177       
     178        @Override
     179        public void start(GpxTrack track, GpxTrackSegment segment) {
     180            // Nothing to do here for now
     181        }
     182
     183        @Override
     184        public void end(GpxTrack track, GpxTrackSegment segment) {
     185            // Nothing to do here for now
     186        }
     187
     188       
     189        /**
     190         * Adds a track or route to the internal track list.
     191         *
     192         * @param trackName the track name
     193         */
    156194        private void addTrackOrRoute(String trackName) {
    157                 if (buffer.size() > 0) {
    158                    
    159                         System.out.println("Add track " + trackName + ", n =  " + buffer.size()); // TODO: Remove
    160                        
    161                         ElevationProfileBase ep = new ElevationProfileBase(trackName);
    162                         ep.setWayPoints(buffer);
    163                         ep.setName(trackName);
    164                         children.add(ep);
    165                         buffer.clear();
     195                if (buffer.size() > 0) {                       
     196                        curProfile.setWayPoints(buffer);
     197                        curProfile.setName(trackName);
     198                        children.add(curProfile);
    166199                }
    167200        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationProfileBase.java

    r29948 r29955  
    2121import org.openstreetmap.josm.data.gpx.WayPoint;
    2222import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     23import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    2324
    2425/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/GpxIterator.java

    r29907 r29955  
    4545                if (data == null) return;
    4646                if (visitor == null) return;
     47               
     48                if (data.isEmpty()) return;
    4749               
    4850                visitor.start();
     
    9496               
    9597                Collection<GpxTrackSegment> segments = trk.getSegments();
    96                 visitor.start();
    97 
     98               
    9899                if (segments != null) {
     100                        visitor.start(trk);
     101                        // visit all segments
    99102                        for (GpxTrackSegment segment : segments) {
    100                                 Collection<WayPoint> waypts = segment.getWayPoints();
    101                                 // no visitor here...
     103                            Collection<WayPoint> waypts = segment.getWayPoints();
     104                                // no visitor here...
    102105                                if (waypts == null)
    103106                                        continue;
    104 
     107                               
     108                                visitor.start(trk, segment);
     109                               
    105110                                for (WayPoint wayPoint : waypts) {
    106111                                        visitor.visit(wayPoint);
    107112                                }
     113                               
     114                                visitor.end(trk, segment);
    108115                        }
    109                 }
    110                 visitor.end();
     116                        visitor.end(trk);
     117                }               
     118               
    111119        }
    112120
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/IGpxVisitor.java

    r29907 r29955  
    1515package org.openstreetmap.josm.plugins.elevation.gpx;
    1616
     17import org.openstreetmap.josm.data.gpx.GpxTrack;
     18import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    1719import org.openstreetmap.josm.data.gpx.WayPoint;
    1820
     
    2325public interface IGpxVisitor extends IGpxWaypointVisitor {
    2426        /**
    25          * Starts a GPX route, track or way point collection.
     27         * Starts a GPX route or way point collection.
    2628         */
    2729        void start();
    2830       
    2931        /**
    30          * Ends a GPX route, track or way point collection.
     32         * Ends a GPX route or way point collection.
    3133         */
    3234        void end();
     35       
     36        /**
     37         * Starts a GPX track.
     38         */
     39        void start(GpxTrack track);
     40       
     41        /**
     42         * Ends a GPX track.
     43         */
     44        void end(GpxTrack track);
     45
     46       
     47        /**
     48         * Starts a segment within a GPX track.
     49         */
     50        void start(GpxTrack track, GpxTrackSegment segment);
     51       
     52        /**
     53         * Ends a segment within a GPX track.
     54         */
     55        void end(GpxTrack track, GpxTrackSegment segment);
    3356       
    3457        /**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/WayPointMap.java

    r29948 r29955  
    22
    33import java.util.ArrayList;
     4
     5import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    46
    57public class WayPointMap extends ArrayList<IElevationProfile> {
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java

    r29950 r29955  
    3535import org.openstreetmap.josm.gui.MapView;
    3636import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     37import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    3738import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    38 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    3939import org.openstreetmap.josm.tools.CheckParameterUtil;
    4040
     
    6262        private static final Color START_COLOR = Color.GREEN;
    6363        private static final Color END_POINT = Color.RED;
     64        private static final Color LEVEL_GAIN_COLOR = Color.GREEN;
     65        private static final Color LEVEL_LOSS_COLOR = Color.RED;
    6466        private static final Color MARKER_POINT = Color.YELLOW;
    6567        // Predefined radians
     
    9395                switch (kind) {
    9496                case Plain:
    95                     return Color.LIGHT_GRAY;
     97                        return Color.LIGHT_GRAY;
    9698                case ElevationLevelLoss:
     99                        return LEVEL_LOSS_COLOR;
    97100                case ElevationLevelGain:
    98                         if (z > profile.getAverageHeight()) {
    99                                 return HIGH_COLOR;
    100                         } else {
    101                                 return LOW_COLOR;
    102                         }
     101                        return LEVEL_GAIN_COLOR;
    103102                case Highlighted:
    104103                        return Color.ORANGE;
     
    108107                        return Color.getHSBColor(0, 1.0f, 1.0f); // red
    109108                case ElevationGainLow:
    110                         return Color.getHSBColor(0.3f, 0.7f, 1.0f); // green with low sat
     109                        return Color.getHSBColor(0.3f, 0.5f, 1.0f); // green with low sat
    111110                case ElevationLossLow:
    112                         return Color.getHSBColor(0, 0.7f, 1.0f); // red with low sat
     111                        return Color.getHSBColor(0, 0.5f, 1.0f); // red with low sat
    113112                case FullHour:
    114113                        return MARKER_POINT;
     
    238237                        int ele = ((int) Math.rint(ElevationHelper.getElevation(wpt) / 100.0)) * 100;
    239238                        drawLabelWithTriangle(ElevationHelper.getElevationText(ele), pnt.x, pnt.y
    240                                         + g.getFontMetrics().getHeight(), g, c, 8,
     239                                        + g.getFontMetrics().getHeight(), g, Color.darkGray, 8,
    241240                                        getColorForWaypoint(profile, wpt, kind),
    242                                         TriangleDir.Up);
     241                                        kind == ElevationWayPointKind.ElevationLevelGain ? TriangleDir.Up : TriangleDir.Down);
    243242                }
    244243
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java

    r29950 r29955  
    4040import org.openstreetmap.josm.gui.layer.Layer;
    4141import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     42import org.openstreetmap.josm.plugins.elevation.IElevationModel;
    4243import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
     44import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    4345import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
    4446import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind;
    45 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel;
    46 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    4747import org.openstreetmap.josm.tools.Shortcut;
    4848/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java

    r29950 r29955  
    3131import org.openstreetmap.josm.gui.layer.Layer;
    3232import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     33import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    3334import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    34 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    3535import org.openstreetmap.josm.tools.ImageProvider;
    3636
     
    8888    @Override
    8989    public Icon getIcon() {
    90         return ImageProvider.get("layer", "elevation_small");
     90        return ImageProvider.get("layer", "elevation");
    9191    }
    9292
     
    245245                // TODO: Provide parameters for high/low thresholds
    246246                if (slope > 2) kind =ElevationWayPointKind.ElevationGainLow;
    247                 if (slope > 10) kind =ElevationWayPointKind.ElevationGainHigh;
     247                if (slope > 15) kind =ElevationWayPointKind.ElevationGainHigh;
    248248            } else {
    249249                if (slope > 2) kind =ElevationWayPointKind.ElevationLossLow;
    250                 if (slope > 10) kind =ElevationWayPointKind.ElevationLossHigh;
     250                if (slope > 15) kind =ElevationWayPointKind.ElevationLossHigh;
    251251            }
    252252        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java

    r29952 r29955  
    3838import org.openstreetmap.josm.data.gpx.WayPoint;
    3939import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     40import org.openstreetmap.josm.plugins.elevation.IElevationModel;
     41import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    4042import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    41 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel;
    42 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    4343
    4444/**
     
    142142           
    143143                int selWp = this.selectedIndex * step;
    144                 if (profile != null && profile.getWayPoints() != null && profile.getWayPoints().size() > selWp) {
     144                if (profile != null && profile.getWayPoints() != null && selWp > 0 && profile.getWayPoints().size() > selWp) {
    145145                        return profile.getWayPoints().get(selWp);
    146146                } else {
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/IElevationProfileRenderer.java

    r29950 r29955  
    2020import org.openstreetmap.josm.data.gpx.WayPoint;
    2121import org.openstreetmap.josm.gui.MapView;
     22import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    2223import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
    23 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    2424
    2525/**
Note: See TracChangeset for help on using the changeset viewer.