1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.osm.PrimitiveId;
|
---|
13 | import org.openstreetmap.josm.gui.download.DownloadObjectDialog;
|
---|
14 | import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
|
---|
15 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Download an OsmPrimitive by specifying type and ID
|
---|
20 | *
|
---|
21 | * @author Matthias Julius
|
---|
22 | */
|
---|
23 | public class DownloadPrimitiveAction extends JosmAction {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code DownloadPrimitiveAction}.
|
---|
27 | */
|
---|
28 | public DownloadPrimitiveAction() {
|
---|
29 | super(tr("Download object..."), "downloadprimitive", tr("Download OSM object by ID."),
|
---|
30 | Shortcut.registerShortcut("system:download_primitive", tr("File: {0}", tr("Download object...")), KeyEvent.VK_O, Shortcut.CTRL_SHIFT), true);
|
---|
31 | putValue("help", ht("/Action/DownloadObject"));
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public void actionPerformed(ActionEvent e) {
|
---|
36 |
|
---|
37 | DownloadObjectDialog dialog = new DownloadObjectDialog();
|
---|
38 | if (dialog.showDialog().getValue() != dialog.getContinueButtonIndex()) return;
|
---|
39 |
|
---|
40 | processItems(dialog.isNewLayerRequested(), dialog.getOsmIds(), dialog.isReferrersRequested(), dialog.isFullRelationRequested());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @param newLayer if the data should be downloaded into a new layer
|
---|
45 | * @param ids List of primitive id to download
|
---|
46 | * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways
|
---|
47 | * @param full if the members of a relation should be downloaded as well
|
---|
48 | */
|
---|
49 | public static void processItems(boolean newLayer, final List<PrimitiveId> ids, boolean downloadReferrers, boolean full) {
|
---|
50 | final DownloadPrimitivesWithReferrersTask task =
|
---|
51 | new DownloadPrimitivesWithReferrersTask(newLayer, ids, downloadReferrers, full, null);
|
---|
52 | Main.worker.submit(task);
|
---|
53 | Main.worker.submit(new Runnable() {
|
---|
54 | @Override
|
---|
55 | public void run() {
|
---|
56 | final List<PrimitiveId> downloaded = task.getDownloadedId();
|
---|
57 | if(downloaded != null) {
|
---|
58 | GuiHelper.runInEDT(new Runnable() {
|
---|
59 | @Override
|
---|
60 | public void run() {
|
---|
61 | Main.main.getCurrentDataSet().setSelected(downloaded);
|
---|
62 | }
|
---|
63 | });
|
---|
64 | }
|
---|
65 | }
|
---|
66 | });
|
---|
67 | }
|
---|
68 | }
|
---|