source: josm/trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java@ 1148

Last change on this file since 1148 was 1148, checked in by framm, 15 years ago
  • fix Open Location bugs, add icon
  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7
8import javax.swing.JCheckBox;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.actions.DownloadAction;
12import org.openstreetmap.josm.gui.PleaseWaitRunnable;
13import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;
14import org.openstreetmap.josm.gui.layer.Layer;
15import org.openstreetmap.josm.gui.layer.GpxLayer;
16import org.openstreetmap.josm.data.gpx.GpxData;
17import org.openstreetmap.josm.data.Bounds;
18import org.openstreetmap.josm.io.BoundingBoxDownloader;
19import org.xml.sax.SAXException;
20
21public class DownloadGpsTask implements DownloadTask {
22
23 private static class Task extends PleaseWaitRunnable {
24 private BoundingBoxDownloader reader;
25 private GpxData rawData;
26 private final boolean newLayer;
27
28 public Task(boolean newLayer, BoundingBoxDownloader reader) {
29 super(tr("Downloading GPS data"));
30 this.reader = reader;
31 this.newLayer = newLayer;
32 }
33
34 @Override public void realRun() throws IOException, SAXException {
35 rawData = reader.parseRawGps();
36 }
37
38 @Override protected void finish() {
39 if (rawData == null)
40 return;
41 rawData.recalculateBounds();
42 Bounds b = rawData.bounds;
43 String name = b.min.lat() + " " + b.min.lon() + " x " + b.max.lat() + " " + b.max.lon();
44 GpxLayer layer = new GpxLayer(rawData, name);
45 if (newLayer || findMergeLayer() == null)
46 Main.main.addLayer(layer);
47 else
48 findMergeLayer().mergeFrom(layer);
49 }
50
51 private Layer findMergeLayer() {
52 if (Main.map == null)
53 return null;
54 Layer active = Main.map.mapView.getActiveLayer();
55 if (active != null && active instanceof GpxLayer)
56 return active;
57 for (Layer l : Main.map.mapView.getAllLayers())
58 if (l instanceof GpxLayer)
59 return l;
60 return null;
61 }
62
63 @Override protected void cancel() {
64 if (reader != null)
65 reader.cancel();
66 }
67 }
68
69 private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));
70
71 public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
72 Task task = new Task(action.dialog.newLayer.isSelected(), new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon));
73 Main.worker.execute(task);
74 }
75
76 public JCheckBox getCheckBox() {
77 return checkBox;
78 }
79
80 public String getPreferencesSuffix() {
81 return "gps";
82 }
83
84 public void loadUrl(boolean a,java.lang.String b) {
85 // FIXME this is not currently used
86 }
87}
Note: See TracBrowser for help on using the repository browser.