Changeset 16850 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r16847 r16850 270 270 jumpToPrevious, 271 271 new ConvertFromGpxLayerAction(this), 272 new DownloadAlongTrackAction( data),272 new DownloadAlongTrackAction(Collections.singleton(data)), 273 273 new DownloadWmsAlongTrackAction(data), 274 274 SeparatorLayerAction.INSTANCE, -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java
r15502 r16850 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.awt.geom.Path2D; 8 import java.util.Collection; 9 import java.util.List; 10 import java.util.stream.Collectors; 11 12 import javax.swing.Action; 13 import javax.swing.JMenuItem; 7 14 8 15 import org.openstreetmap.josm.actions.DownloadAlongAction; 9 16 import org.openstreetmap.josm.data.gpx.GpxData; 10 import org.openstreetmap.josm.data.gpx.IGpxTrack;11 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment;12 17 import org.openstreetmap.josm.data.gpx.WayPoint; 13 18 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 14 19 import org.openstreetmap.josm.gui.help.HelpUtil; 20 import org.openstreetmap.josm.gui.layer.GpxLayer; 21 import org.openstreetmap.josm.gui.layer.Layer; 22 import org.openstreetmap.josm.tools.Utils; 15 23 16 24 /** … … 20 28 * @since 5715 21 29 */ 22 public class DownloadAlongTrackAction extends DownloadAlongAction {30 public class DownloadAlongTrackAction extends DownloadAlongAction implements Layer.LayerAction, Layer.MultiLayerAction { 23 31 24 32 private static final int NEAR_TRACK = 0; … … 33 41 private static final String PREF_DOWNLOAD_ALONG_TRACK_NEAR = "downloadAlongTrack.near"; 34 42 35 private final transient GpxDatadata;43 private final transient Collection<GpxData> data; 36 44 37 45 /** … … 39 47 * @param data The GPX data used to download along 40 48 */ 41 public DownloadAlongTrackAction( GpxDatadata) {49 public DownloadAlongTrackAction(Collection<GpxData> data) { 42 50 super(tr("Download from OSM along this track"), "downloadalongtrack", null, null, false); 43 51 this.data = data; … … 60 68 Path2D gpxPath = new Path2D.Double(); 61 69 if (near == NEAR_TRACK || near == NEAR_BOTH) { 62 for (IGpxTrack trk : data.tracks) { 63 for (IGpxTrackSegment segment : trk.getSegments()) { 64 boolean first = true; 65 for (WayPoint p : segment.getWayPoints()) { 66 if (first) { 67 gpxPath.moveTo(p.lon(), p.lat()); 68 first = false; 69 } else { 70 gpxPath.lineTo(p.lon(), p.lat()); 71 } 70 data.stream().flatMap(GpxData::getTrackSegmentsStream).forEach(segment -> { 71 boolean first = true; 72 for (WayPoint p : segment.getWayPoints()) { 73 if (first) { 74 gpxPath.moveTo(p.lon(), p.lat()); 75 first = false; 76 } else { 77 gpxPath.lineTo(p.lon(), p.lat()); 72 78 } 73 79 } 74 } 80 }); 75 81 } 76 82 if (near == NEAR_WAYPOINTS || near == NEAR_BOTH) { 77 for (WayPoint p : data.waypoints){83 data.stream().flatMap(d -> d.getWaypoints().stream()).forEach(p -> { 78 84 gpxPath.moveTo(p.lon(), p.lat()); 79 85 gpxPath.closePath(); 80 } 86 }); 81 87 } 82 88 return createCalcTask(gpxPath, panel, tr("Download from OSM along this track"), 1 == ret); 83 89 } 90 91 @Override 92 public Component createMenuComponent() { 93 return new JMenuItem(this); 94 } 95 96 @Override 97 public boolean supportLayers(List<Layer> layers) { 98 return !Utils.filteredCollection(layers, GpxLayer.class).isEmpty(); 99 } 100 101 @Override 102 public Action getMultiLayerAction(List<Layer> layers) { 103 final List<GpxData> gpxData = Utils.filteredCollection(layers, GpxLayer.class) 104 .stream().map(layer -> layer.data) 105 .collect(Collectors.toList()); 106 return new DownloadAlongTrackAction(gpxData); 107 } 84 108 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java
r16159 r16850 52 52 // Perform action 53 53 final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + file); 54 final PleaseWaitRunnable retval = new DownloadAlongTrackAction( gpx).createTask();54 final PleaseWaitRunnable retval = new DownloadAlongTrackAction(Collections.singleton(gpx)).createTask(); 55 55 56 56 // assert that we were indeed presented with the expected HelpAwareOptionPane
Note:
See TracChangeset
for help on using the changeset viewer.