Ignore:
Timestamp:
27.10.2009 01:21:32 (3 years ago)
Author:
Gubaer
Message:

Cleanup in download logic (less global, more encapsulation)

File:
1 edited

Legend:

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

    r2323 r2327  
    22package org.openstreetmap.josm.actions; 
    33 
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    45import static org.openstreetmap.josm.tools.I18n.tr; 
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    66 
    77import java.awt.BorderLayout; 
     
    1515 
    1616import org.openstreetmap.josm.Main; 
    17 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 
     17import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 
     18import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 
    1819import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 
    1920import org.openstreetmap.josm.gui.ExtendedDialog; 
     
    3132 */ 
    3233public class DownloadAction extends JosmAction { 
     34     
    3335 
    3436    public DownloadDialog dialog; 
     37    private ExtendedDialog downloadDialog; 
    3538 
    3639    public DownloadAction() { 
     
    4548     */ 
    4649    protected ExtendedDialog createUploadDialog() { 
    47         dialog = new DownloadDialog(); 
     50        if (dialog == null) 
     51            dialog = new DownloadDialog(); 
     52        dialog.restoreSettings(); 
    4853        JPanel downPanel = new JPanel(new BorderLayout()); 
    4954        downPanel.add(dialog, BorderLayout.CENTER); 
     
    5358                new Dimension(1000,600)); 
    5459 
    55         ExtendedDialog dialog = new ExtendedDialog(Main.parent, 
     60        if (downloadDialog == null) { 
     61            downloadDialog= new ExtendedDialog(Main.parent, 
    5662                tr("Download"), 
    5763                new String[] {tr("OK"), tr("Cancel")}); 
    58         dialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */); 
    59         dialog.setButtonIcons(new String[] {"ok", "cancel"}); 
    60         dialog.setRememberWindowGeometry(prefName, wg); 
    61         return dialog; 
     64            downloadDialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */); 
     65            downloadDialog.setButtonIcons(new String[] {"ok", "cancel"}); 
     66            downloadDialog.setRememberWindowGeometry(prefName, wg); 
     67        } 
     68        return downloadDialog; 
    6269    } 
    6370 
     
    6572        ExtendedDialog dlg = createUploadDialog(); 
    6673        boolean finish = false; 
    67         while (!finish) { 
     74        while (!finish) {             
    6875            dlg.showDialog(); 
    69             Main.pref.put("download.newlayer", dialog.newLayer.isSelected()); 
    7076            if (dlg.getValue() == 1 /* OK */) { 
    71                 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab())); 
    72                 for (DownloadTask task : dialog.downloadTasks) { 
    73                     Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected()); 
    74                     if (task.getCheckBox().isSelected()) { 
    75                         // asynchronously launch the download task ... 
    76                         Future<?> future = task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null); 
    77                         // ... and the continuation when the download task is finished 
    78                         Main.worker.submit(new PostDownloadHandler(task, future)); 
    79                         finish = true; 
    80                     } 
     77                dialog.rememberSettings(); 
     78                if (dialog.isDownloadOsmData()) { 
     79                    DownloadOsmTask task = new DownloadOsmTask(); 
     80                    Future<?> future = task.download(this, dialog.getSelectedDownloadArea(), null); 
     81                    Main.worker.submit(new PostDownloadHandler(task, future)); 
     82                    finish = true; 
     83                } 
     84                if (dialog.isDownloadGpxData()) { 
     85                    DownloadGpsTask task = new DownloadGpsTask(); 
     86                    Future<?> future = task.download(this,dialog.getSelectedDownloadArea(), null); 
     87                    Main.worker.submit(new PostDownloadHandler(task, future)); 
     88                    finish = true; 
    8189                } 
    8290            } else { 
Note: See TracChangeset for help on using the changeset viewer.