Changeset 5369 in josm


Ignore:
Timestamp:
Jul 26, 2012 7:54:44 PM (10 months ago)
Author:
simon04
Message:

Suggest imagery layers for downloaded area based on <bounds>.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r5345 r5369  
    55 
    66import java.io.IOException; 
     7import java.util.ArrayList; 
    78import java.util.Collection; 
     9import java.util.HashSet; 
     10import java.util.List; 
     11import java.util.Set; 
    812import java.util.concurrent.Future; 
    913import java.util.regex.Matcher; 
    1014import java.util.regex.Pattern; 
    1115 
     16import javax.swing.JOptionPane; 
    1217import org.openstreetmap.josm.Main; 
    1318import org.openstreetmap.josm.data.Bounds; 
    1419import org.openstreetmap.josm.data.coor.LatLon; 
     20import org.openstreetmap.josm.data.imagery.ImageryInfo; 
     21import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 
    1522import org.openstreetmap.josm.data.osm.DataSet; 
    1623import org.openstreetmap.josm.data.osm.DataSource; 
    1724import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 
     25import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 
    1826import org.openstreetmap.josm.gui.PleaseWaitRunnable; 
    1927import org.openstreetmap.josm.gui.layer.Layer; 
     
    2533import org.openstreetmap.josm.io.OsmTransferCanceledException; 
    2634import org.openstreetmap.josm.io.OsmTransferException; 
     35import org.openstreetmap.josm.tools.Utils; 
    2736import org.xml.sax.SAXException; 
    2837 
     
    6776    /** 
    6877     * Loads a given URL from the OSM Server 
    69      * @param True if the data should be saved to a new layer 
    70      * @param The URL as String 
     78     * @param new_layer True if the data should be saved to a new layer 
     79     * @param url The URL as String 
    7180     */ 
    7281    public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) { 
     
    216225                targetLayer.onPostDownloadFromServer(); 
    217226            } 
     227 
     228            suggestImageryLayers(); 
    218229        } 
    219230         
     
    234245            } 
    235246        } 
     247 
     248        protected void suggestImageryLayers() { 
     249            final LatLon center = currentBounds.getCenter(); 
     250            final Set<ImageryInfo> layers = new HashSet<ImageryInfo>(); 
     251 
     252            for (ImageryInfo i : ImageryLayerInfo.instance.getDefaultLayers()) { 
     253                if (i.getBounds() != null && i.getBounds().contains(center)) { 
     254                    layers.add(i); 
     255                } 
     256            } 
     257            layers.removeAll(ImageryLayerInfo.instance.getLayers()); 
     258            if (layers.isEmpty()) { 
     259                return; 
     260            } 
     261 
     262            final List<String> layerNames = new ArrayList<String>(); 
     263            for (ImageryInfo i : layers) { 
     264                layerNames.add(i.getName()); 
     265            } 
     266 
     267            if (!ConditionalOptionPaneUtil.showConfirmationDialog( 
     268                    "download.suggest-imagery-layer", 
     269                    Main.parent, 
     270                    tr("<html>For the downloaded area, the following additional imagery layers are available: {0}" + 
     271                            "Do you want to add those layers to the <em>Imagery</em> menu?" + 
     272                            "<br>(If needed, you can remove those entries in the <em>Preferences</em>.)", 
     273                            Utils.joinAsHtmlUnorderedList(layerNames)), 
     274                    tr("Add imagery layers?"), 
     275                    JOptionPane.YES_NO_OPTION, 
     276                    JOptionPane.QUESTION_MESSAGE, 
     277                    JOptionPane.YES_OPTION)) { 
     278                return; 
     279            } 
     280 
     281            ImageryLayerInfo.addLayers(layers); 
     282        } 
     283 
    236284    } 
    237285} 
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r4881 r5369  
    9898    private String countryCode = ""; 
    9999    private String icon; 
     100    // when adding a field, also adapt the ImageryInfo(ImageryInfo) constructor 
    100101 
    101102    /** auxiliary class to save an ImageryInfo object in the preferences */ 
     
    246247 
    247248    public ImageryInfo(ImageryInfo i) { 
    248         this.name=i.name; 
    249         this.url=i.url; 
    250         this.cookies=i.cookies; 
    251         this.imageryType=i.imageryType; 
    252         this.defaultMinZoom=i.defaultMinZoom; 
    253         this.defaultMaxZoom=i.defaultMaxZoom; 
    254         this.pixelPerDegree=i.pixelPerDegree; 
     249        this.name = i.name; 
     250        this.url = i.url; 
     251        this.defaultEntry = i.defaultEntry; 
     252        this.cookies = i.cookies; 
    255253        this.eulaAcceptanceRequired = null; 
     254        this.imageryType = i.imageryType; 
     255        this.pixelPerDegree = i.pixelPerDegree; 
     256        this.defaultMaxZoom = i.defaultMaxZoom; 
     257        this.defaultMinZoom = i.defaultMinZoom; 
    256258        this.bounds = i.bounds; 
     259        this.serverProjections = i.serverProjections; 
    257260        this.attributionText = i.attributionText; 
    258261        this.attributionLinkURL = i.attributionLinkURL; 
     
    261264        this.termsOfUseText = i.termsOfUseText; 
    262265        this.termsOfUseURL = i.termsOfUseURL; 
    263         this.serverProjections = i.serverProjections; 
     266        this.countryCode = i.countryCode; 
    264267        this.icon = i.icon; 
     268    } 
     269 
     270    @Override 
     271    public boolean equals(Object o) { 
     272        if (this == o) return true; 
     273        if (o == null || getClass() != o.getClass()) return false; 
     274 
     275        ImageryInfo that = (ImageryInfo) o; 
     276 
     277        if (imageryType != that.imageryType) return false; 
     278        if (url != null ? !url.equals(that.url) : that.url != null) return false; 
     279 
     280        return true; 
     281    } 
     282 
     283    @Override 
     284    public int hashCode() { 
     285        int result = url != null ? url.hashCode() : 0; 
     286        result = 31 * result + (imageryType != null ? imageryType.hashCode() : 0); 
     287        return result; 
     288    } 
     289 
     290    @Override 
     291    public String toString() { 
     292        return "ImageryInfo{" + 
     293                "name='" + name + '\'' + 
     294                ", countryCode='" + countryCode + '\'' + 
     295                ", url='" + url + '\'' + 
     296                ", imageryType=" + imageryType + 
     297                '}'; 
    265298    } 
    266299 
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r4881 r5369  
    150150        Main.main.menu.imageryMenu.refreshImageryMenu(); 
    151151    } 
     152 
     153    public static void addLayers(Collection<ImageryInfo> infos) { 
     154        for (ImageryInfo i : infos) { 
     155            instance.add(i); 
     156        } 
     157        instance.save(); 
     158        Collections.sort(instance.layers); 
     159        Main.main.menu.imageryMenu.refreshImageryMenu(); 
     160    } 
    152161} 
Note: See TracChangeset for help on using the changeset viewer.