Changeset 6160 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-08-20T18:17:28+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r6070 r6160 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import com.kitfox.svg.SVGDiagram;5 3 6 4 import java.awt.Dimension; … … 8 6 import java.awt.image.BufferedImage; 9 7 import java.util.HashMap; 8 10 9 import javax.swing.ImageIcon; 10 11 import com.kitfox.svg.SVGDiagram; 11 12 12 13 /** … … 16 17 * In the first case, 'svg' is not null and in the latter case, 'imgCache' has 17 18 * at least one entry for the key DEFAULT_DIMENSION. 19 * @since 4271 18 20 */ 19 21 class ImageResource { … … 22 24 * Caches the image data for resized versions of the same image. 23 25 */ 24 private HashMap<Dimension, BufferedImage> imgCache = new HashMap<Dimension, BufferedImage>();26 private HashMap<Dimension, Image> imgCache = new HashMap<Dimension, Image>(); 25 27 private SVGDiagram svg; 26 28 public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1); 27 29 28 public ImageResource( BufferedImage img) {30 public ImageResource(Image img) { 29 31 CheckParameterUtil.ensureParameterNotNull(img); 30 32 imgCache.put(DEFAULT_DIMENSION, img); … … 45 47 * and (width, -1) to set the width, but otherwise scale the image 46 48 * proportionally. 49 * @return ImageIcon object for the image of this resource, scaled according to dim 47 50 */ 48 51 public ImageIcon getImageIcon(Dimension dim) { 49 52 if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0) 50 53 throw new IllegalArgumentException(); 51 BufferedImage img = imgCache.get(dim);54 Image img = imgCache.get(dim); 52 55 if (img != null) { 53 56 return new ImageIcon(img); … … 61 64 return new ImageIcon(img); 62 65 } else { 63 BufferedImage base = imgCache.get(DEFAULT_DIMENSION);66 Image base = imgCache.get(DEFAULT_DIMENSION); 64 67 if (base == null) throw new AssertionError(); 65 68 … … 86 89 * @param maxSize The maximum size. One of the dimensions (widht or height) can be -1, 87 90 * which means it is not bounded. 91 * @return ImageIcon object for the image of this resource, scaled down if needed, according to maxSize 88 92 */ 89 93 public ImageIcon getImageIconBounded(Dimension maxSize) { … … 96 100 realHeight = svg.getHeight(); 97 101 } else { 98 BufferedImage base = imgCache.get(DEFAULT_DIMENSION);102 Image base = imgCache.get(DEFAULT_DIMENSION); 99 103 if (base == null) throw new AssertionError(); 100 104 ImageIcon icon = new ImageIcon(base);
Note:
See TracChangeset
for help on using the changeset viewer.