Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java	(revision 4821)
+++ trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java	(revision 4822)
@@ -46,4 +46,5 @@
 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.HorizontalTextAlignment;
 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.VerticalTextAlignment;
+import org.openstreetmap.josm.gui.mappaint.MapImage;
 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle;
 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol;
@@ -505,7 +506,7 @@
     }
 
-    public void drawLinePattern(Way way, ImageIcon pattern) {
-        final int width = pattern.getIconWidth();
-        final int height = pattern.getIconHeight();
+    public void drawLinePattern(Way way, Image pattern) {
+        final int width = pattern.getWidth(null);
+        final int height = pattern.getHeight(null);
 
         Point lastP = null;
@@ -530,13 +531,13 @@
 
                 if (dist > 0) {
-                    g.drawImage(pattern.getImage(), 0, 0, (int) dist, height,
+                    g.drawImage(pattern, 0, 0, (int) dist, height,
                             width - (int) dist, 0, width, height, null);
                 }
                 while (dist < segmentLength) {
                     if (dist + width > segmentLength) {
-                        g.drawImage(pattern.getImage(), (int) dist, 0, (int) segmentLength, height,
+                        g.drawImage(pattern, (int) dist, 0, (int) segmentLength, height,
                                 0, 0, (int) segmentLength - (int) dist, height, null);
                     } else {
-                        pattern.paintIcon(nc, g, (int) dist, 0);
+                        g.drawImage(pattern, (int) dist, 0, nc);
                     }
                     dist += width;
@@ -550,16 +551,16 @@
     }
 
-    public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member) {
+    public void drawNodeIcon(Node n, Image img, float alpha, boolean selected, boolean member) {
         Point p = nc.getPoint(n);
 
-        final int w = icon.getIconWidth(), h=icon.getIconHeight();
+        final int w = img.getWidth(null), h=img.getHeight(null);
         if(n.isHighlighted()) {
             drawPointHighlight(p, Math.max(w, h));
         }
 
-        if (iconAlpha != 1f) {
-            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha));
-        }
-        icon.paintIcon ( nc, g, p.x-w/2, p.y-h/2 );
+        if (alpha != 1f) {
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
+        }
+        g.drawImage(img, p.x-w/2, p.y-h/2, nc);
         g.setPaintMode();
         if (selected || member)
@@ -802,9 +803,9 @@
     }
 
-    public void drawArea(Way w, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
-        drawArea(w, getPath(w), color, fillImage, fillImageAlpha, text);
-    }
-
-    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
+    public void drawArea(Way w, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
+        drawArea(w, getPath(w), color, fillImage, text);
+    }
+
+    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
 
         Shape area = path.createTransformedShape(nc.getAffineTransform());
@@ -815,10 +816,10 @@
                 g.fill(area);
             } else {
-                TexturePaint texture = new TexturePaint(fillImage,
+                TexturePaint texture = new TexturePaint(fillImage.img,
                         //                        new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight()));
-                        new Rectangle(0, 0, fillImage.getWidth(), fillImage.getHeight()));
+                        new Rectangle(0, 0, fillImage.img.getWidth(null), fillImage.img.getHeight(null)));
                 g.setPaint(texture);
-                if (fillImageAlpha != 1f) {
-                    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fillImageAlpha));
+                if (fillImage.alpha != 1f) {
+                    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fillImage.alpha));
                 }
                 g.fill(area);
@@ -871,5 +872,5 @@
     }
 
-    public void drawArea(Relation r, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
+    public void drawArea(Relation r, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
         Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
         if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) {
@@ -881,5 +882,5 @@
                 drawArea(r, p,
                         pd.selected ? settings.getRelationSelectedColor(color.getAlpha()) : color,
-                                fillImage, fillImageAlpha, text);
+                                fillImage, text);
             }
         }
@@ -898,12 +899,12 @@
     }
 
