Changeset 12655 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-08-26T00:23:18+02:00 (7 years ago)
Author:
michael2402
Message:

See #15167: Add javadoc, improve code style.

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  
    1313 * {@link DownloadDialog}.
    1414 * @param <T> The type of the data that a download source uses.
     15 * @since 12652
    1516 */
    1617public abstract class AbstractDownloadSourcePanel<T> extends JPanel {
    1718
     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     */
    1823    public AbstractDownloadSourcePanel(final DownloadSource<T> downloadSource) {
    1924        Objects.requireNonNull(downloadSource);
     
    5358     * Performs the logic needed in case if the user triggered the download
    5459     * action in {@link DownloadDialog}.
     60     * @param settings The settings to check.
    5561     * @return Returns {@code true} if the required procedure of handling the
    5662     * download action succeeded and {@link DownloadDialog} can be closed, e.g. validation,
    5763     * otherwise {@code false}.
    5864     */
    59     public abstract boolean checkDownload(Bounds bbox, DownloadSettings settings);
     65    public abstract boolean checkDownload(DownloadSettings settings);
    6066
    6167    /**
     
    8793    /**
    8894     * 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
    9196     */
    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);
    9499    }
    95100}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r12654 r12655  
    473473     */
    474474    public DownloadSettings getDownloadSettings() {
    475         return new DownloadSettings(isNewLayerRequired(), isZoomToDownloadedDataRequired());
     475        return new DownloadSettings(currentBounds, isNewLayerRequired(), isZoomToDownloadedDataRequired());
    476476    }
    477477
     
    545545        }
    546546
     547        /**
     548         * Cancels the download
     549         */
    547550        public void run() {
    548551            setCanceled(true);
     
    569572        }
    570573
     574        /**
     575         * Starts the download, if possible
     576         */
    571577        public void run() {
    572578            Component panel = downloadSourcesTab.getSelectedComponent();
     
    574580                AbstractDownloadSourcePanel<?> pnl = (AbstractDownloadSourcePanel<?>) panel;
    575581                DownloadSettings downloadSettings = getDownloadSettings();
    576                 if (pnl.checkDownload(currentBounds, downloadSettings)) {
     582                if (pnl.checkDownload(downloadSettings)) {
    577583                    rememberSettings();
    578584                    setCanceled(false);
    579585                    setVisible(false);
    580                     pnl.triggerDownload(currentBounds, downloadSettings);
     586                    pnl.triggerDownload(downloadSettings);
    581587                }
    582588            }
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadSettings.java

    r12652 r12655  
    22package org.openstreetmap.josm.gui.download;
    33
     4import java.util.Optional;
     5
     6import org.openstreetmap.josm.data.Bounds;
     7
    48/**
    59 * The global settings of {@link DownloadDialog}.
     10 * <p>
     11 * This class is immutable
     12 * @since 12652
    613 */
    714public final class DownloadSettings {
    815
    9     private boolean downloadAsNewLayer;
    10     private boolean zoomToDownloadedData;
     16    private final Bounds downloadBounds;
     17    private final boolean downloadAsNewLayer;
     18    private final boolean zoomToDownloadedData;
    1119
    1220    /**
    1321     * Initializes a new instance of {@code DownloadSettings}.
     22     * @param bbox The bounding box
    1423     * @param downloadAsNewLayer The flag defining if a new layer must be created for the downloaded data.
    1524     * @param zoomToDownloadedData The flag defining if the map view, see {@link SlippyMapChooser},
    1625     *                             must zoom to the downloaded data.
    1726     */
    18     public DownloadSettings(boolean downloadAsNewLayer, boolean zoomToDownloadedData) {
     27    public DownloadSettings(Bounds bbox, boolean downloadAsNewLayer, boolean zoomToDownloadedData) {
     28        this.downloadBounds = bbox;
    1929        this.downloadAsNewLayer = downloadAsNewLayer;
    2030        this.zoomToDownloadedData = zoomToDownloadedData;
     
    3646        return this.zoomToDownloadedData;
    3747    }
     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    }
    3860}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadSource.java

    r12652 r12655  
    22package org.openstreetmap.josm.gui.download;
    33
    4 
    5 import org.openstreetmap.josm.data.Bounds;
    6 
    74/**
    85 * Defines an interface for different download sources.
     6 * <p>
     7 * Plugins may implement this to provide new download sources to the main download dialog.
    98 * @param <T> The type of the data that a download source uses.
     9 * @since 12652
    1010 */
    1111public interface DownloadSource<T> {
     
    1919    /**
    2020     * Downloads the data.
    21      * @param bbox The bounding box. Can be null if no bounding box selected.
    2221     * @param data The required data for the download source.
    2322     * @param settings The global settings of the download dialog, see {@link DownloadDialog}.
    2423     */
    25     void doDownload(Bounds bbox, T data, DownloadSettings settings);
     24    void doDownload(T data, DownloadSettings settings);
    2625
    2726    /**
  • trunk/src/org/openstreetmap/josm/gui/download/OSMDownloadSource.java

    r12652 r12655  
    3838/**
    3939 * Class defines the way data is fetched from the OSM server.
     40 * @since 12652
    4041 */
    4142public class OSMDownloadSource implements DownloadSource<OSMDownloadSource.OSMDownloadData> {
     
    4748
    4849    @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"));
    5053        boolean zoom = settings.zoomToData();
    5154        boolean newLayer = settings.asNewLayer();
     
    126129    /**
    127130     * The GUI representation of the OSM download source.
     131     * @since 12652
    128132     */
    129133    public static class OSMDownloadSourcePanel extends AbstractDownloadSourcePanel<OSMDownloadData> {
     
    138142        private static final BooleanProperty DOWNLOAD_NOTES = new BooleanProperty("download.osm.notes", false);
    139143
     144        /**
     145         * Creates a new {@link OSMDownloadSourcePanel}
     146         * @param ds The osm download source the panel is for
     147         */
    140148        public OSMDownloadSourcePanel(OSMDownloadSource ds) {
    141149            super(ds);
     
    192200
    193201        @Override
    194         public boolean checkDownload(Bounds bbox, DownloadSettings settings) {
     202        public boolean checkDownload(DownloadSettings settings) {
    195203            /*
    196204             * It is mandatory to specify the area to download from OSM.
    197205             */
    198             if (bbox == null) {
     206            if (!settings.getDownloadBounds().isPresent()) {
    199207                JOptionPane.showMessageDialog(
    200208                        this.getParent(),
     
    304312     */
    305313    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;
    309317
    310318        OSMDownloadData(boolean downloadOSMData, boolean downloadNotes, boolean downloadGPX) {
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r12652 r12655  
    4141/**
    4242 * Class defines the way data is fetched from Overpass API.
     43 * @since 12652
    4344 */
    4445public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> {
     
    5051
    5152    @Override
    52     public void doDownload(Bounds bbox, OverpassDownloadData data, DownloadSettings settings) {
     53    public void doDownload(OverpassDownloadData data, DownloadSettings settings) {
    5354        /*
    5455         * In order to support queries generated by the Overpass Turbo Query Wizard tool
    5556         * which do not require the area to be specified.
    5657         */
    57         Bounds area = bbox != null ? bbox : new Bounds(0, 0, 0, 0);
     58        Bounds area = settings.getDownloadBounds().orElse(new Bounds(0, 0, 0, 0));
    5859        DownloadOsmTask task = new DownloadOsmTask();
    5960        task.setZoomAfterDownload(settings.zoomToData());
     
    8182    /**
    8283     * The GUI representation of the Overpass download source.
     84     * @since 12652
    8385     */
    8486    public static class OverpassDownloadSourcePanel extends AbstractDownloadSourcePanel<OverpassDownloadData> {
     
    9193        private static final String ACTION_IMG_SUBDIR = "dialogs";
    9294
     95        /**
     96         * Create a new {@link OverpassDownloadSourcePanel}
     97         * @param ds The download source to create the panel for
     98         */
    9399        public OverpassDownloadSourcePanel(OverpassDownloadSource ds) {
    94100            super(ds);
     
    208214
    209215        @Override
    210         public boolean checkDownload(Bounds bbox, DownloadSettings settings) {
     216        public boolean checkDownload(DownloadSettings settings) {
    211217            String query = getData().getQuery();
    212218
     
    215221             * is not restricted to bbox.
    216222             */
    217             if (bbox == null && query.contains("{{bbox}}")) {
     223            if (!settings.getDownloadBounds().isPresent() && query.contains("{{bbox}}")) {
    218224                JOptionPane.showMessageDialog(
    219225                        this.getParent(),
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java

    r12652 r12655  
    3434 * This dialog provides an easy and fast way to create an overpass query.
    3535 * @since 12576
     36 * @since 12652: Moved here
    3637 */
    3738public final class OverpassQueryWizardDialog extends ExtendedDialog {
Note: See TracChangeset for help on using the changeset viewer.