Changeset 11525 in josm for trunk/src/com/kitfox/svg/SVGUniverse.java
- Timestamp:
- 2017-02-02T00:08:08+01:00 (9 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/SVGUniverse.java (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/SVGUniverse.java
r10865 r11525 4 4 * All rights reserved. 5 5 * 6 * Redistribution and use in source and binary forms, with or 6 * Redistribution and use in source and binary forms, with or 7 7 * without modification, are permitted provided that the following 8 8 * conditions are met: 9 9 * 10 * - Redistributions of source code must retain the above 10 * - Redistributions of source code must retain the above 11 11 * copyright notice, this list of conditions and the following 12 12 * disclaimer. 13 13 * - Redistributions in binary form must reproduce the above 14 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 15 * disclaimer in the documentation and/or other materials 16 16 * provided with the distribution. 17 17 * … … 27 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 32 * projects can be found at http://www.kitfox.com … … 36 36 package com.kitfox.svg; 37 37 38 import com.kitfox.svg.app.beans.SVGIcon;39 38 import java.awt.Graphics2D; 40 39 import java.awt.image.BufferedImage; … … 58 57 import java.util.Base64; 59 58 import java.util.HashMap; 60 import java.util.Iterator;61 59 import java.util.logging.Level; 62 60 import java.util.logging.Logger; 63 61 import java.util.zip.GZIPInputStream; 62 64 63 import javax.imageio.ImageIO; 65 64 import javax.xml.parsers.ParserConfigurationException; 66 65 import javax.xml.parsers.SAXParserFactory; 66 67 67 import org.xml.sax.EntityResolver; 68 68 import org.xml.sax.InputSource; … … 70 70 import org.xml.sax.SAXParseException; 71 71 import org.xml.sax.XMLReader; 72 73 import com.kitfox.svg.app.beans.SVGIcon; 72 74 73 75 /** … … 89 91 * initiated from streams will have the scheme <i>svgSalamander</i>. 90 92 */ 91 final HashMap loadedDocs = new HashMap(); 92 final HashMap loadedFonts = new HashMap(); 93 final HashMap loadedImages = new HashMap(); 93 final HashMap<URI, SVGDiagram> loadedDocs = new HashMap<>(); 94 final HashMap<String, Font> loadedFonts = new HashMap<>(); 95 final HashMap<URL, SoftReference<BufferedImage>> loadedImages = new HashMap<>(); 94 96 public static final String INPUTSTREAM_SCHEME = "svgSalamander"; 95 97 /** … … 141 143 public Font getDefaultFont() 142 144 { 143 for (Iterator it = loadedFonts.values().iterator(); it.hasNext();) 144 { 145 return (Font) it.next(); 145 for (Font font : loadedFonts.values()) { 146 return font; 146 147 } 147 148 return null; … … 150 151 public Font getFont(String fontName) 151 152 { 152 return (Font)loadedFonts.get(fontName);153 return loadedFonts.get(fontName); 153 154 } 154 155 … … 183 184 } 184 185 185 SoftReference ref = new SoftReference(img); 186 SoftReference<BufferedImage> ref = new SoftReference<>(img); 186 187 loadedImages.put(url, ref); 187 188 … … 218 219 } 219 220 220 SoftReference ref; 221 SoftReference<BufferedImage> ref; 221 222 try 222 223 { … … 231 232 icon.paintIcon(null, g, 0, 0); 232 233 g.dispose(); 233 ref = new SoftReference(img); 234 ref = new SoftReference<>(img); 234 235 } else 235 236 { 236 237 BufferedImage img = ImageIO.read(imageURL); 237 ref = new SoftReference(img); 238 ref = new SoftReference<>(img); 238 239 } 239 240 loadedImages.put(imageURL, ref); … … 247 248 BufferedImage getImage(URL imageURL) 248 249 { 249 SoftReference ref = (SoftReference)loadedImages.get(imageURL);250 SoftReference<BufferedImage> ref = loadedImages.get(imageURL); 250 251 if (ref == null) 251 252 { … … 253 254 } 254 255 255 BufferedImage img = (BufferedImage)ref.get();256 BufferedImage img = ref.get(); 256 257 //If image was cleared from memory, reload it 257 258 if (img == null) … … 265 266 "Could not load image", e); 266 267 } 267 ref = new SoftReference(img); 268 ref = new SoftReference<>(img); 268 269 loadedImages.put(imageURL, ref); 269 270 } … … 308 309 URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null); 309 310 310 SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);311 SVGDiagram dia = loadedDocs.get(xmlBase); 311 312 if (dia == null && loadIfAbsent) 312 313 { … … 316 317 317 318 loadSVG(url, false); 318 dia = (SVGDiagram)loadedDocs.get(xmlBase);319 dia = loadedDocs.get(xmlBase); 319 320 if (dia == null) 320 321 { … … 349 350 } 350 351 351 SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);352 SVGDiagram dia = loadedDocs.get(xmlBase); 352 353 if (dia != null || !loadIfAbsent) 353 354 { … … 372 373 373 374 loadSVG(url, false); 374 dia = (SVGDiagram)loadedDocs.get(xmlBase);375 dia = loadedDocs.get(xmlBase); 375 376 return dia; 376 377 } catch (Exception e) … … 604 605 /** 605 606 * Get list of uris of all loaded documents and subdocuments. 606 * @return 607 */ 608 public ArrayList getLoadedDocumentURIs() 609 { 610 return new ArrayList(loadedDocs.keySet()); 611 } 612 607 * @return 608 */ 609 public ArrayList<URI> getLoadedDocumentURIs() 610 { 611 return new ArrayList<>(loadedDocs.keySet()); 612 } 613 613 614 /** 614 615 * Remove loaded document from cache. 615 * @param uri 616 * @param uri 616 617 */ 617 618 public void removeDocument(URI uri) … … 619 620 loadedDocs.remove(uri); 620 621 } 621 622 622 623 public boolean isVerbose() 623 624 {
Note:
See TracChangeset
for help on using the changeset viewer.
