1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.FileInputStream;
|
---|
8 | import java.io.IOException;
|
---|
9 |
|
---|
10 | import javax.swing.JOptionPane;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
14 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
16 |
|
---|
17 | public class NMEAImporter extends FileImporter {
|
---|
18 |
|
---|
19 | public NMEAImporter() {
|
---|
20 | super(
|
---|
21 | new ExtensionFileFilter("nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files")
|
---|
22 | + " (*.nmea *.nme *.nma *.log *.txt)"));
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override public void importData(File file) throws IOException {
|
---|
26 | String fn = file.getName();
|
---|
27 | NmeaReader r = new NmeaReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile());
|
---|
28 | if (r.getNumberOfCoordinates() > 0) {
|
---|
29 | r.data.storageFile = file;
|
---|
30 | GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
|
---|
31 | Main.main.addLayer(gpxLayer);
|
---|
32 | if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
|
---|
33 | MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer);
|
---|
34 | if (ml.data.size() > 0) {
|
---|
35 | Main.main.addLayer(ml);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | showNmeaInfobox(r.getNumberOfCoordinates() > 0, r);
|
---|
40 | }
|
---|
41 |
|
---|
42 | private void showNmeaInfobox(boolean success, NmeaReader r) {
|
---|
43 | String msg = tr("Coordinates imported: ") + r.getNumberOfCoordinates() + "\n" + tr("Malformed sentences: ")
|
---|
44 | + r.getParserMalformed() + "\n" + tr("Checksum errors: ") + r.getParserChecksumErrors() + "\n";
|
---|
45 | if (!success) {
|
---|
46 | msg += tr("Unknown sentences: ") + r.getParserUnknown() + "\n";
|
---|
47 | }
|
---|
48 | msg += tr("Zero coordinates: ") + r.getParserZeroCoordinates();
|
---|
49 | if (success) {
|
---|
50 | JOptionPane.showMessageDialog(
|
---|
51 | Main.parent,
|
---|
52 | msg,
|
---|
53 | tr("NMEA import success"),
|
---|
54 | JOptionPane.INFORMATION_MESSAGE);
|
---|
55 | } else {
|
---|
56 | JOptionPane.showMessageDialog(Main.parent, msg, tr("NMEA import failure!"), JOptionPane.ERROR_MESSAGE);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|