Index: /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java
===================================================================
--- /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java	(revision 9712)
+++ /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java	(revision 9713)
@@ -17,9 +17,10 @@
  * 
  */
-public class DefaultMapController extends JMapController implements
-		MouseListener, MouseMotionListener, MouseWheelListener {
+public class DefaultMapController extends JMapController implements MouseListener,
+		MouseMotionListener, MouseWheelListener {
 
-	private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK
-			| MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
+	private static final int MOUSE_BUTTONS_MASK =
+			MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK
+					| MouseEvent.BUTTON2_DOWN_MASK;
 
 	public DefaultMapController(JMapViewer map) {
@@ -34,4 +35,5 @@
 
 	private int movementMouseButton = MouseEvent.BUTTON3;
+	private int movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
 
 	private boolean wheelZoomEnabled = true;
@@ -41,20 +43,18 @@
 		if (!movementEnabled || !isMoving)
 			return;
-		// Is only right mouse button presed?
-		if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
-
+		// Is only the selected mouse button pressed?
+		if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == movementMouseButtonMask) {
+			Point p = e.getPoint();
 			if (lastDragPoint != null) {
-				Point p = e.getPoint();
 				int diffx = lastDragPoint.x - p.x;
 				int diffy = lastDragPoint.y - p.y;
 				map.moveMap(diffx, diffy);
 			}
-			lastDragPoint = e.getPoint();
+			lastDragPoint = p;
 		}
 	}
 
 	public void mouseClicked(MouseEvent e) {
-		if (doubleClickZoomEnabled && e.getClickCount() == 2
-				&& e.getButton() == MouseEvent.BUTTON1)
+		if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
 			map.zoomIn(e.getPoint());
 	}
@@ -109,4 +109,17 @@
 	public void setMovementMouseButton(int movementMouseButton) {
 		this.movementMouseButton = movementMouseButton;
+		switch (movementMouseButton) {
+		case MouseEvent.BUTTON1:
+			movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK;
+			break;
+		case MouseEvent.BUTTON2:
+			movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK;
+			break;
+		case MouseEvent.BUTTON3:
+			movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
+			break;
+		default:
+			throw new RuntimeException("Unsupported button");
+		}
 	}
 
Index: /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
===================================================================
--- /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java	(revision 9712)
+++ /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java	(revision 9713)
@@ -29,7 +29,7 @@
 		final JMapViewer map = new JMapViewer();
 		// final JMapViewer map = new JMapViewer(new MemoryTileCache(),4);
-		// map.setTileLoader(new
-		// OsmFileCacheTileLoader(map,OsmTileLoader.MAP_MAPNIK));
-		new DefaultMapController(map);
+		// map.setTileLoader(new OsmFileCacheTileLoader(map,
+		// OsmTileLoader.MAP_MAPNIK));
+		// new DefaultMapController(map);
 		setLayout(new BorderLayout());
 		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -37,6 +37,7 @@
 		JPanel panel = new JPanel();
 		add(panel, BorderLayout.NORTH);
-		JLabel label = new JLabel(
-				"Use right mouse button to move,\n left double click or mouse wheel to zoom.");
+		JLabel label =
+				new JLabel("Use right mouse button to move,\n "
+						+ "left double click or mouse wheel to zoom.");
 		panel.add(label);
 		JButton button = new JButton("setDisplayToFitMapMarkers");
Index: /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
===================================================================
--- /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java	(revision 9712)
+++ /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java	(revision 9713)
@@ -43,6 +43,6 @@
 	 * Vectors for clock-wise tile painting
 	 */
-	protected static final Point[] move = { new Point(1, 0), new Point(0, 1),
-			new Point(-1, 0), new Point(0, -1) };
+	protected static final Point[] move =
+			{ new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1) };
 
 	public static final int MAX_ZOOM = 18;
