Ignore:
Timestamp:
2015-10-22T14:01:47+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #11998 - add two new protected boolean members to simplify customization of OSM download task for plugins + fix some javadoc/sonar issues

File:
1 edited

Legend:

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

    r8908 r8927  
    4747
    4848    protected String newLayerName;
     49
     50    /** This allows subclasses to ignore this warning */
     51    protected boolean warnAboutEmptyArea = true;
    4952
    5053    @Override
     
    123126    /**
    124127     * This allows subclasses to perform operations on the URL before {@link #loadUrl} is performed.
     128     * @param url the original URL
     129     * @return the modified URL
    125130     */
    126131    protected String modifyUrlBeforeLoad(String url) {
     
    130135    /**
    131136     * Loads a given URL from the OSM Server
    132      * @param new_layer True if the data should be saved to a new layer
     137     * @param newLayer True if the data should be saved to a new layer
    133138     * @param url The URL as String
    134139     */
    135140    @Override
    136     public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {
    137         url = modifyUrlBeforeLoad(url);
    138         downloadTask = new DownloadTask(new_layer,
    139                 new OsmServerLocationReader(url),
     141    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     142        String newUrl = modifyUrlBeforeLoad(url);
     143        downloadTask = new DownloadTask(newLayer,
     144                new OsmServerLocationReader(newUrl),
    140145                progressMonitor);
    141146        currentBounds = null;
    142147        // Extract .osm filename from URL to set the new layer name
    143         extractOsmFilename("https?://.*/(.*\\.osm)", url);
     148        extractOsmFilename("https?://.*/(.*\\.osm)", newUrl);
    144149        return Main.worker.submit(downloadTask);
    145150    }
     
    169174
    170175        protected final boolean newLayer;
     176        protected final boolean zoomAfterDownload;
    171177        protected DataSet dataSet;
    172178
     
    179185         * exception will be thrown directly in EDT. When this runnable is executed using executor framework
    180186         * then use false unless you read result of task (because exception will get lost if you don't)
     187         * @param zoomAfterDownload If true, the map view will zoom to download area after download
    181188         */
    182         public AbstractInternalTask(boolean newLayer, String title, boolean ignoreException) {
     189        public AbstractInternalTask(boolean newLayer, String title, boolean ignoreException, boolean zoomAfterDownload) {
    183190            super(title, ignoreException);
    184191            this.newLayer = newLayer;
     192            this.zoomAfterDownload = zoomAfterDownload;
    185193        }
    186194
     
    194202         * exception will be thrown directly in EDT. When this runnable is executed using executor framework
    195203         * then use false unless you read result of task (because exception will get lost if you don't)
     204         * @param zoomAfterDownload If true, the map view will zoom to download area after download
    196205         */
    197         public AbstractInternalTask(boolean newLayer, String title, ProgressMonitor progressMonitor, boolean ignoreException) {
     206        public AbstractInternalTask(boolean newLayer, String title, ProgressMonitor progressMonitor, boolean ignoreException,
     207                boolean zoomAfterDownload) {
    198208            super(title, progressMonitor, ignoreException);
    199209            this.newLayer = newLayer;
     210            this.zoomAfterDownload = zoomAfterDownload;
    200211        }
    201212
     
    206217
    207218        protected int getNumDataLayers() {
     219            if (!Main.isDisplayingMapView()) return 0;
    208220            int count = 0;
    209             if (!Main.isDisplayingMapView()) return 0;
    210221            Collection<Layer> layers = Main.map.mapView.getAllLayers();
    211222            for (Layer layer : layers) {
     
    276287                }
    277288                layer.mergeFrom(dataSet);
    278                 computeBboxAndCenterScale(bounds);
     289                if (zoomAfterDownload) {
     290                    computeBboxAndCenterScale(bounds);
     291                }
    279292                layer.onPostDownloadFromServer();
    280293            }
     
    285298        protected final OsmServerReader reader;
    286299
     300        /**
     301         * Constructs a new {@code DownloadTask}.
     302         * @param newLayer if {@code true}, force download to a new layer
     303         * @param reader OSM data reader
     304         * @param progressMonitor progress monitor
     305         */
    287306        public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {
    288             super(newLayer, tr("Downloading data"), progressMonitor, false);
     307            super(newLayer, tr("Downloading data"), progressMonitor, false, true);
    289308            this.reader = reader;
    290309        }
     
    324343                return; // user canceled download or error occurred
    325344            if (dataSet.allPrimitives().isEmpty()) {
    326                 rememberErrorMessage(tr("No data found in this area."));
     345                if (warnAboutEmptyArea) {
     346                    rememberErrorMessage(tr("No data found in this area."));
     347                }
    327348                // need to synthesize a download bounds lest the visual indication of downloaded area doesn't work
    328349                dataSet.dataSources.add(new DataSource(currentBounds != null ? currentBounds :
Note: See TracChangeset for help on using the changeset viewer.