diff --git a/data/maps.xsd b/data/maps.xsd
index 59fa397..b847c02 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..32e73bd 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.Dimension; |
| 6 | 7 | import java.awt.event.ActionEvent; |
| 7 | | |
| | 8 | import java.util.Collection; |
| | 9 | import javax.swing.Action; |
| | 10 | import javax.swing.ImageIcon; |
| 8 | 11 | import javax.swing.JOptionPane; |
| 9 | | |
| 10 | 12 | import org.openstreetmap.josm.Main; |
| 11 | 13 | import org.openstreetmap.josm.data.imagery.ImageryInfo; |
| 12 | 14 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; |
| 13 | 15 | import org.openstreetmap.josm.gui.layer.ImageryLayer; |
| | 16 | import org.openstreetmap.josm.tools.ImageProvider; |
| 14 | 17 | |
| 15 | 18 | public class AddImageryLayerAction extends JosmAction implements AdaptableAction { |
| 16 | 19 | |
| | 20 | private static final int MAX_ICON_SIZE = 24; |
| 17 | 21 | private final ImageryInfo info; |
| 18 | 22 | |
| 19 | 23 | public AddImageryLayerAction(ImageryInfo info) { |
| … |
… |
public class AddImageryLayerAction extends JosmAction implements AdaptableAction
|
| 21 | 25 | putValue("toolbar", "imagery_" + info.getToolbarName()); |
| 22 | 26 | this.info = info; |
| 23 | 27 | installAdapters(); |
| | 28 | |
| | 29 | // change toolbar icon from if specified |
| | 30 | try { |
| | 31 | if (info.getIcon() != null) { |
| | 32 | ImageIcon i = ImageProvider.getIfAvailable( |
| | 33 | (Collection<String>) null, null, "", info.getIcon(), null, null, |
| | 34 | new Dimension(MAX_ICON_SIZE, MAX_ICON_SIZE), false); |
| | 35 | putValue(Action.SMALL_ICON, i); |
| | 36 | } |
| | 37 | } catch (Exception ex) { |
| | 38 | throw new RuntimeException(ex.getMessage(), ex); |
| | 39 | } |
| 24 | 40 | } |
| 25 | 41 | |
| 26 | 42 | @Override |
| … |
… |
public class AddImageryLayerAction extends JosmAction implements AdaptableAction
|
| 52 | 68 | setEnabled(false); |
| 53 | 69 | } |
| 54 | 70 | } |
| 55 | | } |
| | 71 | } |
| | 72 | 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 373717d..7530575 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; |
| | 53 | import java.io.StringReader; |
| 51 | 54 | |
| 52 | 55 | /** |
| 53 | 56 | * Helper class to support the application with images. |
| … |
… |
public class ImageProvider {
|
| 74 | 77 | * The icon cache |
| 75 | 78 | */ |
| 76 | 79 | private static Map<String, ImageResource> cache = new HashMap<String, ImageResource>(); |
| 77 | | |
| | 80 | |
| 78 | 81 | /** |
| 79 | 82 | * Return an image from the specified location. Throws a RuntimeException if |
| 80 | 83 | * the image cannot be located. |
| … |
… |
public class ImageProvider {
|
| 166 | 169 | return ir.getImageIcon(dim == null ? ImageResource.DEFAULT_DIMENSION : dim, sanitize); |
| 167 | 170 | } |
| 168 | 171 | |
| | 172 | /** |
| | 173 | * {@code data:[<mediatype>][;base64],<data>} |
| | 174 | * @see RFC2397 |
| | 175 | */ |
| | 176 | private static final Pattern dataUrlPattern = Pattern.compile( |
| | 177 | "^data:([a-zA-Z]+/[a-zA-Z+]+)?(;base64)?,(.+)$"); |
| | 178 | |
| 169 | 179 | static ImageResource getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) { |
| 170 | 180 | if (name == null) |
| 171 | 181 | return null; |
| 172 | 182 | ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; |
| 173 | 183 | |
| | 184 | try { |
| | 185 | if (name.startsWith("data:")) { |
| | 186 | Matcher m = dataUrlPattern.matcher(name); |
| | 187 | if (m.matches()) { |
| | 188 | String mediatype = m.group(1); |
| | 189 | String base64 = m.group(2); |
| | 190 | String data = m.group(3); |
| | 191 | byte[] bytes = ";base64".equals(base64) |
| | 192 | ? Base64.decodeBase64(data) |
| | 193 | : URLDecoder.decode(data, "utf-8").getBytes(); |
| | 194 | if (mediatype != null && mediatype.contains("svg")) { |
| | 195 | URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name); |
| | 196 | SVGDiagram svg = getSvgUniverse().getDiagram(uri); |
| | 197 | return new ImageResource(svg); |
| | 198 | } else { |
| | 199 | return new ImageResource(new ImageIcon(bytes).getImage(), true); |
| | 200 | } |
| | 201 | } |
| | 202 | } |
| | 203 | } catch (UnsupportedEncodingException ex) { |
| | 204 | throw new RuntimeException(ex.getMessage(), ex); |
| | 205 | } catch (IOException ex) { |
| | 206 | throw new RuntimeException(ex.getMessage(), ex); |
| | 207 | } |
| | 208 | |
| 174 | 209 | if (name.startsWith("http://")) { |
| 175 | 210 | String url = name; |
| 176 | 211 | ImageResource ir = cache.get(url); |