Changeset 6054 in josm
- Timestamp:
- 2013-07-06T21:15:51+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r5977 r6054 1633 1633 public void removeObsolete() { 1634 1634 String[] obsolete = { 1635 "color.Imagery fade", // 08/2012 - wrong property caused by #6723, can be removed mid-2013 1635 "downloadAlong.downloadAlongTrack.distance", // 07/2013 - can be removed mid-2014. Replaced by downloadAlongWay.distance 1636 "downloadAlong.downloadAlongTrack.area", // 07/2013 - can be removed mid-2014. Replaced by downloadAlongWay.area 1637 "gpxLayer.downloadAlongTrack.distance", // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.distance 1638 "gpxLayer.downloadAlongTrack.area", // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.area 1639 "gpxLayer.downloadAlongTrack.near", // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.near 1636 1640 }; 1637 1641 for (String key : obsolete) { -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java
r6053 r6054 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagLayout;7 6 import java.awt.event.ActionEvent; 8 7 import java.awt.geom.Area; 9 8 import java.awt.geom.Rectangle2D; 10 import java.util.ArrayList;11 import java.util.Collection;12 import java.util.List;13 import java.util.concurrent.Future;14 15 import javax.swing.AbstractAction;16 import javax.swing.JLabel;17 import javax.swing.JList;18 import javax.swing.JOptionPane;19 import javax.swing.JPanel;20 9 21 10 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions. downloadtasks.DownloadTaskList;11 import org.openstreetmap.josm.actions.DownloadAlongAction; 23 12 import org.openstreetmap.josm.data.coor.LatLon; 24 13 import org.openstreetmap.josm.data.gpx.GpxData; … … 27 16 import org.openstreetmap.josm.data.gpx.WayPoint; 28 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 18 import org.openstreetmap.josm.gui.help.HelpUtil; 29 19 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 30 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;31 import org.openstreetmap.josm.gui.progress.ProgressMonitor;32 import org.openstreetmap.josm.tools.GBC;33 import org.openstreetmap.josm.tools.ImageProvider;34 20 35 21 /** … … 38 24 * @author fred 39 25 */ 40 public class DownloadAlongTrackAction extends AbstractAction { 26 public class DownloadAlongTrackAction extends DownloadAlongAction { 27 41 28 static final int NEAR_TRACK = 0; 42 29 static final int NEAR_WAYPOINTS = 1; 43 30 static final int NEAR_BOTH = 2; 44 45 private static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "gpxLayer.downloadAlongTrack.distance";46 private static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "gpxLayer.downloadAlongTrack.area";47 private static final String PREF_DOWNLOAD_ALONG_TRACK_NEAR = "gpxLayer.downloadAlongTrack.near";48 31 49 50 private final Integer[] dist = {5000, 500, 50}; 51 private final Integer[] area = {20, 10, 5, 1}; 32 private static final String PREF_DOWNLOAD_ALONG_TRACK_OSM = "downloadAlongTrack.download.osm"; 33 private static final String PREF_DOWNLOAD_ALONG_TRACK_GPS = "downloadAlongTrack.download.gps"; 34 35 private static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlongTrack.distance"; 36 private static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlongTrack.area"; 37 private static final String PREF_DOWNLOAD_ALONG_TRACK_NEAR = "downloadAlongTrack.near"; 52 38 53 39 private final GpxData data; 54 40 41 /** 42 * Constructs a new {@code DownloadAlongTrackAction} 43 * @param data The GPX data used to download along 44 */ 55 45 public DownloadAlongTrackAction(GpxData data) { 56 super(tr("Download from OSM along this track"), ImageProvider.get("downloadalongtrack"));46 super(tr("Download from OSM along this track"), "downloadalongtrack", null, null, true); 57 47 this.data = data; 58 48 } … … 60 50 @Override 61 51 public void actionPerformed(ActionEvent e) { 62 /* 63 * build selection dialog 64 */ 65 JPanel msg = new JPanel(new GridBagLayout()); 66 msg.add(new JLabel(tr("Download everything within:")), GBC.eol()); 67 String[] s = new String[dist.length]; 68 for (int i = 0; i < dist.length; ++i) { 69 s[i] = tr("{0} meters", dist[i]); 52 53 final DownloadAlongPanel panel = new DownloadAlongPanel( 54 PREF_DOWNLOAD_ALONG_TRACK_OSM, PREF_DOWNLOAD_ALONG_TRACK_GPS, 55 PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, PREF_DOWNLOAD_ALONG_TRACK_AREA, PREF_DOWNLOAD_ALONG_TRACK_NEAR); 56 57 if (0 != panel.showInDownloadDialog(tr("Download from OSM along this track"), HelpUtil.ht("/Action/DownloadAlongTrack"))) { 58 return; 70 59 } 71 JList buffer = new JList(s); 72 buffer.setSelectedIndex(Main.pref.getInteger(PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, 0)); 73 msg.add(buffer, GBC.eol()); 74 msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol()); 75 s = new String[area.length]; 76 for (int i = 0; i < area.length; ++i) { 77 s[i] = tr("{0} sq km", area[i]); 78 } 79 JList maxRect = new JList(s); 80 maxRect.setSelectedIndex(Main.pref.getInteger(PREF_DOWNLOAD_ALONG_TRACK_AREA, 0)); 81 msg.add(maxRect, GBC.eol()); 82 msg.add(new JLabel(tr("Download near:")), GBC.eol()); 83 JList downloadNear = new JList(new String[]{tr("track only"), tr("waypoints only"), tr("track and waypoints")}); 84 downloadNear.setSelectedIndex(Main.pref.getInteger(PREF_DOWNLOAD_ALONG_TRACK_NEAR, 0)); 85 msg.add(downloadNear, GBC.eol()); 86 int ret = JOptionPane.showConfirmDialog(Main.parent, msg, tr("Download from OSM along this track"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 87 switch (ret) { 88 case JOptionPane.CANCEL_OPTION: 89 case JOptionPane.CLOSED_OPTION: 90 return; 91 default: 92 // continue 93 } 94 Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, buffer.getSelectedIndex()); 95 Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_AREA, maxRect.getSelectedIndex()); 96 final int near = downloadNear.getSelectedIndex(); 97 Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_NEAR, near); 60 61 final int near = panel.getNear(); 62 98 63 /* 99 64 * Find the average latitude for the data we're contemplating, so we can know how many … … 126 91 * and then stop because it has more than 50k nodes. 127 92 */ 128 Integer i = buffer.getSelectedIndex(); 129 final int buffer_dist = dist[i < 0 ? 0 : i]; 130 i = maxRect.getSelectedIndex(); 131 final double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale; 93 final double buffer_dist = panel.getDistance(); 94 final double max_area = panel.getArea() / 10000.0 / scale; 132 95 final double buffer_y = buffer_dist / 100000.0; 133 96 final double buffer_x = buffer_y / scale; … … 161 124 return; 162 125 } 163 confirmAndDownloadAreas(a, max_area, progressMonitor); 126 confirmAndDownloadAreas(a, max_area, panel.isDownloadOsmData(), panel.isDownloadGpxData(), 127 tr("Download from OSM along this track"), progressMonitor); 164 128 } 165 129 … … 223 187 Main.worker.submit(new CalculateDownloadArea()); 224 188 } 225 226 /**227 * Area "a" contains the hull that we would like to download data for. however we228 * can only download rectangles, so the following is an attempt at finding a number of229 * rectangles to download.230 *231 * The idea is simply: Start out with the full bounding box. If it is too large, then232 * split it in half and repeat recursively for each half until you arrive at something233 * small enough to download. The algorithm is improved by always using the intersection234 * between the rectangle and the actual desired area. For example, if you have a track235 * that goes like this: +----+ | /| | / | | / | |/ | +----+ then we would first look at236 * downloading the whole rectangle (assume it's too big), after that we split it in half237 * (upper and lower half), but we donot request the full upper and lower rectangle, only238 * the part of the upper/lower rectangle that actually has something in it.239 *240 * This functions calculates the rectangles, asks the user to continue and downloads241 * the areas if applicable.242 */243 private void confirmAndDownloadAreas(Area a, double max_area, ProgressMonitor progressMonitor) {244 List<Rectangle2D> toDownload = new ArrayList<Rectangle2D>();245 addToDownload(a, a.getBounds(), toDownload, max_area);246 if (toDownload.isEmpty()) {247 return;248 }249 JPanel msg = new JPanel(new GridBagLayout());250 msg.add(new JLabel(tr("<html>This action will require {0} individual<br>" + "download requests. Do you wish<br>to continue?</html>", toDownload.size())), GBC.eol());251 if (toDownload.size() > 1) {252 int ret = JOptionPane.showConfirmDialog(Main.parent, msg, tr("Download from OSM along this track"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);253 switch (ret) {254 case JOptionPane.CANCEL_OPTION:255 case JOptionPane.CLOSED_OPTION:256 return;257 default:258 // continue259 }260 }261 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));262 final Future<?> future = new DownloadTaskList().download(false, toDownload, true, false, monitor);263 Main.worker.submit(new Runnable() {264 @Override265 public void run() {266 try {267 future.get();268 } catch (Exception e) {269 e.printStackTrace();270 return;271 }272 monitor.close();273 }274 });275 }276 277 private static void addToDownload(Area a, Rectangle2D r, Collection<Rectangle2D> results, double max_area) {278 Area tmp = new Area(r);279 // intersect with sought-after area280 tmp.intersect(a);281 if (tmp.isEmpty()) {282 return;283 }284 Rectangle2D bounds = tmp.getBounds2D();285 if (bounds.getWidth() * bounds.getHeight() > max_area) {286 // the rectangle gets too large; split it and make recursive call.287 Rectangle2D r1;288 Rectangle2D r2;289 if (bounds.getWidth() > bounds.getHeight()) {290 // rectangles that are wider than high are split into a left and right half,291 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth() / 2, bounds.getHeight());292 r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2, bounds.getY(),293 bounds.getWidth() / 2, bounds.getHeight());294 } else {295 // others into a top and bottom half.296 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() / 2);297 r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY() + bounds.getHeight() / 2, bounds.getWidth(),298 bounds.getHeight() / 2);299 }300 addToDownload(a, r1, results, max_area);301 addToDownload(a, r2, results, max_area);302 } else {303 results.add(bounds);304 }305 }306 307 189 }
Note:
See TracChangeset
for help on using the changeset viewer.