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

Last change on this file since 2254 was 2254, checked in by stoecker, 15 years ago

i18n update

File size: 2.7 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 org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
13import org.openstreetmap.josm.data.osm.DataSource;
14import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
15import org.openstreetmap.josm.tools.Shortcut;
16
17public class UpdateDataAction extends JosmAction{
18 public UpdateDataAction() {
19 super(tr("Update data"),
20 "updatedata",
21 tr("Updates the objects in the current data layer from the server."),
22 Shortcut.registerShortcut("file:updatedata",
23 tr("Update data"),
24 KeyEvent.VK_U,
25 Shortcut.GROUP_HOTKEY),
26 true);
27 }
28
29 /**
30 * Refreshes the enabled state
31 *
32 */
33 @Override
34 protected void updateEnabledState() {
35 setEnabled(getEditLayer() != null);
36 }
37
38 public void actionPerformed(ActionEvent e) {
39 if (! isEnabled())
40 return;
41 if (getEditLayer() == null)
42 return;
43
44 int bboxCount = 0;
45 List<Area> areas = new ArrayList<Area>();
46 for(DataSource ds : getEditLayer().data.dataSources) {
47 areas.add(new Area(ds.bounds.asRect()));
48 }
49
50 // The next two blocks removes every intersection from every DataSource Area
51 // This prevents downloading the same data numerous times at intersections
52 // and also skips smaller bounding boxes that are contained within larger ones
53 // entirely.
54 for(int i = 0; i < areas.size(); i++) {
55 for(int j = i+1; j < areas.size(); j++) {
56 areas.get(i).subtract(areas.get(j));
57 }
58 }
59
60 for(int i = areas.size()-1; i > 0 ; i--) {
61 for(int j = i-1; j > 0; j--) {
62 areas.get(i).subtract(areas.get(j));
63 }
64 }
65
66 for(Area a : areas) {
67 if(a.isEmpty()) {
68 continue;
69 }
70 bboxCount++;
71 }
72
73 if(bboxCount == 0) {
74 // no bounds defined in the dataset? we update all primitives in the data set
75 // using a series of multi fetch requests
76 //
77 new UpdateSelectionAction().updatePrimitives(getEditLayer().data.allPrimitives());
78 } else {
79 // bounds defined? => use the bbox downloader
80 //
81 new DownloadOsmTaskList().download(false, areas, new PleaseWaitProgressMonitor(tr("Updating data")));
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.