source: josm/trunk/src/org/openstreetmap/josm/gui/io/importexport/NMEAImporter.java

Last change on this file was 18179, checked in by Don-vip, 3 years ago

fix #4282 - Support for OziExplorer Waypoint files

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io.importexport;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.io.IOException;
8import java.io.InputStream;
9
10import org.openstreetmap.josm.actions.ExtensionFileFilter;
11import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData;
12import org.openstreetmap.josm.io.nmea.NmeaReader;
13
14/**
15 * File importer allowing to import NMEA-0183 files (*.nmea/nme/nma/log/txt files).
16 * @since 1637
17 */
18public class NMEAImporter extends GpxLikeImporter<NmeaReader> {
19
20 /**
21 * The NMEA file filter (*.nmea *.nme *.nma *.log *.txt files).
22 */
23 public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
24 "nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files"), false);
25
26 /**
27 * Constructs a new {@code NMEAImporter}.
28 */
29 public NMEAImporter() {
30 super(FILE_FILTER, NmeaReader.class);
31 }
32
33 @Override
34 protected void appendInfoboxContent(StringBuilder msg, boolean success, NmeaReader r) {
35 msg.append(tr("Malformed sentences: {0}", r.getParserMalformed())).append("<br>")
36 .append(tr("Checksum errors: {0}", r.getParserChecksumErrors())).append("<br>");
37 if (!success) {
38 msg.append(tr("Unknown sentences: {0}", r.getParserUnknown())).append("<br>");
39 }
40 msg.append(tr("Zero coordinates: {0}", r.getParserZeroCoordinates()));
41 }
42
43 /**
44 * Replies the new GPX and marker layers corresponding to the specified NMEA file.
45 * @param is input stream to NMEA 0183 data
46 * @param associatedFile NMEA file
47 * @param gpxLayerName The GPX layer name
48 * @return the new GPX and marker layers corresponding to the specified NMEA file
49 * @throws IOException if an I/O error occurs
50 */
51 public static GpxImporterData loadLayers(InputStream is, final File associatedFile,
52 final String gpxLayerName) throws IOException {
53 final NmeaReader r = buildAndParse(is, NmeaReader.class);
54 final boolean parsedProperly = r.getNumberOfCoordinates() > 0;
55 r.getGpxData().storageFile = associatedFile;
56 return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName);
57 }
58}
Note: See TracBrowser for help on using the repository browser.