Index: trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java	(revision 2402)
+++ trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java	(revision 2403)
@@ -7,12 +7,23 @@
 import java.awt.Dimension;
 import java.awt.GridBagLayout;
+import java.awt.Toolkit;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.FlavorEvent;
+import java.awt.datatransfer.FlavorListener;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusAdapter;
 import java.awt.event.FocusEvent;
-
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.IOException;
+
+import javax.swing.AbstractAction;
 import javax.swing.BorderFactory;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
@@ -26,4 +37,5 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.OsmUrlToBounds;
 
@@ -39,9 +51,9 @@
 
     private JTextField[] latlon = null;
-    private final JTextArea osmUrl = new JTextArea();
+    private final JTextArea tfOsmUrl = new JTextArea();
     private final JTextArea showUrl = new JTextArea();
     private DownloadDialog parent;
 
-    
+
     protected void buildDownloadAreaInputFields() {
         latlon = new JTextField[4];
@@ -58,5 +70,5 @@
         latlon[2].addFocusListener(latChecker);
         latlon[2].addActionListener(latChecker);
-        
+
         LonValueChecker lonChecker = new LonValueChecker(latlon[1]);
         latlon[1].addFocusListener(lonChecker);
@@ -66,19 +78,18 @@
         latlon[3].addFocusListener(lonChecker);
         latlon[3].addActionListener(lonChecker);
-        
-    }
-    
+    }
+
     public void addGui(final DownloadDialog gui) {
         buildDownloadAreaInputFields();
-        JPanel dlg = new JPanel(new GridBagLayout());
-
-        osmUrl.getDocument().addDocumentListener(new OsmUrlRefresher());
+        final JPanel dlg = new JPanel(new GridBagLayout());
+
+        tfOsmUrl.getDocument().addDocumentListener(new OsmUrlRefresher());
 
         // select content on receiving focus. this seems to be the default in the
         // windows look+feel but not for others. needs invokeLater to avoid strange
         // side effects that will cancel out the newly made selection otherwise.
-        osmUrl.addFocusListener(new SelectAllOnFocusHandler(osmUrl));
-        osmUrl.setLineWrap(true);
-        osmUrl.setBorder(latlon[0].getBorder());
+        tfOsmUrl.addFocusListener(new SelectAllOnFocusHandler(tfOsmUrl));
+        tfOsmUrl.setLineWrap(true);
+        tfOsmUrl.setBorder(latlon[0].getBorder());
 
         dlg.add(new JLabel(tr("min lat")), GBC.std().insets(10,20,5,0));
@@ -92,5 +103,30 @@
 
         dlg.add(new JLabel(tr("URL from www.openstreetmap.org (you can paste an URL here to download the area)")), GBC.eol().insets(10,20,5,0));
-        dlg.add(osmUrl, GBC.eop().insets(10,0,5,0).fill());
+        dlg.add(tfOsmUrl, GBC.eop().insets(10,0,5,0).fill());
+        tfOsmUrl.addMouseListener(
+                new MouseAdapter() {
+                    @Override
+                    public void mousePressed(MouseEvent e) {
+                        checkPopup(e);
+                    }
+
+                    @Override
+                    public void mouseClicked(MouseEvent e) {
+                        checkPopup(e);
+                    }
+
+                    @Override
+                    public void mouseReleased(MouseEvent e) {
+                        checkPopup(e);
+                    }
+
+                    private void checkPopup(MouseEvent e) {
+                        if (e.isPopupTrigger()) {
+                            OsmUrlPopup popup = new OsmUrlPopup();
+                            popup.show(tfOsmUrl, e.getX(), e.getY());
+                        }
+                    }
+                }
+        );
         dlg.add(showUrl, GBC.eop().insets(10,0,5,5));
         showUrl.setEditable(false);
@@ -102,10 +138,10 @@
     }
 
-    
+
     public void setDownloadArea(Bounds area) {
         updateBboxFields(area);
         updateUrl(area);
     }
-    
+
     public Bounds getDownloadArea() {
         double[] values = new double[4];
@@ -120,11 +156,11 @@
             return null;
         if (!LatLon.isValidLat(values[2]) || !LatLon.isValidLon(values[3]))
-            return null;        
+            return null;
         return new Bounds(values);
     }
 
     private boolean parseURL(DownloadDialog gui) {
-        Bounds b = OsmUrlToBounds.parse(osmUrl.getText());
-        if(b == null) return false;        
+        Bounds b = OsmUrlToBounds.parse(tfOsmUrl.getText());
+        if(b == null) return false;
         gui.boundingBoxChanged(b,BoundingBoxSelection.this);
         updateBboxFields(b);
@@ -148,9 +184,9 @@
         showUrl.setText(OsmUrlToBounds.getURL(area));
     }
