Changeset 18042 in josm for trunk/src/org
- Timestamp:
- 2021-07-16T20:15:07+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/layer
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r18034 r18042 25 25 import java.beans.PropertyChangeListener; 26 26 import java.io.File; 27 import java.io.IOException;28 import java.io.InputStream;29 27 import java.text.DateFormat; 30 28 import java.text.ParseException; … … 32 30 import java.time.Instant; 33 31 import java.util.ArrayList; 34 import java.util.Arrays;35 32 import java.util.Collections; 36 33 import java.util.Comparator; … … 72 69 73 70 import org.openstreetmap.josm.actions.DiskAccessAction; 74 import org.openstreetmap.josm.actions.ExtensionFileFilter;75 71 import org.openstreetmap.josm.data.gpx.GpxData; 76 72 import org.openstreetmap.josm.data.gpx.GpxImageCorrelation; … … 82 78 import org.openstreetmap.josm.gui.ExtendedDialog; 83 79 import org.openstreetmap.josm.gui.MainApplication; 84 import org.openstreetmap.josm.gui.io.importexport.GpxImporter;85 80 import org.openstreetmap.josm.gui.io.importexport.ImageImporter; 86 import org.openstreetmap.josm.gui.io.importexport.NMEAImporter;87 import org.openstreetmap.josm.gui.io.importexport.RtkLibImporter;88 81 import org.openstreetmap.josm.gui.layer.GpxLayer; 89 82 import org.openstreetmap.josm.gui.layer.Layer; … … 92 85 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 93 86 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 87 import org.openstreetmap.josm.gui.layer.gpx.GpxDataHelper; 94 88 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 95 import org.openstreetmap.josm.gui.widgets.FileChooserManager;96 89 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 97 90 import org.openstreetmap.josm.gui.widgets.JosmTextField; 98 import org.openstreetmap.josm.io.Compression;99 import org.openstreetmap.josm.io.GpxReader;100 import org.openstreetmap.josm.io.IGpxReader;101 import org.openstreetmap.josm.io.nmea.NmeaReader;102 91 import org.openstreetmap.josm.spi.preferences.Config; 103 92 import org.openstreetmap.josm.spi.preferences.IPreferences; … … 109 98 import org.openstreetmap.josm.tools.Pair; 110 99 import org.openstreetmap.josm.tools.date.DateUtils; 111 import org.xml.sax.SAXException;112 100 113 101 /** … … 280 268 private int lastNumMatched; 281 269 282 /** This class is called when the user doesn't find the GPX file he needs in the files that have 270 /** 271 * This class is called when the user doesn't find the GPX file he needs in the files that have 283 272 * been loaded yet. It displays a FileChooser dialog to select the GPX file to be loaded. 284 273 */ … … 287 276 @Override 288 277 public void actionPerformed(ActionEvent e) { 289 ExtensionFileFilter gpxFilter = GpxImporter.getFileFilter(); 290 AbstractFileChooser fc = new FileChooserManager(true, null).createFileChooser(false, null, 291 Arrays.asList(gpxFilter, NMEAImporter.FILE_FILTER, RtkLibImporter.FILE_FILTER), gpxFilter, JFileChooser.FILES_ONLY) 292 .openFileChooser(); 293 if (fc == null) 294 return; 295 File sel = fc.getSelectedFile(); 296 297 try { 298 outerPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 299 removeDuplicates(sel); 300 GpxData data = null; 301 try (InputStream iStream = Compression.getUncompressedFileInputStream(sel)) { 302 IGpxReader reader = gpxFilter.accept(sel) ? new GpxReader(iStream) : new NmeaReader(iStream); 303 reader.parse(false); 304 data = reader.getGpxData(); 305 data.storageFile = sel; 306 307 } catch (SAXException ex) { 308 Logging.error(ex); 309 JOptionPane.showMessageDialog( 310 MainApplication.getMainFrame(), 311 tr("Error while parsing {0}", sel.getName())+": "+ex.getMessage(), 312 tr("Error"), 313 JOptionPane.ERROR_MESSAGE 314 ); 315 return; 316 } catch (IOException ex) { 317 Logging.error(ex); 318 JOptionPane.showMessageDialog( 319 MainApplication.getMainFrame(), 320 tr("Could not read \"{0}\"", sel.getName())+'\n'+ex.getMessage(), 321 tr("Error"), 322 JOptionPane.ERROR_MESSAGE 323 ); 324 return; 325 } 326 327 GpxDataWrapper elem = new GpxDataWrapper(sel.getName(), data, sel); 328 gpxModel.addElement(elem); 329 gpxModel.setSelectedItem(elem); 330 statusBarUpdater.matchAndUpdateStatusBar(); 331 } finally { 332 outerPanel.setCursor(Cursor.getDefaultCursor()); 278 File sel = GpxDataHelper.chooseGpxDataFile(); 279 if (sel != null) { 280 try { 281 outerPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 282 removeDuplicates(sel); 283 GpxData data = GpxDataHelper.loadGpxData(sel); 284 if (data != null) { 285 GpxDataWrapper elem = new GpxDataWrapper(sel.getName(), data, sel); 286 gpxModel.addElement(elem); 287 gpxModel.setSelectedItem(elem); 288 statusBarUpdater.matchAndUpdateStatusBar(); 289 } 290 } finally { 291 outerPanel.setCursor(Cursor.getDefaultCursor()); 292 } 333 293 } 334 294 } … … 1407 1367 closeDialog(); 1408 1368 } 1409 1410 1369 }
Note:
See TracChangeset
for help on using the changeset viewer.