Index: applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java
===================================================================
--- applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java	(revision 11490)
+++ applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java	(revision 11496)
@@ -3,5 +3,4 @@
  * @author Stefan Kaintoch, Raphael Mack
  * license: GPLv3 or any later version
- * @version $Id: GlobalSatDg100.java 3 2007-10-30 19:40:04Z ramack $
  */
 package org.openstreetmap.josm.plugins.globalsat;
@@ -23,4 +22,5 @@
 import org.kaintoch.gps.globalsat.dg100.ByteHelper;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.gpx.GpxData;
 import org.openstreetmap.josm.data.gpx.GpxTrack;
@@ -34,12 +34,12 @@
 public class GlobalsatDg100
 {
-	public class ConnectionException extends Exception{
-		ConnectionException(Exception cause){
-			super(cause);
-		}
-		ConnectionException(String msg){
-			super(msg);
-		}
-	}
+    public class ConnectionException extends Exception{
+        ConnectionException(Exception cause){
+            super(cause);
+        }
+        ConnectionException(String msg){
+            super(msg);
+        }
+    }
 
     public static final int TIMEOUT = 2000;
@@ -115,7 +115,13 @@
     private CommPortIdentifier portIdentifier;
     private SerialPort port = null;
+
+    private boolean cancelled = false;
     
     public GlobalsatDg100(CommPortIdentifier portId){
         this.portIdentifier = portId;
+    }
+
+    public void cancel(){
+        cancelled = true;
     }
 
@@ -126,10 +132,15 @@
     public GpxData readData() throws ConnectionException {
         GpxData result = null;
+        int cnt = 0;
+        cancelled = false;
         if(port == null){
             connect();
         }
-        
+        Main.pleaseWaitDlg.progress.setValue(0);
+
         List<FileInfoRec> fileInfoList = readFileInfoList();
         List<GpsRec> gpsRecList = readGpsRecList(fileInfoList);
+
+        Main.pleaseWaitDlg.progress.setMaximum(gpsRecList.size());
         if(gpsRecList.size() > 0){
             GpsRec last = null;
@@ -140,4 +151,7 @@
             trk.trackSegs.add(seg);
             for(GpsRec r:gpsRecList){
+                if(cancelled){
+                    return result;
+                }
                 WayPoint p = wayPointFrom(r);
                 if(r.equals(last)){
@@ -147,4 +161,5 @@
                 }
                 last = r;
+                Main.pleaseWaitDlg.progress.setValue(cnt++);
             }
         }
@@ -243,4 +258,8 @@
         int len = sendCmd(src, response, -1);
         return Response.parseResponse(response, len);
+    }
+
+    public boolean isCancelled(){
+        return cancelled;
     }
 
Index: applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java
===================================================================
--- applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java	(revision 11490)
+++ applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java	(revision 11496)
@@ -5,4 +5,6 @@
 
 import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.GridBagConstraints;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
@@ -16,4 +18,5 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JButton;
 import javax.swing.JTabbedPane;
 import javax.swing.JComboBox;
@@ -41,39 +44,105 @@
 public class GlobalsatImportDialog extends JPanel {
 	
-	// the JOptionPane that contains this dialog. required for the closeDialog() method.
-	private JOptionPane optionPane;
-        private JCheckBox delete;
-        private JComboBox portCombo;
-        private List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>();
+    // the JOptionPane that contains this dialog. required for the closeDialog() method.
+    private JOptionPane optionPane;
+    private JCheckBox delete;
+    private JComboBox portCombo;
+    private List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>();
 
-	public GlobalsatImportDialog() {
-            portCombo = new JComboBox();
-            portCombo.setRenderer(new ListCellRenderer(){
-                    public java.awt.Component getListCellRendererComponent(JList list, Object o, int x, boolean a, boolean b){
-                        return new JLabel(((CommPortIdentifier)o).getName());
+    public GlobalsatImportDialog() {
+        GridBagConstraints c = new GridBagConstraints();
+        JButton refreshBtn, configBtn;
+
+        setLayout(new GridBagLayout());
+
+        portCombo = new JComboBox();
+        portCombo.setRenderer(new ListCellRenderer(){
+                public java.awt.Component getListCellRendererComponent(JList list, Object o, int x, boolean a, boolean b){
+                    String value = ((CommPortIdentifier)o).getName();
+                    if(value == null){
+                        value = "null";
                     }
-                });
-            portCombo.addActionListener(new ActionListener(){
-                    public void actionPerformed(java.awt.event.ActionEvent e){
-                        Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier)portCombo.getSelectedItem()).getName());
+                    return new JLabel(value);
+                }
+            });
+        portCombo.addActionListener(new ActionListener(){
+                public void actionPerformed(java.awt.event.ActionEvent e){
+                    Object i = portCombo.getSelectedItem();
+                    if(i instanceof CommPortIdentifier){
+                        Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier)i).getName());
                     }
-                });
-            refreshPorts();
-            delete = new JCheckBox(tr("delete data after import"));
-            delete.setSelected(Main.pref.getBoolean("globalsat.deleteAfterDownload", false));
-            setLayout(new GridBagLayout());
-            add(portCombo);
-            add(delete);
-	}
+                }
+            });
+
+        refreshPorts();
+        c.insets = new Insets(4,4,4,4);
+        c.gridwidth = 1;
+        c.weightx = 0.8;
+        c.fill = GridBagConstraints.HORIZONTAL;
+        c.gridx = 0;
+        c.gridy = 0;
+        add(new JLabel(tr("Port:")), c);
+
+        c.gridwidth = 1;
+        c.gridx = 1;
+        c.gridy = 0;
+        c.weightx = 1.5;
+        add(portCombo, c);
+
+        refreshBtn = new JButton(tr("Refresh"));
+        refreshBtn.addActionListener(new ActionListener(){
+                public void actionPerformed(java.awt.event.ActionEvent e){
+                    refreshPorts();
+                }
+            });
+        refreshBtn.setToolTipText(tr("refresh the port list"));
+        c.gridwidth = 1;
+        c.weightx = 1.0;
+        c.fill = GridBagConstraints.HORIZONTAL;
+        c.gridx = 2;
+        c.gridy = 0;
+        add(refreshBtn, c);
+
+        configBtn = new JButton(tr("Configure"));
+        configBtn.addActionListener(new ActionListener(){
+                public void actionPerformed(java.awt.event.ActionEvent e){
+                    System.out.println("configureing the device");
+                }
+            });
+        configBtn.setToolTipText(tr("configure the connected DG100"));
+        c.gridwidth = 1;
+        c.weightx = 1.0;
+        c.fill = GridBagConstraints.HORIZONTAL;
+        c.gridx = 2;
+        c.gridy = 1;
+        //        add(configBtn, c);
+
+        
+        delete = new JCheckBox(tr("delete data after import"));
+        delete.setSelected(Main.pref.getBoolean("globalsat.deleteAfterDownload", false));
+
+        c.gridwidth = 3;
+        c.fill = GridBagConstraints.HORIZONTAL;
+        c.gridx = 0;
+        c.gridy = 2;
+        add(delete, c);
+    }
 
     public void refreshPorts(){
+        String sel = Main.pref.get("globalsat.portIdentifier");
+        portCombo.setVisible(false);
         portCombo.removeAllItems();
-        for(Enumeration e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){
+
+        Enumeration e = CommPortIdentifier.getPortIdentifiers();
+        for(e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){
             CommPortIdentifier port = (CommPortIdentifier)e.nextElement();
             if(port.getPortType() == CommPortIdentifier.PORT_SERIAL){
                 portCombo.addItem(port);
+                if(sel != null && port.getName() == sel){
+                    portCombo.setSelectedItem(port);
+                }
             }
         }
-        portCombo.setSelectedItem(Main.pref.get("globalsat.portIdentifier"));
+        portCombo.setVisible(true);
     }
 	
@@ -85,10 +154,10 @@
         return (CommPortIdentifier)portCombo.getSelectedItem();
     }
