Changeset 2889 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2010-01-24T14:20:12+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r2853 r2889 17 17 import java.awt.image.BufferedImage; 18 18 import java.io.File; 19 import java.io.InputStream; 19 20 import java.io.IOException; 20 21 import java.net.MalformedURLException; … … 26 27 import java.util.List; 27 28 import java.util.Map; 29 import java.util.zip.ZipEntry; 30 import java.util.zip.ZipFile; 28 31 29 32 import javax.swing.Icon; … … 88 91 */ 89 92 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name) { 93 return getIfAvailable(dirs, id, subdir, name, null); 94 } 95 96 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) { 90 97 if (name == null) 91 98 return null; … … 116 123 if (dirs != null && dirs.size() > 0) { 117 124 cache_name = "id:" + id + ":" + full_name; 125 if(archive != null) 126 cache_name += ":" + archive.getName(); 118 127 } 119 128 120 129 Image img = cache.get(cache_name); 121 130 if (img == null) { 131 if(archive != null) 132 { 133 try 134 { 135 ZipFile zipFile = new ZipFile(archive); 136 ZipEntry entry = zipFile.getEntry(full_name); 137 if(entry != null) 138 { 139 int size = (int)entry.getSize(); 140 int offs = 0; 141 byte[] buf = new byte[size]; 142 InputStream is = zipFile.getInputStream(entry); 143 while(size > 0) 144 { 145 int l = is.read(buf, offs, size); 146 offs += l; 147 size -= l; 148 } 149 img = Toolkit.getDefaultToolkit().createImage(buf); 150 } 151 } catch (Exception e) { 152 System.err.println(tr("Warning: failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString())); 153 } 154 } 122 155 // getImageUrl() does a ton of "stat()" calls and gets expensive 123 156 // and redundant when you have a whole ton of objects. So, … … 125 158 // and don't bother to create a URL unless we're actually 126 159 // creating the image. 127 URL path = getImageUrl(full_name, dirs); 128 if (path == null) 129 return null; 130 img = Toolkit.getDefaultToolkit().createImage(path); 160 if(img == null) 161 { 162 URL path = getImageUrl(full_name, dirs); 163 if (path == null) 164 return null; 165 img = Toolkit.getDefaultToolkit().createImage(path); 166 } 131 167 cache.put(cache_name, img); 132 168 }
Note:
See TracChangeset
for help on using the changeset viewer.