Changeset 4960 in josm
- Timestamp:
- 2012-02-16T20:58:54+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r4139 r4960 30 30 public JumpToAction() { 31 31 super(tr("Jump To Position"), null, tr("Opens a dialog that allows to jump to a specific location"), Shortcut.registerShortcut("tools:jumpto", tr("Tool: {0}", tr("Jump To Position")), 32 KeyEvent.VK_ G, Shortcut.GROUP_HOTKEY), false);32 KeyEvent.VK_J, Shortcut.GROUP_HOTKEY), false); 33 33 putValue("toolbar", "action/jumpto"); 34 34 Main.toolbar.register(this); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4937 r4960 332 332 locations.add("/usr/lib/josm/"); 333 333 return locations; 334 }335 336 @Deprecated337 synchronized public boolean hasKey(final String key) {338 return properties.containsKey(key);339 334 } 340 335 -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r4822 r4960 18 18 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 19 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;21 20 import org.openstreetmap.josm.tools.Utils; 22 21 … … 45 44 IconReference iconRef = c.get("fill-image", null, IconReference.class); 46 45 if (iconRef != null) { 47 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1 , SanitizeMode.MAKE_BUFFEREDIMAGE);46 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1); 48 47 if (icon != null) { 49 48 if (!(icon.getImage() instanceof BufferedImage)) -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r4936 r4960 27 27 import org.openstreetmap.josm.io.MirroredInputStream; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;30 29 31 30 /** … … 89 88 90 89 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) {95 90 final String namespace = ref.source.getPrefName(); 96 91 ImageIcon i = new ImageProvider(ref.iconName) … … 100 95 .setWidth(width) 101 96 .setHeight(height) 102 .setSanitize(sanitize)103 97 .setOptional(true).get(); 104 98 if(i == null) … … 108 102 } 109 103 return i; 110 }111 112 public static ImageIcon getNoIcon_Icon(StyleSource source) {113 return getNoIcon_Icon(source, SanitizeMode.OFF);114 104 } 115 105 … … 122 112 * can be null if the defaults are turned off by user 123 113 */ 124 public static ImageIcon getNoIcon_Icon(StyleSource source , SanitizeMode sanitize) {114 public static ImageIcon getNoIcon_Icon(StyleSource source) { 125 115 return new ImageProvider("misc/no_icon.png") 126 116 .setDirs(getIconSourceDirs(source)) 127 117 .setId("mappaint."+source.getPrefName()) 128 118 .setArchive(source.zipIcons) 129 .setSanitize(sanitize)130 119 .setOptional(true).get(); 131 120 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4938 r4960 85 85 } 86 86 87 public static enum SanitizeMode {88 OFF, // never sanitize the image89 ALWAYS, // always copy to a new BufferedImage90 MAKE_BUFFEREDIMAGE // make sure the returned image is instance of BufferedImage91 }92 93 87 protected Collection<String> dirs; 94 88 protected String id; … … 100 94 protected int maxWidth = -1; 101 95 protected int maxHeight = -1; 102 protected SanitizeMode sanitize;103 96 protected boolean optional; 104 97 … … 204 197 public ImageProvider setMaxHeight(int maxHeight) { 205 198 this.maxHeight = maxHeight; 206 return this;207 }208 209 /**210 * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues.211 */212 public ImageProvider setSanitize(SanitizeMode sanitize) {213 this.sanitize = sanitize;214 199 return this; 215 200 } … … 240 225 } 241 226 if (maxWidth != -1 || maxHeight != -1) 242 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight) , sanitize);227 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 243 228 else 244 return ir.getImageIcon(new Dimension(width, height) , sanitize);229 return ir.getImageIcon(new Dimension(width, height)); 245 230 } 246 231 … … 292 277 if (mediatype != null && mediatype.contains("image/svg+xml")) { 293 278 URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name); 294 SVGDiagram svg = getSvgUniverse().getDiagram(uri); 295 return new ImageResource(svg); 279 return new ImageResource(getSvgUniverse().getDiagram(uri)); 296 280 } else { 297 return new ImageResource(new ImageIcon(bytes).getImage() , true);281 return new ImageResource(new ImageIcon(bytes).getImage()); 298 282 } 299 283 } … … 406 390 img = ImageIO.read(is.getFile().toURI().toURL()); 407 391 } catch (IOException e) {} 408 return img == null ? null : new ImageResource(img , true);392 return img == null ? null : new ImageResource(img); 409 393 default: 410 394 throw new AssertionError(); … … 475 459 img = ImageIO.read(new ByteArrayInputStream(buf)); 476 460 } catch (IOException e) {} 477 return img == null ? null : new ImageResource(img , false);461 return img == null ? null : new ImageResource(img); 478 462 default: 479 463 throw new AssertionError(); … … 509 493 img = ImageIO.read(path); 510 494 } catch (IOException e) {} 511 return img == null ? null : new ImageResource(img , true);495 return img == null ? null : new ImageResource(img); 512 496 default: 513 497 throw new AssertionError(); … … 767 751 } 768 752 769 public static BufferedImage sanitize(Image img) {770 (new ImageIcon(img)).getImage(); // load competely771 int width = img.getWidth(null);772 int height = img.getHeight(null);773 BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);774 result.getGraphics().drawImage(img, 0, 0, null);775 return result;776 }777 778 753 public static Image createImageFromSvg(SVGDiagram svg, Dimension dim) { 779 754 float realWidth = svg.getWidth(); -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r4824 r4960 9 9 import java.util.HashMap; 10 10 import javax.swing.ImageIcon; 11 12 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;13 11 14 12 /** … … 24 22 * Caches the image data for resized versions of the same image. 25 23 */ 26 private HashMap<Dimension, Image Wrapper> imgCache = new HashMap<Dimension, ImageWrapper>();24 private HashMap<Dimension, Image> imgCache = new HashMap<Dimension, Image>(); 27 25 private SVGDiagram svg; 28 26 public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1); 29 27 30 /** 31 * remember whether the image has been sanitized 32 */ 33 private static class ImageWrapper { 34 Image img; 35 boolean sanitized; 36 37 public ImageWrapper(Image img, boolean sanitized) { 38 CheckParameterUtil.ensureParameterNotNull(img); 39 this.img = img; 40 this.sanitized = sanitized; 41 } 42 } 43 44 public ImageResource(Image img, boolean sanitized) { 28 public ImageResource(Image img) { 45 29 CheckParameterUtil.ensureParameterNotNull(img); 46 imgCache.put(DEFAULT_DIMENSION, new ImageWrapper(img, sanitized));30 imgCache.put(DEFAULT_DIMENSION, img); 47 31 } 48 32 … … 53 37 54 38 public ImageIcon getImageIcon() { 55 return getImageIcon(DEFAULT_DIMENSION , SanitizeMode.OFF);39 return getImageIcon(DEFAULT_DIMENSION); 56 40 } 57 41 … … 61 45 * and (width, -1) to set the width, but otherwise scale the image 62 46 * proportionally. 63 * @param sanitize Whether the returned image should be copied to a BufferedImage64 * to avoid certain problem with native image formats.65 47 */ 66 public ImageIcon getImageIcon(Dimension dim , SanitizeMode sanitize) {48 public ImageIcon getImageIcon(Dimension dim) { 67 49 if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0) 68 50 throw new IllegalArgumentException(); 69 ImageWrapper iw = imgCache.get(dim); 70 if (iw != null) { 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 } 76 } 77 return new ImageIcon(iw.img); 51 Image img = imgCache.get(dim); 52 if (img != null) { 53 return new ImageIcon(img); 78 54 } 79 55 if (svg != null) { 80 Imageimg = ImageProvider.createImageFromSvg(svg, dim);81 imgCache.put(dim, new ImageWrapper(img, true));56 img = ImageProvider.createImageFromSvg(svg, dim); 57 imgCache.put(dim, img); 82 58 return new ImageIcon(img); 83 59 } else { 84 Image Wrapperbase = imgCache.get(DEFAULT_DIMENSION);60 Image base = imgCache.get(DEFAULT_DIMENSION); 85 61 if (base == null) throw new AssertionError(); 86 62 87 63 int width = dim.width; 88 64 int height = dim.height; 89 ImageIcon icon = new ImageIcon(base .img);65 ImageIcon icon = new ImageIcon(base); 90 66 if (width == -1) { 91 67 width = icon.getIconWidth() * height / icon.getIconHeight(); … … 93 69 height = icon.getIconHeight() * width / icon.getIconWidth(); 94 70 } 95 Image img;96 71 img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); 97 boolean sanitized = false; 98 if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(img instanceof BufferedImage))) { 99 img = ImageProvider.sanitize(img); 100 sanitized = true; 101 } 102 imgCache.put(dim, new ImageWrapper(img, sanitized)); 72 imgCache.put(dim, img); 103 73 return new ImageIcon(img); 104 74 } … … 112 82 * which means it is not bounded. 113 83 */ 114 public ImageIcon getImageIconBounded(Dimension maxSize , SanitizeMode sanitize) {84 public ImageIcon getImageIconBounded(Dimension maxSize) { 115 85 if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0) 116 86 throw new IllegalArgumentException(); … … 121 91 realHeight = svg.getHeight(); 122 92 } else { 123 Image Wrapperbase = imgCache.get(DEFAULT_DIMENSION);93 Image base = imgCache.get(DEFAULT_DIMENSION); 124 94 if (base == null) throw new AssertionError(); 125 ImageIcon icon = new ImageIcon(base .img);95 ImageIcon icon = new ImageIcon(base); 126 96 realWidth = icon.getIconWidth(); 127 97 realHeight = icon.getIconHeight(); … … 138 108 139 109 if (maxWidth == -1 && maxHeight == -1) 140 return getImageIcon(DEFAULT_DIMENSION , sanitize);110 return getImageIcon(DEFAULT_DIMENSION); 141 111 else if (maxWidth == -1) 142 return getImageIcon(new Dimension(-1, maxHeight) , sanitize);112 return getImageIcon(new Dimension(-1, maxHeight)); 143 113 else if (maxHeight == -1) 144 return getImageIcon(new Dimension(maxWidth, -1) , sanitize);114 return getImageIcon(new Dimension(maxWidth, -1)); 145 115 else 146 116 if (realWidth / maxWidth > realHeight / maxHeight) 147 return getImageIcon(new Dimension(maxWidth, -1) , sanitize);117 return getImageIcon(new Dimension(maxWidth, -1)); 148 118 else 149 return getImageIcon(new Dimension(-1, maxHeight) , sanitize);119 return getImageIcon(new Dimension(-1, maxHeight)); 150 120 } 151 121 }
Note:
See TracChangeset
for help on using the changeset viewer.