Changeset 12655 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-08-26T00:23:18+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/download
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/download/AbstractDownloadSourcePanel.java
r12654 r12655 13 13 * {@link DownloadDialog}. 14 14 * @param <T> The type of the data that a download source uses. 15 * @since 12652 15 16 */ 16 17 public abstract class AbstractDownloadSourcePanel<T> extends JPanel { 17 18 19 /** 20 * Called when creating a new {@link AbstractDownloadSourcePanel} for the given download source 21 * @param downloadSource The download source this panel is for 22 */ 18 23 public AbstractDownloadSourcePanel(final DownloadSource<T> downloadSource) { 19 24 Objects.requireNonNull(downloadSource); … … 53 58 * Performs the logic needed in case if the user triggered the download 54 59 * action in {@link DownloadDialog}. 60 * @param settings The settings to check. 55 61 * @return Returns {@code true} if the required procedure of handling the 56 62 * download action succeeded and {@link DownloadDialog} can be closed, e.g. validation, 57 63 * otherwise {@code false}. 58 64 */ 59 public abstract boolean checkDownload( Bounds bbox,DownloadSettings settings);65 public abstract boolean checkDownload(DownloadSettings settings); 60 66 61 67 /** … … 87 93 /** 88 94 * Tells the {@link DownloadSource} to start downloading 89 * @param currentBounds The bounds to download for 90 * @param downloadSettings The remaining download settings 95 * @param downloadSettings The download settings 91 96 */ 92 public void triggerDownload( Bounds currentBounds,DownloadSettings downloadSettings) {93 getDownloadSource().doDownload( currentBounds,getData(), downloadSettings);97 public void triggerDownload(DownloadSettings downloadSettings) { 98 getDownloadSource().doDownload(getData(), downloadSettings); 94 99 } 95 100 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r12654 r12655 473 473 */ 474 474 public DownloadSettings getDownloadSettings() { 475 return new DownloadSettings( isNewLayerRequired(), isZoomToDownloadedDataRequired());475 return new DownloadSettings(currentBounds, isNewLayerRequired(), isZoomToDownloadedDataRequired()); 476 476 } 477 477 … … 545 545 } 546 546 547 /** 548 * Cancels the download 549 */ 547 550 public void run() { 548 551 setCanceled(true); … … 569 572 } 570 573 574 /** 575 * Starts the download, if possible 576 */ 571 577 public void run() { 572 578 Component panel = downloadSourcesTab.getSelectedComponent(); … … 574 580 AbstractDownloadSourcePanel<?> pnl = (AbstractDownloadSourcePanel<?>) panel; 575 581 DownloadSettings downloadSettings = getDownloadSettings(); 576 if (pnl.checkDownload( currentBounds,downloadSettings)) {582 if (pnl.checkDownload(downloadSettings)) { 577 583 rememberSettings(); 578 584 setCanceled(false); 579 585 setVisible(false); 580 pnl.triggerDownload( currentBounds,downloadSettings);586 pnl.triggerDownload(downloadSettings); 581 587 } 582 588 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadSettings.java
r12652 r12655 2 2 package org.openstreetmap.josm.gui.download; 3 3 4 import java.util.Optional; 5 6 import org.openstreetmap.josm.data.Bounds; 7 4 8 /** 5 9 * The global settings of {@link DownloadDialog}. 10 * <p> 11 * This class is immutable 12 * @since 12652 6 13 */ 7 14 public final class DownloadSettings { 8 15 9 private boolean downloadAsNewLayer; 10 private boolean zoomToDownloadedData; 16 private final Bounds downloadBounds; 17 private final boolean downloadAsNewLayer; 18 private final boolean zoomToDownloadedData; 11 19 12 20 /** 13 21 * Initializes a new instance of {@code DownloadSettings}. 22 * @param bbox The bounding box 14 23 * @param downloadAsNewLayer The flag defining if a new layer must be created for the downloaded data. 15 24 * @param zoomToDownloadedData The flag defining if the map view, see {@link SlippyMapChooser}, 16 25 * must zoom to the downloaded data. 17 26 */ 18 public DownloadSettings(boolean downloadAsNewLayer, boolean zoomToDownloadedData) { 27 public DownloadSettings(Bounds bbox, boolean downloadAsNewLayer, boolean zoomToDownloadedData) { 28 this.downloadBounds = bbox; 19 29 this.downloadAsNewLayer = downloadAsNewLayer; 20 30 this.zoomToDownloadedData = zoomToDownloadedData; … … 36 46 return this.zoomToDownloadedData; 37 47 } 48 49 /** 50 * Gets the download bounds that are requested 51 * @return The bounds or an empty {@link Optional} if no bounds are selected 52 */ 53 public Optional<Bounds> getDownloadBounds() { 54 if (downloadBounds == null) { 55 return Optional.empty(); 56 } else { 57 return Optional.of(downloadBounds); 58 } 59 } 38 60 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadSource.java
r12652 r12655 2 2 package org.openstreetmap.josm.gui.download; 3 3 4 5 import org.openstreetmap.josm.data.Bounds;6 7 4 /** 8 5 * Defines an interface for different download sources. 6 * <p> 7 * Plugins may implement this to provide new download sources to the main download dialog. 9 8 * @param <T> The type of the data that a download source uses. 9 * @since 12652 10 10 */ 11 11 public interface DownloadSource<T> { … … 19 19 /** 20 20 * Downloads the data. 21 * @param bbox The bounding box. Can be null if no bounding box selected.22 21 * @param data The required data for the download source. 23 22 * @param settings The global settings of the download dialog, see {@link DownloadDialog}. 24 23 */ 25 void doDownload( Bounds bbox,T data, DownloadSettings settings);24 void doDownload(T data, DownloadSettings settings); 26 25 27 26 /** -
trunk/src/org/openstreetmap/josm/gui/download/OSMDownloadSource.java
r12652 r12655 38 38 /** 39 39 * Class defines the way data is fetched from the OSM server. 40 * @since 12652 40 41 */ 41 42 public class OSMDownloadSource implements DownloadSource<OSMDownloadSource.OSMDownloadData> { … … 47 48 48 49 @Override 49 public void doDownload(Bounds bbox, OSMDownloadData data, DownloadSettings settings) { 50 public void doDownload(OSMDownloadData data, DownloadSettings settings) { 51 Bounds bbox = settings.getDownloadBounds() 52 .orElseThrow(() -> new IllegalArgumentException("OSM downloads requires bounds")); 50 53 boolean zoom = settings.zoomToData(); 51 54 boolean newLayer = settings.asNewLayer(); … … 126 129 /** 127 130 * The GUI representation of the OSM download source. 131 * @since 12652 128 132 */ 129 133 public static class OSMDownloadSourcePanel extends AbstractDownloadSourcePanel<OSMDownloadData> { … … 138 142 private static final BooleanProperty DOWNLOAD_NOTES = new BooleanProperty("download.osm.notes", false); 139 143 144 /** 145 * Creates a new {@link OSMDownloadSourcePanel} 146 * @param ds The osm download source the panel is for 147 */ 140 148 public OSMDownloadSourcePanel(OSMDownloadSource ds) { 141 149 super(ds); … … 192 200 193 201 @Override 194 public boolean checkDownload( Bounds bbox,DownloadSettings settings) {202 public boolean checkDownload(DownloadSettings settings) { 195 203 /* 196 204 * It is mandatory to specify the area to download from OSM. 197 205 */ 198 if ( bbox == null) {206 if (!settings.getDownloadBounds().isPresent()) { 199 207 JOptionPane.showMessageDialog( 200 208 this.getParent(), … … 304 312 */ 305 313 static class OSMDownloadData { 306 private boolean downloadOSMData;307 private boolean downloadNotes;308 private boolean downloadGPX;314 private final boolean downloadOSMData; 315 private final boolean downloadNotes; 316 private final boolean downloadGPX; 309 317 310 318 OSMDownloadData(boolean downloadOSMData, boolean downloadNotes, boolean downloadGPX) { -
trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java
r12652 r12655 41 41 /** 42 42 * Class defines the way data is fetched from Overpass API. 43 * @since 12652 43 44 */ 44 45 public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> { … … 50 51 51 52 @Override 52 public void doDownload( Bounds bbox,OverpassDownloadData data, DownloadSettings settings) {53 public void doDownload(OverpassDownloadData data, DownloadSettings settings) { 53 54 /* 54 55 * In order to support queries generated by the Overpass Turbo Query Wizard tool 55 56 * which do not require the area to be specified. 56 57 */ 57 Bounds area = bbox != null ? bbox : new Bounds(0, 0, 0, 0);58 Bounds area = settings.getDownloadBounds().orElse(new Bounds(0, 0, 0, 0)); 58 59 DownloadOsmTask task = new DownloadOsmTask(); 59 60 task.setZoomAfterDownload(settings.zoomToData()); … … 81 82 /** 82 83 * The GUI representation of the Overpass download source. 84 * @since 12652 83 85 */ 84 86 public static class OverpassDownloadSourcePanel extends AbstractDownloadSourcePanel<OverpassDownloadData> { … … 91 93 private static final String ACTION_IMG_SUBDIR = "dialogs"; 92 94 95 /** 96 * Create a new {@link OverpassDownloadSourcePanel} 97 * @param ds The download source to create the panel for 98 */ 93 99 public OverpassDownloadSourcePanel(OverpassDownloadSource ds) { 94 100 super(ds); … … 208 214 209 215 @Override 210 public boolean checkDownload( Bounds bbox,DownloadSettings settings) {216 public boolean checkDownload(DownloadSettings settings) { 211 217 String query = getData().getQuery(); 212 218 … … 215 221 * is not restricted to bbox. 216 222 */ 217 if ( bbox == null&& query.contains("{{bbox}}")) {223 if (!settings.getDownloadBounds().isPresent() && query.contains("{{bbox}}")) { 218 224 JOptionPane.showMessageDialog( 219 225 this.getParent(), -
trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java
r12652 r12655 34 34 * This dialog provides an easy and fast way to create an overpass query. 35 35 * @since 12576 36 * @since 12652: Moved here 36 37 */ 37 38 public final class OverpassQueryWizardDialog extends ExtendedDialog {
Note:
See TracChangeset
for help on using the changeset viewer.