source: josm/trunk/src/org/openstreetmap/josm/actions/DownloadAction.java@ 12574

Last change on this file since 12574 was 12574, checked in by michael2402, 7 years ago

Apply #15057: Improve the over pass turbo dialog

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

  • Property svn:eol-style set to native
File size: 5.1 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[612]2package org.openstreetmap.josm.actions;
3
[2327]4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
[612]5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
[11774]9import java.util.ArrayList;
10import java.util.List;
[12574]11import java.util.Optional;
[11774]12import java.util.concurrent.ExecutionException;
[2322]13import java.util.concurrent.Future;
[612]14
[12574]15import javax.swing.JOptionPane;
16
[612]17import org.openstreetmap.josm.Main;
[11774]18import org.openstreetmap.josm.actions.downloadtasks.AbstractDownloadTask;
[2327]19import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
[7531]20import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
[2327]21import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
[2322]22import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
[2330]23import org.openstreetmap.josm.data.Bounds;
[11774]24import org.openstreetmap.josm.data.ProjectionBounds;
25import org.openstreetmap.josm.data.ViewportData;
[612]26import org.openstreetmap.josm.gui.download.DownloadDialog;
[11774]27import org.openstreetmap.josm.gui.util.GuiHelper;
28import org.openstreetmap.josm.tools.Pair;
[1084]29import org.openstreetmap.josm.tools.Shortcut;
[612]30
31/**
[655]32 * Action that opens a connection to the osm server and downloads map data.
[612]33 *
34 * An dialog is displayed asking the user to specify a rectangle to grab.
35 * The url and account settings from the preferences are used.
36 *
37 * @author imi
38 */
39public class DownloadAction extends JosmAction {
[7509]40
[6509]41 /**
42 * Constructs a new {@code DownloadAction}.
43 */
[1169]44 public DownloadAction() {
[1212]45 super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
[11621]46 Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download from OSM...")), KeyEvent.VK_DOWN, Shortcut.CTRL_SHIFT),
47 true);
[2323]48 putValue("help", ht("/Action/Download"));
[1169]49 }
[612]50
[6084]51 @Override
[2132]52 public void actionPerformed(ActionEvent e) {
[2331]53 DownloadDialog dialog = DownloadDialog.getInstance();
[2335]54 dialog.restoreSettings();
[2331]55 dialog.setVisible(true);
[12574]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));
[1847]85 }
[12574]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));
[1847]95 }
[12574]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));
[7531]105 }
[12574]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);
[11774]120 }
[12574]121 } catch (InterruptedException | ExecutionException ex) {
122 Main.warn(ex);
[11774]123 }
[12574]124 }
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)));
129 }
130 });
[2512]131 }
132 }
[612]133}
Note: See TracBrowser for help on using the repository browser.