1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.awt.geom.Area;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import javax.swing.JOptionPane;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
|
---|
16 | import org.openstreetmap.josm.data.osm.DataSource;
|
---|
17 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
18 |
|
---|
19 | public class UpdateDataAction extends JosmAction {
|
---|
20 | public UpdateDataAction() {
|
---|
21 | super(tr("Update Data"),
|
---|
22 | "updatedata",
|
---|
23 | tr("Updates the current data layer from the server (re-downloads data)"),
|
---|
24 | Shortcut.registerShortcut("file:updatedata",
|
---|
25 | tr("Update Data"),
|
---|
26 | KeyEvent.VK_U,
|
---|
27 | Shortcut.GROUP_HOTKEY),
|
---|
28 | true);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void actionPerformed(ActionEvent e) {
|
---|
32 | int bboxCount = 0;
|
---|
33 | List<Area> areas = new ArrayList<Area>();
|
---|
34 | for(DataSource ds : Main.main.createOrGetEditLayer().data.dataSources) {
|
---|
35 | areas.add(new Area(ds.bounds.asRect()));
|
---|
36 | }
|
---|
37 |
|
---|
38 | // The next two blocks removes every intersection from every DataSource Area
|
---|
39 | // This prevents downloading the same data numerous times at intersections
|
---|
40 | // and also skips smaller bounding boxes that are contained within larger ones
|
---|
41 | // entirely.
|
---|
42 | for(int i = 0; i < areas.size(); i++) {
|
---|
43 | for(int j = i+1; j < areas.size(); j++) {
|
---|
44 | areas.get(i).subtract(areas.get(j));
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | for(int i = areas.size()-1; i > 0 ; i--) {
|
---|
49 | for(int j = i-1; j > 0; j--) {
|
---|
50 | areas.get(i).subtract(areas.get(j));
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | for(Area a : areas) {
|
---|
55 | if(a.isEmpty()) {
|
---|
56 | continue;
|
---|
57 | }
|
---|
58 | bboxCount++;
|
---|
59 | }
|
---|
60 |
|
---|
61 | if(bboxCount == 0) {
|
---|
62 | JOptionPane.showMessageDialog(Main.parent,
|
---|
63 | tr("No data to update found. Have you already opened or downloaded a data layer?"));
|
---|
64 | return;
|
---|
65 | }
|
---|
66 |
|
---|
67 | new DownloadOsmTaskList().download(false, areas);
|
---|
68 | }
|
---|
69 | }
|
---|