Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java	(revision 4004)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java	(revision 4005)
@@ -21,5 +21,4 @@
 import org.openstreetmap.josm.gui.mappaint.ElemStyle;
 import org.openstreetmap.josm.gui.mappaint.ElemStyles;
-import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle;
@@ -40,17 +39,42 @@
 
     private class StyleCollector {
-        private List<Pair<ElemStyle, OsmPrimitive>> styleElems;
-        protected boolean memberSelected = false;
-        private Class klass;
-
-        public StyleCollector(Class<?> klass) {
+        private final boolean drawArea;
+        private final boolean drawMultipolygon;
+        private final boolean drawRestriction;
+        private final boolean memberSelected;
+
+        private final List<Pair<ElemStyle, OsmPrimitive>> styleElems;
+
+        public StyleCollector(boolean drawArea, boolean drawMultipolygon, boolean drawRestriction, boolean memberSelected) {
+            this.drawArea = drawArea;
+            this.drawMultipolygon = drawMultipolygon;
+            this.drawRestriction = drawRestriction;
+            this.memberSelected = memberSelected;
             styleElems = new ArrayList<Pair<ElemStyle, OsmPrimitive>>();
-            this.klass = klass;
-        }
-
-        public void add(OsmPrimitive osm) {
+        }
+
+        public void add(Node osm) {
             StyleList sl = styles.get(osm, circum, nc);
             for (ElemStyle s : sl) {
-                if (klass.isInstance(s)) {
+                styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));
+            }
+        }
+
+        public void add(Way osm) {
+            StyleList sl = styles.get(osm, circum, nc);
+            for (ElemStyle s : sl) {
+                if (!drawArea && s instanceof AreaElemStyle) {
+                    continue;
+                }
+                styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));
+            }
+        }
+
+        public void add(Relation osm) {
+            StyleList sl = styles.get(osm, circum, nc);
+            for (ElemStyle s : sl) {
+                if (drawMultipolygon && drawArea && s instanceof AreaElemStyle) {
+                    styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));
+                } else if (drawRestriction && s instanceof NodeElemStyle) {
                     styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));
                 }
@@ -63,12 +87,4 @@
                 p.a.paintPrimitive(p.b, paintSettings, painter, data.isSelected(p.b), memberSelected);
             }
-        }
-
-        public boolean isMemberSelected() {
-            return memberSelected;
-        }
-
-        public void setMemberSelected(boolean memberSelected) {
-            this.memberSelected = memberSelected;
         }
     }
@@ -116,99 +132,62 @@
         this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic);
 
