Changeset 6053 in josm
- Timestamp:
- 2013-07-06T18:23:35+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r6046 r6053 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.actions.downloadtasks.Download OsmTaskList;15 import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList; 16 16 import org.openstreetmap.josm.data.osm.DataSource; 17 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 89 89 // 90 90 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data")); 91 final Future<?> future = new Download OsmTaskList().download(false /* no new layer */, areasToDownload, monitor);91 final Future<?> future = new DownloadTaskList().download(false /* no new layer */, areasToDownload, true, false, monitor); 92 92 Main.worker.submit( 93 93 new Runnable() { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java
r6051 r6053 40 40 * a list in the end. 41 41 * @author xeen 42 * 42 * @since 6053 43 43 */ 44 public class Download OsmTaskList {45 private List<DownloadTask> osmTasks = new LinkedList<DownloadTask>();46 private List<Future<?>> osmTaskFutures = new LinkedList<Future<?>>();44 public class DownloadTaskList { 45 private List<DownloadTask> tasks = new LinkedList<DownloadTask>(); 46 private List<Future<?>> taskFutures = new LinkedList<Future<?>>(); 47 47 private ProgressMonitor progressMonitor; 48 48 49 private void addDownloadTask(DownloadTask dt, Rectangle2D td, int i, int n) { 50 ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false); 51 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, n, n - i)); 52 Future<?> future = dt.download(false, new Bounds(td), childProgress); 53 taskFutures.add(future); 54 tasks.add(dt); 55 } 56 49 57 /** 50 58 * Downloads a list of areas from the OSM Server 51 59 * @param newLayer Set to true if all areas should be put into a single new layer 52 60 * @param rects The List of Rectangle2D to download 61 * @param osmData Set to true if OSM data should be downloaded 62 * @param gpxData Set to true if GPX data should be downloaded 53 63 * @param progressMonitor The progress monitor 54 64 * @return The Future representing the asynchronous download task 55 65 */ 56 public Future<?> download(boolean newLayer, List<Rectangle2D> rects, ProgressMonitor progressMonitor) {66 public Future<?> download(boolean newLayer, List<Rectangle2D> rects, boolean osmData, boolean gpxData, ProgressMonitor progressMonitor) { 57 67 this.progressMonitor = progressMonitor; 58 68 if (newLayer) { … … 61 71 Main.map.mapView.setActiveLayer(l); 62 72 } 63 64 progressMonitor.beginTask(null, rects.size()); 73 74 int n = (osmData && gpxData ? 2 : 1)*rects.size(); 75 progressMonitor.beginTask(null, n); 65 76 int i = 0; 66 77 for (Rectangle2D td : rects) { 67 78 i++; 68 DownloadTask dt = new DownloadOsmTask();69 ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false);70 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size() - i));71 Future<?> future = dt.download(false, new Bounds(td), childProgress);72 osmTaskFutures.add(future);73 osmTasks.add(dt);79 if (osmData) { 80 addDownloadTask(new DownloadOsmTask(), td, i, n); 81 } 82 if (gpxData) { 83 addDownloadTask(new DownloadGpsTask(), td, i, n); 84 } 74 85 } 75 86 progressMonitor.addCancelListener(new CancelListener() { 76 87 @Override 77 88 public void operationCanceled() { 78 for (DownloadTask dt : osmTasks) {89 for (DownloadTask dt : tasks) { 79 90 dt.cancel(); 80 91 } 81 92 } 82 93 }); 83 return Main.worker.submit(new PostDownloadProcessor( ));94 return Main.worker.submit(new PostDownloadProcessor(osmData)); 84 95 } 85 96 … … 88 99 * @param newLayer Set to true if all areas should be put into a single new layer 89 100 * @param areas The Collection of Areas to download 101 * @param osmData Set to true if OSM data should be downloaded 102 * @param gpxData Set to true if GPX data should be downloaded 90 103 * @param progressMonitor The progress monitor 91 104 * @return The Future representing the asynchronous download task 92 105 */ 93 public Future<?> download(boolean newLayer, Collection<Area> areas, ProgressMonitor progressMonitor) {106 public Future<?> download(boolean newLayer, Collection<Area> areas, boolean osmData, boolean gpxData, ProgressMonitor progressMonitor) { 94 107 progressMonitor.beginTask(tr("Updating data")); 95 108 try { … … 99 112 } 100 113 101 return download(newLayer, rects, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));114 return download(newLayer, rects, osmData, gpxData, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 102 115 } finally { 103 116 progressMonitor.finishTask(); … … 203 216 public Set<OsmPrimitive> getDownloadedPrimitives() { 204 217 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 205 for (DownloadTask task : osmTasks) {218 for (DownloadTask task : tasks) { 206 219 if (task instanceof DownloadOsmTask) { 207 220 DataSet ds = ((DownloadOsmTask) task).getDownloadedData(); … … 215 228 216 229 class PostDownloadProcessor implements Runnable { 230 231 private final boolean osmData; 232 233 public PostDownloadProcessor(boolean osmData) { 234 this.osmData = osmData; 235 } 236 217 237 /** 218 238 * Grabs and displays the error messages after all download threads have finished. … … 224 244 // wait for all download tasks to finish 225 245 // 226 for (Future<?> future : osmTaskFutures) {246 for (Future<?> future : taskFutures) { 227 247 try { 228 248 future.get(); … … 233 253 } 234 254 LinkedHashSet<Object> errors = new LinkedHashSet<Object>(); 235 for (DownloadTask dt : osmTasks) {255 for (DownloadTask dt : tasks) { 236 256 errors.addAll(dt.getErrorObjects()); 237 257 } … … 262 282 263 283 // FIXME: this is a hack. We assume that the user canceled the whole download if at 264 // least 265 // one task was canceled or if it failed 284 // least one task was canceled or if it failed 266 285 // 267 for (DownloadTask task : osmTasks) {268 if (task instanceof DownloadOsmTask) {269 DownloadOsmTask osmTask = (DownloadOsmTask) task;270 if ( osmTask.isCanceled() || osmTask.isFailed())286 for (DownloadTask task : tasks) { 287 if (task instanceof AbstractDownloadTask) { 288 AbstractDownloadTask absTask = (AbstractDownloadTask) task; 289 if (absTask.isCanceled() || absTask.isFailed()) 271 290 return; 272 291 } 273 292 } 274 293 final OsmDataLayer editLayer = Main.map.mapView.getEditLayer(); 275 if (editLayer != null ) {294 if (editLayer != null && osmData) { 276 295 final Set<OsmPrimitive> myPrimitives = getCompletePrimitives(editLayer.data); 277 for (DownloadTask task : osmTasks) {296 for (DownloadTask task : tasks) { 278 297 if (task instanceof DownloadOsmTask) { 279 298 DataSet ds = ((DownloadOsmTask) task).getDownloadedData(); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java
r5927 r6053 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.downloadtasks.Download OsmTaskList;22 import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList; 23 23 import org.openstreetmap.josm.data.coor.LatLon; 24 24 import org.openstreetmap.josm.data.gpx.GpxData; … … 260 260 } 261 261 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data")); 262 final Future<?> future = new Download OsmTaskList().download(false, toDownload, monitor);262 final Future<?> future = new DownloadTaskList().download(false, toDownload, true, false, monitor); 263 263 Main.worker.submit(new Runnable() { 264 264 @Override
Note:
See TracChangeset
for help on using the changeset viewer.