Index: applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java
===================================================================
--- applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java	(revision 13457)
+++ applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java	(revision 13458)
@@ -20,4 +20,5 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.lang.String;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
@@ -47,4 +48,5 @@
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.tools.Base64;
 import org.openstreetmap.josm.tools.GBC;
@@ -60,4 +62,5 @@
     private JTextField tagsField = new JTextField();
     private JCheckBox publicCheckbox = new JCheckBox();
+    private JButton OkButton = new JButton();
 
     public static final String API_VERSION = "0.5";
@@ -93,5 +96,5 @@
         jScrollPane1.setViewportView(OutputDisplay);
 
-        JButton OkButton = new JButton(tr("Upload GPX track"));
+        OkButton.setText(tr("Upload GPX track"));
         OkButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -106,6 +109,4 @@
             }
         });
-
-        JLabel directUploadLabel = new JLabel(tr("Direct Upload to OpenStreetMap"));
 
         publicCheckbox.setText(tr("Public"));
@@ -166,14 +167,18 @@
         if(checkForErrors(username, password, description, gpxData))
             return;
-
+				
+				OkButton.setEnabled(false);
+				
         description = description.replaceAll("[&?/\\\\]"," ");
         tags = tags.replaceAll("[&?/\\\\.,;]"," ");
-
-        OutputDisplay.setText(tr("Starting to upload selected file to openstreetmap.org"));
+        
+        Main.pleaseWaitDlg.progress.setValue(0);
+        Main.pleaseWaitDlg.setIndeterminate(true); 
+        Main.pleaseWaitDlg.currentAction.setText(tr("Connecting..."));
+        // We don't support cancellation yet, so do not advertise it
+        Main.pleaseWaitDlg.cancel.setEnabled(false);
 
         try {
             URL url = new URL("http://www.openstreetmap.org/api/" + API_VERSION + "/gpx/create");
-            //System.err.println("url: " + url);
-            //OutputDisplay.setText("Uploading in Progress");
             HttpURLConnection connect = (HttpURLConnection) url.openConnection();
             connect.setConnectTimeout(15000);
@@ -185,27 +190,27 @@
             connect.addRequestProperty("Expect", "");
             connect.connect();
-            DataOutputStream out  = new DataOutputStream(new BufferedOutputStream(connect.getOutputStream()));
-
+            
+            Main.pleaseWaitDlg.currentAction.setText(tr("Uploading GPX track..."));
+            DataOutputStream out  = new DataOutputStream(new BufferedOutputStream(connect.getOutputStream()));            
             writeContentDispositionGpxData(out, "file", gpxData);
             writeContentDisposition(out, "description", description);
-            writeContentDisposition(out, "tags", (tags!=null && tags.length()>0) ? tags : "");
+            writeContentDisposition(out, "tags", (tags != null && tags.length() > 0) ? tags : "");
             writeContentDisposition(out, "public", isPublic ? "1" : "0");
-
             out.writeBytes("--" + BOUNDARY + "--" + LINE_END);
             out.flush();
-
-            int returnCode = connect.getResponseCode();
+            
             String returnMsg = connect.getResponseMessage();
-            //System.err.println(returnCode);
-            OutputDisplay.setText(returnMsg);
-
-            if (returnCode != 200) {
+            boolean success = returnMsg.equals("OK");
+            OutputDisplay.setText(success ? tr("GPX upload was successful") : returnMsg);
+
+            if (connect.getResponseCode() != 200) {
                 if (connect.getHeaderField("Error") != null)
                     returnMsg += "\n" + connect.getHeaderField("Error");
-                connect.disconnect();
             }
             out.close();
             connect.disconnect();
-
+            
+            OkButton.setEnabled(!success);
+            
         } catch(UnsupportedEncodingException ignore) {
         } catch (MalformedURLException e) {
@@ -214,6 +219,5 @@
         }
     }
-
-
+    
     private boolean checkForErrors(String username, String password, String description, GpxData gpxData) {
         String errors="";
@@ -245,16 +249,23 @@
         if(checkForGPXLayer()) return;
 
-        //System.out.println(Descriptionfield);
-        try {
-            upload(Main.pref.get("osm-server.username"),
-                   Main.pref.get("osm-server.password"),
-                   descriptionField.getText(),
-                   tagsField.getText(),
-                   publicCheckbox.isSelected(),
-                   ((GpxLayer)Main.map.mapView.getActiveLayer()).data
-            );
-        } catch (IOException ex) {
-            Logger.getLogger(UploadDataGui.class.getName()).log(Level.SEVERE, null, ex);
-        }
+        PleaseWaitRunnable uploadTask = new PleaseWaitRunnable(tr("Uploading GPX Track")){
+            @Override protected void realRun() throws IOException {
+                  setAlwaysOnTop(false);
+                  upload(Main.pref.get("osm-server.username"),
+                         Main.pref.get("osm-server.password"),
+                         descriptionField.getText(),
+                         tagsField.getText(),
+                         publicCheckbox.isSelected(),
+                         ((GpxLayer)Main.map.mapView.getActiveLayer()).data
+                  );
+            }
+            @Override protected void finish() {
+                setAlwaysOnTop(true);
+            }
+            @Override protected void cancel() {
+            }
+        };
+        
+        Main.worker.execute(uploadTask);
     }
 
@@ -267,5 +278,9 @@
         out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"" + LINE_END);
         out.writeBytes(LINE_END);
-        out.writeBytes(value + LINE_END);
+        // DataOutputStream's "writeUTF" method is unsuitable here because it adds two
+        // char length bytes in front
+        byte[] temp=value.getBytes("UTF-8");
+        out.write(temp, 0, temp.length);
+        out.writeBytes(LINE_END);
     }
 
@@ -275,6 +290,4 @@
         out.writeBytes("Content-Type: application/octet-stream" + LINE_END);
         out.writeBytes(LINE_END);
-
-        OutputDisplay.setText(tr("Transferring data to server"));
         new GpxWriter(out).write(gpxData);
         out.flush();
