| 63 | | List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>(); |
| 64 | | |
| 65 | | if (data.isDownloadOSMData()) { |
| 66 | | DownloadOsmTask task = new DownloadOsmTask(); |
| 67 | | task.setZoomAfterDownload(zoom && !data.isDownloadGPX() && !data.isDownloadNotes()); |
| 68 | | Future<?> future = task.download(new DownloadParams().withNewLayer(newLayer), bbox, null); |
| 69 | | MainApplication.worker.submit(new PostDownloadHandler(task, future)); |
| 70 | | if (zoom) { |
| 71 | | tasks.add(new Pair<>(task, future)); |
| | 77 | final List<Pair<AbstractDownloadTask<?>, Future<?>>> tasks = new ArrayList<>(); |
| | 78 | IDownloadSourceType zoomTask = zoom ? data.stream().findFirst().orElse(null) : null; |
| | 79 | data.stream().filter(IDownloadSourceType::isEnabled).forEach(type -> { |
| | 80 | try { |
| | 81 | AbstractDownloadTask<?> task = type.getDownloadClass().getDeclaredConstructor().newInstance(); |
| | 82 | task.setZoomAfterDownload(type.equals(zoomTask)); |
| | 83 | Future<?> future = task.download(new DownloadParams().withNewLayer(newLayer), bbox, null); |
| | 84 | MainApplication.worker.submit(new PostDownloadHandler(task, future)); |
| | 85 | if (zoom) { |
| | 86 | tasks.add(new Pair<AbstractDownloadTask<?>, Future<?>>(task, future)); |
| | 87 | } |
| | 88 | } catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
| | 89 | | InvocationTargetException | NoSuchMethodException | SecurityException e) { |
| | 90 | Logging.error(e); |
| 75 | | if (data.isDownloadGPX()) { |
| 76 | | DownloadGpsTask task = new DownloadGpsTask(); |
| 77 | | task.setZoomAfterDownload(zoom && !data.isDownloadOSMData() && !data.isDownloadNotes()); |
| 78 | | Future<?> future = task.download(new DownloadParams().withNewLayer(newLayer), bbox, null); |
| 79 | | MainApplication.worker.submit(new PostDownloadHandler(task, future)); |
| 80 | | if (zoom) { |
| 81 | | tasks.add(new Pair<>(task, future)); |
| 82 | | } |
| 83 | | } |
| 84 | | |
| 85 | | if (data.isDownloadNotes()) { |
| 86 | | DownloadNotesTask task = new DownloadNotesTask(); |
| 87 | | task.setZoomAfterDownload(zoom && !data.isDownloadOSMData() && !data.isDownloadGPX()); |
| 88 | | Future<?> future = task.download(new DownloadParams(), bbox, null); |
| 89 | | MainApplication.worker.submit(new PostDownloadHandler(task, future)); |
| 90 | | if (zoom) { |
| 91 | | tasks.add(new Pair<>(task, future)); |
| 92 | | } |
| 93 | | } |
| 94 | | |
| | 132 | * @return The possible downloads that JOSM can make in the default Download |
| | 133 | * screen |
| | 134 | * @since xxx |
| | 135 | */ |
| | 136 | public List<IDownloadSourceType> getDownloadTypes() { |
| | 137 | return Collections.unmodifiableList(DOWNLOAD_SOURCES); |
| | 138 | } |
| | 139 | |
| | 140 | /** |
| | 141 | * Get the instance of a data download type |
| | 142 | * |
| | 143 | * @param <T> The type to get |
| | 144 | * @param typeClazz The class of the type |
| | 145 | * @return The type instance |
| | 146 | * @since xxx |
| | 147 | */ |
| | 148 | public <T extends IDownloadSourceType> T getDownloadType(Class<T> typeClazz) { |
| | 149 | return DOWNLOAD_SOURCES.stream().filter(typeClazz::isInstance).map(typeClazz::cast).findFirst().orElse(null); |
| | 150 | } |
| | 151 | |
| | 152 | /** |
| | 153 | * @param type The IDownloadSourceType object to remove |
| | 154 | * @return true See {@link List#remove}, but it also returns false if the |
| | 155 | * parameter is a class from JOSM core. |
| | 156 | * @since xxx |
| | 157 | */ |
| | 158 | public boolean removeDownloadType(IDownloadSourceType type) { |
| | 159 | boolean modified = false; |
| | 160 | if (!(type instanceof OsmDataDownloadType) && !(type instanceof GpsDataDownloadType) |
| | 161 | && !(type instanceof NotesDataDownloadType)) { |
| | 162 | modified = DOWNLOAD_SOURCES.remove(type); |
| | 163 | } |
| | 164 | return modified; |
| | 165 | } |
| | 166 | |
| | 167 | /** |
| | 168 | * Add a download type to the default JOSM download window |
| | 169 | * |
| | 170 | * @param type The initialized type to download |
| | 171 | * @return See {@link List#add}, but it also returns false if the class |
| | 172 | * already has an instance in the list or it is a class from JOSM core. |
| | 173 | * @since xxx |
| | 174 | */ |
| | 175 | public boolean addDownloadType(IDownloadSourceType type) { |
| | 176 | boolean modified = false; |
| | 177 | if (!(type instanceof OsmDataDownloadType) && !(type instanceof GpsDataDownloadType) |
| | 178 | && !(type instanceof NotesDataDownloadType) |
| | 179 | || DOWNLOAD_SOURCES.stream() |
| | 180 | .noneMatch(possibility -> type.getClass().isInstance(possibility))) { |
| | 181 | modified = DOWNLOAD_SOURCES.add(type); |
| | 182 | } else { |
| | 183 | throw new IllegalArgumentException("There can only be one instance of a class added, and it cannot be a built-in class."); |
| | 184 | } |
| | 185 | return modified; |
| | 186 | } |
| | 187 | |
| | 188 | /** |
| 169 | | cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true); |
| 170 | | cbDownloadOsmData.setToolTipText(tr("Select to download OSM data in the selected download area.")); |
| 171 | | cbDownloadOsmData.getModel().addChangeListener(checkboxChangeListener); |
| 172 | | |
| 173 | | cbDownloadGpxData = new JCheckBox(tr("Raw GPS data")); |
| 174 | | cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces in the selected download area.")); |
| 175 | | cbDownloadGpxData.getModel().addChangeListener(checkboxChangeListener); |
| 176 | | |
| 177 | | cbDownloadNotes = new JCheckBox(tr("Notes")); |
| 178 | | cbDownloadNotes.setToolTipText(tr("Select to download notes in the selected download area.")); |
| 179 | | cbDownloadNotes.getModel().addChangeListener(checkboxChangeListener); |
| 180 | | |
| 184 | | add(cbDownloadOsmData, GBC.std().insets(1, 5, 1, 5)); |
| 185 | | add(cbDownloadGpxData, GBC.std().insets(1, 5, 1, 5)); |
| 186 | | add(cbDownloadNotes, GBC.eol().insets(1, 5, 1, 5)); |
| | 220 | DOWNLOAD_SOURCES |
| | 221 | .forEach(obj -> add(obj.getCheckBox(checkboxChangeListener), GBC.std().insets(1, 5, 1, 5))); |
| 235 | | if (!isDownloadOsmData() && !isDownloadGpxData() && !isDownloadNotes()) { |
| | 263 | if (DOWNLOAD_SOURCES.stream().noneMatch(IDownloadSourceType::isEnabled)) { |
| | 264 | StringBuilder line1 = new StringBuilder("<html>").append(tr("None of")); |
| | 265 | StringBuilder line2 = new StringBuilder(tr("Please choose to either download")); |
| | 266 | |
| | 267 | DOWNLOAD_SOURCES.forEach(type -> { |
| | 268 | line1.append(" <strong>").append(type.getCheckBox().getText()).append("</strong> "); |
| | 269 | line2.append(' ').append(type.getCheckBox().getText()).append(tr(", or")); |
| | 270 | }); |
| | 271 | line1.append(tr("is enabled.")).append("<br>"); |
| | 272 | line2.append(tr(" all.")).append("</html>"); |
| 238 | | tr("<html>Neither <strong>{0}</strong> nor <strong>{1}</strong> nor <strong>{2}</strong> is enabled.<br>" |
| 239 | | + "Please choose to either download OSM data, or GPX data, or Notes, or all.</html>", |
| 240 | | cbDownloadOsmData.getText(), |
| 241 | | cbDownloadGpxData.getText(), |
| 242 | | cbDownloadNotes.getText() |
| 243 | | ), |
| | 275 | line1.append(line2).toString(), |
| 305 | | boolean isAreaTooLarge = false; |
| 306 | | if (!isDownloadNotes() && !isDownloadOsmData() && !isDownloadGpxData()) { |
| 307 | | isAreaTooLarge = false; |
| 308 | | } else if (isDownloadNotes() && !isDownloadOsmData() && !isDownloadGpxData()) { |
| 309 | | // see max_note_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/settings.yml |
| 310 | | isAreaTooLarge = bbox.getArea() > Config.getPref().getDouble("osm-server.max-request-area-notes", 25); |
| 311 | | } else { |
| 312 | | // see max_request_area in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/settings.yml |
| 313 | | isAreaTooLarge = bbox.getArea() > Config.getPref().getDouble("osm-server.max-request-area", 0.25); |
| 314 | | } |
| 315 | | |
| 316 | | displaySizeCheckResult(isAreaTooLarge); |
| | 346 | displaySizeCheckResult(DOWNLOAD_SOURCES.stream() |
| | 347 | .anyMatch(type -> type.isDownloadAreaTooLarge(bbox))); |
| 339 | | OSMDownloadData(boolean downloadOSMData, boolean downloadNotes, boolean downloadGPX) { |
| 340 | | this.downloadOSMData = downloadOSMData; |
| 341 | | this.downloadNotes = downloadNotes; |
| 342 | | this.downloadGPX = downloadGPX; |
| | 367 | private List<IDownloadSourceType> downloadPossibilities; |
| | 368 | |
| | 369 | /** |
| | 370 | * @param downloadPossibilities A list of DataDownloadTypes (instantiated, with |
| | 371 | * options set) |
| | 372 | */ |
| | 373 | OSMDownloadData(List<IDownloadSourceType> downloadPossibilities) { |
| | 374 | this.downloadPossibilities = downloadPossibilities; |
| 349 | | boolean isDownloadNotes() { |
| 350 | | return downloadNotes; |
| | 385 | private static class OsmDataDownloadType implements IDownloadSourceType { |
| | 386 | static final BooleanProperty IS_ENABLED = new BooleanProperty("download.osm.data", true); |
| | 387 | JCheckBox cbDownloadOsmData; |
| | 388 | |
| | 389 | @Override |
| | 390 | public JCheckBox getCheckBox(ChangeListener checkboxChangeListener) { |
| | 391 | if (cbDownloadOsmData == null) { |
| | 392 | cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true); |
| | 393 | cbDownloadOsmData.setToolTipText(tr("Select to download OSM data in the selected download area.")); |
| | 394 | cbDownloadOsmData.getModel().addChangeListener(checkboxChangeListener); |
| | 395 | } |
| | 396 | if (checkboxChangeListener != null) { |
| | 397 | cbDownloadOsmData.getModel().addChangeListener(checkboxChangeListener); |
| | 398 | } |
| | 399 | return cbDownloadOsmData; |
| | 419 | |
| | 420 | private static class GpsDataDownloadType implements IDownloadSourceType { |
| | 421 | static final BooleanProperty IS_ENABLED = new BooleanProperty("download.osm.gps", false); |
| | 422 | private JCheckBox cbDownloadGpxData; |
| | 423 | |
| | 424 | @Override |
| | 425 | public JCheckBox getCheckBox(ChangeListener checkboxChangeListener) { |
| | 426 | if (cbDownloadGpxData == null) { |
| | 427 | cbDownloadGpxData = new JCheckBox(tr("Raw GPS data")); |
| | 428 | cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces in the selected download area.")); |
| | 429 | } |
| | 430 | if (checkboxChangeListener != null) { |
| | 431 | cbDownloadGpxData.getModel().addChangeListener(checkboxChangeListener); |
| | 432 | } |
| | 433 | |
| | 434 | return cbDownloadGpxData; |
| | 435 | } |
| | 436 | |
| | 437 | @Override |
| | 438 | public Class<? extends AbstractDownloadTask<GpxData>> getDownloadClass() { |
| | 439 | return DownloadGpsTask.class; |
| | 440 | } |
| | 441 | |
| | 442 | @Override |
| | 443 | public BooleanProperty getBooleanProperty() { |
| | 444 | return IS_ENABLED; |
| | 445 | } |
| | 446 | |
| | 447 | @Override |
| | 448 | public boolean isDownloadAreaTooLarge(Bounds bound) { |
| | 449 | return false; |
| | 450 | } |
| | 451 | } |
| | 452 | |
| | 453 | private static class NotesDataDownloadType implements IDownloadSourceType { |
| | 454 | static final BooleanProperty IS_ENABLED = new BooleanProperty("download.osm.notes", false); |
| | 455 | private JCheckBox cbDownloadNotes; |
| | 456 | |
| | 457 | @Override |
| | 458 | public JCheckBox getCheckBox(ChangeListener checkboxChangeListener) { |
| | 459 | if (cbDownloadNotes == null) { |
| | 460 | cbDownloadNotes = new JCheckBox(tr("Notes")); |
| | 461 | cbDownloadNotes.setToolTipText(tr("Select to download notes in the selected download area.")); |
| | 462 | } |
| | 463 | if (checkboxChangeListener != null) { |
| | 464 | cbDownloadNotes.getModel().addChangeListener(checkboxChangeListener); |
| | 465 | } |
| | 466 | |
| | 467 | return cbDownloadNotes; |
| | 468 | } |
| | 469 | |
| | 470 | @Override |
| | 471 | public Class<? extends AbstractDownloadTask<NoteData>> getDownloadClass() { |
| | 472 | return DownloadNotesTask.class; |
| | 473 | } |
| | 474 | |
| | 475 | @Override |
| | 476 | public BooleanProperty getBooleanProperty() { |
| | 477 | return IS_ENABLED; |
| | 478 | } |
| | 479 | |
| | 480 | @Override |
| | 481 | public boolean isDownloadAreaTooLarge(Bounds bound) { |
| | 482 | // see max_note_request_area in |
| | 483 | // https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml |
| | 484 | return bound.getArea() > Config.getPref().getDouble("osm-server.max-request-area-notes", 25); |
| | 485 | } |
| | 486 | } |