-    public void drawRestriction(ImageIcon icon, Point pVia, double vx, double vx2, double vy, double vy2, double iconAngle, boolean selected) {
-        /* rotate icon with direction last node in from to */
-        ImageIcon rotatedIcon = ImageProvider.createRotatedImage(null /*icon2*/, icon, iconAngle);
-
-        /* scale down icon to 16*16 pixels */
-        ImageIcon smallIcon = new ImageIcon(rotatedIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH));
-        int w = smallIcon.getIconWidth(), h=smallIcon.getIconHeight();
-        smallIcon.paintIcon (nc, g, (int)(pVia.x+vx+vx2)-w/2, (int)(pVia.y+vy+vy2)-h/2 );
+    public void drawRestriction(Image img, Point pVia, double vx, double vx2, double vy, double vy2, double angle, boolean selected) {
+        /* rotate image with direction last node in from to */
+        Image rotatedImg = ImageProvider.createRotatedImage(null , img, angle);
+
+        /* scale down image to 16*16 pixels */
+        Image smallImg = new ImageIcon(rotatedImg.getScaledInstance(16 , 16, Image.SCALE_SMOOTH)).getImage();
+        int w = smallImg.getWidth(null), h=smallImg.getHeight(null);
+        g.drawImage(smallImg, (int)(pVia.x+vx+vx2)-w/2, (int)(pVia.y+vy+vy2)-h/2, nc);
 
         if (selected) {
@@ -913,5 +914,5 @@
     }
 
-    public void drawRestriction(Relation r, NodeElemStyle icon) {
+    public void drawRestriction(Relation r, MapImage<Image> icon) {
         Way fromWay = null;
         Way toWay = null;
@@ -1084,5 +1085,5 @@
         }
 
-        drawRestriction(inactive || r.isDisabled() ? icon.getDisabledIcon() : icon.icon,
+        drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon.img,
                 pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected());
     }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4821)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4822)
@@ -1,4 +1,6 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.gui.mappaint;
+
+import static org.openstreetmap.josm.tools.Utils.equal;
 
 import java.awt.Color;
@@ -26,21 +28,18 @@
      */
     public Color color;
-    public BufferedImage fillImage;
-    public float fillImageAlpha;
+    public MapImage<BufferedImage> fillImage;
     public TextElement text;
 
-    protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
+    protected AreaElemStyle(Cascade c, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
         super(c, -1000f);
         CheckParameterUtil.ensureParameterNotNull(color);
         this.color = color;
         this.fillImage = fillImage;
-        this.fillImageAlpha = fillImageAlpha;
         this.text = text;
     }
 
     public static AreaElemStyle create(Cascade c) {
-        BufferedImage fillImage = null;
+        MapImage<BufferedImage> fillImage = null;
         Color color = null;
-        float fillImageAlpha = 1f;
 
         IconReference iconRef = c.get("fill-image", null, IconReference.class);
@@ -50,15 +49,15 @@
                 if (!(icon.getImage() instanceof BufferedImage))
                     throw new RuntimeException();
-                fillImage = (BufferedImage) icon.getImage();
+                fillImage = new MapImage<BufferedImage>(iconRef.iconName, iconRef.source);
+                fillImage.img = (BufferedImage) icon.getImage();
 
-                color = new Color(fillImage.getRGB(fillImage.getWidth() / 2, fillImage.getHeight() / 2));
+                color = new Color(fillImage.img.getRGB(
+                        fillImage.img.getWidth() / 2, fillImage.img.getHeight() / 2)
+                );
 
-                fillImageAlpha = Utils.color_int2float(Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))));
-                Float pAlpha = c.get("fill-opacity", null, Float.class);
+                fillImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))));
+                Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class));
                 if (pAlpha != null) {
-                    if (pAlpha < 0f || pAlpha > 1f) {
-                        pAlpha= 1f;
-                    }
-                    fillImageAlpha = pAlpha;
+                    fillImage.alpha = pAlpha;
                 }
             }
@@ -82,5 +81,5 @@
         
         if (color != null)
-            return new AreaElemStyle(c, color, fillImage, fillImageAlpha, text);
+            return new AreaElemStyle(c, color, fillImage, text);
         else
             return null;
@@ -97,5 +96,5 @@
                 }
             }
-            painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, text);
+            painter.drawArea((Way) osm, myColor, fillImage, text);
         } else if (osm instanceof Relation)
         {
@@ -106,5 +105,5 @@
                 }
             }
-            painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, text);
+            painter.drawArea((Relation) osm, myColor, fillImage, text);
         }
     }
@@ -118,11 +117,9 @@
         AreaElemStyle other = (AreaElemStyle) obj;
         // we should get the same image object due to caching
-        if (fillImage != other.fillImage)
+        if (!equal(fillImage, other.fillImage))
             return false;
-        if (!Utils.equal(color, other.color))
+        if (!equal(color, other.color))
             return false;
-        if (fillImageAlpha != other.fillImageAlpha)
-            return false;
-        if (!Utils.equal(text, other.text))
+        if (!equal(text, other.text))
             return false;
         return true;
