Changeset 22295 in osm for applications/editors/josm/plugins/download_along
- Timestamp:
- 2010-07-13T02:34:51+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlong.java
r22293 r22295 12 12 13 13 import javax.swing.JLabel; 14 import javax.swing.JList; 14 15 import javax.swing.JMenuItem; 15 16 import javax.swing.JOptionPane; … … 33 34 34 35 public class DownloadAlong extends Plugin { 36 private static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlong.downloadAlongTrack.distance"; 37 private static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlong.downloadAlongTrack.area"; 38 35 39 JMenuItem DownloadAlong; 36 40 … … 47 51 */ 48 52 private static final long serialVersionUID = 1L; 53 49 54 public DownloadAlongAction() { 50 55 super(tr("Download along..."), "download_along", … … 71 76 } 72 77 78 JPanel msg = new JPanel(new GridBagLayout()); 79 Integer dist[] = { 5000, 500, 50 }; 80 Integer area[] = { 20, 10, 5, 1 }; 81 82 msg.add(new JLabel(tr("Download everything within:")), GBC.eol()); 83 String s[] = new String[dist.length]; 84 for (int i = 0; i < dist.length; ++i) { 85 s[i] = tr("{0} meters", dist[i]); 86 } 87 JList buffer = new JList(s); 88 buffer.setSelectedIndex(Main.pref.getInteger( 89 PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, 0)); 90 msg.add(buffer, GBC.eol()); 91 92 msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol()); 93 s = new String[area.length]; 94 for (int i = 0; i < area.length; ++i) { 95 s[i] = tr("{0} sq km", area[i]); 96 } 97 JList maxRect = new JList(s); 98 maxRect.setSelectedIndex(Main.pref.getInteger( 99 PREF_DOWNLOAD_ALONG_TRACK_AREA, 0)); 100 msg.add(maxRect, GBC.eol()); 101 102 int ret = JOptionPane.showConfirmDialog(Main.parent, msg, 103 tr("Download from OSM along this track"), 104 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 105 switch (ret) { 106 case JOptionPane.CANCEL_OPTION: 107 case JOptionPane.CLOSED_OPTION: 108 return; 109 default: 110 // continue 111 } 112 113 Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, buffer 114 .getSelectedIndex()); 115 Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_AREA, maxRect 116 .getSelectedIndex()); 117 73 118 /* 74 119 * Find the average latitude for the data we're contemplating, so we can … … 96 141 * because it has more than 50k nodes. 97 142 */ 98 // Integer i = buffer.getSelectedIndex(); 99 // int buffer_dist = dist[i < 0 ? 0 : i]; 100 int buffer_dist = 5000; 143 Integer i = buffer.getSelectedIndex(); 144 int buffer_dist = dist[i < 0 ? 0 : i]; 101 145 double buffer_y = buffer_dist / 100000.0; 102 146 double buffer_x = buffer_y / scale; 103 // i = maxRect.getSelectedIndex(); 104 // double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale; 105 double max_area = 20 / 10000.0 / scale; 147 i = maxRect.getSelectedIndex(); 148 double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale; 106 149 Area a = new Area(); 107 150 Rectangle2D r = new Rectangle2D.Double(); … … 148 191 addToDownload(a, a.getBounds(), toDownload, max_area); 149 192 150 JPanelmsg = new JPanel(new GridBagLayout());193 msg = new JPanel(new GridBagLayout()); 151 194 152 195 msg.add(new JLabel(tr("<html>This action will require {0} individual<br>" … … 155 198 156 199 if (toDownload.size() > 1) { 157 intret = JOptionPane.showConfirmDialog(Main.parent, msg,200 ret = JOptionPane.showConfirmDialog(Main.parent, msg, 158 201 tr("Download from OSM along this track"), 159 202 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); … … 183 226 } 184 227 185 private static void addToDownload(Area a, Rectangle2D r, Collection<Rectangle2D> results, double max_area) { 228 private static void addToDownload(Area a, Rectangle2D r, 229 Collection<Rectangle2D> results, double max_area) { 186 230 Area tmp = new Area(r); 187 231 // intersect with sought-after area 188 232 tmp.intersect(a); 189 233 if (tmp.isEmpty()) 190 234 return; 191 235 Rectangle2D bounds = tmp.getBounds2D(); 192 236 if (bounds.getWidth() * bounds.getHeight() > max_area) { 193 // the rectangle gets too large; split it and make recursive call. 194 Rectangle2D r1; 195 Rectangle2D r2; 196 if (bounds.getWidth() > bounds.getHeight()) { 197 // rectangles that are wider than high are split into a left and right half, 198 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth() / 2, bounds.getHeight()); 199 r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2, bounds.getY(), 200 bounds.getWidth() / 2, bounds.getHeight()); 201 } else { 202 // others into a top and bottom half. 203 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() / 2); 204 r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY() + bounds.getHeight() / 2, bounds.getWidth(), 205 bounds.getHeight() / 2); 206 } 207 addToDownload(a, r1, results, max_area); 208 addToDownload(a, r2, results, max_area); 237 // the rectangle gets too large; split it and make recursive call. 238 Rectangle2D r1; 239 Rectangle2D r2; 240 if (bounds.getWidth() > bounds.getHeight()) { 241 // rectangles that are wider than high are split into a left and right 242 // half, 243 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds 244 .getWidth() / 2, bounds.getHeight()); 245 r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2, 246 bounds.getY(), bounds.getWidth() / 2, bounds.getHeight()); 247 } else { 248 // others into a top and bottom half. 249 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds 250 .getWidth(), bounds.getHeight() / 2); 251 r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY() 252 + bounds.getHeight() / 2, bounds.getWidth(), 253 bounds.getHeight() / 2); 254 } 255 addToDownload(a, r1, results, max_area); 256 addToDownload(a, r2, results, max_area); 209 257 } else { 210 results.add(bounds); 211 } 212 } 213 214 258 results.add(bounds); 259 } 260 } 261 215 262 @Override 216 263 protected void updateEnabledState(
Note:
See TracChangeset
for help on using the changeset viewer.