Changeset 17364 in josm for trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
- Timestamp:
- 2020-11-26T22:24:27+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r17144 r17364 954 954 continue; 955 955 } 956 ir = getIfAvailableLocalURL( path, type);956 ir = getIfAvailableLocalURL(subdir + name, path, type); 957 957 if (ir != null) { 958 958 cache.put(cacheName, ir); … … 984 984 svg = getSvgUniverse().getDiagram(uri); 985 985 } 986 return svg == null ? null : new ImageResource( svg);986 return svg == null ? null : new ImageResource(url, svg); 987 987 case OTHER: 988 988 BufferedImage img = null; … … 992 992 Logging.log(Logging.LEVEL_WARN, "Exception while reading HTTP image:", e); 993 993 } 994 return img == null ? null : new ImageResource( img);994 return img == null ? null : new ImageResource(url, img); 995 995 default: 996 996 throw new AssertionError("Unsupported type: " + type); … … 1041 1041 return null; 1042 1042 } 1043 return new ImageResource( svg);1043 return new ImageResource(url, svg); 1044 1044 } else { 1045 1045 try { … … 1050 1050 // CHECKSTYLE.ON: LineLength 1051 1051 Image img = read(new ByteArrayInputStream(bytes), false, true); 1052 return img == null ? null : new ImageResource( img);1052 return img == null ? null : new ImageResource(url, img); 1053 1053 } catch (IOException | UnsatisfiedLinkError e) { 1054 1054 Logging.log(Logging.LEVEL_WARN, "Exception while reading image:", e); … … 1125 1125 svg = getSvgUniverse().getDiagram(uri); 1126 1126 } 1127 return svg == null ? null : new ImageResource( svg);1127 return svg == null ? null : new ImageResource(fullName, svg); 1128 1128 case OTHER: 1129 1129 while (size > 0) { … … 1138 1138 Logging.warn(e); 1139 1139 } 1140 return img == null ? null : new ImageResource( img);1140 return img == null ? null : new ImageResource(fullName, img); 1141 1141 default: 1142 1142 throw new AssertionError("Unknown ImageType: "+type); … … 1157 1157 * @return the requested image or null if the request failed 1158 1158 */ 1159 private static ImageResource getIfAvailableLocalURL( URL path, ImageType type) {1159 private static ImageResource getIfAvailableLocalURL(String cacheKey, URL path, ImageType type) { 1160 1160 switch (type) { 1161 1161 case SVG: 1162 SVGDiagram svg = null; 1163 synchronized (getSvgUniverse()) { 1164 try { 1165 URI uri = null; 1162 return new ImageResource(cacheKey, () -> { 1163 synchronized (getSvgUniverse()) { 1166 1164 try { 1167 uri = getSvgUniverse().loadSVG(path); 1168 } catch (InvalidPathException e) { 1169 Logging.error("Cannot open {0}: {1}", path, e.getMessage()); 1170 Logging.trace(e); 1165 URI uri = null; 1166 try { 1167 uri = getSvgUniverse().loadSVG(path); 1168 } catch (InvalidPathException e) { 1169 Logging.error("Cannot open {0}: {1}", path, e.getMessage()); 1170 Logging.trace(e); 1171 } 1172 if (uri == null && "jar".equals(path.getProtocol())) { 1173 URL betterPath = Utils.betterJarUrl(path); 1174 if (betterPath != null) { 1175 uri = getSvgUniverse().loadSVG(betterPath); 1176 } 1177 } 1178 return getSvgUniverse().getDiagram(uri); 1179 } catch (SecurityException | IOException e) { 1180 Logging.log(Logging.LEVEL_WARN, "Unable to read SVG", e); 1171 1181 } 1172 if (uri == null && "jar".equals(path.getProtocol())) { 1173 URL betterPath = Utils.betterJarUrl(path); 1174 if (betterPath != null) { 1175 uri = getSvgUniverse().loadSVG(betterPath); 1176 } 1177 } 1178 svg = getSvgUniverse().getDiagram(uri); 1179 } catch (SecurityException | IOException e) { 1180 Logging.log(Logging.LEVEL_WARN, "Unable to read SVG", e); 1181 } 1182 } 1183 return svg == null ? null : new ImageResource(svg); 1182 } 1183 return null; 1184 }); 1184 1185 case OTHER: 1185 1186 BufferedImage img = null; … … 1196 1197 Logging.debug(e); 1197 1198 } 1198 return img == null ? null : new ImageResource( img);1199 return img == null ? null : new ImageResource(path.toString(), img); 1199 1200 default: 1200 1201 throw new AssertionError(); … … 1394 1395 */ 1395 1396 public static Image createBoundedImage(Image img, int maxSize) { 1396 return new ImageResource(img ).getImageIconBounded(new Dimension(maxSize, maxSize)).getImage();1397 return new ImageResource(img.toString(), img).getImageIconBounded(new Dimension(maxSize, maxSize)).getImage(); 1397 1398 } 1398 1399 … … 1933 1934 } 1934 1935 1936 /** 1937 * Prints statistics concerning the image loading caches. 1938 */ 1939 public static void printStatistics() { 1940 Logging.info(getSvgUniverse().statistics()); 1941 Logging.info(ImageResource.statistics()); 1942 } 1943 1935 1944 @Override 1936 1945 public String toString() {
Note:
See TracChangeset
for help on using the changeset viewer.