diff --git a/data/maps.xsd b/data/maps.xsd
index 59fa397..98195bb 100644
|
a
|
b
|
|
| 623 | 623 | <xs:element name="terms-of-use-url" minOccurs="0" maxOccurs="1" type="xs:string" /> |
| 624 | 624 | <!-- The ISO 3166 country code --> |
| 625 | 625 | <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" minOccurs="0" maxOccurs="1" type="xs:string" /> |
| 626 | 628 | </xs:all> |
| 627 | 629 | </xs:complexType> |
| 628 | 630 | </xs:element> |
diff --git a/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java b/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
index 95cccca..80cfa4d 100644
|
a
|
b
|
package org.openstreetmap.josm.actions;
|
| 3 | 3 | |
| 4 | 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | 5 | |
| | 6 | import java.awt.Image; |
| 6 | 7 | import java.awt.event.ActionEvent; |
| 7 | | |
| | 8 | import javax.swing.Action; |
| | 9 | import javax.swing.ImageIcon; |
| 8 | 10 | import javax.swing.JOptionPane; |
| 9 | | |
| 10 | 11 | import org.openstreetmap.josm.Main; |
| 11 | 12 | import org.openstreetmap.josm.data.imagery.ImageryInfo; |
| 12 | 13 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; |
| 13 | 14 | import org.openstreetmap.josm.gui.layer.ImageryLayer; |
| | 15 | import org.openstreetmap.josm.tools.ImageProvider; |
| 14 | 16 | |
| 15 | 17 | public class AddImageryLayerAction extends JosmAction implements AdaptableAction { |
| 16 | 18 | |
| | 19 | private static final int MAX_ICON_SIZE = 24; |
| 17 | 20 | private final ImageryInfo info; |
| 18 | 21 | |
| 19 | 22 | 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); |
| 21 | 27 | putValue("toolbar", "imagery_" + info.getToolbarName()); |
| 22 | 28 | this.info = info; |
| 23 | 29 | installAdapters(); |
| | 30 | |
| | 31 | // change toolbar icon from if specified |
| | 32 | try { |
| | 33 | if (info.getIcon() != null) { |
| | 34 | ImageIcon i = ImageProvider.getIfAvailable(info.getIcon()); |
| | 35 | if (i.getIconHeight() > MAX_ICON_SIZE || i.getIconWidth() > MAX_ICON_SIZE) { |
| | 36 | i = new ImageIcon(i.getImage().getScaledInstance(MAX_ICON_SIZE, MAX_ICON_SIZE, Image.SCALE_SMOOTH)); |
| | 37 | } |
| | 38 | putValue(Action.SMALL_ICON, i); |
| | 39 | } |
| | 40 | } catch (Exception ex) { |
| | 41 | throw new RuntimeException(ex.getMessage(), ex); |
| | 42 | } |
| 24 | 43 | } |
| 25 | 44 | |
| 26 | 45 | @Override |
| … |
… |
public class AddImageryLayerAction extends JosmAction implements AdaptableAction
|
| 52 | 71 | setEnabled(false); |
| 53 | 72 | } |
| 54 | 73 | } |
| 55 | | } |
| | 74 | } |
| | 75 | No newline at end of file |
diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java b/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
index 955d94e..538eda4 100644
|
a
|
b
|
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 84 | 84 | private String termsOfUseText; |
| 85 | 85 | private String termsOfUseURL; |
| 86 | 86 | private String countryCode = ""; |
| | 87 | private String icon; |
| 87 | 88 | |
| 88 | 89 | /** auxiliary class to save an ImageryInfo object in the preferences */ |
| 89 | 90 | public static class ImageryPreferenceEntry { |
| … |
… |
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 105 | 106 | @pref String bounds; |
| 106 | 107 | @pref String shapes; |
| 107 | 108 | @pref String projections; |
| | 109 | @pref String icon; |
| 108 | 110 | |
| 109 | 111 | public ImageryPreferenceEntry() { |
| 110 | 112 | } |
| … |
… |
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 125 | 127 | max_zoom = i.defaultMaxZoom; |
| 126 | 128 | min_zoom = i.defaultMinZoom; |
| 127 | 129 | cookies = i.cookies; |
| | 130 | icon = i.icon; |
| 128 | 131 | if (i.bounds != null) { |
| 129 | 132 | bounds = i.bounds.encodeAsString(","); |
| 130 | 133 | String shapesString = ""; |
| … |
… |
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 218 | 221 | termsOfUseText = e.terms_of_use_text; |
| 219 | 222 | termsOfUseURL = e.terms_of_use_url; |
| 220 | 223 | countryCode = e.country_code; |
| | 224 | icon = e.icon; |
| 221 | 225 | } |
| 222 | 226 | |
| 223 | 227 | public ImageryInfo(Collection<String> list) { |
| … |
… |
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 284 | 288 | this.termsOfUseText = i.termsOfUseText; |
| 285 | 289 | this.termsOfUseURL = i.termsOfUseURL; |
| 286 | 290 | this.serverProjections = i.serverProjections; |
| | 291 | this.icon = i.icon; |
| 287 | 292 | } |
| 288 | 293 | |
| 289 | 294 | @Override |
| … |
… |
public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
|
| 514 | 519 | this.countryCode = countryCode; |
| 515 | 520 | } |
| 516 | 521 | |
| | 522 | public String getIcon() { |
| | 523 | return icon; |
| | 524 | } |
| | 525 | |
| | 526 | public void setIcon(String icon) { |
| | 527 | this.icon = icon; |
| | 528 | } |
| | 529 | |
| 517 | 530 | /** |
| 518 | 531 | * Get the projections supported by the server. Only relevant for |
| 519 | 532 | * WMS-type ImageryInfo at the moment. |
diff --git a/src/org/openstreetmap/josm/io/imagery/ImageryReader.java b/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
index acdec59..10f8ab3 100644
|
a
|
b
|
package org.openstreetmap.josm.io.imagery;
|
| 4 | 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | 5 | import static org.openstreetmap.josm.tools.Utils.equal; |
| 6 | 6 | |
| 7 | | import java.io.BufferedReader; |
| 8 | 7 | import java.io.IOException; |
| 9 | 8 | import java.io.InputStream; |
| 10 | | import java.io.InputStreamReader; |
| 11 | | import java.io.UnsupportedEncodingException; |
| 12 | 9 | import java.util.ArrayList; |
| 13 | 10 | import java.util.Arrays; |
| 14 | 11 | import java.util.List; |
| … |
… |
import java.util.Stack;
|
| 17 | 14 | import javax.xml.parsers.ParserConfigurationException; |
| 18 | 15 | import javax.xml.parsers.SAXParserFactory; |
| 19 | 16 | |
| 20 | | import org.openstreetmap.josm.Main; |
| 21 | 17 | import org.openstreetmap.josm.data.imagery.ImageryInfo; |
| 22 | 18 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; |
| 23 | 19 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; |
| 24 | 20 | import org.openstreetmap.josm.data.imagery.Shape; |
| 25 | 21 | import org.openstreetmap.josm.io.MirroredInputStream; |
| 26 | 22 | import org.openstreetmap.josm.io.UTFInputStreamReader; |
| 27 | | import org.openstreetmap.josm.tools.Utils; |
| 28 | 23 | import org.xml.sax.Attributes; |
| 29 | 24 | import org.xml.sax.InputSource; |
| 30 | 25 | import org.xml.sax.SAXException; |
| … |
… |
public class ImageryReader {
|
| 129 | 124 | "terms-of-use-text", |
| 130 | 125 | "terms-of-use-url", |
| 131 | 126 | "country-code", |
| | 127 | "icon", |
| 132 | 128 | }).contains(qName)) { |
| 133 | 129 | newState = State.ENTRY_ATTRIBUTE; |
| 134 | 130 | } else if (qName.equals("bounds")) { |
| … |
… |
public class ImageryReader {
|
| 259 | 255 | entry.setTermsOfUseURL(accumulator.toString()); |
| 260 | 256 | } else if (qName.equals("country-code")) { |
| 261 | 257 | entry.setCountryCode(accumulator.toString()); |
| | 258 | } else if (qName.equals("icon")) { |
| | 259 | entry.setIcon(accumulator.toString()); |
| 262 | 260 | } else { |
| 263 | 261 | } |
| 264 | 262 | break; |
diff --git a/src/org/openstreetmap/josm/tools/ImageProvider.java b/src/org/openstreetmap/josm/tools/ImageProvider.java
index 39678d6..06ee30c 100644
|
a
|
b
|
import java.io.ByteArrayInputStream;
|
| 20 | 20 | import java.io.File; |
| 21 | 21 | import java.io.IOException; |
| 22 | 22 | import java.io.InputStream; |
| | 23 | import java.io.UnsupportedEncodingException; |
| 23 | 24 | import java.net.MalformedURLException; |
| 24 | 25 | import java.net.URI; |
| 25 | 26 | import java.net.URL; |
| | 27 | import java.net.URLDecoder; |
| 26 | 28 | import java.util.Arrays; |
| 27 | 29 | import java.util.Collection; |
| 28 | 30 | import java.util.HashMap; |
| 29 | 31 | import java.util.Map; |
| | 32 | import java.util.regex.Matcher; |
| | 33 | import java.util.regex.Pattern; |
| 30 | 34 | import java.util.zip.ZipEntry; |
| 31 | 35 | import java.util.zip.ZipFile; |
| 32 | 36 | import javax.swing.Icon; |
| 33 | 37 | import javax.swing.ImageIcon; |
| 34 | | |
| | 38 | import org.apache.commons.codec.binary.Base64; |
| 35 | 39 | import org.openstreetmap.josm.Main; |
| 36 | 40 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType; |
| 37 | 41 | import org.openstreetmap.josm.io.MirroredInputStream; |
| 38 | 42 | import org.openstreetmap.josm.plugins.PluginHandler; |
| 39 | | import org.openstreetmap.josm.tools.Utils; |
| 40 | 43 | import org.xml.sax.Attributes; |
| 41 | 44 | import org.xml.sax.EntityResolver; |
| 42 | 45 | import org.xml.sax.InputSource; |
| … |
… |
import org.xml.sax.SAXException;
|
| 44 | 47 | import org.xml.sax.XMLReader; |
| 45 | 48 | import org.xml.sax.helpers.DefaultHandler; |
| 46 | 49 | import org.xml.sax.helpers.XMLReaderFactory; |
| 47 | | |
| 48 | 50 | import com.kitfox.svg.SVGDiagram; |
| 49 | 51 | import com.kitfox.svg.SVGException; |
| 50 | 52 | import com.kitfox.svg.SVGUniverse; |
| … |
… |
public class ImageProvider {
|
| 153 | 155 | return ir.getImageIcon(dim == null ? ImageResource.DEFAULT_DIMENSION : dim, sanitize); |
| 154 | 156 | } |
| 155 | 157 | |
| | 158 | /** |
| | 159 | * {@code data:[<mediatype>][;base64],<data>} |
| | 160 | * @see RFC2397 |
| | 161 | */ |
| | 162 | private static final Pattern dataUrlPattern = Pattern.compile( |
| | 163 | "^data:([a-zA-Z]+/[a-zA-Z]+)?(;base64)?,(.+)$"); |
| | 164 | |
| 156 | 165 | private static ImageResource getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) { |
| 157 | 166 | if (name == null) |
| 158 | 167 | return null; |
| 159 | 168 | ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; |
| 160 | 169 | |
| | 170 | try { |
| | 171 | if (name.startsWith("data:")) { |
| | 172 | Matcher m = dataUrlPattern.matcher(name); |
| | 173 | if (m.matches()) { |
| | 174 | String mediatype = m.group(1); |
| | 175 | String base64 = m.group(2); |
| | 176 | String data = m.group(3); |
| | 177 | byte[] bytes = ";base64".equals(base64) |
| | 178 | ? Base64.decodeBase64(data) |
| | 179 | : URLDecoder.decode(data, "utf-8").getBytes(); |
| | 180 | return new ImageResource(new ImageIcon(bytes).getImage(), true); |
| | 181 | } |
| | 182 | } |
| | 183 | } catch (UnsupportedEncodingException ex) { |
| | 184 | throw new RuntimeException(ex.getMessage(), ex); |
| | 185 | } |
| | 186 | |
| 161 | 187 | if (name.startsWith("http://")) { |
| 162 | 188 | String url = name; |
| 163 | 189 | ImageResource ir = cache.get(url); |