Index: trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 2450)
@@ -11,5 +11,4 @@
 import java.awt.Cursor;
 import java.awt.EventQueue;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Point;
@@ -41,4 +40,5 @@
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.SelectionChangedListener;
 import org.openstreetmap.josm.data.coor.EastNorth;
@@ -879,5 +879,5 @@
     }
 
-    public void paint(Graphics g, MapView mv) {
+    public void paint(Graphics2D g, MapView mv, Bounds box) {
         if (!drawHelperLine || wayIsFinished || shift) return;
 
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 2450)
@@ -8,5 +8,4 @@
 import java.awt.Color;
 import java.awt.Cursor;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Point;
@@ -29,4 +28,5 @@
 import org.openstreetmap.josm.command.MoveCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.Node;
@@ -230,5 +230,5 @@
     }
 
-    public void paint(Graphics g, MapView mv) {
+    public void paint(Graphics2D g, MapView mv, Bounds box) {
         if (mode == Mode.select) {
             // Nothing to do
Index: trunk/src/org/openstreetmap/josm/data/osm/BBox.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/BBox.java	(revision 2450)
+++ trunk/src/org/openstreetmap/josm/data/osm/BBox.java	(revision 2450)
@@ -0,0 +1,145 @@
+package org.openstreetmap.josm.data.osm;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
+
+public class BBox {
+
+    private double xmin = Double.POSITIVE_INFINITY;
+    private double xmax = Double.NEGATIVE_INFINITY;
+    private double ymin = Double.POSITIVE_INFINITY;
+    private double ymax = Double.NEGATIVE_INFINITY;
+
+    public BBox(Bounds bounds) {
+        add(bounds.getMin());
+        add(bounds.getMax());
+    }
+
+    public BBox(LatLon a, LatLon b) {
+        add(a);
+        add(b);
+    }
+
+    public BBox(double a_x, double a_y, double b_x, double b_y)  {
+        xmin = Math.min(a_x, b_x);
+        xmax = Math.max(a_x, b_x);
+        ymin = Math.min(a_y, b_y);
+        ymax = Math.max(a_y, b_y);
+        sanity();
+    }
+
+    public BBox(Way w) {
+        for (Node n : w.getNodes()) {
+            LatLon coor = n.getCoor();
+            if (coor == null) {
+                continue;
+            }
+            add(coor);
+        }
+    }
+
+    private void sanity()  {
+        if (xmin < -180.0) {
+            xmin = -180.0;
+        }
+        if (xmax >  180.0) {
+            xmax =  180.0;
+        }
+        if (ymin <  -90.0) {
+            ymin =  -90.0;
+        }
+        if (ymax >   90.0) {
+            ymax =   90.0;
+        }
+    }
+
+    public void add(LatLon c) {
+        add(c.lon(), c.lat());
+    }
+
+    public void add(double x, double y) {
+        xmin = Math.min(xmin, x);
+        xmax = Math.max(xmax, x);
+        ymin = Math.min(ymin, y);
+        ymax = Math.max(ymax, y);
+        sanity();
+    }
+
+    public void addPrimitive(OsmPrimitive primitive, double extraSpace) {
+        BBox primBbox = primitive.getBBox();
+        add(primBbox.xmin - extraSpace, primBbox.ymin - extraSpace);
+        add(primBbox.xmax + extraSpace, primBbox.ymax + extraSpace);
+    }
+
+    public double height() {
+        return ymax-ymin;
+    }
+
+    public double width() {
+        return xmax-xmin;
+    }
+
+    public boolean bounds(BBox b) {
+        if (!(xmin <= b.xmin) ||
+                !(xmax >= b.xmax) ||
+                !(ymin <= b.ymin) ||
+                !(ymax >= b.ymax))
+            return false;
+        return true;
+    }
+
+    public boolean bounds(LatLon c) {
+        if ((xmin <= c.lon()) &&
+                (xmax >= c.lon()) &&
+                (ymin <= c.lat()) &&
+                (ymax >= c.lat()))
+            return true;
+        return false;
+    }
+
+    public boolean inside(BBox b) {
+        if (xmin >= b.xmax)
+            return false;
+        if (xmax <= b.xmin)
+            return false;
+        if (ymin >= b.ymax)
+            return false;
+        if (ymax <= b.ymin)
+            return false;
+        return true;
+    }
+
+    public boolean intersects(BBox b) {
+        return this.inside(b) || b.inside(this);
+    }
+
+    public List<LatLon> points()  {
+        LatLon p1 = new LatLon(ymin, xmin);
+        LatLon p2 = new LatLon(ymin, xmax);
+        LatLon p3 = new LatLon(ymax, xmin);
+        LatLon p4 = new LatLon(ymax, xmax);
+        List<LatLon> ret = new ArrayList<LatLon>(4);
+        ret.add(p1);
+        ret.add(p2);
+        ret.add(p3);
+        ret.add(p4);
+        return ret;
+    }
+
+    public LatLon getTopLeft() {
+        return new LatLon(ymax, xmin);
+    }
+
+    public LatLon getBottomRight() {
+        return new LatLon(ymin, xmax);
+    }
+
+    @Override
+    public String toString() {
+        return "[ x: " + xmin + " -> " + xmax +
+        ", y: " + ymin + " -> " + ymax + " ]";
+    }
+}
Index: trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 2450)
@@ -20,5 +20,4 @@
 
 import org.openstreetmap.josm.data.SelectionChangedListener;
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 
 /**
Index: trunk/src/org/openstreetmap/josm/data/osm/Node.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 2450)
@@ -5,5 +5,4 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 import org.openstreetmap.josm.data.osm.visitor.Visitor;
 
Index: trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 2450)
@@ -19,5 +19,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 import org.openstreetmap.josm.data.osm.visitor.Visitor;
 import org.openstreetmap.josm.gui.mappaint.ElemStyle;
@@ -219,5 +218,5 @@
      * @param disabled true, if this primitive is disabled; false, otherwise
      */
-    public void setDisabled(boolean disabled) {
+    void setDisabled(boolean disabled) {
         if (disabled) {
             flags |= FLAG_DISABLED;
Index: trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java	(revision 2450)
@@ -58,141 +58,5 @@
     public static double WORLD_PARTS = (1 << NR_LEVELS);
 
-    public static int MAX_OBJECTS_PER_LEVEL = 16;
-    // has to be a power of 2
-    public static int TILES_PER_LEVEL_SHIFT = 2;
-    public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;
-    // Maybe this should just be a Rectangle??
-    public static class BBox
-    {
-        private double xmin = Double.POSITIVE_INFINITY;
-        private double xmax = Double.NEGATIVE_INFINITY;
-        private double ymin = Double.POSITIVE_INFINITY;
-        private double ymax = Double.NEGATIVE_INFINITY;
-        void sanity()
-        {
-            if (xmin < -180.0) {
-                xmin = -180.0;
-            }
-            if (xmax >  180.0) {
-                xmax =  180.0;
-            }
-            if (ymin <  -90.0) {
-                ymin =  -90.0;
-            }
-            if (ymax >   90.0) {
-                ymax =   90.0;
-            }
-            if ((xmin < -180.0) ||
-                    (xmax >  180.0) ||
-                    (ymin <  -90.0) ||
-                    (ymax >   90.0))
-                throw new IllegalArgumentException("bad BBox: " + this);
-        }
-        @Override
-        public String toString()
-        {
-            return "[ x: " + xmin + " -> " + xmax +
-            ", y: " + ymin + " -> " + ymax + " ]";
-        }
-        double min(double a, double b)
-        {
-            if (a < b)
-                return a;
-            return b;
-        }
-        double max(double a, double b)
-        {
-            if (a > b)
-                return a;
-            return b;
-        }
-        private void add(LatLon c)
-        {
-            xmin = min(xmin, c.lon());
-            xmax = max(xmax, c.lon());
-            ymin = min(ymin, c.lat());
-            ymax = max(ymax, c.lat());
-        }
-        public BBox(LatLon a, LatLon b)
-        {
-            add(a);
-            add(b);
-            sanity();
-        }
-        public BBox(double a_x, double a_y, double b_x, double b_y)
-        {
-            xmin = min(a_x, b_x);
-            xmax = max(a_x, b_x);
-            ymin = min(a_y, b_y);
-            ymax = max(a_y, b_y);
-            sanity();
-        }
-        public BBox(Way w)
-        {
-            for (Node n : w.getNodes()) {
-                LatLon coor = n.getCoor();
-                if (coor == null) {
-                    continue;
-                }
-                add(coor);
-            }
-            this.sanity();
-        }
-        public double height()
-        {
-            return ymax-ymin;
-        }
-        public double width()
-        {
-            return xmax-xmin;
-        }
-        boolean bounds(BBox b)
-        {
-            if (!(xmin <= b.xmin) ||
-                    !(xmax >= b.xmax) ||
-                    !(ymin <= b.ymin) ||
-                    !(ymax >= b.ymax))
-                return false;
-            return true;
-        }
-        boolean bounds(LatLon c)
-        {
-            if ((xmin <= c.lon()) &&
-                    (xmax >= c.lon()) &&
-                    (ymin <= c.lat()) &&
-                    (ymax >= c.lat()))
-                return true;
-            return false;
-        }
-        boolean inside(BBox b)
-        {
-            if (xmin >= b.xmax)
-                return false;
-            if (xmax <= b.xmin)
-                return false;
-            if (ymin >= b.ymax)
-                return false;
-            if (ymax <= b.ymin)
-                return false;
-            return true;
-        }
-        boolean intersects(BBox b)
-        {
-            return this.inside(b) || b.inside(this);
-        }
-        List<LatLon> points()
-        {
-            LatLon p1 = new LatLon(ymin, xmin);
-            LatLon p2 = new LatLon(ymin, xmax);
-            LatLon p3 = new LatLon(ymax, xmin);
-            LatLon p4 = new LatLon(ymax, xmax);
-            List<LatLon> ret = new ArrayList<LatLon>();
-            ret.add(p1);
-            ret.add(p2);
-            ret.add(p3);
-            ret.add(p4);
-            return ret;
-        }
-    }
+    public static int MAX_OBJECTS_PER_LEVEL = 2;
     class QBLevel
     {
@@ -294,6 +158,7 @@
                     continue;
                 }
-                if (children == null)
+                if (children == null) {
                     children = newChildren();
+                }
                 if (children[new_index] == null) {
                     children[new_index] = new QBLevel(this, new_index);
@@ -725,8 +590,6 @@
         public BBox bbox()
         {
-            if (bbox != null) {
-                bbox.sanity();
+            if (bbox != null)
                 return bbox;
-            }
             if (level == 0) {
                 bbox = new BBox(-180, 90, 180, -90);
@@ -738,5 +601,4 @@
                 bbox = new BBox(bottom_left, top_right);
             }
-            bbox.sanity();
             return bbox;
         }
@@ -1100,5 +962,4 @@
             out("search bbox before sanity: " +  bbox);
         }
-        bbox.sanity();
         if (debug) {
             out("search bbox after sanity: " +  bbox);
@@ -1124,5 +985,4 @@
     {
         BBox bbox = new BBox(b1.lon(), b1.lat(), b2.lon(), b2.lat());
-        bbox.sanity();
         return this.search(bbox);
     }
Index: trunk/src/org/openstreetmap/josm/data/osm/Relation.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/Relation.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/Relation.java	(revision 2450)
@@ -7,5 +7,4 @@
 import java.util.Set;
 
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 import org.openstreetmap.josm.data.osm.visitor.Visitor;
 import org.openstreetmap.josm.tools.CopyList;
Index: trunk/src/org/openstreetmap/josm/data/osm/Way.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/Way.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/Way.java	(revision 2450)
@@ -9,5 +9,4 @@
 import java.util.List;
 
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 import org.openstreetmap.josm.data.osm.visitor.Visitor;
 import org.openstreetmap.josm.tools.CopyList;
Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java	(revision 2450)
@@ -32,6 +32,8 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.BBox;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -114,9 +116,9 @@
             return (styles != null) ? styles.getIcon(osm) : null;
 
-        if(osm.mappaintStyle == null && styles != null) {
-            osm.mappaintStyle = styles.getIcon(osm);
-        }
-
-        return (IconElemStyle)osm.mappaintStyle;
+            if(osm.mappaintStyle == null && styles != null) {
+                osm.mappaintStyle = styles.getIcon(osm);
+            }
+
+            return (IconElemStyle)osm.mappaintStyle;
     }
 
@@ -1445,5 +1447,6 @@
     /* Shows areas before non-areas */
     @Override
-    public void visitAll(DataSet data, Boolean virtual) {
+    public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
+        BBox bbox = new BBox(bounds);
         this.data = data;
         //boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
@@ -1521,5 +1524,5 @@
             /*** AREAS ***/
             //    profilerN = 0;
-            for (final Way osm : selectedLast(data, data.getWays())) {
+            for (final Way osm : selectedLast(data, data.searchWays(bbox))) {
                 if (drawable(osm)
                         && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid) {
@@ -1614,5 +1617,5 @@
         /*** NODES ***/
         //profilerN = 0;
-        for (final Node osm: data.getNodes()) {
+        for (final Node osm: data.searchNodes(bbox)) {
             if (!osm.incomplete && !osm.isDeleted() && (data.isSelected(osm) || !osm.isFiltered())
                     && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid)
@@ -1634,5 +1637,5 @@
             //    profilerN = 0;
             currentColor = nodeColor;
-            for (final OsmPrimitive osm: data.getWays()) {
+            for (final OsmPrimitive osm: data.searchWays(bbox)) {
                 if (osm.isUsable() && !osm.isFiltered()
                         && osm.mappaintVisibleCode != viewid )
Index: trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java	(revision 2450)
@@ -19,4 +19,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -129,5 +130,5 @@
 
     DataSet ds;
-    public void visitAll(DataSet data, Boolean virtual) {
+    public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
         this.ds = data;
         //boolean profiler = Main.pref.getBoolean("simplepaint.profiler",false);
Index: trunk/src/org/openstreetmap/josm/gui/MapView.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 2450)
@@ -50,4 +50,5 @@
 import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker;
 import org.openstreetmap.josm.tools.AudioPlayer;
+
 
 /**
@@ -385,9 +386,11 @@
         tempG.fillRect(0, 0, getWidth(), getHeight());
 
+        Bounds box = getLatLonBounds(g.getClipBounds());
+
         for (Layer l: getVisibleLayersInZOrder()) {
-            l.paint(tempG, this);
+            l.paint(tempG, this, box);
         }
         for (MapViewPaintable mvp : temporaryLayers) {
-            mvp.paint(tempG, this);
+            mvp.paint(tempG, this, box);
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 2450)
@@ -4,4 +4,5 @@
 
 import java.awt.Point;
+import java.awt.Rectangle;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -20,4 +21,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.BBox;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -25,5 +27,4 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WaySegment;
-import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
 import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.help.Helpful;
@@ -154,4 +155,32 @@
     public LatLon getLatLon(int x, int y) {
         return getProjection().eastNorth2latlon(getEastNorth(x, y));
+    }
+
+    /**
+     * @param r
+     * @return Minimum bounds that will cover rectangle
+     */
+    public Bounds getLatLonBounds(Rectangle r) {
+        // TODO Maybe this should be (optional) method of Projection implementation
+        EastNorth p1 = getEastNorth(r.x, r.y);
+        EastNorth p2 = getEastNorth(r.x + r.width, r.y + r.height);
+
+        Bounds result = new Bounds(Main.proj.eastNorth2latlon(p1));
+
+        double eastMin = Math.min(p1.east(), p2.east());
+        double eastMax = Math.max(p1.east(), p2.east());
+        double northMin = Math.min(p1.north(), p2.north());
+        double northMax = Math.min(p1.north(), p2.north());
+        double deltaEast = (eastMax - eastMin) / 10;
+        double deltaNorth = (northMax - northMin) / 10;
+
+        for (int i=0; i < 10; i++) {
+            result.extend(Main.proj.eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMin)));
+            result.extend(Main.proj.eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMax)));
+            result.extend(Main.proj.eastNorth2latlon(new EastNorth(eastMin, northMin  + i * deltaNorth)));
+            result.extend(Main.proj.eastNorth2latlon(new EastNorth(eastMax, northMin  + i * deltaNorth)));
+        }
+
+        return result;
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java	(revision 2450)
@@ -9,5 +9,4 @@
 import java.awt.Component;
 import java.awt.Cursor;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GridBagLayout;
@@ -63,4 +62,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.RenameLayerAction;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.coor.CachedLatLon;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -641,5 +641,5 @@
     }
 
-    @Override public void paint(Graphics g, MapView mv) {
+    @Override public void paint(Graphics2D g, MapView mv, Bounds box) {
         int clickedIndex = -1;
 
Index: trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 2450)
@@ -10,5 +10,4 @@
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GridBagLayout;
@@ -49,4 +48,5 @@
 import org.openstreetmap.josm.actions.RenameLayerAction;
 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -143,9 +143,9 @@
                         tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                 switch (answer) {
-                    case JOptionPane.CANCEL_OPTION:
-                    case JOptionPane.CLOSED_OPTION:
-                        return;
-                    default:
-                        // continue
+                case JOptionPane.CANCEL_OPTION:
+                case JOptionPane.CLOSED_OPTION:
+                    return;
+                default:
+                    // continue
                 }
                 if (group.getSelection() == r[0].getModel()) {
@@ -174,12 +174,12 @@
                 );
                 switch (answer) {
-                    case 0:
-                        Main.pref.putColor("layer " + getName(), c.getColor());
-                        break;
-                    case 1:
-                        return;
-                    case 2:
-                        Main.pref.putColor("layer " + getName(), null);
-                        break;
+                case 0:
+                    Main.pref.putColor("layer " + getName(), c.getColor());
+                    break;
+                case 1:
+                    return;
+                case 2:
+                    Main.pref.putColor("layer " + getName(), null);
+                    break;
                 }
                 Main.map.repaint();
@@ -444,5 +444,5 @@
 
     @Override
-    public void paint(Graphics g, MapView mv) {
+    public void paint(Graphics2D g, MapView mv, Bounds box) {
 
         /****************************************************************
@@ -490,6 +490,5 @@
         if(lineWidth != 0)
         {
-            Graphics2D g2d = (Graphics2D)g;
-            g2d.setStroke(new BasicStroke(lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
+            g.setStroke(new BasicStroke(lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
         }
 
@@ -531,29 +530,29 @@
 
                             switch (colored) {
-                                case velocity:
-                                    double dtime = trkPnt.time - oldWp.time;
-                                    double vel = dist / dtime;
-                                    double velColor = vel / colorTracksTune * 255;
-                                    // Bad case first
-                                    if (dtime <= 0 || vel < 0 || velColor > 255) {
-                                        trkPnt.customColoring = colors[255];
-                                    } else {
-                                        trkPnt.customColoring = colors[(int) (velColor)];
+                            case velocity:
+                                double dtime = trkPnt.time - oldWp.time;
+                                double vel = dist / dtime;
+                                double velColor = vel / colorTracksTune * 255;
+                                // Bad case first
+                                if (dtime <= 0 || vel < 0 || velColor > 255) {
+                                    trkPnt.customColoring = colors[255];
+                                } else {
+                                    trkPnt.customColoring = colors[(int) (velColor)];
+                                }
+                                break;
+
+                            case dilution:
+                                if (trkPnt.attr.get("hdop") != null) {
+                                    float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue();
+                                    if (hdop < 0) {
+                                        hdop = 0;
                                     }
-                                    break;
-
-                                case dilution:
-                                    if (trkPnt.attr.get("hdop") != null) {
-                                        float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue();
-                                        if (hdop < 0) {
-                                            hdop = 0;
-                                        }
-                                        int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
-                                        // High hdop is bad, but high values in colors are green.
-                                        // Therefore inverse the logic
-                                        int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
-                                        trkPnt.customColoring = colors[hdopcolor];
-                                    }
-                                    break;
+                                    int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
+                                    // High hdop is bad, but high values in colors are green.
+                                    // Therefore inverse the logic
+                                    int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
+                                    trkPnt.customColoring = colors[hdopcolor];
+                                }
+                                break;
                             }
 
@@ -838,9 +837,9 @@
             );
             switch(ret) {
-                case JOptionPane.CANCEL_OPTION:
-                case JOptionPane.CLOSED_OPTION:
-                    return;
-                default:
-                    // continue
+            case JOptionPane.CANCEL_OPTION:
+            case JOptionPane.CLOSED_OPTION:
+                return;
+            default:
+                // continue
             }
 
@@ -936,9 +935,9 @@
                 );
                 switch(ret) {
-                    case JOptionPane.CANCEL_OPTION:
-                    case JOptionPane.CLOSED_OPTION:
-                        return;
-                    default:
-                        // continue
+                case JOptionPane.CANCEL_OPTION:
+                case JOptionPane.CLOSED_OPTION:
+                    return;
+                default:
+                    // continue
                 }
             }
Index: trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 2450)
@@ -6,5 +6,5 @@
 
 import java.awt.Component;
-import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeListener;
@@ -20,4 +20,5 @@
 import org.openstreetmap.josm.actions.SaveAction;
 import org.openstreetmap.josm.actions.SaveAsAction;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
 import org.openstreetmap.josm.gui.MapView;
@@ -98,5 +99,5 @@
      * @param mv The object that can translate GeoPoints to screen coordinates.
      */
-    abstract public void paint(Graphics g, MapView mv);
+    abstract public void paint(Graphics2D g, MapView mv, Bounds box);
     /**
      * Return a representative small image for this layer. The image must not
Index: trunk/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java	(revision 2450)
@@ -2,6 +2,7 @@
 package org.openstreetmap.josm.gui.layer;
 
-import java.awt.Graphics;
+import java.awt.Graphics2D;
 
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.gui.MapView;
 
@@ -12,5 +13,5 @@
      * @param mv The object that can translate GeoPoints to screen coordinates.
      */
-    abstract public void paint(Graphics g, MapView mv);
+    void paint(Graphics2D g, MapView mv, Bounds bbox);
 
 }
Index: trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 2450)
@@ -12,5 +12,4 @@
 import java.awt.Component;
 import java.awt.Composite;
-import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GridBagLayout;
@@ -40,4 +39,5 @@
 import org.openstreetmap.josm.actions.RenameLayerAction;
 import org.openstreetmap.josm.command.PurgePrimitivesCommand;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.conflict.ConflictCollection;
@@ -204,5 +204,5 @@
      * Draw nodes last to overlap the ways they belong to.
      */
-    @Override public void paint(final Graphics g, final MapView mv) {
+    @Override public void paint(final Graphics2D g, final MapView mv, Bounds box) {
         boolean active = mv.getActiveLayer() == this;
         boolean inactive = !active && Main.pref.getBoolean("draw.data.inactive_color", true);
@@ -245,5 +245,5 @@
         painter.setNavigatableComponent(mv);
         painter.inactive = inactive;
-        painter.visitAll(data, virtual);
+        painter.visitAll(data, virtual, box);
         Main.map.conflictDialog.paintConflicts(g, mv);
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 2450)
@@ -9,5 +9,5 @@
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.GridBagLayout;
 import java.awt.Point;
@@ -33,4 +33,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.RenameLayerAction;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
 import org.openstreetmap.josm.data.coor.EastNorth;
@@ -122,5 +123,5 @@
     }
 
-    @Override public void paint(Graphics g, MapView mv) {
+    @Override public void paint(Graphics2D g, MapView mv, Bounds box) {
         g.setColor(Main.pref.getColor(marktr("gps point"), "layer "+getName(), Color.gray));
         Point old = null;
@@ -244,12 +245,12 @@
                         JOptionPane.PLAIN_MESSAGE, null,options, options[0]);
                 switch (answer) {
-                    case 0:
-                        Main.pref.putColor("layer "+getName(), c.getColor());
-                        break;
-                    case 1:
-                        return;
-                    case 2:
-                        Main.pref.putColor("layer "+getName(), null);
-                        break;
+                case 0:
+                    Main.pref.putColor("layer "+getName(), c.getColor());
+                    break;
+                case 1:
+                    return;
+                case 2:
+                    Main.pref.putColor("layer "+getName(), null);
+                    break;
                 }
                 Main.map.repaint();
Index: trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 2449)
+++ trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 2450)
@@ -8,5 +8,5 @@
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Point;
 import java.awt.event.ActionEvent;
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.RenameLayerAction;
+import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.gpx.GpxData;
@@ -152,5 +153,5 @@
     }
 
-    @Override public void paint(Graphics g, MapView mv) {
+    @Override public void paint(Graphics2D g, MapView mv, Bounds box) {
         boolean mousePressedTmp = mousePressed;
         Point mousePos = mv.getMousePosition();
@@ -210,12 +211,12 @@
                 );
                 switch (answer) {
-                    case 0:
-                        Main.pref.putColor("layer "+getName(), c.getColor());
-                        break;
-                    case 1:
-                        return;
-                    case 2:
-                        Main.pref.putColor("layer "+getName(), null);
-                        break;
+                case 0:
+                    Main.pref.putColor("layer "+getName(), c.getColor());
+                    break;
+                case 1:
+                    return;
+                case 2:
+                    Main.pref.putColor("layer "+getName(), null);
+                    break;
                 }
                 Main.map.repaint();
