Changeset 4713 in josm
- Timestamp:
- 2011-12-26T21:48:25+01:00 (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/maps.xsd
r4493 r4713 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> -
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r4531 r4713 5 5 6 6 import java.awt.event.ActionEvent; 7 7 import javax.swing.Action; 8 import javax.swing.ImageIcon; 8 9 import javax.swing.JOptionPane; 9 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.imagery.ImageryInfo; 12 12 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 13 13 import org.openstreetmap.josm.gui.layer.ImageryLayer; 14 import org.openstreetmap.josm.tools.ImageRequest; 14 15 15 16 public class AddImageryLayerAction extends JosmAction implements AdaptableAction { 16 17 18 private static final int MAX_ICON_SIZE = 24; 17 19 private final ImageryInfo info; 18 20 … … 22 24 this.info = info; 23 25 installAdapters(); 26 27 // change toolbar icon from if specified 28 try { 29 if (info.getIcon() != null) { 30 ImageIcon i = new ImageRequest().setName(info.getIcon()).setMaxHeight(MAX_ICON_SIZE).setMaxWidth(MAX_ICON_SIZE).get(); 31 putValue(Action.SMALL_ICON, i); 32 } 33 } catch (Exception ex) { 34 throw new RuntimeException(ex.getMessage(), ex); 35 } 24 36 } 25 37 -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4506 r4713 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 */ … … 106 107 @pref String shapes; 107 108 @pref String projections; 109 @pref String icon; 108 110 109 111 public ImageryPreferenceEntry() { … … 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(","); … … 219 222 termsOfUseURL = e.terms_of_use_url; 220 223 countryCode = e.country_code; 224 icon = e.icon; 221 225 } 222 226 … … 285 289 this.termsOfUseURL = i.termsOfUseURL; 286 290 this.serverProjections = i.serverProjections; 291 this.icon = i.icon; 287 292 } 288 293 … … 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 -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r4492 r4713 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; … … 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; … … 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; … … 130 125 "terms-of-use-url", 131 126 "country-code", 127 "icon", 132 128 }).contains(qName)) { 133 129 newState = State.ENTRY_ATTRIBUTE; … … 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 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4712 r4713 21 21 import java.io.IOException; 22 22 import java.io.InputStream; 23 import java.io.StringReader; 24 import java.io.UnsupportedEncodingException; 23 25 import java.net.MalformedURLException; 24 26 import java.net.URI; 25 27 import java.net.URL; 28 import java.net.URLDecoder; 26 29 import java.util.Arrays; 27 30 import java.util.Collection; 28 31 import java.util.HashMap; 29 32 import java.util.Map; 33 import java.util.regex.Matcher; 34 import java.util.regex.Pattern; 30 35 import java.util.zip.ZipEntry; 31 36 import java.util.zip.ZipFile; 32 37 import javax.swing.Icon; 33 38 import javax.swing.ImageIcon; 34 39 import org.apache.commons.codec.binary.Base64; 35 40 import org.openstreetmap.josm.Main; 36 41 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 37 42 import org.openstreetmap.josm.io.MirroredInputStream; 38 43 import org.openstreetmap.josm.plugins.PluginHandler; 39 import org.openstreetmap.josm.tools.Utils;40 44 import org.xml.sax.Attributes; 41 45 import org.xml.sax.EntityResolver; … … 45 49 import org.xml.sax.helpers.DefaultHandler; 46 50 import org.xml.sax.helpers.XMLReaderFactory; 47 48 51 import com.kitfox.svg.SVGDiagram; 49 52 import com.kitfox.svg.SVGException; … … 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; 182 183 try { 184 if (name.startsWith("data:")) { 185 Matcher m = dataUrlPattern.matcher(name); 186 if (m.matches()) { 187 String mediatype = m.group(1); 188 String base64 = m.group(2); 189 String data = m.group(3); 190 byte[] bytes = ";base64".equals(base64) 191 ? Base64.decodeBase64(data) 192 : URLDecoder.decode(data, "utf-8").getBytes(); 193 if (mediatype != null && mediatype.contains("image/svg+xml")) { 194 URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name); 195 SVGDiagram svg = getSvgUniverse().getDiagram(uri); 196 return new ImageResource(svg); 197 } else { 198 return new ImageResource(new ImageIcon(bytes).getImage(), true); 199 } 200 } 201 } 202 } catch (UnsupportedEncodingException ex) { 203 throw new RuntimeException(ex.getMessage(), ex); 204 } catch (IOException ex) { 205 throw new RuntimeException(ex.getMessage(), ex); 206 } 207 172 208 ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; 173 209
Note:
See TracChangeset
for help on using the changeset viewer.