@@ -134,5 +131,4 @@
         hash = 61 * hash + color.hashCode();
         hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0);
-        hash = 61 * hash + Float.floatToIntBits(fillImageAlpha);
         hash = 61 * hash + (text != null ? text.hashCode() : 0);
         return hash;
@@ -142,5 +138,5 @@
     public String toString() {
         return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) +
-                " fillImageAlpha=" + fillImageAlpha + " fillImage=[" + fillImage + "]}";
+                " fillImage=[" + fillImage + "]}";
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4821)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4822)
@@ -1,4 +1,6 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.gui.mappaint;
+
+import java.awt.Image;
 
 import javax.swing.ImageIcon;
@@ -15,7 +17,7 @@
 public class LinePatternElemStyle extends ElemStyle {
 
-    public ImageIcon pattern;
+    public MapImage<Image> pattern;
 
-    public LinePatternElemStyle(Cascade c, ImageIcon pattern) {
+    public LinePatternElemStyle(Cascade c, MapImage<Image> pattern) {
         super(c, -1f);
         this.pattern = pattern;
@@ -31,5 +33,7 @@
         if (icon == null)
             return null;
-        return new LinePatternElemStyle(c, icon);
+        MapImage<Image> pattern = new MapImage<Image>(iconRef.iconName, iconRef.source);
+        pattern.img = icon.getImage();
+        return new LinePatternElemStyle(c, pattern);
     }
 
@@ -37,5 +41,5 @@
     public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
         Way w = (Way)primitive;
-        painter.drawLinePattern(w, pattern);
+        painter.drawLinePattern(w, pattern.img);
     }
 
@@ -52,5 +56,5 @@
             return false;
         final LinePatternElemStyle other = (LinePatternElemStyle) obj;
-        return pattern.getImage() == other.pattern.getImage();
+        return pattern.equals(other.pattern);
     }
 
@@ -62,5 +66,5 @@
     @Override
     public String toString() {
-        return "LinePatternElemStyle{" + super.toString() + "pattern=" + pattern + '}';
+        return "LinePatternElemStyle{" + super.toString() + "pattern=[" + pattern + "]}";
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4821)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4822)
@@ -6,8 +6,8 @@
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Image;
 import java.awt.Rectangle;
 import java.awt.Stroke;
 
-import javax.swing.GrayFilter;
 import javax.swing.ImageIcon;
 
@@ -27,6 +27,5 @@
  */
 public class NodeElemStyle extends ElemStyle {
-    public ImageIcon icon;
-    public int iconAlpha;
+    public MapImage<Image> mapImage;
     public Symbol symbol;
 
@@ -96,8 +95,7 @@
     public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
 
-    protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol) {
+    protected NodeElemStyle(Cascade c, MapImage<Image> mapImage, Symbol symbol) {
         super(c, 1000f);
-        this.icon = icon;
-        this.iconAlpha = iconAlpha == null ? 0 : iconAlpha;
+        this.mapImage = mapImage;
         this.symbol = symbol;
     }
@@ -110,22 +108,19 @@
         Cascade c = env.mc.getCascade(env.layer);
 
-        Pair<ImageIcon, Integer> icon = createIcon(env);
+        MapImage<Image> mapImage = createIcon(env);
         Symbol symbol = null;
-        if (icon == null) {
+        if (mapImage == null) {
             symbol = createSymbol(env);
         }
 
-        // optimization: if we neither have a symbol, nor an icon
+        // optimization: if we neither have a symbol, nor a mapImage
         // we don't have to check for the remaining style properties and we don't
         // have to allocate a node element style.
-        if (!allowDefault && symbol == null && icon == null) return null;
-
-        return new NodeElemStyle(c,
-                icon == null ? null : icon.a,
-                icon == null ? null : icon.b,
-                symbol);
-    }
-
-    private static Pair<ImageIcon, Integer> createIcon(Environment env) {
+        if (!allowDefault && symbol == null && mapImage == null) return null;
+
+        return new NodeElemStyle(c, mapImage, symbol);
+    }
+
+    private static MapImage<Image> createIcon(Environment env) {
         Cascade c = env.mc.getCascade(env.layer);
         Cascade c_def = env.mc.getCascade("default");
@@ -150,14 +145,20 @@
         int height = heightF == null ? -1 : Math.round(heightF);
 
+        MapImage<Image> mapImage = new MapImage<Image>(iconRef.iconName, iconRef.source);
+
         ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height);
-        if (icon == null)
-            return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source), 255);
-        int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
-        Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
-        if (pAlpha != null) {
-            iconAlpha = pAlpha;
-        }
-
-        return new Pair<ImageIcon, Integer>(icon, iconAlpha);
+        if (icon == null) {
+            mapImage.img = MapPaintStyles.getNoIcon_Icon(iconRef.source).getImage();
+        } else {
+            mapImage.img = icon.getImage();
+            mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
+            Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
+            if (pAlpha != null) {
+                mapImage.alpha = pAlpha;
+            }
+            mapImage.width = width;
+            mapImage.height = height;
+        }
+        return mapImage;
     }
 
