[1637] | 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;
|
---|
[2851] | 16 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
[1637] | 17 |
|
---|
| 18 | public class NMEAImporter extends FileImporter {
|
---|
| 19 |
|
---|
| 20 | public NMEAImporter() {
|
---|
| 21 | super(
|
---|
[2290] | 22 | new ExtensionFileFilter("nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files")
|
---|
| 23 | + " (*.nmea *.nme *.nma *.log *.txt)"));
|
---|
[1637] | 24 | }
|
---|
| 25 |
|
---|
[2851] | 26 | @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
|
---|
[1637] | 27 | String fn = file.getName();
|
---|
| 28 | NmeaReader r = new NmeaReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile());
|
---|
| 29 | if (r.getNumberOfCoordinates() > 0) {
|
---|
| 30 | r.data.storageFile = file;
|
---|
| 31 | GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
|
---|
| 32 | Main.main.addLayer(gpxLayer);
|
---|
| 33 | if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
|
---|
| 34 | MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer);
|
---|
| 35 | if (ml.data.size() > 0) {
|
---|
| 36 | Main.main.addLayer(ml);
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | showNmeaInfobox(r.getNumberOfCoordinates() > 0, r);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | private void showNmeaInfobox(boolean success, NmeaReader r) {
|
---|
| 44 | String msg = tr("Coordinates imported: ") + r.getNumberOfCoordinates() + "\n" + tr("Malformed sentences: ")
|
---|
[1857] | 45 | + r.getParserMalformed() + "\n" + tr("Checksum errors: ") + r.getParserChecksumErrors() + "\n";
|
---|
| 46 | if (!success) {
|
---|
[1637] | 47 | msg += tr("Unknown sentences: ") + r.getParserUnknown() + "\n";
|
---|
[1857] | 48 | }
|
---|
[1637] | 49 | msg += tr("Zero coordinates: ") + r.getParserZeroCoordinates();
|
---|
| 50 | if (success) {
|
---|
[2017] | 51 | JOptionPane.showMessageDialog(
|
---|
[1857] | 52 | Main.parent,
|
---|
| 53 | msg,
|
---|
| 54 | tr("NMEA import success"),
|
---|
| 55 | JOptionPane.INFORMATION_MESSAGE);
|
---|
[1637] | 56 | } else {
|
---|
[2163] | 57 | JOptionPane.showMessageDialog(Main.parent, msg, tr("NMEA import failure!"), JOptionPane.ERROR_MESSAGE);
|
---|
[1637] | 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | }
|
---|