- Timestamp:
- 2018-07-07T14:09:37+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/importexport/NMEAImporter.java
r12846 r14010 24 24 import org.openstreetmap.josm.io.nmea.NmeaReader; 25 25 import org.openstreetmap.josm.spi.preferences.Config; 26 import org.xml.sax.SAXException; 26 27 27 28 /** … … 48 49 final String fn = file.getName(); 49 50 try (InputStream fis = Compression.getUncompressedFileInputStream(file)) { 50 final NmeaReader r = new NmeaReader(fis);51 final NmeaReader r = buildAndParse(fis); 51 52 if (r.getNumberOfCoordinates() > 0) { 52 r. data.storageFile = file;53 final GpxLayer gpxLayer = new GpxLayer(r. data, fn, true);53 r.getGpxData().storageFile = file; 54 final GpxLayer gpxLayer = new GpxLayer(r.getGpxData(), fn, true); 54 55 final File fileFinal = file; 55 56 … … 57 58 MainApplication.getLayerManager().addLayer(gpxLayer); 58 59 if (Config.getPref().getBoolean("marker.makeautomarkers", true)) { 59 MarkerLayer ml = new MarkerLayer(r. data, tr("Markers from {0}", fn), fileFinal, gpxLayer);60 MarkerLayer ml = new MarkerLayer(r.getGpxData(), tr("Markers from {0}", fn), fileFinal, gpxLayer); 60 61 if (!ml.data.isEmpty()) { 61 62 MainApplication.getLayerManager().addLayer(ml); … … 103 104 public static GpxImporterData loadLayers(InputStream is, final File associatedFile, 104 105 final String gpxLayerName, String markerLayerName) throws IOException { 105 final NmeaReader r = new NmeaReader(is);106 final NmeaReader r = buildAndParse(is); 106 107 final boolean parsedProperly = r.getNumberOfCoordinates() > 0; 107 r.data.storageFile = associatedFile; 108 return GpxImporter.loadLayers(r.data, parsedProperly, gpxLayerName, markerLayerName); 108 r.getGpxData().storageFile = associatedFile; 109 return GpxImporter.loadLayers(r.getGpxData(), parsedProperly, gpxLayerName, markerLayerName); 110 } 111 112 static NmeaReader buildAndParse(InputStream fis) throws IOException { 113 final NmeaReader r = new NmeaReader(fis); 114 try { 115 r.parse(true); 116 } catch (SAXException e) { 117 throw new IOException(e); 118 } 119 return r; 109 120 } 110 121 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r13220 r14010 23 23 import java.io.IOException; 24 24 import java.io.InputStream; 25 import java.nio.file.Files;26 25 import java.text.DateFormat; 27 26 import java.text.ParseException; 28 27 import java.text.SimpleDateFormat; 29 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 30 import java.util.Collection; 31 31 import java.util.Collections; … … 38 38 import java.util.TimeZone; 39 39 import java.util.concurrent.TimeUnit; 40 import java.util.zip.GZIPInputStream;41 40 42 41 import javax.swing.AbstractAction; … … 60 59 import javax.swing.event.DocumentEvent; 61 60 import javax.swing.event.DocumentListener; 62 import javax.swing.filechooser.FileFilter;63 61 64 62 import org.openstreetmap.josm.Main; 65 63 import org.openstreetmap.josm.actions.DiskAccessAction; 64 import org.openstreetmap.josm.actions.ExtensionFileFilter; 66 65 import org.openstreetmap.josm.data.gpx.GpxConstants; 67 66 import org.openstreetmap.josm.data.gpx.GpxData; … … 72 71 import org.openstreetmap.josm.gui.ExtendedDialog; 73 72 import org.openstreetmap.josm.gui.MainApplication; 73 import org.openstreetmap.josm.gui.io.importexport.GpxImporter; 74 74 import org.openstreetmap.josm.gui.io.importexport.JpgImporter; 75 import org.openstreetmap.josm.gui.io.importexport.NMEAImporter; 75 76 import org.openstreetmap.josm.gui.layer.GpxLayer; 76 77 import org.openstreetmap.josm.gui.layer.Layer; 77 78 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 79 import org.openstreetmap.josm.gui.widgets.FileChooserManager; 78 80 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 79 81 import org.openstreetmap.josm.gui.widgets.JosmTextField; 82 import org.openstreetmap.josm.io.Compression; 80 83 import org.openstreetmap.josm.io.GpxReader; 84 import org.openstreetmap.josm.io.IGpxReader; 85 import org.openstreetmap.josm.io.nmea.NmeaReader; 81 86 import org.openstreetmap.josm.spi.preferences.Config; 82 87 import org.openstreetmap.josm.tools.GBC; … … 85 90 import org.openstreetmap.josm.tools.Logging; 86 91 import org.openstreetmap.josm.tools.Pair; 87 import org.openstreetmap.josm.tools.Utils;88 92 import org.openstreetmap.josm.tools.date.DateUtils; 89 93 import org.xml.sax.SAXException; … … 251 255 252 256 @Override 253 public void actionPerformed(ActionEvent arg0) { 254 FileFilter filter = new FileFilter() { 255 @Override 256 public boolean accept(File f) { 257 return f.isDirectory() || Utils.hasExtension(f, "gpx", "gpx.gz"); 258 } 259 260 @Override 261 public String getDescription() { 262 return tr("GPX Files (*.gpx *.gpx.gz)"); 263 } 264 }; 265 AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null); 257 public void actionPerformed(ActionEvent e) { 258 ExtensionFileFilter gpxFilter = GpxImporter.getFileFilter(); 259 AbstractFileChooser fc = new FileChooserManager(true, null).createFileChooser(false, null, 260 Arrays.asList(gpxFilter, NMEAImporter.FILE_FILTER), gpxFilter, JFileChooser.FILES_ONLY).openFileChooser(); 266 261 if (fc == null) 267 262 return; … … 287 282 } 288 283 GpxData data = null; 289 try (InputStream iStream = createInputStream(sel)) {290 GpxReader reader = new GpxReader(iStream);284 try (InputStream iStream = Compression.getUncompressedFileInputStream(sel)) { 285 IGpxReader reader = gpxFilter.accept(sel) ? new GpxReader(iStream) : new NmeaReader(iStream); 291 286 reader.parse(false); 292 287 data = reader.getGpxData(); … … 327 322 } 328 323 } 329 330 private InputStream createInputStream(File sel) throws IOException {331 if (Utils.hasExtension(sel, "gpx.gz")) {332 return new GZIPInputStream(Files.newInputStream(sel.toPath()));333 } else {334 return Files.newInputStream(sel.toPath());335 }336 }337 324 } 338 325 -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r13901 r14010 42 42 * @author imi, ramack 43 43 */ 44 public class GpxReader implements GpxConstants {44 public class GpxReader implements GpxConstants, IGpxReader { 45 45 46 46 private enum State { … … 579 579 * @throws IOException if any I/O error occurs 580 580 */ 581 @Override 581 582 public boolean parse(boolean tryToFinish) throws SAXException, IOException { 582 583 Parser parser = new Parser(); … … 604 605 } 605 606 606 /** 607 * Replies the GPX data. 608 * @return The GPX data 609 */ 607 @Override 610 608 public GpxData getGpxData() { 611 609 return gpxData; -
trunk/src/org/openstreetmap/josm/io/nmea/NmeaReader.java
r12620 r14010 14 14 import java.util.Date; 15 15 import java.util.Locale; 16 import java.util.Objects; 16 17 import java.util.Optional; 17 18 … … 21 22 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 22 23 import org.openstreetmap.josm.data.gpx.WayPoint; 24 import org.openstreetmap.josm.io.IGpxReader; 23 25 import org.openstreetmap.josm.io.IllegalDataException; 24 26 import org.openstreetmap.josm.tools.Logging; 25 27 import org.openstreetmap.josm.tools.date.DateUtils; 28 import org.xml.sax.SAXException; 26 29 27 30 /** … … 40 43 * @author cbrill 41 44 */ 42 public class NmeaReader {45 public class NmeaReader implements IGpxReader { 43 46 44 47 enum VTG { … … 129 132 } 130 133 131 public GpxData data; 134 private final InputStream source; 135 GpxData data; 132 136 133 137 private final SimpleDateFormat rmcTimeFmt = new SimpleDateFormat("ddMMyyHHmmss.SSS", Locale.ENGLISH); … … 171 175 */ 172 176 public NmeaReader(InputStream source) throws IOException { 177 this.source = Objects.requireNonNull(source); 173 178 rmcTimeFmt.setTimeZone(DateUtils.UTC); 174 179 rmcTimeFmtStd.setTimeZone(DateUtils.UTC); 175 180 } 181 182 @Override 183 public boolean parse(boolean tryToFinish) throws SAXException, IOException { 176 184 // create the data tree 177 185 data = new GpxData(); … … 184 192 if (loopstartChar == -1) 185 193 //TODO tell user about the problem? 186 return ;194 return false; 187 195 sb.append((char) loopstartChar); 188 196 ps.pDate = "010100"; // TODO date problem … … 210 218 } catch (IllegalDataException e) { 211 219 Logging.warn(e); 212 } 220 return false; 221 } 222 return true; 213 223 } 214 224 … … 529 539 return new LatLon(lat, lon); 530 540 } 541 542 @Override 543 public GpxData getGpxData() { 544 return data; 545 } 531 546 }
Note:
See TracChangeset
for help on using the changeset viewer.