Changeset 11774 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2017-03-25T17:33:06+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r11658 r11774 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList; 10 import java.util.List; 11 import java.util.concurrent.ExecutionException; 9 12 import java.util.concurrent.Future; 10 13 11 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask; 12 16 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 13 17 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask; … … 15 19 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 16 20 import org.openstreetmap.josm.data.Bounds; 21 import org.openstreetmap.josm.data.ProjectionBounds; 22 import org.openstreetmap.josm.data.ViewportData; 17 23 import org.openstreetmap.josm.gui.download.DownloadDialog; 24 import org.openstreetmap.josm.gui.util.GuiHelper; 25 import org.openstreetmap.josm.tools.Pair; 18 26 import org.openstreetmap.josm.tools.Shortcut; 19 27 … … 45 53 if (!dialog.isCanceled()) { 46 54 dialog.rememberSettings(); 47 Bounds area = dialog.getSelectedDownloadArea(); 55 final Bounds area = dialog.getSelectedDownloadArea(); 56 final boolean zoom = dialog.isZoomToDownloadedDataRequired(); 57 final List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>(); 48 58 if (dialog.isDownloadOsmData()) { 49 59 DownloadOsmTask task = new DownloadOsmTask(); 50 task.setZoomAfterDownload( dialog.isZoomToDownloadedDataRequired());60 task.setZoomAfterDownload(zoom && !dialog.isDownloadGpxData() && !dialog.isDownloadNotes()); 51 61 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 52 62 Main.worker.submit(new PostDownloadHandler(task, future)); 63 if (zoom) { 64 tasks.add(new Pair<>(task, future)); 65 } 53 66 } 54 67 if (dialog.isDownloadGpxData()) { 55 68 DownloadGpsTask task = new DownloadGpsTask(); 56 task.setZoomAfterDownload( dialog.isZoomToDownloadedDataRequired());69 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadNotes()); 57 70 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 58 71 Main.worker.submit(new PostDownloadHandler(task, future)); 72 if (zoom) { 73 tasks.add(new Pair<>(task, future)); 74 } 59 75 } 60 76 if (dialog.isDownloadNotes()) { 61 77 DownloadNotesTask task = new DownloadNotesTask(); 62 task.setZoomAfterDownload( dialog.isZoomToDownloadedDataRequired());78 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadGpxData()); 63 79 Future<?> future = task.download(false, area, null); 64 80 Main.worker.submit(new PostDownloadHandler(task, future)); 81 if (zoom) { 82 tasks.add(new Pair<>(task, future)); 83 } 84 } 85 if (zoom && tasks.size() > 1) { 86 Main.worker.submit(() -> { 87 ProjectionBounds bounds = null; 88 // Wait for completion of download jobs 89 for (Pair<AbstractDownloadTask<?>, Future<?>> p : tasks) { 90 try { 91 p.b.get(); 92 ProjectionBounds b = p.a.getDownloadProjectionBounds(); 93 if (bounds == null) { 94 bounds = b; 95 } else if (b != null) { 96 bounds.extend(b); 97 } 98 } catch (InterruptedException | ExecutionException ex) { 99 Main.warn(ex); 100 } 101 } 102 // Zoom to the larger download bounds 103 if (Main.map != null && bounds != null) { 104 final ProjectionBounds pb = bounds; 105 GuiHelper.runInEDTAndWait(() -> Main.map.mapView.zoomTo(new ViewportData(pb))); 106 } 107 }); 65 108 } 66 109 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java
r11658 r11774 5 5 import java.util.List; 6 6 7 import org.openstreetmap.josm.data.ProjectionBounds; 7 8 import org.openstreetmap.josm.io.XmlWriter; 8 9 … … 170 171 return new String[]{}; 171 172 } 173 174 /** 175 * Returns the projection bounds of downloaded data. 176 * @return the projection bounds of downloaded data or {@code null} 177 * @since 11774 178 */ 179 public ProjectionBounds getDownloadProjectionBounds() { 180 return null; 181 } 172 182 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r11658 r11774 15 15 import org.openstreetmap.josm.data.Bounds; 16 16 import org.openstreetmap.josm.data.Bounds.ParseMethod; 17 import org.openstreetmap.josm.data.ProjectionBounds; 17 18 import org.openstreetmap.josm.data.ViewportData; 18 19 import org.openstreetmap.josm.data.gpx.GpxData; … … 39 40 40 41 private DownloadTask downloadTask; 42 private GpxLayer gpxLayer; 41 43 42 44 private static final String PATTERN_TRACE_ID = "https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data"; … … 114 116 } 115 117 118 @Override 119 public ProjectionBounds getDownloadProjectionBounds() { 120 return gpxLayer != null ? gpxLayer.getViewProjectionBounds() : null; 121 } 122 116 123 class DownloadTask extends PleaseWaitRunnable { 117 124 private final OsmServerReader reader; … … 130 137 if (isCanceled()) 131 138 return; 132 ProgressMonitor subMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 133 rawData = reader.parseRawGps(subMonitor); 139 rawData = reader.parseRawGps(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 134 140 } catch (OsmTransferException e) { 135 141 if (isCanceled()) … … 149 155 tr("Markers from {0}", name)); 150 156 151 GpxLayergpxLayer = addOrMergeLayer(layers.getGpxLayer(), findGpxMergeLayer());157 gpxLayer = addOrMergeLayer(layers.getGpxLayer(), findGpxMergeLayer()); 152 158 addOrMergeLayer(layers.getMarkerLayer(), findMarkerMergeLayer(gpxLayer)); 153 159 … … 158 164 if (layer == null) return null; 159 165 if (newLayer || mergeLayer == null) { 160 Main.getLayerManager().addLayer(layer );166 Main.getLayerManager().addLayer(layer, zoomAfterDownload); 161 167 return layer; 162 168 } else { 163 169 mergeLayer.mergeFrom(layer); 164 170 mergeLayer.invalidate(); 165 if (Main.map != null && zoomAfterDownload ) {171 if (Main.map != null && zoomAfterDownload && layer instanceof GpxLayer) { 166 172 Main.map.mapView.scheduleZoomTo(new ViewportData(layer.getViewProjectionBounds())); 167 173 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
r11658 r11774 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.data.Bounds; 16 import org.openstreetmap.josm.data.ProjectionBounds; 16 17 import org.openstreetmap.josm.data.ViewportData; 17 18 import org.openstreetmap.josm.data.notes.Note; … … 40 41 41 42 private DownloadTask downloadTask; 43 private NoteLayer noteLayer; 42 44 43 45 /** … … 96 98 } 97 99 100 @Override 101 public ProjectionBounds getDownloadProjectionBounds() { 102 return noteLayer != null ? noteLayer.getViewProjectionBounds() : null; 103 } 104 98 105 abstract class DownloadTask extends PleaseWaitRunnable { 99 106 protected OsmServerReader reader; … … 117 124 List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class); 118 125 if (!noteLayers.isEmpty()) { 119 noteLayers.get(0).getNoteData().addNotes(notesData); 126 noteLayer = noteLayers.get(0); 127 noteLayer.getNoteData().addNotes(notesData); 120 128 if (Main.map != null && zoomAfterDownload) { 121 Main.map.mapView.scheduleZoomTo(new ViewportData(noteLayer s.get(0).getViewProjectionBounds()));129 Main.map.mapView.scheduleZoomTo(new ViewportData(noteLayer.getViewProjectionBounds())); 122 130 } 123 131 } else { 124 Main.getLayerManager().addLayer(new NoteLayer(notesData, tr("Notes")) );132 Main.getLayerManager().addLayer(new NoteLayer(notesData, tr("Notes")), zoomAfterDownload); 125 133 } 126 134 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r11735 r11774 19 19 import org.openstreetmap.josm.data.DataSource; 20 20 import org.openstreetmap.josm.data.ProjectionBounds; 21 import org.openstreetmap.josm.data.ViewportData; 21 22 import org.openstreetmap.josm.data.coor.LatLon; 22 23 import org.openstreetmap.josm.data.osm.DataSet; … … 175 176 } 176 177 178 @Override 179 public ProjectionBounds getDownloadProjectionBounds() { 180 return downloadTask != null ? downloadTask.computeBbox(currentBounds) : null; 181 } 182 177 183 /** 178 184 * Superclass of internal download task. … … 253 259 } 254 260 255 protected void computeBboxAndCenterScale(Bounds bounds) {256 ProjectionBounds pb = computeBbox(bounds);257 BoundingXYVisitor v = new BoundingXYVisitor();258 v.visit(pb);259 Main.map.mapView.zoomTo(v);260 }261 262 261 protected OsmDataLayer addNewLayerIfRequired(String newLayerName) { 263 262 int numDataLayers = getNumDataLayers(); … … 268 267 final OsmDataLayer layer = createNewLayer(newLayerName); 269 268 if (Main.main != null) 270 Main.getLayerManager().addLayer(layer );269 Main.getLayerManager().addLayer(layer, zoomAfterDownload); 271 270 return layer; 272 271 } … … 280 279 Collection<OsmPrimitive> primitivesToUpdate = searchPrimitivesToUpdate(bounds, layer.data); 281 280 layer.mergeFrom(dataSet); 282 if ( zoomAfterDownload) {283 computeBboxAndCenterScale(bounds);281 if (Main.map != null && zoomAfterDownload) { 282 Main.map.mapView.zoomTo(new ViewportData(computeBbox(bounds))); 284 283 } 285 284 if (!primitivesToUpdate.isEmpty()) { -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r10300 r11774 97 97 98 98 /** 99 * Extends bounds to include bounds {@code b}. 100 * @param b bounds to include 101 * @since 11774 102 */ 103 public void extend(ProjectionBounds b) { 104 if (b.minEast < minEast) { 105 minEast = b.minEast; 106 } 107 if (b.maxEast > maxEast) { 108 maxEast = b.maxEast; 109 } 110 if (b.minNorth < minNorth) { 111 minNorth = b.minNorth; 112 } 113 if (b.maxNorth > maxNorth) { 114 maxNorth = b.maxNorth; 115 } 116 } 117 118 /** 99 119 * Returns the center east/north. 100 120 * @return the center east/north -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r11765 r11774 343 343 registeredLayers.put(layer, painter); 344 344 345 ProjectionBounds viewProjectionBounds = layer.getViewProjectionBounds(); 346 if (viewProjectionBounds != null) { 347 scheduleZoomTo(new ViewportData(viewProjectionBounds)); 345 if (e.isZoomRequired()) { 346 ProjectionBounds viewProjectionBounds = layer.getViewProjectionBounds(); 347 if (viewProjectionBounds != null) { 348 scheduleZoomTo(new ViewportData(viewProjectionBounds)); 349 } 348 350 } 349 351 -
trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java
r11746 r11774 71 71 } 72 72 73 /** 74 * Returns the {@code LayerManager} at the origin of this event. 75 * @return the {@code LayerManager} at the origin of this event 76 */ 73 77 public LayerManager getSource() { 74 78 return source; … … 82 86 public static class LayerAddEvent extends LayerManagerEvent { 83 87 private final Layer addedLayer; 84 85 LayerAddEvent(LayerManager source, Layer addedLayer) { 88 private final boolean requiresZoom; 89 90 LayerAddEvent(LayerManager source, Layer addedLayer, boolean requiresZoom) { 86 91 super(source); 87 92 this.addedLayer = addedLayer; 93 this.requiresZoom = requiresZoom; 88 94 } 89 95 … … 94 100 public Layer getAddedLayer() { 95 101 return addedLayer; 102 } 103 104 /** 105 * Determines if an initial zoom is required. 106 * @return {@code true} if a zoom is required when this layer is added 107 * @since 11774 108 */ 109 public final boolean isZoomRequired() { 110 return requiresZoom; 96 111 } 97 112 … … 182 197 183 198 /** 199 * Add a layer. The layer will be added at a given position and the mapview zoomed at its projection bounds. 200 * @param layer The layer to add 201 */ 202 public void addLayer(final Layer layer) { 203 addLayer(layer, true); 204 } 205 206 /** 184 207 * Add a layer. The layer will be added at a given position. 185 208 * @param layer The layer to add 186 */ 187 public void addLayer(final Layer layer) { 209 * @param initialZoom whether if the mapview must be zoomed at layer projection bounds 210 */ 211 public void addLayer(final Layer layer, final boolean initialZoom) { 188 212 // we force this on to the EDT Thread to make events fire from there. 189 213 // The synchronization lock needs to be held by the EDT. 190 GuiHelper.runInEDTAndWaitWithException(() -> realAddLayer(layer ));191 } 192 193 protected synchronized void realAddLayer(Layer layer ) {214 GuiHelper.runInEDTAndWaitWithException(() -> realAddLayer(layer, initialZoom)); 215 } 216 217 protected synchronized void realAddLayer(Layer layer, boolean initialZoom) { 194 218 if (containsLayer(layer)) { 195 219 throw new IllegalArgumentException("Cannot add a layer twice: " + layer); … … 199 223 checkPosition(position); 200 224 insertLayerAt(layer, position); 201 fireLayerAdded(layer );225 fireLayerAdded(layer, initialZoom); 202 226 if (Main.map != null) { 203 227 layer.hookUpMapView(); // needs to be after fireLayerAdded … … 366 390 if (fireAdd) { 367 391 for (Layer l : getLayers()) { 368 listener.layerAdded(new LayerAddEvent(this, l ));392 listener.layerAdded(new LayerAddEvent(this, l, true)); 369 393 } 370 394 } … … 399 423 } 400 424 401 private void fireLayerAdded(Layer layer ) {425 private void fireLayerAdded(Layer layer, boolean initialZoom) { 402 426 GuiHelper.assertCallFromEdt(); 403 LayerAddEvent e = new LayerAddEvent(this, layer );427 LayerAddEvent e = new LayerAddEvent(this, layer, initialZoom); 404 428 for (LayerChangeListener l : layerChangeListeners) { 405 429 try { -
trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
r10999 r11774 242 242 243 243 @Override 244 protected synchronized void realAddLayer(Layer layer ) {244 protected synchronized void realAddLayer(Layer layer, boolean initialZoom) { 245 245 if (getLayers().isEmpty()) { 246 246 LayerAvailabilityEvent e = new LayerAvailabilityEvent(this, true); … … 249 249 } 250 250 } 251 super.realAddLayer(layer );251 super.realAddLayer(layer, initialZoom); 252 252 253 253 // update the active layer automatically.
Note:
See TracChangeset
for help on using the changeset viewer.