@@ -102,6 +102,6 @@
 		setPreferredSize(new Dimension(400, 400));
 		try {
-			loadingImage = ImageIO.read(JMapViewer.class
-					.getResourceAsStream("images/hourglass.png"));
+			loadingImage =
+					ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png"));
 		} catch (Exception e1) {
 			loadingImage = null;
@@ -123,6 +123,5 @@
 		int size = 18;
 		try {
-			ImageIcon icon = new ImageIcon(getClass().getResource(
-					"images/plus.png"));
+			ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png"));
 			zoomInButton = new JButton(icon);
 		} catch (Exception e) {
@@ -140,6 +139,5 @@
 		add(zoomInButton);
 		try {
-			ImageIcon icon = new ImageIcon(getClass().getResource(
-					"images/minus.png"));
+			ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png"));
 			zoomOutButton = new JButton(icon);
 		} catch (Exception e) {
@@ -170,6 +168,5 @@
 	 */
 	public void setDisplayPositionByLatLon(double lat, double lon, int zoom) {
-		setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2),
-				lat, lon, zoom);
+		setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), lat, lon, zoom);
 	}
 
@@ -189,6 +186,5 @@
 	 *            {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM}
 	 */
-	public void setDisplayPositionByLatLon(Point mapPoint, double lat,
-			double lon, int zoom) {
+	public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) {
 		int x = OsmMercator.LonToX(lon, zoom);
 		int y = OsmMercator.LatToY(lat, zoom);
@@ -197,6 +193,5 @@
 
 	public void setDisplayPosition(int x, int y, int zoom) {
-		setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y,
-				zoom);
+		setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom);
 	}
 
@@ -210,8 +205,16 @@
 		p.y = y - mapPoint.y + getHeight() / 2;
 		center = p;
-		this.zoom = zoom;
-		if (zoomSlider.getValue() != zoom)
-			zoomSlider.setValue(zoom);
-		repaint();
+		setIgnoreRepaint(true);
+		try {
+			int oldZoom = this.zoom;
+			this.zoom = zoom;
+			if (oldZoom != zoom)
+				zoomChanged(oldZoom);
+			if (zoomSlider.getValue() != zoom)
+				zoomSlider.setValue(zoom);
+		} finally {
+			setIgnoreRepaint(false);
+			repaint();
+		}
 	}
 
@@ -240,10 +243,10 @@
 		// System.out.println(y_min + " < y < " + y_max);
 		// System.out.println("tiles: " + width + " " + height);
-		int zoom = MAX_ZOOM;
+		int newZoom = MAX_ZOOM;
 		int x = x_max - x_min;
 		int y = y_max - y_min;
 		while (x > width || y > height) {
 			// System.out.println("zoom: " + zoom + " -> " + x + " " + y);
-			zoom--;
+			newZoom--;
 			x >>= 1;
 			y >>= 1;
@@ -251,8 +254,8 @@
 		x = x_min + (x_max - x_min) / 2;
 		y = y_min + (y_max - y_min) / 2;
-		int z = 1 << (MAX_ZOOM - zoom);
+		int z = 1 << (MAX_ZOOM - newZoom);
 		x /= z;
 		y /= z;
-		setDisplayPosition(x, y, zoom);
+		setDisplayPosition(x, y, newZoom);
 	}
 
@@ -334,6 +337,5 @@
 					x++;
 				for (int z = 0; z < x; z++) {
-					if (x_min <= posx && posx <= x_max && y_min <= posy
-							&& posy <= y_max) { // tile
+					if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { // tile
 						// is
 						// visible
@@ -419,5 +421,4 @@
 			return;
 		Point2D.Double zoomPos = getPosition(mapPoint);
-		// addMapMarker(new MapMarkerDot(Color.RED, zoomPos.x, zoomPos.y));
 		jobDispatcher.cancelOutstandingJobs(); // Clearing outstanding load
 		// requests
@@ -450,8 +451,18 @@
 		}
 		if (!tile.isLoaded()) {
-			jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley,
-					zoom));
+			jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, zoom));
 		}
 		return tile;
+	}
+
+	/**
+	 * Every time the zoom level changes this method is called. Override it in
+	 * derived implementations for adapting zoom dependent values. The new zoom
+	 * level can be obtained via {@link #getZoom()}.
+	 * 
+	 * @param oldZoom
+	 *            the previous zoom level
+	 */
+	protected void zoomChanged(int oldZoom) {
 	}
 
