Ticket #7193: gpxlayer.patch
File gpxlayer.patch, 3.9 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/io/GpxImporter.java
23 23 24 24 public class GpxImporter extends FileImporter { 25 25 26 protected GpxLayer gpxLayer; 27 protected MarkerLayer markerLayer; 28 protected Runnable postLayerTask; 26 protected class GpxImporterData { 27 public GpxLayer gpxLayer; 28 public MarkerLayer markerLayer; 29 public Runnable postLayerTask; 30 } 29 31 30 32 public GpxImporter() { 31 33 super(new ExtensionFileFilter("gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)")); … … 39 41 is = new FileInputStream(file); 40 42 } 41 43 String fileName = file.getName(); 42 loadLayers(is, file, fileName, tr("Markers from {0}", fileName), progressMonitor);44 final GpxImporterData data = loadLayers(is, file, fileName, tr("Markers from {0}", fileName), progressMonitor); 43 45 44 46 // FIXME: remove UI stuff from the IO subsystem 45 47 GuiHelper.runInEDT(new Runnable() { 46 48 public void run() { 47 if ( markerLayer != null) {48 Main.main.addLayer( markerLayer);49 if (data.markerLayer != null) { 50 Main.main.addLayer(data.markerLayer); 49 51 } 50 if ( gpxLayer != null) {51 Main.main.addLayer( gpxLayer);52 if (data.gpxLayer != null) { 53 Main.main.addLayer(data.gpxLayer); 52 54 } 53 postLayerTask.run();55 data.postLayerTask.run(); 54 56 } 55 57 }); 56 58 } 57 59 58 public voidloadLayers(InputStream is, final File associatedFile,60 public GpxImporterData loadLayers(InputStream is, final File associatedFile, 59 61 final String gpxLayerName, String markerLayerName, ProgressMonitor progressMonitor) throws IOException { 62 final GpxImporterData data = new GpxImporterData(); 60 63 try { 61 64 final GpxReader r = new GpxReader(is); 62 65 final boolean parsedProperly = r.parse(true); 63 66 r.data.storageFile = associatedFile; 64 67 if (r.data.hasRoutePoints() || r.data.hasTrackPoints()) { 65 gpxLayer = new GpxLayer(r.data, gpxLayerName, associatedFile != null);68 data.gpxLayer = new GpxLayer(r.data, gpxLayerName, associatedFile != null); 66 69 } 67 70 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !r.data.waypoints.isEmpty()) { 68 markerLayer = new MarkerLayer(r.data, markerLayerName, associatedFile,gpxLayer, false);69 if ( markerLayer.data.size() == 0) {70 markerLayer = null;71 data.markerLayer = new MarkerLayer(r.data, markerLayerName, associatedFile, data.gpxLayer, false); 72 if (data.markerLayer.data.size() == 0) { 73 data.markerLayer = null; 71 74 } 72 75 } 73 postLayerTask = new Runnable() {76 data.postLayerTask = new Runnable() { 74 77 @Override 75 78 public void run() { 76 if ( markerLayer != null) {77 markerLayer.addMouseHandler();79 if (data.markerLayer != null) { 80 data.markerLayer.addMouseHandler(); 78 81 } 79 82 if (!parsedProperly) { 80 83 String msg; … … 93 96 e.printStackTrace(); 94 97 throw new IOException(tr("Parsing data for layer ''{0}'' failed", gpxLayerName)); 95 98 } 99 return data; 96 100 } 97 98 public GpxLayer getGpxLayer() {99 return gpxLayer;100 }101 102 public MarkerLayer getMarkerLayer() {103 return markerLayer;104 }105 106 public Runnable getPostLayerTask() {107 return postLayerTask;108 }109 101 }