Ignore:
Timestamp:
2017-08-06T20:13:06+02:00 (7 years ago)
Author:
michael2402
Message:

Apply #15057: Improve the over pass turbo dialog

Adds the ability to add favorites and a new wizard dialog with examples.

File:
1 edited

Legend:

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

    r11774 r12574  
    99import java.util.ArrayList;
    1010import java.util.List;
     11import java.util.Optional;
    1112import java.util.concurrent.ExecutionException;
    1213import java.util.concurrent.Future;
     14
     15import javax.swing.JOptionPane;
    1316
    1417import org.openstreetmap.josm.Main;
     
    5154        dialog.restoreSettings();
    5255        dialog.setVisible(true);
    53         if (!dialog.isCanceled()) {
    54             dialog.rememberSettings();
    55             final Bounds area = dialog.getSelectedDownloadArea();
    56             final boolean zoom = dialog.isZoomToDownloadedDataRequired();
    57             final List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>();
    58             if (dialog.isDownloadOsmData()) {
    59                 DownloadOsmTask task = new DownloadOsmTask();
    60                 task.setZoomAfterDownload(zoom && !dialog.isDownloadGpxData() && !dialog.isDownloadNotes());
    61                 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
    62                 Main.worker.submit(new PostDownloadHandler(task, future));
    63                 if (zoom) {
    64                     tasks.add(new Pair<>(task, future));
     56
     57        if (dialog.isCanceled()) {
     58            return;
     59        }
     60
     61        dialog.rememberSettings();
     62
     63        Optional<Bounds> selectedArea = dialog.getSelectedDownloadArea();
     64        if (!selectedArea.isPresent()) {
     65            JOptionPane.showMessageDialog(
     66                    dialog,
     67                    tr("Please select a download area first."),
     68                    tr("Error"),
     69                    JOptionPane.ERROR_MESSAGE
     70            );
     71            return;
     72        }
     73
     74        final Bounds area = selectedArea.get();
     75        final boolean zoom = dialog.isZoomToDownloadedDataRequired();
     76        final List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>();
     77
     78        if (dialog.isDownloadOsmData()) {
     79            DownloadOsmTask task = new DownloadOsmTask();
     80            task.setZoomAfterDownload(zoom && !dialog.isDownloadGpxData() && !dialog.isDownloadNotes());
     81            Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
     82            Main.worker.submit(new PostDownloadHandler(task, future));
     83            if (zoom) {
     84                tasks.add(new Pair<>(task, future));
     85            }
     86        }
     87
     88        if (dialog.isDownloadGpxData()) {
     89            DownloadGpsTask task = new DownloadGpsTask();
     90            task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadNotes());
     91            Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
     92            Main.worker.submit(new PostDownloadHandler(task, future));
     93            if (zoom) {
     94                tasks.add(new Pair<>(task, future));
     95            }
     96        }
     97
     98        if (dialog.isDownloadNotes()) {
     99            DownloadNotesTask task = new DownloadNotesTask();
     100            task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadGpxData());
     101            Future<?> future = task.download(false, area, null);
     102            Main.worker.submit(new PostDownloadHandler(task, future));
     103            if (zoom) {
     104                tasks.add(new Pair<>(task, future));
     105            }
     106        }
     107
     108        if (zoom && tasks.size() > 1) {
     109            Main.worker.submit(() -> {
     110                ProjectionBounds bounds = null;
     111                // Wait for completion of download jobs
     112                for (Pair<AbstractDownloadTask<?>, Future<?>> p : tasks) {
     113                    try {
     114                        p.b.get();
     115                        ProjectionBounds b = p.a.getDownloadProjectionBounds();
     116                        if (bounds == null) {
     117                            bounds = b;
     118                        } else if (b != null) {
     119                            bounds.extend(b);
     120                        }
     121                    } catch (InterruptedException | ExecutionException ex) {
     122                        Main.warn(ex);
     123                    }
    65124                }
    66             }
    67             if (dialog.isDownloadGpxData()) {
    68                 DownloadGpsTask task = new DownloadGpsTask();
    69                 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadNotes());
    70                 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null);
    71                 Main.worker.submit(new PostDownloadHandler(task, future));
    72                 if (zoom) {
    73                     tasks.add(new Pair<>(task, future));
     125                // Zoom to the larger download bounds
     126                if (Main.map != null && bounds != null) {
     127                    final ProjectionBounds pb = bounds;
     128                    GuiHelper.runInEDTAndWait(() -> Main.map.mapView.zoomTo(new ViewportData(pb)));
    74129                }
    75             }
    76             if (dialog.isDownloadNotes()) {
    77                 DownloadNotesTask task = new DownloadNotesTask();
    78                 task.setZoomAfterDownload(zoom && !dialog.isDownloadOsmData() && !dialog.isDownloadGpxData());
    79                 Future<?> future = task.download(false, area, null);
    80                 Main.worker.submit(new PostDownloadHandler(task, future));
    81                 if (zoom) {
    82                     tasks.add(new Pair<>(task, future));
    83                 }
    84             }
    85             if (zoom && tasks.size() > 1) {
    86                 Main.worker.submit(() -> {
    87                     ProjectionBounds bounds = null;
    88                     // Wait for completion of download jobs
    89                     for (Pair<AbstractDownloadTask<?>, Future<?>> p : tasks) {
    90                         try {
    91                             p.b.get();
    92                             ProjectionBounds b = p.a.getDownloadProjectionBounds();
    93                             if (bounds == null) {
    94                                 bounds = b;
    95                             } else if (b != null) {
    96                                 bounds.extend(b);
    97                             }
    98                         } catch (InterruptedException | ExecutionException ex) {
    99                             Main.warn(ex);
    100                         }
    101                     }
    102                     // Zoom to the larger download bounds
    103                     if (Main.map != null && bounds != null) {
    104                         final ProjectionBounds pb = bounds;
    105                         GuiHelper.runInEDTAndWait(() -> Main.map.mapView.zoomTo(new ViewportData(pb)));
    106                     }
    107                 });
    108             }
     130            });
    109131        }
    110132    }
Note: See TracChangeset for help on using the changeset viewer.