Changeset 4195 in josm


Ignore:
Timestamp:
Jul 3, 2011 1:02:51 AM (23 months ago)
Author:
stoecker
Message:

fix slippy map attribution handling and allow bounds and attribution specification in maps specification (not exposed to user currently)

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

Legend:

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

    r4194 r4195  
    77import java.util.regex.Pattern; 
    88 
     9import javax.swing.ImageIcon; 
     10 
     11import org.openstreetmap.josm.Main; 
     12import org.openstreetmap.josm.data.Bounds; 
    913import org.openstreetmap.josm.io.OsmApi; 
    1014import org.openstreetmap.josm.tools.CheckParameterUtil; 
     15import org.openstreetmap.josm.tools.ImageProvider; 
     16import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik; 
     17import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 
    1118 
    1219/** 
     
    3340    } 
    3441 
    35     String name; 
     42    private String name; 
    3643    private String url = null; 
    37     String cookies = null; 
    38     public final String eulaAcceptanceRequired; 
    39     ImageryType imageryType = ImageryType.WMS; 
    40     double pixelPerDegree = 0.0; 
    41     int maxZoom = 0; 
    42     int defaultMaxZoom = 0; 
    43     int defaultMinZoom = 0; 
     44    private String cookies = null; 
     45    private String eulaAcceptanceRequired= null; 
     46    private ImageryType imageryType = ImageryType.WMS; 
     47    private double pixelPerDegree = 0.0; 
     48    private int maxZoom = 0; 
     49    private int defaultMaxZoom = 0; 
     50    private int defaultMinZoom = 0; 
     51    private Bounds bounds = null; 
     52    private String attributionText; 
     53    private String attributionImage; 
     54    private String attributionLinkURL; 
     55    private String termsOfUseURL; 
    4456 
    4557    public ImageryInfo(String name) { 
    4658        this.name=name; 
    47         this.eulaAcceptanceRequired = null; 
    4859    } 
    4960 
     
    5162        this.name=name; 
    5263        setUrl(url); 
    53         this.eulaAcceptanceRequired = null; 
    5464    } 
    5565 
     
    7282        this.cookies=cookies; 
    7383        this.pixelPerDegree=pixelPerDegree; 
    74         this.eulaAcceptanceRequired = null; 
    7584    } 
    7685 
    7786    public ArrayList<String> getInfoArray() { 
    78         String e2 = null; 
    79         String e3 = null; 
    80         String e4 = null; 
    81         if(url != null && !url.isEmpty()) { 
    82             e2 = getFullUrl(); 
    83         } 
    84         if(cookies != null && !cookies.isEmpty()) { 
    85             e3 = cookies; 
    86         } 
    87         if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 
    88             if(pixelPerDegree != 0.0) { 
    89                 e4 = String.valueOf(pixelPerDegree); 
    90             } 
    91         } else { 
    92             if(maxZoom != 0) { 
    93                 e4 = String.valueOf(maxZoom); 
    94             } 
    95         } 
    96         if(e4 != null && e3 == null) { 
    97             e3 = ""; 
    98         } 
    99         if(e3 != null && e2 == null) { 
    100             e2 = ""; 
    101         } 
    102  
    10387        ArrayList<String> res = new ArrayList<String>(); 
    10488        res.add(name); 
    105         if(e2 != null) { 
    106             res.add(e2); 
    107         } 
    108         if(e3 != null) { 
    109             res.add(e3); 
    110         } 
    111         if(e4 != null) { 
    112             res.add(e4); 
    113         } 
     89        res.add((url != null && !url.isEmpty()) ? getFullUrl() : null); 
     90        res.add(cookies); 
     91        if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 
     92            res.add(pixelPerDegree != 0.0 ? String.valueOf(pixelPerDegree) : null); 
     93        } else { 
     94            res.add(maxZoom != 0 ? String.valueOf(maxZoom) : null); 
     95        } 
     96        res.add(bounds != null ? bounds.encodeAsString(",") : null); 
     97        res.add(attributionText); 
     98        res.add(attributionLinkURL); 
     99        res.add(attributionImage); 
     100        res.add(termsOfUseURL); 
    114101        return res; 
    115102    } 
     
    118105        ArrayList<String> array = new ArrayList<String>(list); 
    119106        this.name=array.get(0); 
    120         if(array.size() >= 2) { 
     107        if(array.size() >= 2 && !array.get(1).isEmpty()) { 
    121108            setUrl(array.get(1)); 
    122109        } 
    123         if(array.size() >= 3) { 
     110        if(array.size() >= 3 && !array.get(2).isEmpty()) { 
    124111            this.cookies=array.get(2); 
    125112        } 
    126         if(array.size() >= 4) { 
     113        if(array.size() >= 4 && !array.get(3).isEmpty()) { 
    127114            if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 
    128115                this.pixelPerDegree=Double.valueOf(array.get(3)); 
     
    131118            } 
    132119        } 
    133         this.eulaAcceptanceRequired = null; 
     120        if(array.size() >= 5 && !array.get(4).isEmpty()) { 
     121            try { 
     122                bounds = new Bounds(array.get(4), ","); 
     123            } catch (IllegalArgumentException e) { 
     124                Main.warn(e.toString()); 
     125            } 
     126        } 
     127        if(array.size() >= 6 && !array.get(5).isEmpty()) { 
     128            setAttributionText(array.get(5)); 
     129        } 
     130        if(array.size() >= 7 && !array.get(6).isEmpty()) { 
     131            setAttributionLinkURL(array.get(6)); 
     132        } 
     133        if(array.size() >= 8 && !array.get(7).isEmpty()) { 
     134            setAttributionImage(array.get(7)); 
     135        } 
     136        if(array.size() >= 9 && !array.get(8).isEmpty()) { 
     137            setTermsOfUseURL(array.get(8)); 
     138        } 
    134139    } 
    135140 
     
    139144        this.cookies=i.cookies; 
    140145        this.imageryType=i.imageryType; 
     146        this.defaultMinZoom=i.defaultMinZoom; 
     147        this.maxZoom=i.maxZoom; 
    141148        this.defaultMaxZoom=i.defaultMaxZoom; 
    142149        this.pixelPerDegree=i.pixelPerDegree; 
    143150        this.eulaAcceptanceRequired = null; 
     151        this.bounds = i.bounds; 
     152        this.attributionImage = i.attributionImage; 
     153        this.attributionLinkURL = i.attributionLinkURL; 
     154        this.attributionText = i.attributionText; 
     155        this.termsOfUseURL = i.termsOfUseURL; 
    144156    } 
    145157 
     
    168180    public void setMaxZoom(int maxZoom) { 
    169181        this.maxZoom = maxZoom; 
     182    } 
     183 
     184    public void setBounds(Bounds b) { 
     185        this.bounds = b; 
     186    } 
     187 
     188    public void setAttributionText(String text) { 
     189         attributionText = text; 
     190    } 
     191 
     192    public void setAttributionImage(String text) { 
     193        attributionImage = text; 
     194    } 
     195 
     196    public void setAttributionLinkURL(String text) { 
     197        attributionLinkURL = text; 
     198    } 
     199 
     200    public void setTermsOfUseURL(String text) { 
     201        termsOfUseURL = text; 
    170202    } 
    171203 
     
    224256    } 
    225257 
     258    public String getEulaAcceptanceRequired() { 
     259        return eulaAcceptanceRequired; 
     260    } 
     261 
    226262    public String getFullUrl() { 
    227263        return imageryType.getUrlString() + (defaultMaxZoom != 0 
     
    247283        } 
    248284        return res; 
     285    } 
     286 
     287    public void setAttribution(TMSTileSource s) 
     288    { 
     289        if(attributionLinkURL != null) { 
     290            if(attributionLinkURL.equals("osm")) 
     291                s.setAttributionLinkURL(new Mapnik().getAttributionLinkURL()); 
     292            else 
     293                s.setAttributionLinkURL(attributionLinkURL); 
     294        } 
     295        if(attributionText != null) { 
     296            if(attributionText.equals("osm")) 
     297                s.setAttributionText(new Mapnik().getAttributionText(0, null, null)); 
     298            else 
     299                s.setAttributionText(attributionText); 
     300        } 
     301        if(attributionImage != null) { 
     302            ImageIcon i = ImageProvider.getIfAvailable(null, attributionImage); 
     303            if(i != null) 
     304                s.setAttributionImage(i.getImage()); 
     305        } 
     306        if(termsOfUseURL != null) { 
     307            if(termsOfUseURL.equals("osm")) 
     308                s.setTermsOfUseURL(new Mapnik().getTermsOfUseURL()); 
     309            else 
     310                s.setTermsOfUseURL(termsOfUseURL); 
     311        } 
    249312    } 
    250313 
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r4145 r4195  
    1717import org.openstreetmap.josm.Main; 
    1818import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 
     19import org.openstreetmap.josm.data.Bounds; 
    1920import org.openstreetmap.josm.io.MirroredInputStream; 
    2021 
     
    7374                    { 
    7475                        String val[] = line.split(";"); 
    75                         if(!line.startsWith("#") && (val.length == 3 || val.length == 4)) { 
     76                        if(!line.startsWith("#") && val.length >= 3) { 
    7677                            boolean force = "true".equals(val[0]); 
    7778                            String name = tr(val[1]); 
     
    7980                            String eulaAcceptanceRequired = null; 
    8081 
    81                             if (val.length == 4) { 
     82                            if (val.length >= 4 && !val[3].isEmpty()) { 
    8283                                // 4th parameter optional for license agreement (EULA) 
    8384                                eulaAcceptanceRequired = val[3]; 
    8485                            } 
    8586 
    86                             defaultLayers.add(new ImageryInfo(name, url, eulaAcceptanceRequired)); 
     87                            ImageryInfo info = new ImageryInfo(name, url, eulaAcceptanceRequired); 
     88 
     89                            if (val.length >= 5 && !val[4].isEmpty()) { 
     90                                // 5th parameter optional for bounds 
     91                                try { 
     92                                    info.setBounds(new Bounds(val[4], ",")); 
     93                                } catch (IllegalArgumentException e) { 
     94                                    Main.warn(e.toString()); 
     95                                } 
     96                            } 
     97                            if (val.length >= 6 && !val[5].isEmpty()) { 
     98                                info.setAttributionText(val[5]); 
     99                            } 
     100                            if (val.length >= 7 && !val[6].isEmpty()) { 
     101                                info.setAttributionLinkURL(val[6]); 
     102                            } 
     103                            if (val.length >= 8 && !val[7].isEmpty()) { 
     104                                info.setTermsOfUseURL(val[7]); 
     105                            } 
     106                            if (val.length >= 9 && !val[8].isEmpty()) { 
     107                                info.setAttributionImage(val[8]); 
     108                            } 
     109 
     110                            defaultLayers.add(info); 
    87111 
    88112                            if (force) { 
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r4168 r4195  
    33 
    44import java.awt.Color; 
     5import java.awt.Desktop; 
    56import java.awt.Dimension; 
    67import java.awt.Graphics; 
     
    1213import java.io.File; 
    1314import java.io.IOException; 
     15import java.net.URI; 
     16import java.net.URISyntaxException; 
    1417import java.util.ArrayList; 
    1518import java.util.Arrays; 
     
    217220    } 
    218221 
     222    public boolean handleAttribution(Point p, boolean click) { 
     223        TileSource ts = tileController.getTileSource(); 
     224        if(!ts.requiresAttribution()) 
     225            return false; 
     226 
     227        /* TODO: Somehow indicate the link is clickable state to user */ 
     228 
     229        try { 
     230            if((attrImageBounds != null && attrImageBounds.contains(p)) 
     231            || (attrTextBounds != null && attrTextBounds.contains(p))) { 
     232                if(click) 
     233                    Desktop.getDesktop().browse(new URI(ts.getAttributionLinkURL())); 
     234                /*else 
     235                    Main.warn(ts.getAttributionLinkURL());*/ 
     236                return true; 
     237            } else if(attrToUBounds.contains(p)) { 
     238                if(click) 
     239                    Desktop.getDesktop().browse(new URI(ts.getTermsOfUseURL())); 
     240                /*else 
     241                    Main.warn(ts.getTermsOfUseURL());*/ 
     242                return true; 
     243            } 
     244        } catch (IOException e1) { 
     245            e1.printStackTrace(); 
     246        } catch (URISyntaxException e1) { 
     247            e1.printStackTrace(); 
     248        } 
     249        return false; 
     250    } 
     251 
    219252    protected Point getTopLeftCoordinates() { 
    220253        return new Point(center.x - (getWidth() / 2), center.y - (getHeight() / 2)); 
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapControler.java

    r3720 r4195  
    149149                iSizeButton.toggle(); 
    150150                iSlippyMapChooser.resizeSlippyMap(); 
     151            } else if (iSlippyMapChooser.handleAttribution(e.getPoint(), true)) { 
     152                /* do nothing, handleAttribution() already did the work */ 
    151153            } else if (sourceButton == SourceButton.HIDE_OR_SHOW) { 
    152154                iSourceButton.toggle(); 
    153155                iSlippyMapChooser.repaint(); 
    154  
    155156            } else if (sourceButton != 0) { 
    156157                iSlippyMapChooser.toggleMapSource(iSourceButton.hitToTileSource(sourceButton)); 
     
    170171    @Override 
    171172    public void mouseMoved(MouseEvent e) { 
     173        iSlippyMapChooser.handleAttribution(e.getPoint(), false); 
    172174    } 
    173175 
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4188 r4195  
    159159    private Image attrImage; 
    160160    private String attrTermsUrl; 
    161     private Rectangle attrImageBounds, attrToUBounds; 
     161    private Rectangle attrImageBounds, attrToUBounds, attrTextBounds; 
    162162    private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13); 
    163163    private static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); 
     
    233233    public static TileSource getTileSource(ImageryInfo info) { 
    234234        if (info.getImageryType() == ImageryType.TMS) { 
    235             if(ImageryInfo.isUrlWithPatterns(info.getUrl())) 
    236                 return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
    237             else 
    238                 return new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
     235            if(ImageryInfo.isUrlWithPatterns(info.getUrl())) { 
     236                TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
     237                info.setAttribution(t); 
     238                return t; 
     239            } else { 
     240                TMSTileSource t = new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 
     241                info.setAttribution(t); 
     242                return t; 
     243            } 
    239244        } else if (info.getImageryType() == ImageryType.BING) 
    240245            return new BingAerialTileSource(); 
     
    317322        if(!isProjectionSupported(Main.getProjection())) { 
    318323              JOptionPane.showMessageDialog(Main.parent, 
    319                   tr("TMS layers do not support the projection {1}.\n{2}\n" 
     324                  tr("TMS layers do not support the projection {0}.\n{1}\n" 
    320325                  + "Change the projection or remove the layer.", 
    321326                      Main.getProjection().toCode(), nameSupportedProjections()), 
     
    455460                                return; 
    456461 
    457                             if(attrImageBounds != null && attrImageBounds.contains(e.getPoint())) { 
     462                            if((attrImageBounds != null && attrImageBounds.contains(e.getPoint())) 
     463                            || (attrTextBounds != null && attrTextBounds.contains(e.getPoint()))) { 
    458464                                try { 
    459465                                    java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); 
     
    12001206            // Draw terms of use text 
    12011207            Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g); 
    1202             int textHeight = (int) termsStringBounds.getHeight() - 5; 
     1208            int textRealHeight = (int) termsStringBounds.getHeight(); 
     1209            int textHeight = textRealHeight - 5; 
    12031210            int textWidth = (int) termsStringBounds.getWidth(); 
    12041211            int termsTextY = mv.getHeight() - textHeight; 
     
    12061213                int x = 2; 
    12071214                int y = mv.getHeight() - textHeight; 
    1208                 attrToUBounds = new Rectangle(x, y, textWidth, textHeight); 
     1215                attrToUBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 
    12091216                myDrawString(g, "Background Terms of Use", x, y); 
    12101217            } 
     
    12281235                int y = mv.getHeight() - textHeight; 
    12291236                myDrawString(g, attributionText, x, y); 
     1237                attrTextBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 
    12301238            } 
    12311239 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r4193 r4195  
    530530                    } 
    531531 
    532                     if (info.eulaAcceptanceRequired != null) { 
    533                         if (!confirmEulaAcceptance(gui, info.eulaAcceptanceRequired)) { 
     532                    if (info.getEulaAcceptanceRequired() != null) { 
     533                        if (!confirmEulaAcceptance(gui, info.getEulaAcceptanceRequired())) { 
    534534                            continue outer; 
    535535                        } 
Note: See TracChangeset for help on using the changeset viewer.