Ticket #7182: 7182.patch

File 7182.patch, 8.1 KB (added by simon04, 12 years ago)
  • data/maps.xsd

    diff --git a/data/maps.xsd b/data/maps.xsd
    index 59fa397..53fb356 100644
    a b  
    623623                                                <xs:element name="terms-of-use-url" minOccurs="0" maxOccurs="1" type="xs:string" />
    624624                                                <!-- The ISO 3166 country code -->
    625625                                                <xs:element name="country-code" minOccurs="0" maxOccurs="1" type="tns:iso3166" />
     626                                                <!-- A base64-encoded image that is displayed as menu/toolbar icon -->
     627                                                <xs:element name="icon-base64" minOccurs="0" maxOccurs="1" type="xs:string" />
    626628                                        </xs:all>
    627629                                </xs:complexType>
    628630                        </xs:element>
  • src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java

    diff --git a/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java b/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java
    index cb7c034..cc26148 100644
    a b public class AttributionSupport {  
    2424    private Image attrImage;
    2525    private String attrTermsText;
    2626    private String attrTermsUrl;
     27    private static final int MAX_IMAGE_SIZE = 80;
    2728    public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
    2829    public static final Font ATTR_LINK_FONT;
    2930   
    public class AttributionSupport {  
    4243        boolean requireAttr = source.requiresAttribution();
    4344        if (requireAttr) {
    4445            attrImage = source.getAttributionImage();
     46            if(attrImage!=null)
     47                System.out.println(attrImage.getWidth(null));
     48            if (attrImage != null
     49                    && (attrImage.getWidth(null) > MAX_IMAGE_SIZE
     50                    || attrImage.getHeight(null) > MAX_IMAGE_SIZE)) {
     51                attrImage = attrImage.getScaledInstance(MAX_IMAGE_SIZE, MAX_IMAGE_SIZE, Image.SCALE_SMOOTH);
     52            }
    4553            attrTermsText = source.getTermsOfUseText();
    4654            attrTermsUrl = source.getTermsOfUseURL();
    4755            if (attrTermsUrl != null && attrTermsText == null) {
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java b/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
    index 95cccca..7d40cf6 100644
    a b package org.openstreetmap.josm.actions;  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Image;
    67import java.awt.event.ActionEvent;
    7 
     8import javax.swing.Action;
     9import javax.swing.ImageIcon;
    810import javax.swing.JOptionPane;
    9 
    1011import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1213import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    1314import org.openstreetmap.josm.gui.layer.ImageryLayer;
     15import sun.misc.BASE64Decoder;
    1416
    1517public class AddImageryLayerAction extends JosmAction implements AdaptableAction {
    1618
     19    private static final int MAX_ICON_SIZE = 24;
    1720    private final ImageryInfo info;
    1821
    1922    public AddImageryLayerAction(ImageryInfo info) {
    20         super(info.getMenuName(), /* ICON */"imagery_menu", tr("Add imagery layer {0}",info.getName()), null, false, false);
     23        super(info.getMenuName(),
     24                /* ICON */ "imagery_menu",
     25                tr("Add imagery layer {0}", info.getName()),
     26                null, false, false);
    2127        putValue("toolbar", "imagery_" + info.getToolbarName());
    2228        this.info = info;
    2329        installAdapters();
     30
     31        /* add toolbar icon from attribution image */
     32        try {
     33            ImageIcon i = null;
     34            if (info.getIconBase64() != null) {
     35                i = new ImageIcon(new BASE64Decoder().decodeBuffer(info.getIconBase64()));
     36                if (i.getIconHeight() > MAX_ICON_SIZE || i.getIconWidth() > MAX_ICON_SIZE) {
     37                    i = new ImageIcon(i.getImage().getScaledInstance(MAX_ICON_SIZE, MAX_ICON_SIZE, Image.SCALE_SMOOTH));
     38                }
     39                putValue(Action.SMALL_ICON, i);
     40            } else if (info.getAttributionImage() != null) {
     41                i = new ImageIcon(info.getAttributionImage());
     42            }
     43            if (i != null) {
     44                if (i.getIconHeight() > MAX_ICON_SIZE || i.getIconWidth() > MAX_ICON_SIZE) {
     45                    i = new ImageIcon(i.getImage().getScaledInstance(MAX_ICON_SIZE, MAX_ICON_SIZE, Image.SCALE_SMOOTH));
     46                }
     47                putValue(Action.SMALL_ICON, i);
     48            }
     49        } catch (Exception ex) {
     50            throw new RuntimeException(ex.getMessage(), ex);
     51        }
    2452    }
    2553
    2654    @Override
    public class AddImageryLayerAction extends JosmAction implements AdaptableAction  
    5280            setEnabled(false);
    5381        }
    5482    }
    55 }
     83}
     84 No newline at end of file
  • src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java b/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
    index 955d94e..59170ab 100644
    a b public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    8484    private String termsOfUseText;
    8585    private String termsOfUseURL;
    8686    private String countryCode = "";
     87    private String iconBase64;
    8788
    8889    /** auxiliary class to save an ImageryInfo object in the preferences */
    8990    public static class ImageryPreferenceEntry {
    public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    105106        @pref String bounds;
    106107        @pref String shapes;
    107108        @pref String projections;
     109        @pref String iconBase64;
    108110
    109111        public ImageryPreferenceEntry() {
    110112        }
    public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    125127            max_zoom = i.defaultMaxZoom;
    126128            min_zoom = i.defaultMinZoom;
    127129            cookies = i.cookies;
     130            iconBase64 = i.iconBase64;
    128131            if (i.bounds != null) {
    129132                bounds = i.bounds.encodeAsString(",");
    130133                String shapesString = "";
    public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    218221        termsOfUseText = e.terms_of_use_text;
    219222        termsOfUseURL = e.terms_of_use_url;
    220223        countryCode = e.country_code;
     224        iconBase64 = e.iconBase64;
    221225    }
    222226
    223227    public ImageryInfo(Collection<String> list) {
    public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    284288        this.termsOfUseText = i.termsOfUseText;
    285289        this.termsOfUseURL = i.termsOfUseURL;
    286290        this.serverProjections = i.serverProjections;
     291        this.iconBase64 = i.iconBase64;
    287292    }
    288293
    289294    @Override
    public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {  
    514519        this.countryCode = countryCode;
    515520    }
    516521
     522    public String getIconBase64() {
     523        return iconBase64;
     524    }
     525
     526    public void setIconBase64(String iconBase64) {
     527        this.iconBase64 = iconBase64;
     528    }
     529
    517530    /**
    518531     * Get the projections supported by the server. Only relevant for
    519532     * WMS-type ImageryInfo at the moment.
  • src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    diff --git a/src/org/openstreetmap/josm/io/imagery/ImageryReader.java b/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
    index acdec59..97e0a06 100644
    a b public class ImageryReader {  
    129129                        "terms-of-use-text",
    130130                        "terms-of-use-url",
    131131                        "country-code",
     132                        "icon-base64",
    132133                    }).contains(qName)) {
    133134                        newState = State.ENTRY_ATTRIBUTE;
    134135                    } else if (qName.equals("bounds")) {
    public class ImageryReader {  
    259260                        entry.setTermsOfUseURL(accumulator.toString());
    260261                    } else if (qName.equals("country-code")) {
    261262                        entry.setCountryCode(accumulator.toString());
     263                    } else if (qName.equals("icon-base64")) {
     264                        entry.setIconBase64(accumulator.toString());
    262265                    } else {
    263266                    }
    264267                    break;