Ignore:
Timestamp:
2017-02-02T00:08:08+01:00 (9 years ago)
Author:
Don-vip
Message:

see #14319 - update to latest version of svgSalamander (2017-01-07, patched)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/SVGUniverse.java

    r10865 r11525  
    44 * All rights reserved.
    55 *
    6  * Redistribution and use in source and binary forms, with or 
     6 * Redistribution and use in source and binary forms, with or
    77 * without modification, are permitted provided that the following
    88 * conditions are met:
    99 *
    10  *   - Redistributions of source code must retain the above 
     10 *   - Redistributions of source code must retain the above
    1111 *     copyright notice, this list of conditions and the following
    1212 *     disclaimer.
    1313 *   - Redistributions in binary form must reproduce the above
    1414 *     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
    1616 *     provided with the distribution.
    1717 *
     
    2727 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2828 * 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 *
    3131 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
    3232 * projects can be found at http://www.kitfox.com
     
    3636package com.kitfox.svg;
    3737
    38 import com.kitfox.svg.app.beans.SVGIcon;
    3938import java.awt.Graphics2D;
    4039import java.awt.image.BufferedImage;
     
    5857import java.util.Base64;
    5958import java.util.HashMap;
    60 import java.util.Iterator;
    6159import java.util.logging.Level;
    6260import java.util.logging.Logger;
    6361import java.util.zip.GZIPInputStream;
     62
    6463import javax.imageio.ImageIO;
    6564import javax.xml.parsers.ParserConfigurationException;
    6665import javax.xml.parsers.SAXParserFactory;
     66
    6767import org.xml.sax.EntityResolver;
    6868import org.xml.sax.InputSource;
     
    7070import org.xml.sax.SAXParseException;
    7171import org.xml.sax.XMLReader;
     72
     73import com.kitfox.svg.app.beans.SVGIcon;
    7274
    7375/**
     
    8991     * initiated from streams will have the scheme <i>svgSalamander</i>.
    9092     */
    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<>();
    9496    public static final String INPUTSTREAM_SCHEME = "svgSalamander";
    9597    /**
     
    141143    public Font getDefaultFont()
    142144    {
    143         for (Iterator it = loadedFonts.values().iterator(); it.hasNext();)
    144         {
    145             return (Font) it.next();
     145        for (Font font : loadedFonts.values()) {
     146            return font;
    146147        }
    147148        return null;
     
    150151    public Font getFont(String fontName)
    151152    {
    152         return (Font) loadedFonts.get(fontName);
     153        return loadedFonts.get(fontName);
    153154    }
    154155
     
    183184                    }
    184185
    185                     SoftReference ref = new SoftReference(img);
     186                    SoftReference<BufferedImage> ref = new SoftReference<>(img);
    186187                    loadedImages.put(url, ref);
    187188
     
    218219        }
    219220
    220         SoftReference ref;
     221        SoftReference<BufferedImage> ref;
    221222        try
    222223        {
     
    231232                icon.paintIcon(null, g, 0, 0);
    232233                g.dispose();
    233                 ref = new SoftReference(img);
     234                ref = new SoftReference<>(img);
    234235            } else
    235236            {
    236237                BufferedImage img = ImageIO.read(imageURL);
    237                 ref = new SoftReference(img);
     238                ref = new SoftReference<>(img);
    238239            }
    239240            loadedImages.put(imageURL, ref);
     
    247248    BufferedImage getImage(URL imageURL)
    248249    {
    249         SoftReference ref = (SoftReference) loadedImages.get(imageURL);
     250        SoftReference<BufferedImage> ref = loadedImages.get(imageURL);
    250251        if (ref == null)
    251252        {
     
    253254        }
    254255
    255         BufferedImage img = (BufferedImage) ref.get();
     256        BufferedImage img = ref.get();
    256257        //If image was cleared from memory, reload it
    257258        if (img == null)
     
    265266                    "Could not load image", e);
    266267            }
    267             ref = new SoftReference(img);
     268            ref = new SoftReference<>(img);
    268269            loadedImages.put(imageURL, ref);
    269270        }
     
    308309            URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null);
    309310
    310             SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
     311            SVGDiagram dia = loadedDocs.get(xmlBase);
    311312            if (dia == null && loadIfAbsent)
    312313            {
     
    316317
    317318                loadSVG(url, false);
    318                 dia = (SVGDiagram) loadedDocs.get(xmlBase);
     319                dia = loadedDocs.get(xmlBase);
    319320                if (dia == null)
    320321                {
     
    349350        }
    350351
    351         SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
     352        SVGDiagram dia = loadedDocs.get(xmlBase);
    352353        if (dia != null || !loadIfAbsent)
    353354        {
     
    372373
    373374            loadSVG(url, false);
    374             dia = (SVGDiagram) loadedDocs.get(xmlBase);
     375            dia = loadedDocs.get(xmlBase);
    375376            return dia;
    376377        } catch (Exception e)
     
    604605    /**
    605606     * 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
    613614    /**
    614615     * Remove loaded document from cache.
    615      * @param uri 
     616     * @param uri
    616617     */
    617618    public void removeDocument(URI uri)
     
    619620        loadedDocs.remove(uri);
    620621    }
    621    
     622
    622623    public boolean isVerbose()
    623624    {
Note: See TracChangeset for help on using the changeset viewer.