Changeset 13927 in josm


Ignore:
Timestamp:
2018-06-13T22:17:23+02:00 (5 months ago)
Author:
Don-vip
Message:

see #11000 - Remote control: allow to specify layer_name for import

Location:
trunk
Files:
1 added
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java

    r12636 r13927  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
     11import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    1112import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    1213import org.openstreetmap.josm.data.Bounds;
     
    4748        DownloadNotesTask task = new DownloadNotesTask();
    4849        task.setZoomAfterDownload(false);
    49         Future<?> future = task.download(false, bounds, null);
     50        Future<?> future = task.download(new DownloadParams(), bounds, null);
    5051        MainApplication.worker.submit(new PostDownloadHandler(task, future));
    5152    }
  • trunk/src/org/openstreetmap/josm/actions/DownloadOsmInViewAction.java

    r12636 r13927  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     11import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    1112import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    1213import org.openstreetmap.josm.data.Bounds;
     
    4748    private static class DownloadOsmInViewTask extends DownloadOsmTask {
    4849        Future<?> download(Bounds downloadArea) {
    49             return download(new DownloadTask(false, new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
     50            return download(new DownloadTask(new DownloadParams(), new BoundingBoxDownloader(downloadArea), null, false), downloadArea);
    5051        }
    5152    }
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r13607 r13927  
    3636import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmUrlTask;
    3737import org.openstreetmap.josm.actions.downloadtasks.DownloadSessionTask;
     38import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    3839import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    3940import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     
    225226     */
    226227    public List<Future<?>> openUrl(boolean newLayer, String url) {
    227         return openUrl(newLayer, DOWNLOAD_ZOOMTODATA.get(), url);
     228        return openUrl(new DownloadParams().withNewLayer(newLayer), url);
     229    }
     230
     231    /**
     232     * Open the given URL.
     233     * @param settings download settings
     234     * @param url The URL to open
     235     * @return the list of tasks that have been started successfully (can be empty).
     236     * @since 13927
     237     */
     238    public List<Future<?>> openUrl(DownloadParams settings, String url) {
     239        return openUrl(settings, DOWNLOAD_ZOOMTODATA.get(), url);
    228240    }
    229241
     
    247259     */
    248260    public List<Future<?>> openUrl(boolean newLayer, boolean zoomToData, String url) {
     261        return openUrl(new DownloadParams().withNewLayer(newLayer), zoomToData, url);
     262    }
     263
     264    /**
     265     * Open the given URL.
     266     * @param settings download settings
     267     * @param zoomToData true to zoom to entire newly downloaded data, false otherwise
     268     * @param url The URL to open
     269     * @return the list of tasks that have been started successfully (can be empty).
     270     * @since 13927
     271     */
     272    public List<Future<?>> openUrl(DownloadParams settings, boolean zoomToData, String url) {
    249273        Collection<DownloadTask> tasks = findDownloadTasks(url, false);
    250274
     
    262286            try {
    263287                task.setZoomAfterDownload(zoomToData);
    264                 result.add(MainApplication.worker.submit(new PostDownloadHandler(task, task.loadUrl(newLayer, url, monitor))));
     288                result.add(MainApplication.worker.submit(new PostDownloadHandler(task, task.loadUrl(settings, url, monitor))));
    265289            } catch (IllegalArgumentException e) {
    266290                Logging.error(e);
  • trunk/src/org/openstreetmap/josm/actions/SearchNotesDownloadAction.java

    r12846 r13927  
    1818import org.openstreetmap.josm.Main;
    1919import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
     20import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    2021import org.openstreetmap.josm.gui.ExtendedDialog;
    2122import org.openstreetmap.josm.gui.Notification;
     
    104105            .append(Utils.encodeUrl(trimmedSearchTerm));
    105106
    106         new DownloadNotesTask().loadUrl(false, sb.toString(), null);
     107        new DownloadNotesTask().loadUrl(new DownloadParams(), sb.toString(), null);
    107108    }
    108109}
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractChangesetDownloadTask.java

    r12634 r13927  
    9292
    9393    @Override
    94     public final Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     94    public final Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    9595        return download();
    9696    }
     
    129129
    130130    @Override
    131     public final Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     131    public final Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    132132        return downloadTaskRunnable != null ? MainApplication.worker.submit(downloadTaskRunnable) : null;
    133133    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r13572 r13927  
    5959
    6060    @Override
    61     public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    62         downloadTask = new DownloadTask(newLayer,
     61    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
     62        downloadTask = new DownloadTask(settings,
    6363                new BoundingBoxDownloader(downloadArea), progressMonitor);
    6464        // We need submit instead of execute so we can wait for it to finish and get the error
     
    6868
    6969    @Override
    70     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     70    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    7171        CheckParameterUtil.ensureParameterNotNull(url, "url");
    7272        final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID)
     
    7676                .findFirst();
    7777        if (mappedUrl.isPresent()) {
    78             return loadUrl(newLayer, mappedUrl.get(), progressMonitor);
     78            return loadUrl(settings, mappedUrl.get(), progressMonitor);
    7979        }
    8080        if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT,
    8181                      GpxUrlPattern.EXTERNAL_GPX_FILE, GpxUrlPattern.TASKING_MANAGER)
    8282                .anyMatch(p -> url.matches(p.pattern()))) {
    83             downloadTask = new DownloadTask(newLayer,
     83            downloadTask = new DownloadTask(settings,
    8484                    new OsmServerLocationReader(url), progressMonitor);
    8585            // Extract .gpx filename from URL to set the new layer name
     
    9494            for (int i = 0; i < table.length; i++) {
    9595                if ("bbox".equals(table[i]) && i < table.length-1)
    96                     return download(newLayer, new Bounds(table[i+1], ",", ParseMethod.LEFT_BOTTOM_RIGHT_TOP), progressMonitor);
     96                    return download(settings, new Bounds(table[i+1], ",", ParseMethod.LEFT_BOTTOM_RIGHT_TOP), progressMonitor);
    9797            }
    9898        }
     
    117117        private final boolean newLayer;
    118118
    119         DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {
     119        DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor) {
    120120            super(tr("Downloading GPS data"), progressMonitor, false);
    121121            this.reader = reader;
    122             this.newLayer = newLayer;
     122            this.newLayer = settings.isNewLayer();
    123123        }
    124124
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r13761 r13927  
    6767
    6868    @Override
    69     public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     69    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    7070        downloadTask = new DownloadBoundingBoxTask(new BoundingBoxDownloader(downloadArea), progressMonitor);
    7171        return MainApplication.worker.submit(downloadTask);
     
    7373
    7474    @Override
    75     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     75    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    7676        if (url.matches(PATTERN_COMPRESS)) {
    7777            downloadTask = new DownloadCompressedRawUrlTask(new OsmServerLocationReader(url), progressMonitor, Compression.byExtension(url));
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesUrlBoundsTask.java

    r12284 r13927  
    1818
    1919    @Override
    20     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    21         return download(newLayer, OsmUrlToBounds.parse(url), null);
     20    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
     21        return download(settings, OsmUrlToBounds.parse(url), null);
    2222    }
    2323
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesUrlIdTask.java

    r12284 r13927  
    2121
    2222    @Override
    23     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     23    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    2424        final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
    2525        if (matcher.matches()) {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java

    r13352 r13927  
    3333    /**
    3434     * Loads a given URL
    35      * @param newLayer {@code true} if the data should be saved to a new layer
     35     * @param settings download settings
    3636     * @param url The URL as String
    3737     * @param progressMonitor progress monitor for user interaction
    3838     */
    3939    @Override
    40     public Future<?> loadUrl(boolean newLayer, final String url, ProgressMonitor progressMonitor) {
    41         downloadTask = new DownloadTask(newLayer, new OsmServerLocationReader(url), progressMonitor) {
     40    public Future<?> loadUrl(DownloadParams settings, final String url, ProgressMonitor progressMonitor) {
     41        downloadTask = new DownloadTask(settings, new OsmServerLocationReader(url), progressMonitor) {
    4242            @Override
    4343            protected DataSet parseDataSet() throws OsmTransferException {
     
    4848        currentBounds = null;
    4949        // Extract .osc.gz/xz/bz/bz2/zip filename from URL to set the new layer name
    50         extractOsmFilename(PATTERN_COMPRESS, url);
     50        extractOsmFilename(settings, PATTERN_COMPRESS, url);
    5151        return MainApplication.worker.submit(downloadTask);
    5252    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

    r12635 r13927  
    6262
    6363    @Override
    64     public Future<?> download(boolean newLayer, Bounds downloadArea,
    65             ProgressMonitor progressMonitor) {
     64    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    6665        return null;
    6766    }
    6867
    6968    @Override
    70     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     69    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    7170        final Matcher matcher = Pattern.compile(OSM_WEBSITE_PATTERN).matcher(url);
    7271        if (matcher.matches()) {
    7372            url = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download";
    7473        }
    75         downloadTask = new DownloadTask(newLayer, new OsmServerLocationReader(url), progressMonitor);
     74        downloadTask = new DownloadTask(settings, new OsmServerLocationReader(url), progressMonitor);
    7675        // Extract .osc filename from URL to set the new layer name
    77         extractOsmFilename("https?://.*/(.*\\.osc)", url);
     76        extractOsmFilename(settings, "https?://.*/(.*\\.osc)", url);
    7877        return MainApplication.worker.submit(downloadTask);
    7978    }
     
    8685        /**
    8786         * Constructs a new {@code DownloadTask}.
    88          * @param newLayer if {@code true}, force download to a new layer
     87         * @param settings download settings
    8988         * @param reader OSM data reader
    9089         * @param progressMonitor progress monitor
    9190         */
    92         public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {
    93             super(newLayer, reader, progressMonitor);
     91        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor) {
     92            super(settings, reader, progressMonitor);
    9493        }
    9594
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java

    r13352 r13927  
    3333
    3434    @Override
    35     public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     35    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    3636        return null;
    3737    }
     
    3939    /**
    4040     * Loads a given URL
    41      * @param newLayer {@code true} if the data should be saved to a new layer
     41     * @param settings download settings
    4242     * @param url The URL as String
    4343     * @param progressMonitor progress monitor for user interaction
    4444     */
    4545    @Override
    46     public Future<?> loadUrl(boolean newLayer, final String url, ProgressMonitor progressMonitor) {
    47         downloadTask = new DownloadTask(newLayer, new OsmServerLocationReader(url), progressMonitor) {
     46    public Future<?> loadUrl(DownloadParams settings, final String url, ProgressMonitor progressMonitor) {
     47        downloadTask = new DownloadTask(settings, new OsmServerLocationReader(url), progressMonitor) {
    4848            @Override
    4949            protected DataSet parseDataSet() throws OsmTransferException {
     
    5454        currentBounds = null;
    5555        // Extract .osm.gz/bz/bz2/zip filename from URL to set the new layer name
    56         extractOsmFilename(PATTERN_COMPRESS, url);
     56        extractOsmFilename(settings, PATTERN_COMPRESS, url);
    5757        return MainApplication.worker.submit(downloadTask);
    5858    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmIdTask.java

    r12634 r13927  
    3232
    3333    @Override
    34     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     34    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    3535        final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
    3636        if (matcher.matches()) {
     
    3939            final PrimitiveId primitiveId = new SimplePrimitiveId(id, type);
    4040            final DownloadPrimitivesWithReferrersTask downloadTask = new DownloadPrimitivesWithReferrersTask(
    41                     newLayer, Collections.singletonList(primitiveId), true, true, null, null);
     41                    settings.isNewLayer(), Collections.singletonList(primitiveId), true, true, null, null);
    4242            return MainApplication.worker.submit(downloadTask);
    4343        } else {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r13612 r13927  
    7777
    7878    @Override
    79     public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    80         return download(new BoundingBoxDownloader(downloadArea), newLayer, downloadArea, progressMonitor);
     79    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
     80        return download(new BoundingBoxDownloader(downloadArea), settings, downloadArea, progressMonitor);
    8181    }
    8282
     
    112112     * </pre>
    113113     * @param reader the reader used to parse OSM data (see {@link OsmServerReader#parseOsm})
    114      * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task
    115      *                 selects one of the existing layers as download layer, preferably the active layer.
     114     * @param settings download settings
    116115     * @param downloadArea the area to download
    117116     * @param progressMonitor the progressMonitor
    118117     * @return the future representing the asynchronous task
    119118     */
    120     public Future<?> download(OsmServerReader reader, boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    121         return download(new DownloadTask(newLayer, reader, progressMonitor, zoomAfterDownload), downloadArea);
     119    public Future<?> download(OsmServerReader reader, DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
     120        return download(new DownloadTask(settings, reader, progressMonitor, zoomAfterDownload), downloadArea);
    122121    }
    123122
     
    141140    /**
    142141     * Loads a given URL from the OSM Server
    143      * @param newLayer True if the data should be saved to a new layer
     142     * @param settings download settings
    144143     * @param url The URL as String
    145144     */
    146145    @Override
    147     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     146    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    148147        String newUrl = modifyUrlBeforeLoad(url);
    149         downloadTask = new DownloadTask(newLayer,
     148        downloadTask = new DownloadTask(settings,
    150149                new OsmServerLocationReader(newUrl),
    151150                progressMonitor);
    152151        currentBounds = null;
    153152        // Extract .osm filename from URL to set the new layer name
    154         extractOsmFilename("https?://.*/(.*\\.osm)", newUrl);
     153        extractOsmFilename(settings, "https?://.*/(.*\\.osm)", newUrl);
    155154        return MainApplication.worker.submit(downloadTask);
    156155    }
    157156
    158     protected final void extractOsmFilename(String pattern, String url) {
    159         Matcher matcher = Pattern.compile(pattern).matcher(url);
    160         newLayerName = matcher.matches() ? matcher.group(1) : null;
     157    protected final void extractOsmFilename(DownloadParams settings, String pattern, String url) {
     158        newLayerName = settings.getLayerName();
     159        if (newLayerName == null || newLayerName.isEmpty()) {
     160            Matcher matcher = Pattern.compile(pattern).matcher(url);
     161            newLayerName = matcher.matches() ? matcher.group(1) : null;
     162        }
    161163    }
    162164
     
    190192        /**
    191193         * Constructs a new {@code AbstractInternalTask}.
    192          * @param newLayer if {@code true}, force download to a new layer
     194         * @param settings download settings
    193195         * @param title message for the user
    194196         * @param ignoreException If true, exception will be propagated to calling code. If false then
     
    197199         * @param zoomAfterDownload If true, the map view will zoom to download area after download
    198200         */
    199         public AbstractInternalTask(boolean newLayer, String title, boolean ignoreException, boolean zoomAfterDownload) {
     201        public AbstractInternalTask(DownloadParams settings, String title, boolean ignoreException, boolean zoomAfterDownload) {
    200202            super(title, ignoreException);
    201             this.newLayer = newLayer;
     203            this.newLayer = settings.isNewLayer();
    202204            this.zoomAfterDownload = zoomAfterDownload;
    203205        }
     
    205207        /**
    206208         * Constructs a new {@code AbstractInternalTask}.
    207          * @param newLayer if {@code true}, force download to a new layer
     209         * @param settings download settings
    208210         * @param title message for the user
    209211         * @param progressMonitor progress monitor
     
    213215         * @param zoomAfterDownload If true, the map view will zoom to download area after download
    214216         */
    215         public AbstractInternalTask(boolean newLayer, String title, ProgressMonitor progressMonitor, boolean ignoreException,
     217        public AbstractInternalTask(DownloadParams settings, String title, ProgressMonitor progressMonitor, boolean ignoreException,
    216218                boolean zoomAfterDownload) {
    217219            super(title, progressMonitor, ignoreException);
    218             this.newLayer = newLayer;
     220            this.newLayer = settings.isNewLayer();
    219221            this.zoomAfterDownload = zoomAfterDownload;
    220222        }
     
    348350        /**
    349351         * Constructs a new {@code DownloadTask}.
    350          * @param newLayer if {@code true}, force download to a new layer
     352         * @param settings download settings
    351353         * @param reader OSM data reader
    352354         * @param progressMonitor progress monitor
    353          */
    354         public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {
    355             this(newLayer, reader, progressMonitor, true);
     355         * @since 13927
     356         */
     357        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor) {
     358            this(settings, reader, progressMonitor, true);
    356359        }
    357360
    358361        /**
    359362         * Constructs a new {@code DownloadTask}.
    360          * @param newLayer if {@code true}, force download to a new layer
     363         * @param settings download settings
    361364         * @param reader OSM data reader
    362365         * @param progressMonitor progress monitor
    363366         * @param zoomAfterDownload If true, the map view will zoom to download area after download
    364          * @since 8942
    365          */
    366         public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) {
    367             super(newLayer, tr("Downloading data"), progressMonitor, false, zoomAfterDownload);
     367         * @since 13927
     368         */
     369        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) {
     370            super(settings, tr("Downloading data"), progressMonitor, false, zoomAfterDownload);
    368371            this.reader = reader;
    369372        }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java

    r11329 r13927  
    1717
    1818    @Override
    19     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    20         return download(newLayer, OsmUrlToBounds.parse(url), null);
     19    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
     20        return download(settings, OsmUrlToBounds.parse(url), null);
    2121    }
    2222
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadSessionTask.java

    r12846 r13927  
    3838
    3939    @Override
    40     public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     40    public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    4141        return null;
    4242    }
    4343
    4444    @Override
    45     public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     45    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    4646        if (url != null && (url.matches(PATTERN_SESSION))) {
    4747            try {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

    r13261 r13927  
    4646     * </pre>
    4747     *
    48      * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task
    49      * selects one of the existing layers as download layer, preferably the active layer.
     48     * @param settings download settings
    5049     *
    5150     * @param downloadArea the area to download
    5251     * @param progressMonitor the progressMonitor
    5352     * @return the future representing the asynchronous task
     53     * @since 13927
    5454     */
    55     Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor);
     55    Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor);
    5656
    5757    /**
     
    6262     * be discarded.
    6363
    64      * @param newLayer newLayer true, if the data is to be downloaded into a new layer. If false, the task
    65      * selects one of the existing layers as download layer, preferably the active layer.
     64     * @param settings download settings
    6665     * @param url the url to download from
    6766     * @param progressMonitor the progressMonitor
    6867     * @return the future representing the asynchronous task
    6968     *
    70      * @see #download(boolean, Bounds, ProgressMonitor)
     69     * @see #download(DownloadParams, Bounds, ProgressMonitor)
     70     * @since 13927
    7171     */
    72     Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
     72    Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor);
    7373
    7474    /**
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

    r13842 r13927  
    5555        ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false);
    5656        childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, n, n - i));
    57         Future<?> future = dt.download(false, new Bounds(td), childProgress);
     57        Future<?> future = dt.download(new DownloadParams(), new Bounds(td), childProgress);
    5858        taskFutures.add(future);
    5959        tasks.add(dt);
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r13926 r13927  
    8080import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
    8181import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     82import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    8283import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    8384import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     
    13701371        DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask();
    13711372        // asynchronously launch the download task ...
    1372         Future<?> future = task.download(true, b, null);
     1373        Future<?> future = task.download(new DownloadParams().withNewLayer(true), b, null);
    13731374        // ... and the continuation when the download is finished (this will wait for the download to finish)
    13741375        return Collections.singletonList(MainApplication.worker.submit(new PostDownloadHandler(task, future)));
  • trunk/src/org/openstreetmap/josm/gui/download/OSMDownloadSource.java

    r13501 r13927  
    2323import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
    2424import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     25import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    2526import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    2627import org.openstreetmap.josm.data.Bounds;
     
    6465            DownloadOsmTask task = new DownloadOsmTask();
    6566            task.setZoomAfterDownload(zoom && !data.isDownloadGPX() && !data.isDownloadNotes());
    66             Future<?> future = task.download(newLayer, bbox, null);
     67            Future<?> future = task.download(new DownloadParams().withNewLayer(newLayer), bbox, null);
    6768            MainApplication.worker.submit(new PostDownloadHandler(task, future));
    6869            if (zoom) {
     
    7475            DownloadGpsTask task = new DownloadGpsTask();
    7576            task.setZoomAfterDownload(zoom && !data.isDownloadOSMData() && !data.isDownloadNotes());
    76             Future<?> future = task.download(newLayer, bbox, null);
     77            Future<?> future = task.download(new DownloadParams().withNewLayer(newLayer), bbox, null);
    7778            MainApplication.worker.submit(new PostDownloadHandler(task, future));
    7879            if (zoom) {
     
    8485            DownloadNotesTask task = new DownloadNotesTask();
    8586            task.setZoomAfterDownload(zoom && !data.isDownloadOSMData() && !data.isDownloadGPX());
    86             Future<?> future = task.download(false, bbox, null);
     87            Future<?> future = task.download(new DownloadParams(), bbox, null);
    8788            MainApplication.worker.submit(new PostDownloadHandler(task, future));
    8889            if (zoom) {
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r13335 r13927  
    2626
    2727import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     28import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    2829import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    2930import org.openstreetmap.josm.data.Bounds;
     
    6364        Future<?> future = task.download(
    6465                new OverpassDownloadReader(area, OverpassDownloadReader.OVERPASS_SERVER.get(), data.getQuery()),
    65                 settings.asNewLayer(), area, null);
     66                new DownloadParams().withNewLayer(settings.asNewLayer()), area, null);
    6667        MainApplication.worker.submit(new PostDownloadHandler(task, future, data.getErrorReporter()));
    6768    }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java

    r12846 r13927  
    4040                // As of 2015-04, Overpass Turbo requires this branch of code ...
    4141                Logging.debug("Remote control, /import: defaulting to DownloadOsmTask");
    42                 new DownloadOsmTask().loadUrl(isLoadInNewLayer(), url.toExternalForm(), null);
     42                new DownloadOsmTask().loadUrl(getDownloadParams(), url.toExternalForm(), null);
    4343            } else if (Config.getPref().getBoolean("remotecontrol.import.interactive", true)) {
    4444                // OpenLocationAction queries the user if more than one task is suitable
    45                 MainApplication.getMenu().openLocation.openUrl(isLoadInNewLayer(), url.toExternalForm());
     45                MainApplication.getMenu().openLocation.openUrl(getDownloadParams(), url.toExternalForm());
    4646            } else {
    4747                // Otherwise perform all tasks
    4848                for (DownloadTask task : suitableDownloadTasks) {
    49                     task.loadUrl(isLoadInNewLayer(), url.toExternalForm(), null);
     49                    task.loadUrl(getDownloadParams(), url.toExternalForm(), null);
    5050                }
    5151            }
     
    6464    @Override
    6565    public String[] getOptionalParams() {
    66         return new String[] {"new_layer"};
     66        return new String[] {"new_layer", "layer_name"};
    6767    }
    6868
     
    7474    @Override
    7575    public String[] getUsageExamples() {
    76         return new String[] {"/import?url="+Main.getJOSMWebsite()+"/browser/josm/trunk/data_nodist/direction-arrows.osm"};
     76        return new String[] {"/import?url=" + Utils.encodeUrl(
     77                Main.getJOSMWebsite()+"/browser/josm/trunk/data_nodist/direction-arrows.osm?format=txt")};
    7778    }
    7879
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r13257 r13927  
    1616import org.openstreetmap.josm.actions.AutoScaleAction;
    1717import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     18import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    1819import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    1920import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     
    112113    @Override
    113114    protected void handleRequest() throws RequestHandlerErrorException {
    114         DownloadTask osmTask = new DownloadOsmTask() {
    115             {
    116                 newLayerName = args.get("layer_name");
    117             }
    118         };
     115        DownloadTask osmTask = new DownloadOsmTask();
    119116        try {
    120             boolean newLayer = isLoadInNewLayer();
     117            DownloadParams settings = getDownloadParams();
    121118
    122119            if (command.equals(myCommand)) {
     
    125122                } else {
    126123                    Area toDownload = null;
    127                     if (!newLayer) {
     124                    if (!settings.isNewLayer()) {
    128125                        // find out whether some data has already been downloaded
    129126                        Area present = null;
     
    148145                        Logging.info("RemoteControl: no download necessary");
    149146                    } else {
    150                         Future<?> future = osmTask.download(newLayer, new Bounds(minlat, minlon, maxlat, maxlon),
     147                        Future<?> future = osmTask.download(settings, new Bounds(minlat, minlon, maxlat, maxlon),
    151148                                null /* let the task manage the progress monitor */);
    152149                        MainApplication.worker.submit(new PostDownloadHandler(osmTask, future));
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadDataHandler.java

    r12634 r13927  
    88
    99import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     10import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    1011import org.openstreetmap.josm.data.osm.DataSet;
    1112import org.openstreetmap.josm.gui.MainApplication;
     
    4041    @Override
    4142    protected void handleRequest() throws RequestHandlerErrorException {
    42         MainApplication.worker.submit(new LoadDataTask(isLoadInNewLayer(), dataSet, args.get("layer_name")));
     43        MainApplication.worker.submit(new LoadDataTask(getDownloadParams(), dataSet, args.get("layer_name")));
    4344    }
    4445
     
    103104        /**
    104105         * Constructs a new {@code LoadDataTask}.
    105          * @param newLayer if {@code true}, force download to a new layer
     106         * @param settings download settings
    106107         * @param dataSet data set
    107108         * @param layerName layer name
     109         * @since 13927
    108110         */
    109         public LoadDataTask(boolean newLayer, DataSet dataSet, String layerName) {
    110             super(newLayer, tr("Loading data"), false, true);
     111        public LoadDataTask(DownloadParams settings, DataSet dataSet, String layerName) {
     112            super(settings, tr("Loading data"), false, true);
    111113            this.dataSet = dataSet;
    112114            this.layerName = layerName;
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java

    r13827 r13927  
    6363        }
    6464        if (!ps.isEmpty()) {
    65             final boolean newLayer = isLoadInNewLayer();
     65            final boolean newLayer = getDownloadParams().isNewLayer();
    6666            final boolean relationMembers = Boolean.parseBoolean(args.get("relation_members"));
    6767            final boolean referrers = Boolean.parseBoolean(args.get("referrers"));
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java

    r13827 r13927  
    2020
    2121import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
    2223import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
    2324import org.openstreetmap.josm.spi.preferences.Config;
     
    298299    }
    299300
    300     protected boolean isLoadInNewLayer() {
     301    private boolean isLoadInNewLayer() {
    301302        return args.get("new_layer") != null && !args.get("new_layer").isEmpty()
    302303                ? Boolean.parseBoolean(args.get("new_layer"))
    303304                : Config.getPref().getBoolean(loadInNewLayerKey, loadInNewLayerDefault);
     305    }
     306
     307    protected DownloadParams getDownloadParams() {
     308        return new DownloadParams()
     309                .withNewLayer(isLoadInNewLayer())
     310                .withLayerName(args.get("layer_name"));
    304311    }
    305312
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java

    r13572 r13927  
    4545        mockHttp();
    4646        DownloadGpsTask task = new DownloadGpsTask();
    47         task.loadUrl(false, getRemoteFileUrl(), null).get();
     47        task.loadUrl(new DownloadParams(), getRemoteFileUrl(), null).get();
    4848        GpxData data = task.getDownloadedData();
    4949        assertNotNull(data);
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTaskTest.java

    r12558 r13927  
    4040        mockHttp();
    4141        DownloadNotesTask task = new DownloadNotesTask();
    42         task.loadUrl(false, getRemoteFileUrl(), null).get();
     42        task.loadUrl(new DownloadParams(), getRemoteFileUrl(), null).get();
    4343        NoteData data = task.getDownloadedData();
    4444        assertNotNull(data);
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java

    r12558 r13927  
    4242        mockHttp();
    4343        DownloadOsmTask task = new DownloadOsmTask();
    44         task.loadUrl(false, getRemoteFileUrl(), null).get();
     44        task.loadUrl(new DownloadParams(), getRemoteFileUrl(), null).get();
    4545        DataSet ds = task.getDownloadedData();
    4646        assertNotNull(ds);
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandlerTest.java

    r13261 r13927  
    3737        return new DownloadTask() {
    3838            @Override
    39             public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     39            public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    4040                return null;
    4141            }
     
    6262
    6363            @Override
    64             public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     64            public Future<?> download(DownloadParams settings, Bounds downloadArea, ProgressMonitor progressMonitor) {
    6565                return null;
    6666            }
Note: See TracChangeset for help on using the changeset viewer.