Changeset 8927 in josm for trunk


Ignore:
Timestamp:
2015-10-22T14:01:47+02:00 (9 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

Location:
trunk/src/org/openstreetmap/josm
Files:
4 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 :
  • trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java

    r8846 r8927  
    8989    }
    9090
     91    /**
     92     * Determines if the bounds area is not null
     93     * @return {@code true} if the area is not null
     94     */
    9195    public boolean hasExtend() {
    9296        return !Utils.equalsEpsilon(minEast, maxEast) || !Utils.equalsEpsilon(minNorth, maxNorth);
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r8846 r8927  
    4848    }
    4949
     50    /**
     51     * Visiting call for bounds.
     52     * @param b bounds
     53     */
    5054    public void visit(Bounds b) {
    5155        if (b != null) {
     
    5559    }
    5660
     61    /**
     62     * Visiting call for projection bounds.
     63     * @param b projection bounds
     64     */
    5765    public void visit(ProjectionBounds b) {
    5866        if (b != null) {
     
    6270    }
    6371
     72    /**
     73     * Visiting call for lat/lon.
     74     * @param latlon lat/lon
     75     */
    6476    public void visit(LatLon latlon) {
    6577        if (latlon != null) {
     
    7284    }
    7385
     86    /**
     87     * Visiting call for east/north.
     88     * @param eastNorth east/north
     89     */
    7490    public void visit(EastNorth eastNorth) {
    7591        if (eastNorth != null) {
     
    8298    }
    8399
     100    /**
     101     * Determines if the visitor has a non null bounds area.
     102     * @return {@code true} if the visitor has a non null bounds area
     103     * @see ProjectionBounds#hasExtend
     104     */
    84105    public boolean hasExtend() {
    85106        return bounds != null && bounds.hasExtend();
     
    174195            return;
    175196        // convert size from meters to east/north units
    176         double en_size = size * Main.map.mapView.getScale() / Main.map.mapView.getDist100Pixel() * 100;
    177         visit(bounds.getMin().add(-en_size/2, -en_size/2));
    178         visit(bounds.getMax().add(+en_size/2, +en_size/2));
     197        double enSize = size * Main.map.mapView.getScale() / Main.map.mapView.getDist100Pixel() * 100;
     198        visit(bounds.getMin().add(-enSize/2, -enSize/2));
     199        visit(bounds.getMax().add(+enSize/2, +enSize/2));
    179200    }
    180201
     
    184205    }
    185206
     207    /**
     208     * Compute the bounding box of a collection of primitives.
     209     * @param primitives the collection of primitives
     210     */
    186211    public void computeBoundingBox(Collection<? extends OsmPrimitive> primitives) {
    187212        if (primitives == null) return;
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadDataHandler.java

    r8304 r8927  
    6060    @Override
    6161    public String[] getUsageExamples() {
    62         final String data = Utils.encodeUrl("<osm version='0.6'><node id='-1' lat='1' lon='2' /></osm>");
    6362        return new String[]{
    64                 "/load_data?layer_name=extra_layer&new_layer=true&data=" + data};
     63                "/load_data?layer_name=extra_layer&new_layer=true&data=" +
     64                    Utils.encodeUrl("<osm version='0.6'><node id='-1' lat='1' lon='2' /></osm>")};
    6565    }
    6666
     
    101101        protected final String layerName;
    102102
     103        /**
     104         * Constructs a new {@code LoadDataTask}.
     105         * @param newLayer if {@code true}, force download to a new layer
     106         * @param dataSet data set
     107         * @param layerName layer name
     108         */
    103109        public LoadDataTask(boolean newLayer, DataSet dataSet, String layerName) {
    104             super(newLayer, tr("Loading data"), false);
     110            super(newLayer, tr("Loading data"), false, true);
    105111            this.dataSet = dataSet;
    106112            this.layerName = layerName;
Note: See TracChangeset for help on using the changeset viewer.