Changeset 2330 in josm


Ignore:
Timestamp:
2009-10-27T13:04:39+01:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3794: not download the correct area

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r2328 r2330  
    1010import java.awt.event.KeyEvent;
    1111import java.util.concurrent.Future;
     12import java.util.logging.Logger;
    1213
    1314import javax.swing.JOptionPane;
     
    1819import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    1920import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     21import org.openstreetmap.josm.data.Bounds;
    2022import org.openstreetmap.josm.gui.ExtendedDialog;
    2123import org.openstreetmap.josm.gui.download.DownloadDialog;
     
    3234 */
    3335public class DownloadAction extends JosmAction {
     36    private static final Logger logger = Logger.getLogger(DownloadAction.class.getName());
    3437   
    35 
    3638    private DownloadDialog dialog;
    3739    private ExtendedDialog downloadDialog;
     
    4547    /**
    4648     * Creates the download dialog
     49     *
    4750     * @return the downlaod dialog
    4851     */
    49     protected ExtendedDialog createUploadDialog() {
    50         if (dialog == null)
     52    protected ExtendedDialog createDownloadDialog() {
     53        if (dialog == null) 
    5154            dialog = new DownloadDialog();
    5255        dialog.restoreSettings();
    53         JPanel downPanel = new JPanel(new BorderLayout());
    54         downPanel.add(dialog, BorderLayout.CENTER);
    5556
    5657        final String prefName = dialog.getClass().getName()+ ".geometry";
     
    5960
    6061        if (downloadDialog == null) {
     62            JPanel downPanel = new JPanel(new BorderLayout());
     63            downPanel.add(dialog, BorderLayout.CENTER);
    6164            downloadDialog= new ExtendedDialog(Main.parent,
    6265                tr("Download"),
     
    7073
    7174    public void actionPerformed(ActionEvent e) {
    72         ExtendedDialog dlg = createUploadDialog();
     75        ExtendedDialog dlg = createDownloadDialog();
    7376        boolean finish = false;
    7477        while (!finish) {           
     
    7679            if (dlg.getValue() == 1 /* OK */) {
    7780                dialog.rememberSettings();
     81                Bounds area = dialog.getSelectedDownloadArea();               
    7882                if (dialog.isDownloadOsmData()) {
    7983                    DownloadOsmTask task = new DownloadOsmTask();
    80                     Future<?> future = task.download(dialog.isNewLayerRequired(), dialog.getSelectedDownloadArea(), null);
     84                    Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
    8185                    Main.worker.submit(new PostDownloadHandler(task, future));
    8286                    finish = true;
     
    8488                if (dialog.isDownloadGpxData()) {
    8589                    DownloadGpsTask task = new DownloadGpsTask();
    86                     Future<?> future = task.download(dialog.isNewLayerRequired(),dialog.getSelectedDownloadArea(), null);
     90                    Future<?> future = task.download(dialog.isNewLayerRequired(),area, null);
    8791                    Main.worker.submit(new PostDownloadHandler(task, future));
    8892                    finish = true;
     
    100104            }
    101105        }
    102 
    103         dialog = null;
    104         dlg.dispose();
    105106    }
    106107}
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

    r2328 r2330  
    1111public interface DownloadTask {
    1212    /**
    13      * Execute the download using the given bounding box. Set silent on progressMonitor
    14      * if no error messages should be popped up.
     13     * Asynchronously launches the download task for a given bounding box.
     14     *
     15     * Set <code>progressMonitor</code> to null, if the task should create, open, and close a progress monitor.
     16     * Set progressMonitor to {@see NullProgressMonitor#INSTANCE} if progress information is to
     17     * be discarded.
     18     *
     19     * You can wait for the asynchronous download task to finish by synchronizing on the returned
     20     * {@see Future}, but make sure not to freeze up JOSM. Example:
     21     * <pre>
     22     *    Future<?> future = task.download(...);
     23     *    // DON'T run this on the Swing EDT or JOSM will freeze
     24     *    future.get(); // waits for the dowload task to complete
     25     * </pre>
     26     *
     27     * The following example uses a pattern which is better suited if a task is launched from
     28     * the Swing EDT:
     29     * <pre>
     30     *    final Future<?> future = task.download(...);
     31     *    Runnable runAfterTask = new Runnable() {
     32     *       public void run() {
     33     *           // this is not strictly necessary because of the type of executor service
     34     *           // Main.worker is initialized with, but it doesn't harm either
     35     *           //
     36     *           future.get(); // wait for the download task to complete
     37     *           doSomethingAfterTheTaskCompleted();
     38     *       }
     39     *    }
     40     *    Main.worker.submit(runAfterTask);
     41     * </pre>
     42     *
     43     * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task
     44     * selects one of the existing layers as download layer, preferably the active layer.
     45     *
     46     * @param downloadArea the area to download
     47     * @param progressMonitor the progressMonitor
     48     * @return the future representing the asynchronous task
    1549     */
    1650    Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor);
    1751
    1852    /**
    19      * Execute the download using the given URL
    20      * @param newLayer
    21      * @param url
     53     * Asynchronously launches the download task for a given bounding URL.
     54     *
     55     * Set progressMonitor to null, if the task should create, open, and close a progress monitor.
     56     * Set progressMonitor to {@see NullProgressMonitor#INSTANCE} if progress information is to
     57     * be discarded.
     58 
     59     * @param newLayer newLayer true, if the data is to be downloaded into a new layer. If false, the task
     60     * selects one of the existing layers as download layer, preferably the active layer.
     61     * @param url the url to download from
     62     * @param progressMonitor the progressMonitor
     63     * @return the future representing the asynchronous task
     64     *
     65     * @see #download(boolean, Bounds, ProgressMonitor)
    2266     */
    2367    Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
     
    2872     * Error objects are either {@see String}s with error messages or {@see Exception}s.
    2973     *
    30      * WARNING: Never call this in the same thread you requested the download() or it will cause a
    31      * dead lock. See actions/downloadTasks/DownloadOsmTaskList.java for a proper implementation.
    32      *
    3374     * @return the list of error objects
    3475     */
    3576    List<Object> getErrorObjects();
    3677
     78    /**
     79     * Cancels the asynchronous download task.
     80     *
     81     */
    3782    public void cancel();
    3883}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r2327 r2330  
    148148     * @param eventSource - the DownloadSelection object that fired this notification.
    149149     */
    150     public void boundingBoxChanged(Bounds b, DownloadSelection eventSource) {
     150    public void boundingBoxChanged(Bounds b, DownloadSelection eventSource) {       
    151151        this.currentBounds = b;
    152152        for (DownloadSelection s : downloadSelections) {
Note: See TracChangeset for help on using the changeset viewer.