- Timestamp:
- 2012-01-19T12:49:55+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r4272 r4820 16 16 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 17 17 import org.openstreetmap.josm.tools.CheckParameterUtil; 18 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode; 18 19 import org.openstreetmap.josm.tools.Utils; 19 20 … … 45 46 IconReference iconRef = c.get("fill-image", null, IconReference.class); 46 47 if (iconRef != null) { 47 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);48 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, SanitizeMode.MAKE_BUFFEREDIMAGE); 48 49 if (icon != null) { 49 if (!(icon.getImage() instanceof BufferedImage)) {50 icon = MapPaintStyles.getIcon(iconRef, -1, -1, true);51 }52 50 if (!(icon.getImage() instanceof BufferedImage)) 53 51 throw new RuntimeException(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
r4272 r4820 28 28 if (iconRef == null) 29 29 return null; 30 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1 , false);30 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1); 31 31 if (icon == null) 32 32 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r4721 r4820 27 27 import org.openstreetmap.josm.io.MirroredInputStream; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode; 29 30 30 31 /** … … 87 88 } 88 89 89 public static ImageIcon getIcon(IconReference ref, int width, int height, boolean sanitize) { 90 public static ImageIcon getIcon(IconReference ref, int width, int height) { 91 return getIcon(ref, width, height, SanitizeMode.OFF); 92 } 93 94 public static ImageIcon getIcon(IconReference ref, int width, int height, SanitizeMode sanitize) { 90 95 final String namespace = ref.source.getPrefName(); 91 96 ImageIcon i = new ImageProvider(ref.iconName) … … 105 110 } 106 111 112 public static ImageIcon getNoIcon_Icon(StyleSource source) { 113 return getNoIcon_Icon(source, SanitizeMode.OFF); 114 } 115 107 116 /** 108 117 * No icon with the given name was found, show a dummy icon instead … … 113 122 * can be null if the defaults are turned off by user 114 123 */ 115 public static ImageIcon getNoIcon_Icon(StyleSource source, booleansanitize) {124 public static ImageIcon getNoIcon_Icon(StyleSource source, SanitizeMode sanitize) { 116 125 return new ImageProvider("misc/no_icon.png") 117 126 .setDirs(getIconSourceDirs(source)) -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4415 r4820 150 150 int height = heightF == null ? -1 : Math.round(heightF); 151 151 152 ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height , false);152 ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height); 153 153 if (icon == null) 154 return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source , false), 255);154 return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source), 255); 155 155 int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); 156 156 Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r4272 r4820 74 74 if (imageIcon == null) { 75 75 if (icon != null) { 76 imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1 , false);76 imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1); 77 77 } 78 78 if (imageIcon == null) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4818 r4820 35 35 import java.util.zip.ZipEntry; 36 36 import java.util.zip.ZipFile; 37 37 38 import javax.swing.Icon; 38 39 import javax.swing.ImageIcon; 40 39 41 import org.apache.commons.codec.binary.Base64; 40 42 import org.openstreetmap.josm.Main; … … 81 83 } 82 84 85 public static enum SanitizeMode { 86 OFF, // never sanitize the image 87 ALWAYS, // always copy to a new BufferedImage 88 MAKE_BUFFEREDIMAGE // make sure the returned image is instance of BufferedImage 89 } 90 83 91 protected Collection<String> dirs; 84 92 protected String id; … … 90 98 protected int maxWidth = -1; 91 99 protected int maxHeight = -1; 92 protected booleansanitize;100 protected SanitizeMode sanitize; 93 101 protected boolean optional; 94 102 … … 200 208 * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues. 201 209 */ 202 public ImageProvider setSanitize( booleansanitize) {210 public ImageProvider setSanitize(SanitizeMode sanitize) { 203 211 this.sanitize = sanitize; 204 212 return this; … … 276 284 @Deprecated 277 285 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) { 278 return getIfAvailable(dirs, id, subdir, name, archive, false);286 return getIfAvailable(dirs, id, subdir, name, archive, SanitizeMode.OFF); 279 287 } 280 288 281 289 @Deprecated 282 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, booleansanitize) {290 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, SanitizeMode sanitize) { 283 291 return getIfAvailable(dirs, id, subdir, name, archive, null, sanitize); 284 292 } 285 293 286 294 @Deprecated 287 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, booleansanitize) {295 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, SanitizeMode sanitize) { 288 296 return getIfAvailable(dirs, id, subdir, name, archive, dim, null, sanitize); 289 297 } … … 312 320 @Deprecated 313 321 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, 314 File archive, Dimension dim, Dimension maxSize, booleansanitize) {322 File archive, Dimension dim, Dimension maxSize, SanitizeMode sanitize) { 315 323 ImageProvider p = new ImageProvider(subdir, name).setDirs(dirs).setId(id).setArchive(archive).setSanitize(sanitize).setOptional(true); 316 324 if (dim != null) { -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r4712 r4820 6 6 import java.awt.Dimension; 7 7 import java.awt.Image; 8 import java.awt.image.BufferedImage; 8 9 import java.util.HashMap; 9 10 import javax.swing.ImageIcon; 11 12 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode; 10 13 11 14 /** … … 50 53 51 54 public ImageIcon getImageIcon() { 52 return getImageIcon(DEFAULT_DIMENSION, false);55 return getImageIcon(DEFAULT_DIMENSION, SanitizeMode.OFF); 53 56 } 54 57 … … 58 61 * and (width, -1) to set the width, but otherwise scale the image 59 62 * proportionally. 60 * @param sanitize dWhether the returned image should be copied to a BufferedImage63 * @param sanitize Whether the returned image should be copied to a BufferedImage 61 64 * to avoid certain problem with native image formats. 62 65 */ 63 public ImageIcon getImageIcon(Dimension dim, booleansanitized) {66 public ImageIcon getImageIcon(Dimension dim, SanitizeMode sanitize) { 64 67 if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0) 65 68 throw new IllegalArgumentException(); 66 69 ImageWrapper iw = imgCache.get(dim); 67 70 if (iw != null) { 68 if (sanitized && !iw.sanitized) { 69 iw.img = ImageProvider.sanitize(iw.img); 70 iw.sanitized = true; 71 if (!iw.sanitized) { 72 if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(iw.img instanceof BufferedImage))) { 73 iw.img = ImageProvider.sanitize(iw.img); 74 iw.sanitized = true; 75 } 71 76 } 72 77 return new ImageIcon(iw.img); … … 88 93 height = icon.getIconHeight() * width / icon.getIconWidth(); 89 94 } 90 Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); 91 if (sanitized) { 95 Image img; 96 if (width == dim.width && height == dim.height) { 97 img = icon.getImage(); 98 } else { 99 img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); 100 } 101 boolean sanitized = false; 102 if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(img instanceof BufferedImage))) { 92 103 img = ImageProvider.sanitize(img); 104 sanitized = true; 93 105 } 94 106 imgCache.put(dim, new ImageWrapper(img, sanitized)); … … 104 116 * which means it is not bounded. 105 117 */ 106 public ImageIcon getImageIconBounded(Dimension maxSize, booleansanitized) {118 public ImageIcon getImageIconBounded(Dimension maxSize, SanitizeMode sanitize) { 107 119 if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0) 108 120 throw new IllegalArgumentException(); … … 130 142 131 143 if (maxWidth == -1 && maxHeight == -1) 132 return getImageIcon(DEFAULT_DIMENSION, sanitize d);144 return getImageIcon(DEFAULT_DIMENSION, sanitize); 133 145 else if (maxWidth == -1) 134 return getImageIcon(new Dimension(-1, maxHeight), sanitize d);146 return getImageIcon(new Dimension(-1, maxHeight), sanitize); 135 147 else if (maxHeight == -1) 136 return getImageIcon(new Dimension(maxWidth, -1), sanitize d);148 return getImageIcon(new Dimension(maxWidth, -1), sanitize); 137 149 else 138 150 if (realWidth / maxWidth > realHeight / maxHeight) 139 return getImageIcon(new Dimension(maxWidth, -1), sanitize d);151 return getImageIcon(new Dimension(maxWidth, -1), sanitize); 140 152 else 141 return getImageIcon(new Dimension(-1, maxHeight), sanitize d);153 return getImageIcon(new Dimension(-1, maxHeight), sanitize); 142 154 } 143 155 }
Note:
See TracChangeset
for help on using the changeset viewer.