1 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.Collection;
|
---|
7 |
|
---|
8 | import javax.swing.JCheckBox;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.actions.DownloadAction;
|
---|
12 | import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;
|
---|
13 | import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
---|
14 | import org.openstreetmap.josm.gui.layer.RawGpsLayer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint;
|
---|
16 | import org.openstreetmap.josm.io.BoundingBoxDownloader;
|
---|
17 | import org.xml.sax.SAXException;
|
---|
18 |
|
---|
19 | public class DownloadGpsTask extends PleaseWaitRunnable implements DownloadTask {
|
---|
20 | private DownloadAction action;
|
---|
21 | private BoundingBoxDownloader reader;
|
---|
22 | private Collection<Collection<GpsPoint>> rawData;
|
---|
23 | private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));
|
---|
24 |
|
---|
25 | public DownloadGpsTask() {
|
---|
26 | super(tr("Downloading GPS data"));
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override public void realRun() throws IOException, SAXException {
|
---|
30 | rawData = reader.parseRawGps();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override protected void finish() {
|
---|
34 | if (rawData == null)
|
---|
35 | return;
|
---|
36 | String name = action.latlon[0].getText() + " " + action.latlon[1].getText() + " x " + this.action.latlon[2].getText() + " " + this.action.latlon[3].getText();
|
---|
37 | Main.main.addLayer(new RawGpsLayer(rawData, name, null));
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override protected void cancel() {
|
---|
41 | if (reader != null)
|
---|
42 | reader.cancel();
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
|
---|
47 | this.action = action;
|
---|
48 | reader = new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon);
|
---|
49 | Main.worker.execute(this);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public JCheckBox getCheckBox() {
|
---|
53 | return checkBox;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public String getPreferencesSuffix() {
|
---|
57 | return "gps";
|
---|
58 | }
|
---|
59 | }
|
---|