source: josm/src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java@ 175

Last change on this file since 175 was 175, checked in by imi, 17 years ago
  • fixed bug where cancelling download made other download attempts impossible
  • fixed bug under Linux when download finished while in different virtual desktop
  • fixed concurrent exception sometime arise when downloading incomplete data
File size: 2.6 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.InputEvent;
8import java.awt.event.KeyEvent;
9import java.io.IOException;
10import java.util.Collection;
11import java.util.HashSet;
12
13import javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
19import org.openstreetmap.josm.gui.PleaseWaitRunnable;
20import org.openstreetmap.josm.io.IncompleteDownloader;
21import org.xml.sax.SAXException;
22
23/**
24 * Action that opens a connection to the osm server and download map data.
25 *
26 * An dialog is displayed asking the user to specify a rectangle to grab.
27 * The url and account settings from the preferences are used.
28 *
29 * @author imi
30 */
31public class DownloadIncompleteAction extends JosmAction {
32
33 /**
34 * Open the download dialog and download the data.
35 * Run in the worker thread.
36 */
37 private final class DownloadTask extends PleaseWaitRunnable {
38 private IncompleteDownloader reader;
39
40 private DownloadTask(Collection<Way> toDownload) {
41 super(trn("Downloading {0} segment", "Downloading {0} segments", toDownload.size(), toDownload.size()));
42 reader = new IncompleteDownloader(toDownload);
43 }
44
45 @Override public void realRun() throws IOException, SAXException {
46 reader.parse();
47 }
48
49 @Override protected void finish() {
50 MergeVisitor merger = new MergeVisitor(Main.ds);
51 for (OsmPrimitive osm : reader.data.allPrimitives())
52 osm.visit(merger);
53 Main.parent.repaint();
54 }
55
56 @Override protected void cancel() {
57 reader.cancel();
58 }
59 }
60
61 public DownloadIncompleteAction() {
62 super(tr("Download incomplete objects"), "downloadincomplete", tr("Download all (selected) incomplete ways from the OSM server."), KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
63 }
64
65 public void actionPerformed(ActionEvent e) {
66 Collection<Way> ways = new HashSet<Way>();
67 for (Way w : Main.ds.ways)
68 if (w.isIncomplete() && w.selected)
69 ways.add(w);
70 if (ways.isEmpty()) {
71 JOptionPane.showMessageDialog(Main.parent, tr("Please select an incomplete way."));
72 return;
73 }
74 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.parent, tr("Download {0} incomplete ways?", ways.size()), tr("Download?"), JOptionPane.YES_NO_OPTION))
75 return;
76 PleaseWaitRunnable task = new DownloadTask(ways);
77 Main.worker.execute(task);
78 }
79}
Note: See TracBrowser for help on using the repository browser.