-	/**
-	 * Has to be called after this dialog has been added to a JOptionPane.
-	 * @param optionPane
-	 */
-	public void setOptionPane(JOptionPane optionPane) {
-            this.optionPane = optionPane;
-        }
+    /**
+     * Has to be called after this dialog has been added to a JOptionPane.
+     * @param optionPane
+     */
+    public void setOptionPane(JOptionPane optionPane) {
+        this.optionPane = optionPane;
+    }
 }
Index: applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java
===================================================================
--- applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java	(revision 11490)
+++ applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java	(revision 11496)
@@ -2,4 +2,7 @@
 /// @author Raphael Mack <ramack@raphael-mack.de>
 import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.IOException;
+import org.xml.sax.SAXException;
 
 import java.util.Enumeration;
@@ -16,4 +19,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.plugins.Plugin;
 import org.openstreetmap.josm.actions.JosmAction;
@@ -23,4 +27,59 @@
 
 public class GlobalsatPlugin extends Plugin {
+
+    private static class ImportTask extends PleaseWaitRunnable {
+        public GpxData data;
+        private GlobalsatDg100 dg100;
+        public Exception eee;
+        private boolean deleteAfter;
+
+        public ImportTask(GlobalsatDg100 dg100, boolean delete){
+            super(tr("Importing data from device."));
+            this.dg100 = dg100;
+            deleteAfter = delete;
+        }
+
+        @Override public void realRun() throws IOException, SAXException {
+            Main.pleaseWaitDlg.progress.setValue(0);
+            Main.pleaseWaitDlg.currentAction.setText(tr("Importing data from DG100..."));
+            try{
+                data = dg100.readData();
+            }catch(Exception e){
+                eee = e;
+            }
+        }
+
+        @Override protected void finish() {
+            if(deleteAfter && dg100.isCancelled() == false){
+                Main.pref.put("globalsat.deleteAfterDownload", true);
+                try{
+                    dg100.deleteData();
+                }catch(Exception ex){
+                    JOptionPane.showMessageDialog(Main.parent, tr("Error deleting data.") + " " + ex.toString());
+                }
+            }else{
+                Main.pref.put("globalsat.deleteAfterDownload", false);
+            }
+            if(data != null && data.hasTrackPoints()){
+                Main.main.addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100")));
+                Main.map.repaint();
+            }else{
+                JOptionPane.showMessageDialog(Main.parent, tr("No data found on device."));
+            }
+            if(eee != null){
+                eee.printStackTrace();
+                System.out.println(eee.getMessage());
+                JOptionPane.showMessageDialog(Main.parent, tr("Connection failed.") + " (" + eee.toString() + ")");
+            }
+            dg100.disconnect();
+        }
+
+        @Override protected void cancel() {
+            dg100.cancel();
+            dg100.disconnect();
+        }
+    }
+
+
     GlobalsatImportAction importAction;
     public GlobalsatPlugin() {
@@ -50,25 +109,6 @@
             if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){
                 GlobalsatDg100 dg100 = new GlobalsatDg100(dialog.getPort());
-                try{
-                    GpxData data = dg100.readData();
-                    if(dialog.deleteFilesAfterDownload()){
-                        Main.pref.put("globalsat.deleteAfterDownload", true);
-                        dg100.deleteData();
-                    }else{
-                        Main.pref.put("globalsat.deleteAfterDownload", false);
-                    }
-                    if(data != null && data.hasTrackPoints()){
-                        Main.main.addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100")));
-                        Main.map.repaint();
-                    }else{
-                        JOptionPane.showMessageDialog(Main.parent, tr("No data found on device."));
-                    }
-                }catch(Exception eee){
-                    eee.printStackTrace();
-                    System.out.println(eee.getMessage());
-                    JOptionPane.showMessageDialog(Main.parent, tr("Connection failed.") + " (" + eee.toString() + ")");
-                }finally{
-                    dg100.disconnect();
-                }
+                ImportTask task = new ImportTask(dg100, dialog.deleteFilesAfterDownload());
+                Main.worker.execute(task);
             }
             dlg.dispose();
