Changeset 18179 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2021-08-26T04:12:30+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r17548 r18179 28 28 import org.openstreetmap.josm.gui.io.importexport.OsmChangeImporter; 29 29 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; 30 import org.openstreetmap.josm.gui.io.importexport.OziWptImporter; 30 31 import org.openstreetmap.josm.gui.io.importexport.RtkLibImporter; 31 32 import org.openstreetmap.josm.gui.io.importexport.WMSLayerImporter; … … 68 69 GpxImporter.class, 69 70 NMEAImporter.class, 71 OziWptImporter.class, 70 72 RtkLibImporter.class, 71 73 NoteImporter.class, -
trunk/src/org/openstreetmap/josm/gui/io/importexport/NMEAImporter.java
r16866 r18179 8 8 import java.io.InputStream; 9 9 10 import javax.swing.JOptionPane;11 import javax.swing.SwingUtilities;12 13 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 import org.openstreetmap.josm.gui.HelpAwareOptionPane;15 import org.openstreetmap.josm.gui.MainApplication;16 import org.openstreetmap.josm.gui.Notification;17 11 import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData; 18 import org.openstreetmap.josm.gui.layer.GpxLayer;19 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor;21 import org.openstreetmap.josm.gui.util.GuiHelper;22 import org.openstreetmap.josm.io.Compression;23 12 import org.openstreetmap.josm.io.nmea.NmeaReader; 24 import org.openstreetmap.josm.spi.preferences.Config;25 import org.xml.sax.SAXException;26 13 27 14 /** … … 29 16 * @since 1637 30 17 */ 31 public class NMEAImporter extends FileImporter{18 public class NMEAImporter extends GpxLikeImporter<NmeaReader> { 32 19 33 20 /** … … 41 28 */ 42 29 public NMEAImporter() { 43 super(FILE_FILTER );30 super(FILE_FILTER, NmeaReader.class); 44 31 } 45 32 46 33 @Override 47 public void importData(File file, ProgressMonitor progressMonitor) throws IOException { 48 final String fn = file.getName(); 49 try (InputStream fis = Compression.getUncompressedFileInputStream(file)) { 50 final NmeaReader r = buildAndParse(fis); 51 if (r.getNumberOfCoordinates() > 0) { 52 r.getGpxData().storageFile = file; 53 final GpxLayer gpxLayer = new GpxLayer(r.getGpxData(), fn, true); 54 final File fileFinal = file; 55 56 GuiHelper.runInEDT(() -> { 57 MainApplication.getLayerManager().addLayer(gpxLayer); 58 if (Config.getPref().getBoolean("marker.makeautomarkers", true)) { 59 MarkerLayer ml = new MarkerLayer(r.getGpxData(), tr("Markers from {0}", fn), fileFinal, gpxLayer); 60 if (!ml.data.isEmpty()) { 61 MainApplication.getLayerManager().addLayer(ml); 62 } 63 } 64 }); 65 } 66 showNmeaInfobox(r.getNumberOfCoordinates() > 0, r); 67 } 68 } 69 70 private static void showNmeaInfobox(boolean success, NmeaReader r) { 71 final StringBuilder msg = new StringBuilder(160).append("<html>") 72 .append(tr("Coordinates imported: {0}", r.getNumberOfCoordinates())).append("<br>") 73 .append(tr("Malformed sentences: {0}", r.getParserMalformed())).append("<br>") 34 protected void appendInfoboxContent(StringBuilder msg, boolean success, NmeaReader r) { 35 msg.append(tr("Malformed sentences: {0}", r.getParserMalformed())).append("<br>") 74 36 .append(tr("Checksum errors: {0}", r.getParserChecksumErrors())).append("<br>"); 75 37 if (!success) { 76 38 msg.append(tr("Unknown sentences: {0}", r.getParserUnknown())).append("<br>"); 77 39 } 78 msg.append(tr("Zero coordinates: {0}", r.getParserZeroCoordinates())) 79 .append("</html>"); 80 if (success) { 81 SwingUtilities.invokeLater(() -> new Notification( 82 "<h3>" + tr("NMEA import success:") + "</h3>" + msg.toString()) 83 .setIcon(JOptionPane.INFORMATION_MESSAGE) 84 .show()); 85 } else { 86 HelpAwareOptionPane.showMessageDialogInEDT( 87 MainApplication.getMainFrame(), 88 msg.toString(), 89 tr("NMEA import failure!"), 90 JOptionPane.ERROR_MESSAGE, null); 91 } 40 msg.append(tr("Zero coordinates: {0}", r.getParserZeroCoordinates())); 92 41 } 93 42 … … 102 51 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 103 52 final String gpxLayerName) throws IOException { 104 final NmeaReader r = buildAndParse(is );53 final NmeaReader r = buildAndParse(is, NmeaReader.class); 105 54 final boolean parsedProperly = r.getNumberOfCoordinates() > 0; 106 55 r.getGpxData().storageFile = associatedFile; 107 56 return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName); 108 57 } 109 110 static NmeaReader buildAndParse(InputStream fis) throws IOException {111 final NmeaReader r = new NmeaReader(fis);112 try {113 r.parse(true);114 } catch (SAXException e) {115 throw new IOException(e);116 }117 return r;118 }119 58 } -
trunk/src/org/openstreetmap/josm/gui/io/importexport/RtkLibImporter.java
r16866 r18179 8 8 import java.io.InputStream; 9 9 10 import javax.swing.JOptionPane;11 import javax.swing.SwingUtilities;12 13 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 import org.openstreetmap.josm.gui.HelpAwareOptionPane;15 import org.openstreetmap.josm.gui.MainApplication;16 import org.openstreetmap.josm.gui.Notification;17 11 import org.openstreetmap.josm.gui.io.importexport.GpxImporter.GpxImporterData; 18 import org.openstreetmap.josm.gui.layer.GpxLayer;19 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor;21 import org.openstreetmap.josm.gui.util.GuiHelper;22 import org.openstreetmap.josm.io.Compression;23 12 import org.openstreetmap.josm.io.rtklib.RtkLibPosReader; 24 import org.openstreetmap.josm.spi.preferences.Config;25 import org.xml.sax.SAXException;26 13 27 14 /** … … 29 16 * @since 15247 30 17 */ 31 public class RtkLibImporter extends FileImporter{18 public class RtkLibImporter extends GpxLikeImporter<RtkLibPosReader> { 32 19 33 20 /** … … 41 28 */ 42 29 public RtkLibImporter() { 43 super(FILE_FILTER); 44 } 45 46 @Override 47 public void importData(File file, ProgressMonitor progressMonitor) throws IOException { 48 final String fn = file.getName(); 49 try (InputStream fis = Compression.getUncompressedFileInputStream(file)) { 50 final RtkLibPosReader r = buildAndParse(fis); 51 if (r.getNumberOfCoordinates() > 0) { 52 r.getGpxData().storageFile = file; 53 final GpxLayer gpxLayer = new GpxLayer(r.getGpxData(), fn, true); 54 final File fileFinal = file; 55 56 GuiHelper.runInEDT(() -> { 57 MainApplication.getLayerManager().addLayer(gpxLayer); 58 if (Config.getPref().getBoolean("marker.makeautomarkers", true)) { 59 MarkerLayer ml = new MarkerLayer(r.getGpxData(), tr("Markers from {0}", fn), fileFinal, gpxLayer); 60 if (!ml.data.isEmpty()) { 61 MainApplication.getLayerManager().addLayer(ml); 62 } 63 } 64 }); 65 } 66 showRtkLibInfobox(r.getNumberOfCoordinates() > 0, r); 67 } 68 } 69 70 private static void showRtkLibInfobox(boolean success, RtkLibPosReader r) { 71 final StringBuilder msg = new StringBuilder(160).append("<html>") 72 .append(tr("Coordinates imported: {0}", r.getNumberOfCoordinates())) 73 .append("</html>"); 74 if (success) { 75 SwingUtilities.invokeLater(() -> new Notification( 76 "<h3>" + tr("RTKLib import success:") + "</h3>" + msg.toString()) 77 .setIcon(JOptionPane.INFORMATION_MESSAGE) 78 .show()); 79 } else { 80 HelpAwareOptionPane.showMessageDialogInEDT( 81 MainApplication.getMainFrame(), 82 msg.toString(), 83 tr("RTKLib import failure!"), 84 JOptionPane.ERROR_MESSAGE, null); 85 } 30 super(FILE_FILTER, RtkLibPosReader.class); 86 31 } 87 32 … … 96 41 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 97 42 final String gpxLayerName) throws IOException { 98 final RtkLibPosReader r = buildAndParse(is );43 final RtkLibPosReader r = buildAndParse(is, RtkLibPosReader.class); 99 44 final boolean parsedProperly = r.getNumberOfCoordinates() > 0; 100 45 r.getGpxData().storageFile = associatedFile; 101 46 return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName); 102 47 } 103 104 static RtkLibPosReader buildAndParse(InputStream fis) throws IOException {105 final RtkLibPosReader r = new RtkLibPosReader(fis);106 try {107 r.parse(true);108 } catch (SAXException e) {109 throw new IOException(e);110 }111 return r;112 }113 48 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDataHelper.java
r18051 r18179 72 72 JOptionPane.ERROR_MESSAGE 73 73 ); 74 } catch (IOException ex) {74 } catch (IOException | UnsupportedOperationException ex) { 75 75 Logging.error(ex); 76 76 JOptionPane.showMessageDialog( -
trunk/src/org/openstreetmap/josm/io/IGpxReader.java
r18071 r18179 8 8 9 9 /** 10 * Abstraction of {@code GpxReader}, {@code NmeaReader} and {@code RtkLibPosReader}10 * Abstraction of {@code GpxReader}, {@code NmeaReader}, {@code OziWptReader} and {@code RtkLibPosReader} 11 11 * @since 14010 12 12 */ … … 22 22 * @throws SAXException if any SAX parsing error occurs 23 23 * @throws IOException if any I/O error occurs 24 * @throws UnsupportedOperationException if the format is not supported 24 25 */ 25 26 boolean parse(boolean tryToFinish) throws SAXException, IOException; … … 30 31 */ 31 32 GpxData getGpxData(); 33 34 /** 35 * Returns the number of coordinates that have been successfuly read. 36 * @return the number of coordinates that have been successfuly read 37 * @since 18179 38 */ 39 default int getNumberOfCoordinates() { 40 throw new UnsupportedOperationException(); 41 } 32 42 } -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java
r17841 r18179 215 215 } 216 216 217 /** 218 * Returns the number of coordinates that have been successfuly read. 219 * @return the number of coordinates that have been successfuly read 220 */ 217 @Override 221 218 public int getNumberOfCoordinates() { 222 219 return ps.success; -
trunk/src/org/openstreetmap/josm/io/rtklib/RtkLibPosReader.java
r18048 r18179 111 111 } 112 112 113 /** 114 * Returns the number of coordinates that have been successfully read. 115 * @return the number of coordinates that have been successfully read 116 */ 113 @Override 117 114 public int getNumberOfCoordinates() { 118 115 return success;
Note:
See TracChangeset
for help on using the changeset viewer.