Changeset 6053 in josm


Ignore:
Timestamp:
2013-07-06T18:23:35+02:00 (11 years ago)
Author:
Don-vip
Message:

see #2283 - allow to download both osm and gpx data in DownloadOsmTaskList, thereby renamed to DownloadTaskList

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  
    1313
    1414import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
     15import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
    1616import org.openstreetmap.josm.data.osm.DataSource;
    1717import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    8989            //
    9090            final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
    91             final Future<?> future = new DownloadOsmTaskList().download(false /* no new layer */, areasToDownload, monitor);
     91            final Future<?> future = new DownloadTaskList().download(false /* no new layer */, areasToDownload, true, false, monitor);
    9292            Main.worker.submit(
    9393                    new Runnable() {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

    r6051 r6053  
    4040 * a list in the end.
    4141 * @author xeen
    42  *
     42 * @since 6053
    4343 */
    44 public class DownloadOsmTaskList {
    45     private List<DownloadTask> osmTasks = new LinkedList<DownloadTask>();
    46     private List<Future<?>> osmTaskFutures = new LinkedList<Future<?>>();
     44public class DownloadTaskList {
     45    private List<DownloadTask> tasks = new LinkedList<DownloadTask>();
     46    private List<Future<?>> taskFutures = new LinkedList<Future<?>>();
    4747    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   
    4957    /**
    5058     * Downloads a list of areas from the OSM Server
    5159     * @param newLayer Set to true if all areas should be put into a single new layer
    5260     * @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
    5363     * @param progressMonitor The progress monitor
    5464     * @return The Future representing the asynchronous download task
    5565     */
    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) {
    5767        this.progressMonitor = progressMonitor;
    5868        if (newLayer) {
     
    6171            Main.map.mapView.setActiveLayer(l);
    6272        }
    63 
    64         progressMonitor.beginTask(null, rects.size());
     73       
     74        int n = (osmData && gpxData ? 2 : 1)*rects.size();
     75        progressMonitor.beginTask(null, n);
    6576        int i = 0;
    6677        for (Rectangle2D td : rects) {
    6778            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            }
    7485        }
    7586        progressMonitor.addCancelListener(new CancelListener() {
    7687            @Override
    7788            public void operationCanceled() {
    78                 for (DownloadTask dt : osmTasks) {
     89                for (DownloadTask dt : tasks) {
    7990                    dt.cancel();
    8091                }
    8192            }
    8293        });
    83         return Main.worker.submit(new PostDownloadProcessor());
     94        return Main.worker.submit(new PostDownloadProcessor(osmData));
    8495    }
    8596
     
    8899     * @param newLayer Set to true if all areas should be put into a single new layer
    89100     * @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
    90103     * @param progressMonitor The progress monitor
    91104     * @return The Future representing the asynchronous download task
    92105     */
    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) {
    94107        progressMonitor.beginTask(tr("Updating data"));
    95108        try {
     
    99112            }
    100113
    101             return download(newLayer, rects, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     114            return download(newLayer, rects, osmData, gpxData, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
    102115        } finally {
    103116            progressMonitor.finishTask();
     
    203216    public Set<OsmPrimitive> getDownloadedPrimitives() {
    204217        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    205         for (DownloadTask task : osmTasks) {
     218        for (DownloadTask task : tasks) {
    206219            if (task instanceof DownloadOsmTask) {
    207220                DataSet ds = ((DownloadOsmTask) task).getDownloadedData();
     
    215228
    216229    class PostDownloadProcessor implements Runnable {
     230
     231        private final boolean osmData;
     232       
     233        public PostDownloadProcessor(boolean osmData) {
     234            this.osmData = osmData;
     235        }
     236
    217237        /**
    218238         * Grabs and displays the error messages after all download threads have finished.
     
    224244            // wait for all download tasks to finish
    225245            //
    226             for (Future<?> future : osmTaskFutures) {
     246            for (Future<?> future : taskFutures) {
    227247                try {
    228248                    future.get();
     
    233253            }
    234254            LinkedHashSet<Object> errors = new LinkedHashSet<Object>();
    235             for (DownloadTask dt : osmTasks) {
     255            for (DownloadTask dt : tasks) {
    236256                errors.addAll(dt.getErrorObjects());
    237257            }
     
    262282
    263283            // 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
    266285            //
    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())
    271290                        return;
    272291                }
    273292            }
    274293            final OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
    275             if (editLayer != null) {
     294            if (editLayer != null && osmData) {
    276295                final Set<OsmPrimitive> myPrimitives = getCompletePrimitives(editLayer.data);
    277                 for (DownloadTask task : osmTasks) {
     296                for (DownloadTask task : tasks) {
    278297                    if (task instanceof DownloadOsmTask) {
    279298                        DataSet ds = ((DownloadOsmTask) task).getDownloadedData();
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java

    r5927 r6053  
    2020
    2121import org.openstreetmap.josm.Main;
    22 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
     22import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
    2323import org.openstreetmap.josm.data.coor.LatLon;
    2424import org.openstreetmap.josm.data.gpx.GpxData;
     
    260260        }
    261261        final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
    262         final Future<?> future = new DownloadOsmTaskList().download(false, toDownload, monitor);
     262        final Future<?> future = new DownloadTaskList().download(false, toDownload, true, false, monitor);
    263263        Main.worker.submit(new Runnable() {
    264264            @Override
Note: See TracChangeset for help on using the changeset viewer.