Changeset 4506 in josm


Ignore:
Timestamp:
2011-10-08T13:04:58+02:00 (13 years ago)
Author:
bastiK
Message:

fixed #6816 - attribution for wmslayer (see [o26806])

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r4492 r4506  
    22package org.openstreetmap.josm.data.imagery;
    33
     4import java.awt.Image;
    45import java.util.Arrays;
    56import java.util.ArrayList;
     
    1819import org.openstreetmap.josm.tools.CheckParameterUtil;
    1920import org.openstreetmap.josm.tools.ImageProvider;
     21import org.openstreetmap.gui.jmapviewer.Coordinate;
     22import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
    2023import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik;
    21 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
     24import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTileSource;
    2225
    2326/**
     
    2629 * @author Frederik Ramm <frederik@remote.org>
    2730 */
    28 public class ImageryInfo implements Comparable<ImageryInfo> {
     31public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
    2932
    3033    public enum ImageryType {
     
    325328    }
    326329
    327     public String getAttributionText() {
     330    @Override
     331    public boolean requiresAttribution() {
     332        return attributionText != null || attributionImage != null || termsOfUseText != null || termsOfUseURL != null;
     333    }
     334
     335    @Override
     336    public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {
    328337        return attributionText;
     338    }
     339
     340    @Override
     341    public String getAttributionLinkURL() {
     342        return attributionLinkURL;
     343    }
     344
     345    @Override
     346    public Image getAttributionImage() {
     347        ImageIcon i = ImageProvider.getIfAvailable(attributionImage);
     348        if (i != null) {
     349            return i.getImage();
     350        }
     351        return null;
     352    }
     353
     354    @Override
     355    public String getAttributionImageURL() {
     356        return attributionImageURL;
     357    }
     358
     359    @Override
     360    public String getTermsOfUseText() {
     361        return termsOfUseText;
     362    }
     363
     364    @Override
     365    public String getTermsOfUseURL() {
     366        return termsOfUseURL;
    329367    }
    330368
     
    333371    }
    334372
     373    public void setAttributionImageURL(String text) {
     374        attributionImageURL = text;
     375    }
     376
    335377    public void setAttributionImage(String text) {
    336378        attributionImage = text;
    337379    }
    338380
    339     public void setAttributionImageURL(String text) {
    340         attributionImageURL = text;
    341     }
    342 
    343     public String getAttributionLinkURL() {
    344         return attributionLinkURL;
    345     }
    346 
    347381    public void setAttributionLinkURL(String text) {
    348382        attributionLinkURL = text;
     
    351385    public void setTermsOfUseText(String text) {
    352386        termsOfUseText = text;
    353     }
    354 
    355     public String getTermsOfUseURL() {
    356         return termsOfUseURL;
    357387    }
    358388
     
    542572     * Applies the attribution from this object to a TMSTileSource.
    543573     */
    544     public void setAttribution(TMSTileSource s) {
     574    public void setAttribution(AbstractTileSource s) {
    545575        if (attributionText != null) {
    546576            if (attributionText.equals("osm")) {
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4492 r4506  
    12161216            this.paintTileText(ts, t, g, mv, displayZoomLevel, t);
    12171217        }
    1218        
     1218
    12191219        attribution.paintAttribution(g, mv.getWidth(), mv.getHeight(), getShiftedCoord(topLeft), getShiftedCoord(botRight), displayZoomLevel, this);
    12201220
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r4492 r4506  
    77import java.awt.Graphics;
    88import java.awt.Graphics2D;
     9import java.awt.Image;
    910import java.awt.event.ActionEvent;
     11import java.awt.event.MouseAdapter;
     12import java.awt.event.MouseEvent;
    1013import java.awt.image.BufferedImage;
     14import java.awt.image.ImageObserver;
    1115import java.io.File;
    1216import java.io.FileInputStream;
     
    3034import javax.swing.JMenuItem;
    3135import javax.swing.JOptionPane;
    32 
     36import javax.swing.SwingUtilities;
     37
     38import org.openstreetmap.gui.jmapviewer.AttributionSupport;
    3339import org.openstreetmap.josm.Main;
    3440import org.openstreetmap.josm.actions.DiskAccessAction;
     
    5157import org.openstreetmap.josm.data.preferences.IntegerProperty;
    5258import org.openstreetmap.josm.gui.MapView;
     59import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5360import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    5461import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    6370 * fetched this way is tiled and managed to the disc to reduce server load.
    6471 */
    65 public class WMSLayer extends ImageryLayer implements PreferenceChangedListener {
     72public class WMSLayer extends ImageryLayer implements ImageObserver, PreferenceChangedListener {
    6673    public static final BooleanProperty PROP_ALPHA_CHANNEL = new BooleanProperty("imagery.wms.alpha_channel", true);
    6774    public static final IntegerProperty PROP_SIMULTANEOUS_CONNECTIONS = new IntegerProperty("imagery.wms.simultaneousConnections", 3);
     
    8592    protected final MapView mv;
    8693    public WmsCache cache;
    87 
     94    private AttributionSupport attribution = new AttributionSupport();
    8895
    8996    // Image index boundary for current view
     
    142149        resolution = mv.getDist100PixelText();
    143150
     151        attribution.initialize(this.info);
     152
    144153        if(info.getUrl() != null)
    145154            startGrabberThreads();
    146155
    147156        Main.pref.addPreferenceChangeListener(this);
     157
     158        SwingUtilities.invokeLater(new Runnable() {
     159            @Override
     160            public void run() {
     161                final MouseAdapter adapter = new MouseAdapter() {
     162                    @Override
     163                    public void mouseClicked(MouseEvent e) {
     164                        if (!isVisible()) return;
     165                        if (e.getButton() == MouseEvent.BUTTON1) {
     166                            attribution.handleAttribution(e.getPoint(), true);
     167                        }
     168                    }
     169                };
     170                Main.map.mapView.addMouseListener(adapter);
     171
     172                MapView.addLayerChangeListener(new LayerChangeListener() {
     173                    @Override
     174                    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     175                        //
     176                    }
     177
     178                    @Override
     179                    public void layerAdded(Layer newLayer) {
     180                        //
     181                    }
     182
     183                    @Override
     184                    public void layerRemoved(Layer oldLayer) {
     185                        if (oldLayer == WMSLayer.this) {
     186                            Main.map.mapView.removeMouseListener(adapter);
     187                            MapView.removeLayerChangeListener(this);
     188                        }
     189                    }
     190                });
     191            }
     192        });
    148193    }
    149194
     
    230275            downloadAndPaintVisible(g, mv, false);
    231276        }
     277
     278        attribution.paintAttribution(g, mv.getWidth(), mv.getHeight(), null, null, 0, this);
     279
    232280    }
    233281
     
    289337
    290338    /**
    291      * 
     339     *
    292340     * @return When overlapping is enabled, return visible part of tile. Otherwise return original image
    293341     */
     
    886934        return tr("Supported projections are: {0}", res);
    887935    }
     936
     937    @Override
     938    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
     939        boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0);
     940        Main.map.repaint(done ? 0 : 100);
     941        return !done;
     942    }
     943
    888944}
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r4403 r4506  
    9999    public static ImageIcon get(String name) {
    100100        return get("", name);
     101    }
     102
     103    public static ImageIcon getIfAvailable(String name) {
     104        return getIfAvailable((Collection<String>) null, null, "", name);
    101105    }
    102106
Note: See TracChangeset for help on using the changeset viewer.