source: josm/trunk/src/org/openstreetmap/josm/io/NMEAImporter.java@ 6361

Last change on this file since 6361 was 6132, checked in by bastiK, 11 years ago

see #6963 - new message after successful upload; use notification for NMEA import

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.IOException;
9
10import javax.swing.JOptionPane;
11import javax.swing.SwingUtilities;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.actions.ExtensionFileFilter;
15import org.openstreetmap.josm.gui.HelpAwareOptionPane;
16import org.openstreetmap.josm.gui.Notification;
17import org.openstreetmap.josm.gui.layer.GpxLayer;
18import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
19import org.openstreetmap.josm.gui.progress.ProgressMonitor;
20import org.openstreetmap.josm.gui.util.GuiHelper;
21
22public class NMEAImporter extends FileImporter {
23
24 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
25 "nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files") + " (*.nmea *.nme *.nma *.log *.txt)");
26
27 public NMEAImporter() {
28 super(FILE_FILTER);
29 }
30
31 @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
32 final String fn = file.getName();
33 final NmeaReader r = new NmeaReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile());
34 if (r.getNumberOfCoordinates() > 0) {
35 r.data.storageFile = file;
36 final GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
37 final File fileFinal = file;
38
39 GuiHelper.runInEDT(new Runnable() {
40 @Override
41 public void run() {
42 Main.main.addLayer(gpxLayer);
43 if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
44 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), fileFinal, gpxLayer);
45 if (!ml.data.isEmpty()) {
46 Main.main.addLayer(ml);
47 }
48 }
49 }
50 });
51 }
52 showNmeaInfobox(r.getNumberOfCoordinates() > 0, r);
53 }
54
55 private void showNmeaInfobox(boolean success, NmeaReader r) {
56 final StringBuilder msg = new StringBuilder().append("<html>");
57 msg.append(tr("Coordinates imported: {0}", r.getNumberOfCoordinates()) + "<br>");
58 msg.append(tr("Malformed sentences: {0}", r.getParserMalformed()) + "<br>");
59 msg.append(tr("Checksum errors: {0}", r.getParserChecksumErrors()) + "<br>");
60 if (!success) {
61 msg.append(tr("Unknown sentences: {0}", r.getParserUnknown()) + "<br>");
62 }
63 msg.append(tr("Zero coordinates: {0}", r.getParserZeroCoordinates()));
64 msg.append("</html>");
65 if (success) {
66 SwingUtilities.invokeLater(new Runnable() {
67 @Override
68 public void run() {
69 new Notification(
70 "<h3>" + tr("NMEA import success:") + "</h3>" + msg.toString())
71 .setIcon(JOptionPane.INFORMATION_MESSAGE)
72 .show();
73 }
74 });
75 } else {
76 HelpAwareOptionPane.showMessageDialogInEDT(
77 Main.parent,
78 msg.toString(),
79 tr("NMEA import failure!"),
80 JOptionPane.ERROR_MESSAGE, null);
81 }
82 }
83}
Note: See TracBrowser for help on using the repository browser.