-    
-    
+
+
     class LatValueChecker extends FocusAdapter implements ActionListener{
         private JTextField tfLatValue;
-        
+
         private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1);
         protected void setErrorMessage(String msg) {
@@ -160,12 +196,12 @@
             } else {
                 tfLatValue.setBorder(UIManager.getBorder("TextField.border"));
-                tfLatValue.setToolTipText("");                
-            }
-        }
-     
+                tfLatValue.setToolTipText("");
+            }
+        }
+
         public LatValueChecker(JTextField tfLatValue) {
             this.tfLatValue = tfLatValue;
         }
-        
+
         protected void check() {
             double value = 0;
@@ -178,9 +214,9 @@
             if (!LatLon.isValidLat(value)) {
                 setErrorMessage(tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()));
-                return;            
+                return;
             }
             setErrorMessage(null);
         }
-        
+
         @Override
         public void focusLost(FocusEvent e) {
@@ -189,8 +225,8 @@
 
         public void actionPerformed(ActionEvent e) {
-            check();            
-        }        
-    }
-    
+            check();
+        }
+    }
+
     class LonValueChecker extends FocusAdapter implements ActionListener {
         private JTextField tfLonValue;
@@ -202,12 +238,12 @@
             } else {
                 tfLonValue.setBorder(UIManager.getBorder("TextField.border"));
-                tfLonValue.setToolTipText("");                
-            }
-        }
-        
+                tfLonValue.setToolTipText("");
+            }
+        }
+
         public LonValueChecker(JTextField tfLonValue) {
             this.tfLonValue = tfLonValue;
         }
-        
+
         protected void check() {
             double value = 0;
@@ -215,6 +251,6 @@
                 value = Double.parseDouble(tfLonValue.getText());
             } catch(NumberFormatException ex) {
-               setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText()));
-               return;
+                setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText()));
+                return;
             }
             if (!LatLon.isValidLon(value)) {
@@ -224,5 +260,5 @@
             setErrorMessage(null);
         }
-        
+
         @Override
         public void focusLost(FocusEvent e) {
@@ -232,19 +268,19 @@
         public void actionPerformed(ActionEvent e) {
             check();
-        }        
-    }
-    
+        }
+    }
+
     class SelectAllOnFocusHandler extends FocusAdapter {
         private JTextComponent tfTarget;
         public SelectAllOnFocusHandler(JTextComponent tfTarget) {
-            this.tfTarget = tfTarget;            
-        }
-        
+            this.tfTarget = tfTarget;
+        }
+
         @Override
         public void focusGained(FocusEvent e) {
             tfTarget.selectAll();
-        }        
-    }
-    
+        }
+    }
+
     class OsmUrlRefresher implements DocumentListener {
         public void changedUpdate(DocumentEvent e) { parseURL(parent); }
@@ -252,3 +288,51 @@
         public void removeUpdate(DocumentEvent e) { parseURL(parent); }
     }
+
+    class PasteUrlAction extends AbstractAction implements FlavorListener {
+
+        public PasteUrlAction() {
+            putValue(NAME, tr("Paste"));
+            putValue(SMALL_ICON, ImageProvider.get("paste"));
+            putValue(SHORT_DESCRIPTION, tr("Paste URL from clipboard"));
+            Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this);
+        }
+
+        protected String getClipboardContent() {
+            Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
+            try {
+                if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+                    String text = (String)t.getTransferData(DataFlavor.stringFlavor);
+                    return text;
+                }
+            } catch (UnsupportedFlavorException ex) {
+                ex.printStackTrace();
+                return null;
+            } catch (IOException ex) {
+                ex.printStackTrace();
+                return null;
+            }
+            return null;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            String content = getClipboardContent();
+            if (content != null) {
+                tfOsmUrl.setText(content);
+            }
+        }
+
+        protected void updateEnabledState() {
+            setEnabled(getClipboardContent() != null);
+        }
+
+        public void flavorsChanged(FlavorEvent e) {
+            updateEnabledState();
+        }
+    }
+
+    class OsmUrlPopup extends JPopupMenu {
+        public OsmUrlPopup() {
+            add(new PasteUrlAction());
+        }
+    }
 }
