source: josm/trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java@ 1670

Last change on this file since 1670 was 1670, checked in by Gubaer, 15 years ago

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.awt.geom.Area;
9import java.util.ArrayList;
10import java.util.List;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
16import org.openstreetmap.josm.data.osm.DataSource;
17import org.openstreetmap.josm.tools.Shortcut;
18
19public 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.editLayer().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}
Note: See TracBrowser for help on using the repository browser.