Ignore:
Timestamp:
2009-07-19T17:38:55+02:00 (16 years ago)
Author:
jttt
Message:

PleaseWait refactoring. Progress is now reported using ProgressMonitor interface, that is available through PleaseWaitRunnable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java

    r1756 r1811  
    2323import org.openstreetmap.josm.gui.layer.Layer;
    2424import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     25import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     26import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2527
    2628/**
     
    3335public class DownloadOsmTaskList implements Runnable {
    3436    private List<DownloadTask> osmTasks = new LinkedList<DownloadTask>();
     37    private ProgressMonitor progressMonitor;
    3538
    3639    /**
     
    3942     * @param The List of Rectangle2D to download
    4043     */
    41     public void download(boolean newLayer, List<Rectangle2D> rects) {
     44    public void download(boolean newLayer, List<Rectangle2D> rects, ProgressMonitor progressMonitor) {
     45        this.progressMonitor = progressMonitor;
    4246        if(newLayer) {
    4347            Layer l = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null);
     
    4650        }
    4751
    48         int i = 0;
    49         for(Rectangle2D td : rects) {
    50             i++;
    51             DownloadTask dt = new DownloadOsmTask();
    52             dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), true,
    53                     tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i));
    54             osmTasks.add(dt);
    55         }
    56 
    57         // If we try to get the error message now the download task will never have been started
    58         // and we'd be stuck in a classical dead lock. Instead attach this to the worker and once
    59         // run() gets called all downloadTasks have finished and we can grab the error messages.
    60         Main.worker.execute(this);
     52        progressMonitor.beginTask(null, rects.size());
     53        try {
     54            int i = 0;
     55            for(Rectangle2D td : rects) {
     56                i++;
     57                DownloadTask dt = new DownloadOsmTask();
     58                ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false);
     59                childProgress.setSilent(true);
     60                childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i));
     61                dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress);
     62                osmTasks.add(dt);
     63            }
     64        } finally {
     65            // If we try to get the error message now the download task will never have been started
     66            // and we'd be stuck in a classical dead lock. Instead attach this to the worker and once
     67            // run() gets called all downloadTasks have finished and we can grab the error messages.
     68            Main.worker.execute(this);
     69        }
    6170    }
    6271
     
    7281        }
    7382
    74         download(newLayer, rects);
     83        download(newLayer, rects, NullProgressMonitor.INSTANCE);
    7584    }
    7685
     
    7988     */
    8089    public void run() {
     90        progressMonitor.finishTask();
    8191        String errors = "";
    8292
     
    109119     * Updates the local state of a set of primitives (given by a set of primitive
    110120     * ids) with the state currently held on the server.
    111      * 
     121     *
    112122     * @param potentiallyDeleted a set of ids to check update from the server
    113123     */
     
    135145     * the current state on the server. If yes, retrieves the current state on the server
    136146     * and checks whether the primitives are indeed deleted on the server.
    137      * 
     147     *
    138148     * @param potentiallyDeleted a set of primitives (given by their ids)
    139149     */
     
    177187     * replies true, if the primitive with id <code>id</code> was downloaded into the
    178188     * dataset <code>ds</code>
    179      * 
     189     *
    180190     * @param id the id
    181191     * @param ds the dataset
     
    191201     * replies true, if the primitive with id <code>id</code> was downloaded into the
    192202     * dataset of one of the download tasks
    193      * 
     203     *
    194204     * @param id the id
    195205     * @return true, if the primitive with id <code>id</code> was downloaded into the
    196206     * dataset of one of the download tasks
    197      * 
     207     *
    198208     */
    199209    public boolean wasDownloaded(long id) {
     
    209219    /**
    210220     * Replies the set of primitive ids which have been downloaded by this task list
    211      * 
     221     *
    212222     * @return the set of primitive ids which have been downloaded by this task list
    213223     */
Note: See TracChangeset for help on using the changeset viewer.