diff --git a/src/org/openstreetmap/josm/tools/ImageProvider.java b/src/org/openstreetmap/josm/tools/ImageProvider.java
index 39678d6..f7e6046 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
| 2 | 2 | package org.openstreetmap.josm.tools; |
| 3 | 3 | |
| | 4 | import java.util.Enumeration; |
| | 5 | import java.util.logging.Level; |
| | 6 | import java.util.logging.Logger; |
| 4 | 7 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | 8 | |
| 6 | 9 | import java.awt.Component; |
| … |
… |
import org.xml.sax.helpers.XMLReaderFactory;
|
| 48 | 51 | import com.kitfox.svg.SVGDiagram; |
| 49 | 52 | import com.kitfox.svg.SVGException; |
| 50 | 53 | import com.kitfox.svg.SVGUniverse; |
| | 54 | import java.io.BufferedInputStream; |
| | 55 | import java.io.FileInputStream; |
| | 56 | import java.util.zip.ZipInputStream; |
| 51 | 57 | |
| 52 | 58 | /** |
| 53 | 59 | * Helper class to support the application with images. |
| … |
… |
public class ImageProvider {
|
| 147 | 153 | * around certain issues. |
| 148 | 154 | */ |
| 149 | 155 | public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, boolean sanitize) { |
| | 156 | ImageIcon fromZip = zipImages.get("images/" + name); |
| | 157 | if (fromZip != null) { |
| | 158 | return fromZip; |
| | 159 | } |
| | 160 | |
| 150 | 161 | ImageResource ir = getIfAvailableImpl(dirs, id, subdir, name, archive); |
| 151 | 162 | if (ir == null) |
| 152 | 163 | return null; |
| 153 | 164 | return ir.getImageIcon(dim == null ? ImageResource.DEFAULT_DIMENSION : dim, sanitize); |
| 154 | 165 | } |
| 155 | 166 | |
| | 167 | private static class ZipImages { |
| | 168 | private String filename; |
| | 169 | private Map<String, ImageIcon> icons = new HashMap<String, ImageIcon>(); |
| | 170 | |
| | 171 | public ZipImages(String filename) { |
| | 172 | this.filename = filename; |
| | 173 | try { |
| | 174 | init(); |
| | 175 | } catch (IOException ex) { |
| | 176 | ex.printStackTrace(); |
| | 177 | } |
| | 178 | System.out.println(icons.keySet()); |
| | 179 | } |
| | 180 | |
| | 181 | private void init() throws IOException { |
| | 182 | ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(filename))); |
| | 183 | ZipEntry entry; |
| | 184 | while ((entry = zis.getNextEntry()) != null) { |
| | 185 | if (entry.isDirectory()) { |
| | 186 | continue; |
| | 187 | } |
| | 188 | String name = entry.getName(); |
| | 189 | int size = (int) entry.getSize(); |
| | 190 | byte[] b = new byte[size]; |
| | 191 | int rb = 0; |
| | 192 | int chunk = 0; |
| | 193 | while ((size - rb) > 0) { |
| | 194 | chunk = zis.read(b, rb, size - rb); |
| | 195 | if (chunk == -1) { |
| | 196 | break; |
| | 197 | } |
| | 198 | rb += chunk; |
| | 199 | } |
| | 200 | ImageIcon icon = new ImageIcon(b); |
| | 201 | icons.put(name, icon); |
| | 202 | } |
| | 203 | } |
| | 204 | |
| | 205 | public ImageIcon get(String name) { |
| | 206 | return icons.get(name); |
| | 207 | } |
| | 208 | } |
| | 209 | |
| | 210 | private static final ZipImages zipImages = new ZipImages("/home/simon/src/josm.git/images.zip"); |
| | 211 | |
| 156 | 212 | private static ImageResource getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) { |
| 157 | 213 | if (name == null) |
| 158 | 214 | return null; |
| | 215 | |
| 159 | 216 | ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; |
| 160 | 217 | |
| 161 | 218 | if (name.startsWith("http://")) { |