Index: /applications/editors/josm/plugins/slippy_map_chooser/build.xml
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/build.xml	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/build.xml	(revision 7199)
@@ -0,0 +1,56 @@
+<project name="slippy_map_chooser" default="dist" basedir=".">
+
+  <!-- josm "user home" directory depends on the platform used (windows has a different place than unix/linux) -->
+  <property environment="env"/>
+  <condition property="josm.home.dir" value="${env.APPDATA}/JOSM" else="${user.home}/.josm">
+    <and>
+      <os family="windows"/>
+    </and>
+  </condition>
+
+  <!-- compilation properties -->
+  <property name="josm.build.dir"	value="../../core"/>
+  <property name="josm.plugins.dir" value="${josm.home.dir}/plugins"/>
+  <property name="josm"				location="../../core/dist/josm-custom.jar" />
+  <property name="plugin.build.dir"	value="build"/>
+  <property name="plugin.dist.dir"	value="../../dist"/>
+  <property name="plugin.name"		value="${ant.project.name}"/>
+  <property name="plugin.jar"		value="../../dist/${plugin.name}.jar"/>
+
+  <property name="ant.build.javac.target" value="1.5"/>
+  
+
+  <target name="dist" depends="compile">
+    <!-- images -->
+    <copy todir="build/images">
+      <fileset dir="images" />
+    </copy>
+    
+    <jar destfile="${plugin.jar}" basedir="build">
+    	<manifest>
+			<attribute name="Plugin-Class" value="SlippyMapChooserPlugin" />
+			<attribute name="Plugin-Description" value="Adds a new download dialog that allows to select the download rectangle on the slippy map. With this plugin it's possible to download ways and gpx logs without knowing the coordinates of the desired download rectangle - just navigate to the desired area by zooming and moving the slippy map, mark the area with a rectangle and click download. Works great together with the namefinder plugin!" />
+			<attribute name="Plugin-Author" value="slippy_map_chooser@freakmail.de" />
+			<attribute name="Plugin-Version" value="1.1" />
+		</manifest>
+    </jar>
+  </target>
+
+  <target name="compile" depends="init">
+    <javac srcdir="src" classpath="../../core/dist/josm-custom.jar" destdir="build" />
+  </target>
+  
+  <target name="init">
+    <mkdir dir="${plugin.build.dir}" />
+  </target>
+  
+  <target name="clean">
+    <delete dir="${plugin.build.dir}" />
+    <delete file="${plugin.jar}" />
+  </target>
+  
+  <target name="install" depends="dist">
+    <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
+  </target>
+
+</project>
Index: /applications/editors/josm/plugins/slippy_map_chooser/images/license_tango_project.txt
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/images/license_tango_project.txt	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/images/license_tango_project.txt	(revision 7199)
@@ -0,0 +1,67 @@
+Creative Commons Attribution-ShareAlike 2.5 License Agreement
+
+CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
+
+License
+
+THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
+
+BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
+
+1. Definitions
+
+   1. "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
+   2. "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
+   3. "Licensor" means the individual or entity that offers the Work under the terms of this License.
+   4. "Original Author" means the individual or entity who created the Work.
+   5. "Work" means the copyrightable work of authorship offered under the terms of this License.
+   6. "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
+   7. "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.
+
+2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.
+
+3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
+
+   1. to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
+   2. to create and reproduce Derivative Works;
+   3. to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
+   4. to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
+   5.
+
+      For the avoidance of doubt, where the work is a musical composition:
+         1. Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
+         2. Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
+   6. Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).
+
+The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.
+
+4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
+
+   1. You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
+   2. You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
+   3. If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.
+
+5. Representations, Warranties and Disclaimer
+
+UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
+
+6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. Termination
+
+   1. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
+   2. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
+
+8. Miscellaneous
+
+   1. Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
+   2. Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
+   3. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+   4. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
+   5. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
+
+Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
+
+Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, neither party will use the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time.
+
+Creative Commons may be contacted at http://creativecommons.org/.
Index: /applications/editors/josm/plugins/slippy_map_chooser/images/tango_project.txt
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/images/tango_project.txt	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/images/tango_project.txt	(revision 7199)
@@ -0,0 +1,1 @@
+http://tango.freedesktop.org/Tango_Desktop_Project
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/Logger.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/Logger.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/Logger.java	(revision 7199)
@@ -0,0 +1,66 @@
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+
+/**
+ * 
+ * @author Tim Haussmann
+ */
+
+public class Logger {
+
+	private static Logger iSelf;
+	
+	private File iLogFile;
+	private FileOutputStream iFout;
+	
+	private Logger(String aLogFilePath){
+		if(aLogFilePath != null && !aLogFilePath.equals(""))
+			iLogFile = new File(aLogFilePath);
+		else
+			iLogFile = new File("c:/LogFile.txt");
+		
+		try {
+			iFout = new FileOutputStream(iLogFile, false);
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public static void log(String aMessage){
+		if(iSelf == null)
+			iSelf = new Logger(null);
+		iSelf.logMessage(aMessage);
+	}
+	
+	public static void close(){
+		iSelf.saveLog();
+		iSelf = null;
+	}
+	
+	private void saveLog() {
+		try {
+			iFout.flush();
+			iFout.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public static void setLogFile(String aLogFilePath){
+		iSelf = new Logger(aLogFilePath);
+	}
+
+	private void logMessage(String aMessage){
+		try {
+			iFout.write((aMessage + "\n").getBytes());
+			iFout.flush();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}		
+	}
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMapControl.java	(revision 7199)
@@ -0,0 +1,223 @@
+// This code has been adapted and copied from code that has been written by Immanuel Scholz and others for JOSM.
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+import java.awt.Cursor;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.KeyStroke;
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+/**
+ * This class controls the user input by listening to mouse and key events. Currently implemented is:
+ * - zooming in and out with scrollwheel
+ * - zooming in and centering by double clicking
+ * - selecting an area by clicking and dragging the mouse
+ * 
+ * @author Tim Haussmann
+ */
+public class OsmMapControl extends MouseAdapter implements MouseMotionListener, MouseWheelListener {
+
+	
+	//positions while moving the map
+	private int iLastX = 0;
+	private int iLastY = 0;
+	
+	//start and end point of selection rectangle
+	private Point iStartSelectionPoint;
+	private Point iEndSelectionPoint;
+
+	//the SlippyMapChooserComponent
+	private final SlippyMapChooser iSlippyMapChooser;
+	
+	//The old cursor when we changed it to movement cursor.
+	private Cursor iOldCursor;
+
+	private boolean isMovementInPlace = false;
+	
+	private SizeButton iSizeButton = null;
+
+	
+	private final class ZoomerAction extends AbstractAction {
+		private final String action;
+		public ZoomerAction(String action) {
+			this.action = action;
+        }
+	    public void actionPerformed(ActionEvent e) {
+	    	if (action.equals(".") || action.equals(",")) {
+	    		Point mouse = iSlippyMapChooser.getMousePosition();
+	    		if (mouse == null)
+	    			mouse = new Point((int)iSlippyMapChooser.getBounds().getCenterX(), (int)iSlippyMapChooser.getBounds().getCenterY());
+	    		MouseWheelEvent we = new MouseWheelEvent(iSlippyMapChooser, e.getID(), e.getWhen(), e.getModifiers(), mouse.x, mouse.y, 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, action.equals(",") ? -1 : 1);
+	    		mouseWheelMoved(we);
+	    	} else {
+	    		if (action.equals(tr("left")))
+	    			iSlippyMapChooser.moveMap(-30, 0);
+	    		else if (action.equals("right"))
+	    			iSlippyMapChooser.moveMap(30, 0);
+	    		else if (action.equals("up"))
+	    			iSlippyMapChooser.moveMap(0, -30);
+	    		else if (action.equals("down"))
+	    			iSlippyMapChooser.moveMap(0, 30);
+	    	}
+	    }
+    }
+	
+	
+	
+	/**
+	 * Create a new OsmMapControl
+	 */
+	public OsmMapControl(SlippyMapChooser navComp, JPanel contentPane, SizeButton sizeButton) {
+		this.iSlippyMapChooser = navComp;
+		iSlippyMapChooser.addMouseListener(this);
+		iSlippyMapChooser.addMouseMotionListener(this);
+		iSlippyMapChooser.addMouseWheelListener(this);
+		
+		String[] n = {",",".","up","right","down","left"};
+		int[] k = {KeyEvent.VK_COMMA, KeyEvent.VK_PERIOD, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT};
+
+		if (contentPane != null) {
+			for (int i = 0; i < n.length; ++i) {
+				contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), "MapMover.Zoomer."+n[i]);
+				contentPane.getActionMap().put("MapMover.Zoomer."+n[i], new ZoomerAction(n[i]));
+			}
+		}
+		
+		iSizeButton = sizeButton;
+	}
+
+	/**
+	 * If the right mouse button is pressed and moved while holding, move the map.
+	 * If the left mouse button is pressed start the selection rectangle and stop when left mouse button is released
+	 */
+	public void mouseDragged(MouseEvent e) {			
+		int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
+		//Moving the map
+		if ((e.getModifiersEx() & (MouseEvent.BUTTON3_DOWN_MASK | offMask)) == MouseEvent.BUTTON3_DOWN_MASK) {
+			
+			startMovement(e);
+			
+			//calc the moved distance since the last drag event
+			int distX = e.getX()-iLastX;
+			int distY = e.getY()-iLastY;
+			
+			//change the offset for the origin of the map
+			iSlippyMapChooser.moveMap(-distX, -distY);
+			
+			//update the last position of the mouse for the next dragging event
+			iLastX = e.getX();
+			iLastY = e.getY();
+		}
+		//selecting
+		else if((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK){
+			iEndSelectionPoint = e.getPoint();
+			iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint());
+		}		
+		//end moving of the map 
+		else
+			endMovement();
+	}
+
+	/**
+	 * Start moving the map, if it was the 3rd button (right button).
+	 * Start drawing the selection rectangle if it was the 1st button (left button)
+	 */
+	@Override public void mousePressed(MouseEvent e) {
+		int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
+		if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0)
+			startMovement(e);
+		else if (e.getButton() == MouseEvent.BUTTON1){
+			if(!iSizeButton.hit(e.getPoint())){
+				iStartSelectionPoint = e.getPoint();
+				iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);
+			}
+		}
+	}
+	
+	
+	/**
+	 * When dragging the map change the cursor back to it's pre-move cursor.
+	 * If a double-click occurs center and zoom the map on the clicked location.
+	 */
+	@Override public void mouseReleased(MouseEvent e) {		
+		if (e.getButton() == MouseEvent.BUTTON3)
+			endMovement();
+		else if (e.getButton() == MouseEvent.BUTTON1){
+			if(iSizeButton.hit(e.getPoint())){
+				iSizeButton.toggle();
+				iSlippyMapChooser.resizeSlippyMap();
+			}else{
+				if(e.getClickCount() == 1){
+					iSlippyMapChooser.setSelection(iStartSelectionPoint, e.getPoint());
+					
+					//reset the selections start and end
+					iEndSelectionPoint 	 = null;
+					iStartSelectionPoint = null;
+				}
+				else if(e.getClickCount() == 2){
+					iSlippyMapChooser.centerOnScreenPoint(e.getPoint());
+					iSlippyMapChooser.zoomIn();
+				}		
+			}
+		}			
+	}
+
+	/**
+	 * Start movement by setting a new cursor and remember the current mouse
+	 * position.
+	 */
+	private void startMovement(MouseEvent e) {
+		if (isMovementInPlace)
+			return;
+		isMovementInPlace = true;
+		iLastX = e.getX();
+		iLastY = e.getY();
+		iOldCursor = iSlippyMapChooser.getCursor();
+		iSlippyMapChooser.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+	}
+
+	/**
+	 * End the movement. Setting back the cursor and clear the movement variables
+	 */
+	private void endMovement() {
+		if (!isMovementInPlace)
+			return;
+		isMovementInPlace = false;
+		if (iOldCursor != null)
+			iSlippyMapChooser.setCursor(iOldCursor);
+		else
+			iSlippyMapChooser.setCursor(Cursor.getDefaultCursor());
+		iOldCursor = null;
+	}
+
+	/**
+	 * Zoom the map in and out.
+	 * @param e The wheel event.
+	 */
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		int rot = e.getWheelRotation();
+		//scroll wheel rotated away from user
+		if(rot < 0){
+			iSlippyMapChooser.zoomIn();
+		}
+		//scroll wheel rotated towards the user
+		else if(rot > 0){
+			iSlippyMapChooser.zoomOut();
+		}
+	}
+
+	/**
+	 * Does nothing. Only to satisfy MouseMotionListener
+	 */
+	public void mouseMoved(MouseEvent e) {}
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMercator.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMercator.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/OsmMercator.java	(revision 7199)
@@ -0,0 +1,92 @@
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+/**
+ * This class implements the Mercator Projection as it is used by Openstreetmap (and google). 
+ * It provides methods to translate coordinates from 'map space' into latitude and longitude (on
+ * the WGS84 ellipsoid) and vice versa. Map space is measured in pixels. The origin of the map space
+ * is the top left corner. The map space origin (0,0)  has latitude ~85 and longitude -180
+ * 
+ * @author Tim Haussmann
+ *
+ */
+
+public class OsmMercator{
+
+	private static int TILE_SIZE = 256;	
+	public static final double MAX_LAT = 85.05112877980659;
+	public static final double MIN_LAT = -85.05112877980659;
+	
+	
+	public static double radius(int aZoomlevel){
+		return (TILE_SIZE * Math.pow(2, aZoomlevel))/ (2 * Math.PI);		
+	}
+	
+	/**
+	 * Returns the absolut number of pixels in y or x, defined as:
+	 * 2^Zoomlevel * TILE_WIDTH
+	 * where TILE_WIDTH is the width of a tile in pixels 
+	 * @param aZoomlevel
+	 * @return
+	 */
+	public static int getMaxPixels(int aZoomlevel){
+		return (int) (TILE_SIZE * Math.pow(2, aZoomlevel));
+	}
+		
+	public static int falseEasting(int aZoomlevel){
+		return (int)getMaxPixels(aZoomlevel)/2;
+	}
+	public static int falseNorthing(int aZoomlevel){
+		return (int) ( -1*getMaxPixels(aZoomlevel)/2);
+	}
+	
+	/**
+	 * Transform longitude to pixelspace
+	 * @param aLongitude [-180..180]
+	 * @return [0..2^Zoomlevel*TILE_SIZE[
+	 */
+	public static int LonToX(double aLongitude, int aZoomlevel){		
+		double longitude = Math.toRadians(aLongitude);
+		return (int) ((radius(aZoomlevel) * longitude) + falseEasting(aZoomlevel));
+	}
+	
+	/**
+	 * Transforms latitude to pixelspace	
+	 * @param aLat [-90...90]
+	 * @return [0..2^Zoomlevel*TILE_SIZE[
+	 */
+	public static int LatToY(double aLat, int aZoomlevel){		
+		if(aLat < MIN_LAT)
+			aLat = MIN_LAT;
+		else if(aLat > MAX_LAT)
+			aLat = MAX_LAT;
+		double latitude = Math.toRadians(aLat);
+		return (int) (-1*(radius(aZoomlevel)/2.0 * Math.log((1.0 + Math.sin(latitude))/ (1.0 - Math.sin(latitude)))) - falseNorthing(aZoomlevel));
+	}
+	
+	/**
+	 * Transforms pixel coordinate X to longitude
+	 * @param aX [0..2^Zoomlevel*TILE_WIDTH[
+	 * @return ]-180..180[
+	 */
+	public static double XToLon(int aX, int aZoomlevel){
+		aX -= falseEasting(aZoomlevel);
+		double longRadians = aX/radius(aZoomlevel);
+		double longDegrees = Math.toDegrees(longRadians);
+		double rotations = Math.floor((longDegrees + 180)/360);
+		double longitude = longDegrees - (rotations * 360);
+		return longitude;
+	}
+	
+	/**
+	 * Transforms pixel coordinate Y to latitude
+	 * @param aY [0..2^Zoomlevel*TILE_WIDTH[
+	 * @return [MIN_LAT..MAX_LAT] is about [-85..85]
+	 */
+	public static double YToLat(int aY, int aZoomlevel){
+		aY += falseNorthing(aZoomlevel);
+		double latitude =  (Math.PI/2) - (2 * Math.atan(Math.exp(-1.0 * aY /radius(aZoomlevel))));		
+		return -1*Math.toDegrees(latitude) ;
+	}
+
+	
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/OsmTile.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/OsmTile.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/OsmTile.java	(revision 7199)
@@ -0,0 +1,95 @@
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+import java.awt.image.BufferedImage;
+import java.awt.Color;
+import java.awt.Graphics;
+
+/**
+ * @author Tim Haussmann 
+ */
+
+
+public class OsmTile {
+	
+	public static final int WIDTH = 256;
+	public static final int HEIGHT = 256;
+	
+	private int iX = 0;
+	private int iY = 0;
+	
+	public static final int TileBackgroundColor = 0xe9d3b1;  
+	
+	private BufferedImage iMapImage;
+	
+	private int iZoomLevel = -1;
+	private int iIndexY = -1;
+	private int iIndexX = -1;
+	
+	//image does not exist
+	private boolean isInvalid = false;
+	
+	//for a faster equals implementation
+	private int iHash;
+	
+	public OsmTile( int aZoomLevel, int aIndexX, int aIndexY){
+			
+		iZoomLevel = aZoomLevel;
+		iIndexX = aIndexX;
+		iIndexY = aIndexY;
+		
+		iX = WIDTH * iIndexX;
+		iY = HEIGHT * iIndexY;
+		
+		iHash = toString().hashCode();
+	}
+	
+	public int getZoomlevel(){
+		return iZoomLevel;
+	}
+	
+	public void paint(Graphics g){
+		
+		if(iMapImage != null && ! isInvalid){
+			g.drawImage( iMapImage, iX, iY, null );
+		}
+		else if(isInvalid){
+			//draw nothing
+		}
+		else{
+			g.setColor(Color.RED);
+			g.drawLine(iX, iY, iX+WIDTH-1, iY+HEIGHT-1);
+			g.drawLine(iX, iY+HEIGHT-1, iX+WIDTH-1, iY);
+			g.drawRect(iX, iY, WIDTH-1, HEIGHT-1);
+		}
+	} 
+	
+	public String toString() {
+		return String.valueOf(iZoomLevel) +"/" +
+		String.valueOf(iIndexX) + "/" + 
+		String.valueOf(iIndexY);
+	}
+	public static String key(int aZoomLevel, int aIndexX, int aIndexY){
+		return String.valueOf(aZoomLevel) +"/" +
+		String.valueOf(aIndexX) + "/" + 
+		String.valueOf(aIndexY);
+	}
+
+	/**
+	 * Callback for the TileDB to set the Image of this tile after loading.
+	 * @param aImage
+	 */
+	public void setImage(BufferedImage aImage) {
+		iMapImage = aImage;
+		if(iMapImage == null){
+			isInvalid = true;
+		}
+	}
+
+	/**
+	 * @return the path of this map tile on the remote server (i.e. '/1/2/12.png')
+	 */
+	public String getRemotePath() {
+		return "/"+toString()+".png";
+	}
+	
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/SizeButton.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/SizeButton.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/SizeButton.java	(revision 7199)
@@ -0,0 +1,54 @@
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+
+import java.awt.Graphics;
+import java.awt.Point;
+
+import javax.swing.ImageIcon;
+
+import org.openstreetmap.josm.tools.ImageProvider;
+
+
+
+/**
+ * @author Tim Haussmann
+ */
+public class SizeButton{
+	
+	private int x = 0;
+	private int y = 0;
+	
+	private ImageIcon enlargeImage;
+	private ImageIcon shrinkImage;
+	private boolean isEnlarged = false;
+	
+	
+	public SizeButton(){
+		enlargeImage = ImageProvider.get("", "view-fullscreen.png");
+		shrinkImage = ImageProvider.get("", "view-fullscreen-revert.png");		
+	}
+	
+	public void paint(Graphics g){
+		if(isEnlarged){
+			if(shrinkImage != null)
+				g.drawImage(shrinkImage.getImage(),x,y, null);
+		}else{
+			if(enlargeImage != null)
+				g.drawImage(enlargeImage.getImage(),x,y, null);
+		}
+	}
+	
+	public void toggle(){
+		isEnlarged = !isEnlarged;
+	}
+	
+	public boolean hit(Point point){
+		if(x < point.x && point.x < x + enlargeImage.getIconWidth()){
+			if(y < point.y && point.y < y + enlargeImage.getIconHeight() ){				
+				return true;
+			}
+		}
+		return false;
+	}
+
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooser.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooser.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooser.java	(revision 7199)
@@ -0,0 +1,522 @@
+// This code has been adapted and copied from code that has been written by Immanuel Scholz and others for JOSM.
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.util.Enumeration;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.download.DownloadDialog;
+import org.openstreetmap.josm.gui.download.DownloadSelection;
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+/**
+ * JComponent that displays the slippy map tiles 
+ * @author Tim Haussmann
+ *
+ */
+public class SlippyMapChooser extends JComponent implements DownloadSelection{
+	
+	private static final int MAX_ZOOMLEVEL = 20;
+	private static final int MIN_ZOOMLEVEL = 1;
+
+	private TileDB iTileDB;
+	
+	private DownloadDialog iGui;
+	
+	//the upper left and lower right corners of the selection rectangle
+	Point iSelectionRectStart;
+	Point iSelectionRectEnd;
+	
+	//Offsets for x and y (i.e. to center the first tile)
+	int iOffsetX = 0;
+	int iOffsetY = 0;
+	
+	//the zoom level of the currently shown tiles
+	static int iZoomlevel = 3;
+	
+	private boolean iFirstPaint = true;
+	private LatLon  iFirstPaintCenter = new LatLon(51,7);
+	
+	private SizeButton iSizeButton = new SizeButton();
+	
+	//standard dimension 
+	private Dimension iDownloadDialogDimension;
+	//screen size
+	private Dimension iScreenSize;
+	
+	private LatLon iScreenCenterBeforeResize;
+	private LatLon iSelectionStartBeforeResize;
+	private LatLon iSelectionEndBeforeResize;
+	private boolean isJustResized = false;
+	
+	private int iVisibleTilesX = 2;
+	private int iVisibleTilesY = 3;
+	
+	/**
+	 * Create the chooser component.
+	 */
+	public SlippyMapChooser() {	
+				
+		//create the tile db
+		iTileDB = new TileDB(this);
+		
+		
+	
+		setMinimumSize(new Dimension(350, 350/2));
+	}
+
+	public void addGui(final DownloadDialog gui) {
+		iGui = gui;
+		JPanel temp = new JPanel();
+		temp.setLayout(new BorderLayout());
+		temp.add(this, BorderLayout.CENTER);
+		temp.add(new JLabel((tr("Zoom: Mousewheel or double click.   Move map: Hold right mousebutton and move mouse."))), BorderLayout.SOUTH);
+		iGui.tabpane.add(temp, "Slippy map");
+		
+		new OsmMapControl(this,temp, iSizeButton);
+		repaint();
+    }
+	
+	/**
+	 * Performs resizing of the DownloadDialog in order to enlarge or shrink the map. 
+	 */
+	public void resizeSlippyMap(){
+		if(iScreenSize == null){
+			Component c = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent();
+			//remember the initial set screen dimensions
+			iDownloadDialogDimension = c.getSize();
+			//retrive the size of the display
+			iScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
+		}
+		
+		//remember the screen center (we want to have the same center after resizing)
+		iScreenCenterBeforeResize = getLatLonOfScreenPoint(new Point(getWidth()/2, getHeight()/2));
+		
+		//remember lat/lon of the selection rectangle 
+		if(iSelectionRectEnd != null && iSelectionRectStart != null){
+			iSelectionStartBeforeResize = getLatLonOfScreenPoint(iSelectionRectStart);
+			iSelectionEndBeforeResize   = getLatLonOfScreenPoint(iSelectionRectEnd);
+		}
+		
+		//resize
+		Component co = iGui.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent();
+		Dimension currentDimension = co.getSize();
+		
+		//enlarge
+		if(currentDimension.equals(iDownloadDialogDimension)){
+			//make the each dimension 90% of the absolute display size and center the DownloadDialog
+			int w = iScreenSize.width*90/100;
+			int h = iScreenSize.height*90/100;
+			co.setBounds((iScreenSize.width-w)/2, (iScreenSize.height-h)/2, w, h);
+		}
+		//shrink
+		else{
+			//set the size back to the initial dimensions and center the DownloadDialog
+			int w = iDownloadDialogDimension.width;
+			int h = iDownloadDialogDimension.height;
+			co.setBounds((iScreenSize.width-w)/2, (iScreenSize.height-h)/2, w, h);
+		}
+		
+		//the new dimension are 'available' after (or while) the next repaint
+		isJustResized = true;
+		
+		repaint();
+	}
+
+	/**
+	 * Draw the map.
+	 */
+	@Override public void paint(Graphics g) {
+		
+		if(iFirstPaint){
+			//calculate numbers of visible tiles 			
+			calcVisibleTiles();	
+			
+			//save selection
+			LatLon selStart = null;
+			LatLon selEnd   = null;
+			if(iSelectionRectEnd != null && iSelectionRectStart != null){
+				selStart = getLatLonOfScreenPoint(iSelectionRectStart);
+				selEnd   = getLatLonOfScreenPoint(iSelectionRectEnd);
+			}			
+			centerOnLatLon(iFirstPaintCenter);	
+			//restore selection 
+			if(selStart != null && selEnd != null){
+				iSelectionRectStart = getScreenPointForLatLon(selStart);
+				iSelectionRectEnd   = getScreenPointForLatLon(selEnd);
+			}
+			
+			loadVisibleTiles();
+			iFirstPaint = false;
+			repaint();
+		}
+		
+		if(isJustResized){
+			centerOnLatLon(iScreenCenterBeforeResize);
+			//restore selection 
+			if(iSelectionEndBeforeResize != null && iSelectionStartBeforeResize != null){
+				iSelectionRectStart = getScreenPointForLatLon(iSelectionStartBeforeResize);
+				iSelectionRectEnd   = getScreenPointForLatLon(iSelectionEndBeforeResize);
+			}
+			
+			//calculate numbers of visible tiles 			
+			calcVisibleTiles();			
+			
+			loadVisibleTiles();
+			isJustResized = false;
+		}
+			
+		//translate origin to draw map tiles in 'map space'
+		g.translate(iOffsetX, iOffsetY);
+		
+		//draw tiles of the current zoomlevel
+		for(int y=0; y<iVisibleTilesY; y++){
+			for(int x=0; x<iVisibleTilesX; x++){					
+				OsmTile t = iTileDB.get(OsmTile.key(iZoomlevel,  (-iOffsetX + x*OsmTile.WIDTH)/OsmTile.WIDTH, ((-iOffsetY+ y*OsmTile.HEIGHT)/OsmTile.HEIGHT)));
+				if(t != null){
+					t.paint(g);						
+				}
+			} 
+		}		
+		
+		//translate origin back
+		g.translate(-iOffsetX, -iOffsetY);
+		
+		//draw selection rectangle
+		if(iSelectionRectStart != null && iSelectionRectEnd != null){
+			
+			g.setColor(Color.black);
+			g.drawRect(iSelectionRectStart.x, iSelectionRectStart.y, iSelectionRectEnd.x -iSelectionRectStart.x, iSelectionRectEnd.y -iSelectionRectStart.y);
+		
+			g.setColor(new Color(0.9f,0.7f,0.7f,0.6f));
+			g.fillRect(iSelectionRectStart.x+1, iSelectionRectStart.y+1, iSelectionRectEnd.x -iSelectionRectStart.x-1, iSelectionRectEnd.y -iSelectionRectStart.y-1);
+		}
+		
+		iSizeButton.paint(g);
+	}
+
+	
+	public void boundingBoxChanged(DownloadDialog gui) {
+		
+		//calc the screen coordinates for the new selection rectangle
+		int x1 = OsmMercator.LonToX(gui.minlon, iZoomlevel);
+		int x2 = OsmMercator.LonToX(gui.maxlon, iZoomlevel);
+		int y1 = OsmMercator.LatToY(gui.minlat, iZoomlevel);
+		int y2 = OsmMercator.LatToY(gui.maxlat, iZoomlevel);
+		
+		iSelectionRectStart = new Point(Math.min(x1, x2)+iOffsetX, Math.min(y1, y2)+iOffsetY);
+		iSelectionRectEnd   = new Point(Math.max(x1, x2)+iOffsetX, Math.max(y1, y2)+iOffsetY);
+		
+		//calc zoom level 	
+		double dLat = Math.abs(gui.maxlat - gui.minlat);
+		double dLon = Math.abs(gui.maxlon - gui.minlon);		
+		int zoomLat = (int) (Math.log(90 / dLat)/Math.log(2));
+		int zoomLon = (int) (Math.log(90 / dLon)/Math.log(2));		
+		iZoomlevel = Math.max(zoomLat, zoomLon);
+		
+		//center on the rectangle
+		if(gui.minlat != 0 && gui.maxlat != 0 && gui.minlon != 0 && gui.maxlat != 0){
+			iFirstPaintCenter = new LatLon((gui.minlat + gui.maxlat)/2, (gui.minlon + gui.maxlon)/2);
+			iFirstPaint = true;
+		}
+		repaint();
+	}
+	
+	/**
+	 * Loads all tiles that are visible
+	 */
+	void loadVisibleTiles(){	
+		for(int y=iVisibleTilesY-1; y>=0; y--){
+			for(int x=0; x<iVisibleTilesX; x++){					
+				if(y > 0 && y < iVisibleTilesX-2){
+					iTileDB.loadTile(iZoomlevel, (-iOffsetX + x*OsmTile.WIDTH)/OsmTile.WIDTH,((-iOffsetY+ y*OsmTile.HEIGHT)/OsmTile.HEIGHT), TileDB.PRIO_HIGH );
+				}else{
+					iTileDB.loadTile(iZoomlevel, (-iOffsetX + x*OsmTile.WIDTH)/OsmTile.WIDTH,((-iOffsetY+ y*OsmTile.HEIGHT)/OsmTile.HEIGHT), TileDB.PRIO_LOW );
+				}
+			} 
+		}		
+	}
+
+	/**
+	 * Callback for the OsmMapControl. (Re-)Sets the start and end point of the selection rectangle.
+	 * @param aStart  
+	 * @param aEnd
+	 */
+	void setSelection(Point aStart, Point aEnd){
+		if(aStart == null || aEnd == null)
+			return;
+		iSelectionRectEnd = new Point(Math.max(aEnd.x , aStart.x ) ,Math.max(aEnd.y, aStart.y ));
+		iSelectionRectStart = new Point(Math.min(aEnd.x , aStart.x ) ,Math.min(aEnd.y , aStart.y ));
+		
+		LatLon l1 = getLatLonOfScreenPoint(aStart);	
+		LatLon l2 = getLatLonOfScreenPoint(aEnd);
+		
+		iGui.minlat = Math.min(l1.lat(), l2.lat());
+		iGui.minlon = Math.min(l1.lon(), l2.lon());
+		iGui.maxlat = Math.max(l1.lat(), l2.lat());
+		iGui.maxlon = Math.max(l1.lon(), l2.lon());
+		
+		iGui.boundingBoxChanged(this);
+		
+		repaint();
+	}
+	
+	/**
+	 * Callback for OsmMapControll. Moves the map and the selection rectangle.
+	 * @param x number of pixels to move along the x-axis (longitude)
+	 * @param y number of pixels to move along the y axis (latitude)
+	 */
+	void moveMap(int x, int y) {
+		int moveX = x;
+		int moveY = y;
+		
+		int tempOffsetX = iOffsetX - x;
+		int tempOffsetY = iOffsetY - y;
+		
+		
+		int maxPixels = OsmMercator.getMaxPixels(iZoomlevel);
+		
+		if(moveX != 0){
+			//deactivate dragging if the map is smaller than the DownloadDialog
+			if(maxPixels < getWidth()){
+				//center map horizontally
+				iOffsetX = (getWidth()-maxPixels)/2;	
+				moveX = 0;
+			}else{
+				//don't allow the map to hide outside the JComponent drawing area
+				if(tempOffsetX > 30){
+					if(moveX < 0){
+						moveX = 0;
+						iOffsetX = 30;
+					}
+				}else if(-tempOffsetX > maxPixels + 30 - getWidth()){
+					if(moveX > 0){
+						moveX = 0;
+						iOffsetX = -(maxPixels + 30 - getWidth());
+					}
+				}
+			}
+		}
+		
+		if(moveY != 0){
+			//deactivate dragging if the map is smaller than the DownloadDialog
+			if(maxPixels < getHeight()){
+				//center map vertically
+				iOffsetY = (getHeight()-maxPixels)/2;
+				moveY = 0;
+			}else{
+				//don't allow the map to hide outside the JComponent drawing area
+				if(tempOffsetY > 30){
+					if(moveY < 0){
+						moveY = 0;
+						iOffsetY = 30;
+					}
+				}else if(-tempOffsetY > maxPixels + 30 - getHeight()){
+					if(moveY > 0){
+						moveY = 0;
+						iOffsetY = -(maxPixels + 30 - getHeight());
+					}
+				}
+			}
+		}
+		
+		
+		
+		
+		
+		//execute the movement
+		iOffsetX -= moveX;
+		iOffsetY -= moveY;
+		
+		//also move the selection rect
+		if(iSelectionRectEnd != null && iSelectionRectStart != null){
+			iSelectionRectEnd.x   -= moveX;
+			iSelectionRectEnd.y   -= moveY;
+			iSelectionRectStart.x -= moveX;
+			iSelectionRectStart.y -= moveY;
+		}
+		
+		loadVisibleTiles();
+		
+		repaint();
+	}
+	
+	/**
+	 * Zoom in one level	
+	 * Callback for OsmMapControl. Zoom out one level		 
+	 */
+	void zoomIn(){	
+		
+		//cache center of screen and the selection rectangle
+		LatLon l = getLatLonOfScreenPoint(new Point(getWidth()/2, getHeight()/2));
+		LatLon selStart = null;
+		LatLon selEnd   = null;
+		if(iSelectionRectEnd != null && iSelectionRectStart != null){
+			selStart = getLatLonOfScreenPoint(iSelectionRectStart);
+			selEnd   = getLatLonOfScreenPoint(iSelectionRectEnd);
+		}
+		
+		//increment zoom level
+		iZoomlevel += 1;
+		if(iZoomlevel > MAX_ZOOMLEVEL){
+			iZoomlevel = MAX_ZOOMLEVEL;
+			return;
+		}
+					
+		//center on cached location
+		centerOnLatLon(l);
+		
+		//restore selection 
+		if(selStart != null && selEnd != null){
+			iSelectionRectStart = getScreenPointForLatLon(selStart);
+			iSelectionRectEnd   = getScreenPointForLatLon(selEnd);
+		}
+		
+		loadVisibleTiles();
+		
+		centerMap();
+		
+		repaint();
+	}
+	
+	/**
+	 * Zoom out one level.
+	 * Callback for OsmMapControl. 
+	 */
+	void zoomOut(){
+		//cache center of screen and the selction rect
+		LatLon l = getLatLonOfScreenPoint(new Point(getWidth()/2, getHeight()/2));
+		LatLon selStart = null;
+		LatLon selEnd   = null;
+		if(iSelectionRectEnd != null && iSelectionRectStart != null){
+			selStart = getLatLonOfScreenPoint(iSelectionRectStart);
+			selEnd   = getLatLonOfScreenPoint(iSelectionRectEnd);
+		}
+		
+		//decrement zoom level
+		iZoomlevel -= 1;
+		if(iZoomlevel < MIN_ZOOMLEVEL){
+			iZoomlevel = MIN_ZOOMLEVEL;
+			return;
+		}
+		
+		//center on cached location
+		centerOnLatLon(l);
+		
+		//restore selection 
+		if(selStart != null && selEnd != null){
+			iSelectionRectStart = getScreenPointForLatLon(selStart);
+			iSelectionRectEnd   = getScreenPointForLatLon(selEnd);
+		}
+		
+		loadVisibleTiles();
+		
+		centerMap();
+		
+		repaint();
+	}
+	
+	/**
+	 * Calculates the latitude and longitude of a Point given in map space
+	 * @param aPoint in pixels on the map
+	 * @return the LatLon of the given Point
+	 */
+	private LatLon getLatLonOfPoint(Point aPoint){	
+		return new LatLon(OsmMercator.YToLat(aPoint.y, iZoomlevel),OsmMercator.XToLon(aPoint.x,	iZoomlevel));
+	}
+	
+	/**
+	 * Returns the map coordinates for a LatLon
+	 * @param aLatLon 
+	 * @return
+	 */
+	private Point getPointForLatLon(LatLon aLatLon){
+		Point p = new Point();
+		p.y = OsmMercator.LatToY(aLatLon.lat(), iZoomlevel);
+		p.x = OsmMercator.LonToX(aLatLon.lon(), iZoomlevel);
+		return p;
+	}
+	
+	/**
+	 * Calculates the latitude and longitude of a Point given in screen space (in the JComponent)
+	 * @param aPoint in Pixels on the screen (the JComponent)
+	 * @return the LatLon of the given Point
+	 */
+	LatLon getLatLonOfScreenPoint(Point aPoint){
+		Point mapCoordinates = new Point(aPoint);		
+		mapCoordinates.x -= iOffsetX;
+		mapCoordinates.y -= iOffsetY;			
+		return getLatLonOfPoint(mapCoordinates);
+	}
+	
+	/**
+	 * Calculates the screen coordinates of a LatLon.
+	 * @param aLatLon 
+	 * @return the coordinates as Point in the JComponent 
+	 */
+	Point getScreenPointForLatLon(LatLon aLatLon){
+		Point p = getPointForLatLon(aLatLon);
+		p.x += iOffsetX;
+		p.y += iOffsetY;
+		return p;
+	}
+	
+	
+	/**
+	 * Centers the map on a Point 
+	 * @param aPoint in screen coordinates (JComponent)
+	 */
+	void centerOnScreenPoint(Point aPoint){
+		moveMap(aPoint.x - getWidth()/2, aPoint.y-getHeight()/2);
+	}
+	
+	/**
+	 * Centers the map on the location given by LatLon
+	 * @param aLatLon the location to center on
+	 */
+	private void centerOnLatLon(LatLon aLatLon){		
+		int x = OsmMercator.LonToX(aLatLon.lon(), iZoomlevel);
+		int y = OsmMercator.LatToY(aLatLon.lat(), iZoomlevel);
+		iOffsetX = -x +getWidth()/2;
+		iOffsetY = -y +getHeight()/2;
+		repaint();
+	}
+	
+	/**
+	 * Caclulates the visible tiles for each dimension
+	 */
+	private void calcVisibleTiles(){
+		if(iGui != null){
+			iVisibleTilesX = iGui.getWidth()/256 + 2;
+			iVisibleTilesY = iGui.getHeight()/256 + 2;
+		}
+	}
+	
+	/**
+	 * Centers the map after zooming. I.e. when the map is smaller than the
+	 * component it is shown in.
+	 */
+	private void centerMap(){
+		
+		int maxPixels = OsmMercator.getMaxPixels(iZoomlevel);		
+	
+		if(maxPixels < getWidth()){
+			//center map horizontally
+			iOffsetX = (getWidth()-maxPixels)/2;
+		}
+		if(maxPixels < getHeight()){
+			//center map vertically
+			iOffsetY = (getHeight()-maxPixels)/2;
+		}
+	}
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooserPlugin.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooserPlugin.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/SlippyMapChooserPlugin.java	(revision 7199)
@@ -0,0 +1,79 @@
+// This code has been adapted and copied from code that has been written by Immanuel Scholz and others for JOSM.
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+import java.util.List;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
+import org.openstreetmap.josm.gui.download.DownloadSelection;
+import org.openstreetmap.josm.plugins.Plugin;
+
+/**
+ * @author Tim Haussmann
+ */
+public class SlippyMapChooserPlugin extends Plugin implements PreferenceChangedListener{
+	
+	static String iPluginFolder = "";
+	
+	private static final String KEY_MAX_TILES_IN_DB = "slippy_map_chooser.max_tiles";
+	private static final String KEY_MAX_TILES_REDUCE_BY = "slippy_map_chooser.max_tiles_reduce_by";
+	
+	static int MAX_TILES_IN_DB = 1000;
+	static int MAX_TILES_REDUCE_BY = 100;
+	
+	public SlippyMapChooserPlugin(){
+		// create the plugin folder 
+//		iPluginFolder = getPluginDir();
+//		File pluginFolder = new File(iPluginFolder);
+//		if(!pluginFolder.exists())
+//			pluginFolder.mkdir();
+//		
+//		//init the logger
+//		Logger.setLogFile(iPluginFolder+"\\slippy_map_chooser.log");
+		
+		//Add this plugin to the preference changed listener list
+		Main.pref.listener.add(this);
+		
+		//load prefs
+		String maxTiles = Main.pref.get(KEY_MAX_TILES_IN_DB);
+		if(!maxTiles.equals("")){
+			preferenceChanged(KEY_MAX_TILES_IN_DB, maxTiles);
+		}else{
+			Main.pref.put(KEY_MAX_TILES_IN_DB, String.valueOf(MAX_TILES_IN_DB));
+		}
+		
+		String maxTilesReduce = Main.pref.get(KEY_MAX_TILES_REDUCE_BY);
+		if(!maxTilesReduce.equals("")){
+			preferenceChanged(KEY_MAX_TILES_REDUCE_BY, maxTilesReduce);
+		}else{
+			Main.pref.put(KEY_MAX_TILES_REDUCE_BY, String.valueOf(MAX_TILES_REDUCE_BY));
+		}
+	}
+	
+	
+	public void addDownloadSelection(List<DownloadSelection> list){	
+		list.add(new SlippyMapChooser());		
+	}
+
+
+	public void preferenceChanged(String key, String newValue) {
+		if(key.equals(KEY_MAX_TILES_IN_DB)){
+			try{
+				MAX_TILES_IN_DB = Integer.parseInt(newValue);
+			}catch(Exception e){
+				MAX_TILES_IN_DB = 1000;
+			}
+			
+		}else if(key.equals(KEY_MAX_TILES_REDUCE_BY)){
+			try{
+				MAX_TILES_REDUCE_BY = Integer.parseInt(newValue);
+			}catch(Exception e){
+				MAX_TILES_REDUCE_BY = 100;
+			}
+		}
+	}
+	
+	
+	
+	
+}
Index: /applications/editors/josm/plugins/slippy_map_chooser/src/TileDB.java
===================================================================
--- /applications/editors/josm/plugins/slippy_map_chooser/src/TileDB.java	(revision 7199)
+++ /applications/editors/josm/plugins/slippy_map_chooser/src/TileDB.java	(revision 7199)
@@ -0,0 +1,250 @@
+// License: GPL. Copyright 2007 by Tim Haussmann
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.imageio.ImageIO;
+import javax.swing.JComponent;
+
+
+
+/**
+ *  The TileDB is responsible for fetching and storing all needed map tiles. The tiles
+ *  are stored in memory and are fetched one by one in background.
+ *  Tiles are stored in a HashTable. The path of the tile on the tile server (i.e. '/12/3/5.png') 
+ *  acts as key and the OsmTile as value.
+ *  @author Tim Haussmann
+ *
+ */
+public class TileDB{
+
+	public static final int PRIO_HIGH = 1;
+	public static final int PRIO_LOW = 2;
+	
+	//Osm tile server address
+	private static final String OSM_TILE_SERVER = "http://tile.openstreetmap.org";
+	
+	//Queue for loading tiles
+	private Vector<OsmTile> iTileQueue = new Vector<OsmTile>();	
+	
+	//DB for holding the downloaded tiles
+	private Hashtable<String,OsmTile> iHashTable = new Hashtable<String,OsmTile>(SlippyMapChooserPlugin.MAX_TILES_IN_DB + 50);
+	
+	//the order in that the tiles have been downloaded, needed to delete old ones
+	private Vector<String> iTileOrder = new Vector<String>(SlippyMapChooserPlugin.MAX_TILES_IN_DB + 50);
+	
+	//to update the map after a tile has been loaded
+	private JComponent iSlippyMapChooser;
+	
+	private int[] iMaxLatValues;
+	private int[] iMaxLonValues;
+	
+	/**
+	 * Creates the TileDB.
+	 * @param aWorldChooser
+	 */
+	public TileDB(JComponent aWorldChooser){
+		iSlippyMapChooser = aWorldChooser;
+		
+		iMaxLatValues = new int[20];
+		iMaxLonValues = new int[20];
+		for(int i=0; i<20; i++){
+			iMaxLatValues[i] = OsmMercator.LatToY(OsmMercator.MIN_LAT, i)/OsmTile.HEIGHT;
+			iMaxLonValues[i] = OsmMercator.LonToX(180, i)/OsmTile.WIDTH;
+		}
+		
+		new TileFetcherThread(this);
+		new TileFetcherThread(this);
+		new TileFetcherThread(this);
+		new TileFetcherThread(this);
+	}
+	
+	/**
+	 * Creates a OsmTile if it's not in the Hashtable. New created tiles are added to the
+	 * end of the download queue (Vector) and the DB (Hashtable). After that the fetching thread is 
+	 * notified.
+	 * @param aZoomLevel the zoomlevel for the tile to create
+	 * @param aIndexX the X-index of the tile to create. Must be within [0..2^zoomlevel[
+	 * @param aIndexY the Y-index of the tile to create. Must be within [0..2^zoomlevel[
+	 * @param aPriority PRIO_HIGH adds this tile at the waiting queue start  PRIO_LOW at the end
+	 */
+	public synchronized void loadTile(int aZoomLevel, int aIndexX, int aIndexY, int aPriority)
+	{		
+		
+		if(aZoomLevel <0 || aIndexX <0 || aIndexY <0){
+			return;
+		}else if(iMaxLonValues[aZoomLevel] <= aIndexX ||
+				iMaxLatValues[aZoomLevel] <= aIndexY ){
+			return;
+		}
+		String key = OsmTile.key(aZoomLevel, aIndexX, aIndexY);
+		OsmTile t = iHashTable.get(key);
+		if(t != null){
+			//if a tile is already in the DB and still in the laoding queue
+			//move it to the beginning of the queue in order to make the currently
+			//visible tiles load first
+			if(iTileQueue.remove(t)){				
+				iTileQueue.add(0,t);
+			}
+			return;
+		}
+		
+		t = new OsmTile(aZoomLevel, aIndexX, aIndexY);		
+		iHashTable.put(t.toString(),t);	
+		iTileOrder.add(0,key);
+		
+		if(aPriority == PRIO_LOW){
+			iTileQueue.addElement(t);
+		}else if(aPriority == PRIO_HIGH){
+			iTileQueue.add(0,t);
+		}else{
+			iTileQueue.addElement(t);
+		}
+		
+		//check if old tiles need to be deleted
+		if(iTileOrder.size() > SlippyMapChooserPlugin.MAX_TILES_IN_DB){
+			for(int i=0; i<SlippyMapChooserPlugin.MAX_TILES_REDUCE_BY; i++){
+				String removedKey = iTileOrder.remove(iTileOrder.size()-1);
+				iHashTable.remove(removedKey);
+			}
+		}
+		
+		//Wake up the fetching threads
+		synchronized (this) {
+			notifyAll();
+		}
+	}
+	
+	/**
+	 * Returns the next tile that needs to be loaded. This method is called by the threads
+	 * that fetch the tiles. If the download queue is empty the calling threads are waiting.
+	 * @return the first tile in the download queue with the same zoom level that is currently displayed or just the first. 
+	 */
+	private OsmTile getNextTile(){
+		if(iTileQueue.size() > 0){
+			OsmTile t;
+			Enumeration<OsmTile> e = iTileQueue.elements();
+			while(e.hasMoreElements()){
+				t = e.nextElement();
+				if(t.getZoomlevel() == SlippyMapChooser.iZoomlevel){
+					return t;
+				}
+			}
+			return iTileQueue.firstElement();	
+		}
+		else{			
+			synchronized (this) {
+				try {
+					wait();
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}				
+			}
+			return iTileQueue.firstElement();	
+		}
+	}
+	
+	/**
+	 * Access tiles in the TileDB.
+	 * @return an Enumeration that holds all OsmTiles currently stored in the TileDB (Hashtable)
+	 */
+	public Enumeration<OsmTile> elements() {	
+		return iHashTable.elements();
+	}
+	
+	/**
+	 * Returns a OsmTile by key
+	 * @param aKey 
+	 * @return
+	 */
+	public OsmTile get(String aKey){
+		return iHashTable.get(aKey);
+	}
+	
+	/**
+	 * Delete OsmTiles from the TileDB.
+	 * @param aTile that is to be deleted.
+	 */
+	public void remove(OsmTile aTile){
+		iHashTable.remove(aTile.toString());
+		iTileQueue.removeElement(aTile);
+	}
+
+	/**
+	 * Returns the number of OsmTiles waiting to be fetched from the server.
+	 * @return 
+	 */
+	public int getLoadingQueueSize() {
+		return iTileQueue.size();
+	}
+
+	/**
+	 * Returns the number of tiles stored in the TileDB
+	 * @return
+	 */
+	public int getCachedTilesSize() {		
+		return iHashTable.size();
+	}
+	
+	
+	/***************************************************
+	 * Private inner class to fetch the tiles over http
+	 * *************************************************
+	 */
+	
+	class TileFetcherThread implements Runnable{
+		
+		private TileDB iTileDB;
+		private Thread iThread;
+		
+		public TileFetcherThread(TileDB aTileDB){
+			iTileDB = aTileDB;
+			iThread = new Thread(this);
+			iThread.start();
+		}
+		
+		public void run(){
+			
+			while(true){
+				
+				//get the next tile to load
+				OsmTile t = iTileDB.getNextTile();
+				
+				URL tileUrl = null;
+				try {
+					
+					//build the url to the tile
+					tileUrl = new URL(OSM_TILE_SERVER + t.getRemotePath());
+										
+					//get the tile
+					InputStream in = tileUrl.openStream();
+				
+					//the tile needs the image...					
+					t.setImage(ImageIO.read(in));
+					
+				} catch (MalformedURLException e) {
+//					System.out.println("Catched: " + e.getMessage());
+//					e.printStackTrace();				
+					t.setImage(null);
+				} catch (IOException e) {
+//					System.out.println("Catched: " + e.getMessage());
+//					e.printStackTrace();	
+					t.setImage(null);
+				} catch (Exception e){
+//					System.out.println("Catched: " + e.getMessage());
+//					e.printStackTrace();
+					t.setImage(null);
+				}
+				
+				iTileQueue.removeElement(t);
+				iSlippyMapChooser.repaint();	
+			}
+		}		
+	}
+}