-        StyleCollector scDisabledLines = new StyleCollector(LineElemStyle.class);
-        StyleCollector scSelectedLines = new StyleCollector(LineElemStyle.class);
-        StyleCollector scSelectedAreas = new StyleCollector(AreaElemStyle.class);
-        StyleCollector scMemberLines = new StyleCollector(LineElemStyle.class);
-        scMemberLines.setMemberSelected(true);
-        StyleCollector scNormalAreas = new StyleCollector(AreaElemStyle.class);
-        StyleCollector scNormalLines = new StyleCollector(LineElemStyle.class);
+        StyleCollector scDisabledPrimitives = new StyleCollector(false, false, drawRestriction, false);
+        StyleCollector scSelectedPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, false);
+        StyleCollector scMemberPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, true);
+        StyleCollector scNormalPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, false);
+
+        for (final Node n: data.searchNodes(bbox)) {
+            if (n.isDrawable()) {
+                if (n.isDisabled()) {
+                    scDisabledPrimitives.add(n);
+                } else if (n.isSelected()) {
+                    scSelectedPrimitives.add(n);
+                } else if (n.isMemberOfSelected()) {
+                    scMemberPrimitives.add(n);
+                } else {
+                    scNormalPrimitives.add(n);
+                }
+            }
+        }
         for (final Way w : data.searchWays(bbox)) {
             if (w.isDrawable()) {
                 if (w.isDisabled()) {
-                    scDisabledLines.add(w);
+                    scDisabledPrimitives.add(w);
                 } else if (w.isSelected()) {
-                    scSelectedLines.add(w);
-                    if (drawArea) {
-                        scSelectedAreas.add(w);
-                    }
+                    scSelectedPrimitives.add(w);
                 } else if (w.isMemberOfSelected()) {
-                    scMemberLines.add(w);
-                    if (drawArea) {
-                        scNormalAreas.add(w);
-                    }
+                    scMemberPrimitives.add(w);
                 } else {
-                    scNormalLines.add(w);
-                    if (drawArea) {
-                        scNormalAreas.add(w);
-                    }
-                }
-            }
-        }
-        scDisabledLines.drawAll();
-        scDisabledLines = null;
-
-        StyleCollector scDisabledNodes = new StyleCollector(NodeElemStyle.class);
-        StyleCollector scSelectedNodes = new StyleCollector(NodeElemStyle.class);
-        StyleCollector scMemberNodes = new StyleCollector(NodeElemStyle.class);
-        scMemberNodes.setMemberSelected(true);
-        StyleCollector scNormalNodes = new StyleCollector(NodeElemStyle.class);
-        for (final Node n: data.searchNodes(bbox)) {
-            if (n.isDrawable()) {
-                if (n.isDisabled()) {
-                    scDisabledNodes.add(n);
-                } else if (n.isSelected()) {
-                    scSelectedNodes.add(n);
-                } else if (n.isMemberOfSelected()) {
-                    scMemberNodes.add(n);
-                } else {
-                    scNormalNodes.add(n);
-                }
-            }
-        }
-        scDisabledNodes.drawAll();
-        scDisabledNodes = null;
-
-        StyleCollector scDisabledRestrictions = new StyleCollector(NodeElemStyle.class);
-        StyleCollector scNormalRestrictions = new StyleCollector(NodeElemStyle.class);
-        StyleCollector scSelectedRestrictions = new StyleCollector(NodeElemStyle.class);
+                    scNormalPrimitives.add(w);
+                }
+            }
+        }
         for (Relation r: data.searchRelations(bbox)) {
             if (r.isDrawable()) {
                 if (r.isDisabled()) {
-                    if (drawRestriction) {
-                        scDisabledRestrictions.add(r);
-                    }
+                    scDisabledPrimitives.add(r);
                 } else if (r.isSelected()) {
-                    if (drawMultipolygon) {
-                        scSelectedAreas.add(r);
-                    }
-                    if (drawRestriction) {
-                        scSelectedRestrictions.add(r);
-                    }
+                    scSelectedPrimitives.add(r);
                 } else {
-                    if (drawMultipolygon) {
-                        scNormalAreas.add(r);
-                    }
-                    if (drawRestriction) {
-                        scNormalRestrictions.add(r);
-                    }
-                }
-            }
-        }
-        scDisabledRestrictions.drawAll();
-        scDisabledRestrictions = null;
-
-        scNormalAreas.drawAll();
-        scSelectedAreas.drawAll();
-        scNormalLines.drawAll();
-        scMemberLines.drawAll();
-        scSelectedLines.drawAll();
-        scNormalNodes.drawAll();
-        scNormalRestrictions.drawAll();
-        scMemberNodes.drawAll();
-        scSelectedRestrictions.drawAll();
-        scSelectedNodes.drawAll();
+                    scNormalPrimitives.add(r);
+                }
+            }
+        }
+
+        //long phase1 = System.currentTimeMillis();
+
+        scDisabledPrimitives.drawAll();
+        scDisabledPrimitives = null;
+        scNormalPrimitives.drawAll();
+        scNormalPrimitives = null;
+        scMemberPrimitives.drawAll();
+        scMemberPrimitives = null;
+        scSelectedPrimitives.drawAll();
+        scSelectedPrimitives = null;
 
         painter.drawVirtualNodes(data.searchWays(bbox));
-        //System.err.println("PAINTING TOOK "+(System.currentTimeMillis() - start)+ " (at scale "+circum+")");
+        
+        //long now = System.currentTimeMillis();
+        //System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum));
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4004)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4005)
@@ -30,5 +30,5 @@
 
     protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
-        super(c);
+        super(c, -1000f);
         CheckParameterUtil.ensureParameterNotNull(color);
         this.color = color;
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java	(revision 4004)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java	(revision 4005)
@@ -27,6 +27,6 @@
     }
 
-    protected ElemStyle(Cascade c) {
-        z_index = c.get("z-index", 0f, Float.class);
+    protected ElemStyle(Cascade c, float default_z_index) {
+        z_index = c.get("z-index", default_z_index, Float.class);
         object_z_index = c.get("object-z-index", 0f, Float.class);
         isModifier = c.get("modifier", false, Boolean.class);
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java	(revision 4004)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java	(revision 4005)
@@ -36,5 +36,5 @@
 
     protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, TextElement text, float realWidth) {
-        super(c);
+        super(c, 0f);
         this.line = line;
         this.color = color;
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4004)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4005)
@@ -141,5 +141,5 @@
 
     protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol, NodeTextElement text) {
-        super(c);
+        super(c, 1000f);
         this.icon = icon;
         this.iconAlpha = iconAlpha == null ? 0 : iconAlpha;