@@ -241,7 +242,7 @@
         if (primitive instanceof Node) {
             Node n = (Node) primitive;
-            if (icon != null && painter.isShowIcons()) {
-                painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? getDisabledIcon() : icon,
-                        Utils.color_int2float(iconAlpha), selected, member);
+            if (mapImage != null && painter.isShowIcons()) {
+                painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? mapImage.getDisabled() : mapImage.img,
+                        Utils.color_int2float(mapImage.alpha), selected, member);
             } else if (symbol != null) {
                 Color fillColor = symbol.fillColor;
@@ -303,20 +304,12 @@
 
             }
-        } else if (primitive instanceof Relation && icon != null) {
-            painter.drawRestriction((Relation) primitive, this);
-        }
-    }
-
-    public ImageIcon getDisabledIcon() {
-        if (disabledIcon != null)
-            return disabledIcon;
-        if (icon == null)
-            return null;
-        return disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
+        } else if (primitive instanceof Relation && mapImage != null) {
+            painter.drawRestriction((Relation) primitive, mapImage);
+        }
     }
 
     public Rectangle getBox() {
-        if (icon != null) {
-            int w = icon.getIconWidth(), h=icon.getIconHeight();
+        if (mapImage != null) {
+            int w = mapImage.img.getWidth(null), h = mapImage.img.getHeight(null);
             return new Rectangle(-w/2, -h/2, w, h);
         } else if (symbol != null) {
@@ -338,6 +331,5 @@
     public int hashCode() {
         int hash = super.hashCode();
-        hash = 17 * hash + (icon != null ? icon.getImage().hashCode() : 0);
-        hash = 17 * hash + iconAlpha;
+        hash = 17 * hash + (mapImage != null ? mapImage.hashCode() : 0);
         hash = 17 * hash + (symbol != null ? symbol.hashCode() : 0);
         return hash;
@@ -353,7 +345,5 @@
         final NodeElemStyle other = (NodeElemStyle) obj;
         // we should get the same image object due to caching
-        if (icon != other.icon && (icon == null || other.icon == null || icon.getImage() != other.icon.getImage()))
-            return false;
-        if (this.iconAlpha != other.iconAlpha)
+        if (!equal(mapImage, other.mapImage))
             return false;
         if (!equal(symbol, other.symbol))
@@ -362,11 +352,10 @@
     }
 
-
     @Override
     public String toString() {
         StringBuilder s = new StringBuilder("NodeElemStyle{");
         s.append(super.toString());
-        if (icon != null) {
-            s.append(" icon=" + icon + " iconAlpha=" + iconAlpha);
+        if (mapImage != null) {
+            s.append(" icon=[" + mapImage + "]");
         }
         if (symbol != null) {
Index: trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 4821)
+++ trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 4822)
@@ -760,5 +760,5 @@
      * @return the image after rotating.
      */
-    public static ImageIcon createRotatedImage(Component c, Icon icon, double rotatedAngle) {
+    public static Image createRotatedImage(Component c, Image img, double rotatedAngle) {
         // convert rotatedAngle to a value from 0 to 360
         double originalAngle = rotatedAngle % 360;
@@ -775,6 +775,6 @@
         double radian = Math.toRadians(angle);
 
-        int iw = icon.getIconWidth();
-        int ih = icon.getIconHeight();
+        int iw = img.getWidth(null);
+        int ih = img.getHeight(null);
         int w;
         int h;
@@ -802,8 +802,9 @@
 
         g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
-        icon.paintIcon(c, g2d, -cx, -cy);
+        g2d.drawImage(img, -cx, -cy, c);
 
         g2d.dispose();
-        return new ImageIcon(image);
+        new ImageIcon(image); // load completely
+        return image;
     }
 
