- Timestamp:
- 2010-01-24T14:20:12+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r2839 r2889 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.io.File; 6 import java.io.InputStream; 5 7 import java.io.IOException; 6 8 import java.util.Collection; … … 23 25 private static ElemStyles styles = new ElemStyles(); 24 26 private static Collection<String> iconDirs; 27 private static File zipIcons; 25 28 26 29 public static ElemStyles getStyles() … … 46 49 } 47 50 } 48 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name );51 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name, zipIcons); 49 52 if(i == null) 50 53 { … … 87 90 xmlReader.setErrorHandler(handler); 88 91 MirroredInputStream in = new MirroredInputStream(a[1]); 89 xmlReader.parse(new InputSource(in)); 92 InputStream zip = in.getZipEntry("xml","style"); 93 if(zip != null) 94 { 95 zipIcons = in.getFile(); 96 xmlReader.parse(new InputSource(zip)); 97 } 98 else 99 xmlReader.parse(new InputSource(in)); 90 100 } catch(IOException e) { 91 101 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", a[1], e.toString())); … … 97 107 } 98 108 iconDirs = null; 109 zipIcons = null; 99 110 } 100 111 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r2813 r2889 12 12 import java.awt.event.ActionEvent; 13 13 import java.io.BufferedReader; 14 import java.io.File; 14 15 import java.io.IOException; 16 import java.io.InputStream; 15 17 import java.io.InputStreamReader; 16 18 import java.io.Reader; … … 18 20 import java.util.Arrays; 19 21 import java.util.Collection; 22 import java.util.Collections; 20 23 import java.util.HashMap; 21 24 import java.util.LinkedHashMap; … … 72 75 public String locale_name; 73 76 public final static String OPTIONAL_TOOLTIP_TEXT = "Optional tooltip text"; 77 private static File zipIcons = null; 74 78 75 79 public static abstract class Item { … … 550 554 public void setIcon(String iconName) { 551 555 Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null); 552 ImageIcon icon = ImageProvider.getIfAvailable(s, "presets", null, iconName );556 ImageIcon icon = ImageProvider.getIfAvailable(s, "presets", null, iconName, zipIcons); 553 557 if (icon == null) 554 558 { … … 636 640 try { 637 641 MirroredInputStream s = new MirroredInputStream(source); 642 InputStream zip = s.getZipEntry("xml","preset"); 643 if(zip != null) 644 zipIcons = s.getFile(); 638 645 InputStreamReader r; 639 646 try 640 647 { 641 r = new InputStreamReader( s, "UTF-8");648 r = new InputStreamReader(zip == null ? s : zip, "UTF-8"); 642 649 } 643 650 catch (UnsupportedEncodingException e) 644 651 { 645 r = new InputStreamReader( s);652 r = new InputStreamReader(zip == null ? s: zip); 646 653 } 647 654 allPresets.addAll(TaggingPreset.readAll(new BufferedReader(r))); … … 663 670 ); 664 671 } 672 zipIcons = null; 665 673 } 666 674 return allPresets; -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r2832 r2889 13 13 import java.net.URL; 14 14 import java.net.URLConnection; 15 import java.util.Enumeration; 16 import java.util.zip.ZipEntry; 17 import java.util.zip.ZipFile; 15 18 16 19 import org.openstreetmap.josm.Main; … … 62 65 throw new IOException(); 63 66 fs = new FileInputStream(file); 67 } 68 69 public InputStream getZipEntry(String extension, String namepart) 70 { 71 InputStream res = null; 72 try { 73 if(file != null && (file.getName().endsWith(".zip") 74 || file.getName().endsWith(".ZIP"))) 75 { 76 ZipFile zipFile = new ZipFile(file); 77 ZipEntry resentry = null; 78 Enumeration entries = zipFile.entries(); 79 while(entries.hasMoreElements()) { 80 ZipEntry entry = (ZipEntry)entries.nextElement(); 81 if(entry.getName().endsWith("."+extension)) { 82 /* choose any file with correct extension. When more than 83 one file, prefer the one which matches namepart */ 84 if(resentry == null || entry.getName().indexOf(namepart) >= 0) { 85 resentry = entry; 86 } 87 } 88 } 89 if(resentry != null) { 90 res = zipFile.getInputStream(resentry); 91 } 92 else { 93 zipFile.close(); 94 } 95 } 96 } catch (Exception e) { 97 System.err.println(tr("Warning: failed to handle zip file ''{0}''. Exception was: {1}", file.getName(), e.toString())); 98 } 99 return res; 64 100 } 65 101 -
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.