Index: /trunk/src/org/openstreetmap/josm/Main.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/Main.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/Main.java	(revision 1808)
@@ -403,6 +403,6 @@
                             for (final Layer l : map.mapView.getAllLayers()) {
                                 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) {
-                                    SaveAction save = new SaveAction(l);
-                                    if(!save.doSave()) {
+                                    SaveAction save = new SaveAction();
+                                    if(!save.doSave(l)) {
                                         savefailed = true;
                                     }
Index: /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java	(revision 1808)
@@ -23,9 +23,11 @@
     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
         String curDir = Main.pref.get("lastDirectory");
-        if (curDir.equals(""))
+        if (curDir.equals("")) {
             curDir = ".";
+        }
         JFileChooser fc = new JFileChooser(new File(curDir));
-        if (title != null)
+        if (title != null) {
             fc.setDialogTitle(title);
+        }
 
         fc.setMultiSelectionEnabled(multiple);
@@ -40,6 +42,7 @@
             return null;
 
-        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
+        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
             Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
+        }
 
         if (!open) {
@@ -57,13 +60,13 @@
     }
 
-    public static File createAndOpenSaveFileChooser(String title,
-    String extension)
-    {
+    public static File createAndOpenSaveFileChooser(String title, String extension) {
         String curDir = Main.pref.get("lastDirectory");
-        if (curDir.equals(""))
+        if (curDir.equals("")) {
             curDir = ".";
+        }
         JFileChooser fc = new JFileChooser(new File(curDir));
-        if (title != null)
+        if (title != null) {
             fc.setDialogTitle(title);
+        }
 
         fc.setMultiSelectionEnabled(false);
@@ -78,25 +81,26 @@
             return null;
 
-        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
+        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
             Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
+        }
 
         File file = fc.getSelectedFile();
-        if(extension != null)
-        {
+        if(extension != null){
             String fn = file.getPath();
             if(fn.indexOf('.') == -1)
             {
                 FileFilter ff = fc.getFileFilter();
-                if (ff instanceof ExtensionFileFilter)
+                if (ff instanceof ExtensionFileFilter) {
                     fn += "." + ((ExtensionFileFilter)ff).defaultExtension;
-                else
+                } else {
                     fn += extension;
+                }
                 file = new File(fn);
             }
         }
         if(file == null || (file.exists() && 1 != new ExtendedDialog(Main.parent,
-        tr("Overwrite"), tr("File exists. Overwrite?"),
-        new String[] {tr("Overwrite"), tr("Cancel")},
-        new String[] {"save_as.png", "cancel.png"}).getValue()))
+                tr("Overwrite"), tr("File exists. Overwrite?"),
+                new String[] {tr("Overwrite"), tr("Cancel")},
+                new String[] {"save_as.png", "cancel.png"}).getValue()))
             return null;
         return file;
Index: /trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java	(revision 1808)
@@ -32,4 +32,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.io.GpxWriter;
 import org.openstreetmap.josm.tools.GBC;
@@ -39,21 +40,51 @@
  * Exports data to gpx.
  */
-public class GpxExportAction extends DiskAccessAction {
+public class GpxExportAction extends DiskAccessAction implements LayerChangeListener {
 
     private final static String warningGpl = "<html><font color='red' size='-2'>"+tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.")+"</html>";
 
-    private final Layer layer;
-
-    public GpxExportAction(Layer layer) {
+    public GpxExportAction() {
         super(tr("Export to GPX..."), "exportgpx", tr("Export the data to GPX file."),
-        Shortcut.registerShortcut("file:exportgpx", tr("Export to GPX..."), KeyEvent.VK_E, Shortcut.GROUP_MENU));
-        this.layer = layer;
+                Shortcut.registerShortcut("file:exportgpx", tr("Export to GPX..."), KeyEvent.VK_E, Shortcut.GROUP_MENU));
+        Layer.listeners.add(this);
+        refreshEnabled();
+    }
+
+    protected GpxLayer getLayer() {
+        if (Main.map == null) return null;
+        if (Main.map.mapView == null) return null;
+        if (Main.map.mapView.getActiveLayer() == null) return null;
+        Layer layer = Main.map.mapView.getActiveLayer();
+        if (! (layer instanceof GpxLayer)) return null;
+        return (GpxLayer)layer;
     }
 
     public void actionPerformed(ActionEvent e) {
-        if (layer == null && Main.map == null) {
+        if (!isEnabled())
+            return;
+        GpxLayer layer = getLayer();
+        if (layer == null) {
             JOptionPane.showMessageDialog(Main.parent, tr("Nothing to export. Get some data first."));
             return;
         }
+        export(layer);
+    }
+
+    /**
+     * Exports a layer to a file. Launches a file chooser to request the user to enter a file name.
+     * 
+     * <code>layer</code> must not be null. <code>layer</code> must be an instance of
+     * {@see OsmDataLayer} or {@see GpxLayer}.
+     * 
+     * @param layer the layer
+     * @exception IllegalArgumentException thrown if layer is null
+     * @exception IllegalArgumentException thrown if layer is neither an instance of {@see OsmDataLayer}
+     *  nor of {@see GpxLayer}
+     */
+    public void export(Layer layer) {
+        if (layer == null)
+            throw new IllegalArgumentException(tr("paramenter ''{0'' must not be null", "layer"));
+        if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer))
+            throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
 
         JFileChooser fc = createAndOpenFileChooser(false, false, null);
@@ -64,5 +95,5 @@
             return;
 
-        exportGpx(file, this.layer == null ? Main.main.createOrGetEditLayer() : this.layer);
+        exportGpx(file, layer);
     }
 
@@ -120,24 +151,27 @@
 
         int answer = new ExtendedDialog(Main.parent,
-                        tr("Export options"),
-                        p,
-                        new String[] {tr("Export and Save"), tr("Cancel")},
-                        new String[] {"exportgpx.png", "cancel.png"}).getValue();
+                tr("Export options"),
+                p,
+                new String[] {tr("Export and Save"), tr("Cancel")},
+                new String[] {"exportgpx.png", "cancel.png"}).getValue();
         if (answer != 1)
             return;
 
         Main.pref.put("lastAddAuthor", author.isSelected());
-        if (authorName.getText().length() != 0)
+        if (authorName.getText().length() != 0) {
             Main.pref.put("lastAuthorName", authorName.getText());
-        if (copyright.getText().length() != 0)
+        }
+        if (copyright.getText().length() != 0) {
             Main.pref.put("lastCopyright", copyright.getText());
+        }
 
         GpxData gpxData;
-        if (layer instanceof OsmDataLayer)
+        if (layer instanceof OsmDataLayer) {
             gpxData = ((OsmDataLayer)layer).toGpxData();
-        else if (layer instanceof GpxLayer)
+        } else if (layer instanceof GpxLayer) {
             gpxData = ((GpxLayer)layer).data;
-        else
+        } else {
             gpxData = OsmDataLayer.toGpxData(Main.ds, file);
+        }
 
         // add author and copyright details to the gpx data
@@ -147,14 +181,24 @@
                 gpxData.attr.put(GpxData.META_COPYRIGHT_AUTHOR, authorName.getText());
             }
-            if(email.getText().length() > 0) gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText());
-            if(copyright.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText());
-            if(copyrightYear.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());
+            if(email.getText().length() > 0) {
+                gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText());
+            }
+            if(copyright.getText().length() > 0) {
+                gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText());
+            }
+            if(copyrightYear.getText().length() > 0) {
+                gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());
+            }
         }
 
         // add the description to the gpx data
-        if(desc.getText().length() > 0) gpxData.attr.put(GpxData.META_DESC, desc.getText());
+        if(desc.getText().length() > 0) {
+            gpxData.attr.put(GpxData.META_DESC, desc.getText());
+        }
 
         // add keywords to the gpx data
-        if(keywords.getText().length() > 0) gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText());
+        if(keywords.getText().length() > 0) {
+            gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText());
+        }
 
         try {
@@ -207,9 +251,9 @@
 
         KeyAdapter authorNameListener = new KeyAdapter(){
-                    @Override public void keyReleased(KeyEvent e) {
-                        boolean b = authorName.getText().length()!=0 && author.isSelected();
-                        enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
-                    }
-                };
+            @Override public void keyReleased(KeyEvent e) {
+                boolean b = authorName.getText().length()!=0 && author.isSelected();
+                enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
+            }
+        };
         authorName.addKeyListener(authorNameListener);
 
@@ -226,5 +270,5 @@
                         "public domain",
                         "http://www.gnu.org/copyleft/lesser.html",
-                        "http://www.opensource.org/licenses/bsd-license.php"};
+                "http://www.opensource.org/licenses/bsd-license.php"};
                 String license = "";
                 for (int i : l.getSelectedIndices()) {
@@ -254,12 +298,46 @@
         if (enable && copyrightYear.getText().length()==0) {
             copyrightYear.setText(enable ? Integer.toString(Calendar.getInstance().get(Calendar.YEAR)) : "");
-        } else if (!enable)
+        } else if (!enable) {
             copyrightYear.setText("");
+        }
 
         if (enable && copyright.getText().length()==0) {
             copyright.setText(enable ? Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5") : "");
             copyright.setCaretPosition(0);
-        } else if (!enable)
+        } else if (!enable) {
             copyright.setText("");
+        }
+    }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        boolean check = Main.main != null
+        && Main.map != null
+        && Main.map.mapView !=null
+        && Main.map.mapView.getActiveLayer() != null;
+        if(!check) {
+            setEnabled(false);
+            return;
+        }
+        Layer layer = Main.map.mapView.getActiveLayer();
+        setEnabled(layer instanceof GpxLayer);
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
     }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/SaveAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SaveAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/SaveAction.java	(revision 1808)
@@ -24,19 +24,21 @@
      * @param layer Save this layer.
      */
-    public SaveAction(Layer layer) {
+    public SaveAction() {
         super(tr("Save"), "save", tr("Save the current data."),
-        Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.GROUP_MENU), layer);
+                Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.GROUP_MENU));
     }
 
     @Override public File getFile(Layer layer) {
         File f = layer.getAssociatedFile();
-        if(f != null && ! f.exists())
+        if(f != null && ! f.exists()) {
             f=null;
+        }
         if(f != null && layer instanceof GpxLayer && 1 !=
-        new ExtendedDialog(Main.parent, tr("Overwrite"),
-        tr("File {0} exists. Overwrite?", f.getName()),
-        new String[] {tr("Overwrite"), tr("Cancel")},
-        new String[] {"save_as.png", "cancel.png"}).getValue())
+            new ExtendedDialog(Main.parent, tr("Overwrite"),
+                    tr("File {0} exists. Overwrite?", f.getName()),
+                    new String[] {tr("Overwrite"), tr("Cancel")},
+                    new String[] {"save_as.png", "cancel.png"}).getValue()) {
             f = null;
+        }
         return f == null ? openFileDialog(layer) : f;
     }
Index: /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1808)
@@ -26,4 +26,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.io.GpxImporter;
 import org.openstreetmap.josm.io.GpxWriter;
@@ -34,30 +35,36 @@
 import org.openstreetmap.josm.tools.Shortcut;
 
-public abstract class SaveActionBase extends DiskAccessAction {
-
-    private Layer layer;
-
-    public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut, Layer layer) {
+public abstract class SaveActionBase extends DiskAccessAction implements LayerChangeListener {
+
+    public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut) {
         super(name, iconName, tooltip, shortcut);
-        this.layer = layer;
+        Layer.listeners.add(this);
+        refreshEnabled();
     }
 
     public void actionPerformed(ActionEvent e) {
+        if (!isEnabled())
+            return;
         doSave();
     }
 
-    public Boolean doSave() {
-        Layer layer = this.layer;
+    public boolean doSave() {
+        Layer layer = null;
         if (layer == null && Main.map != null && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
                 || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) {
             layer = Main.map.mapView.getActiveLayer();
         }
-        if (layer == null) {
-            layer = Main.main.createOrGetEditLayer();
-        }
-
+        if (layer == null)
+            return false;
+        return doSave(layer);
+    }
+
+    public boolean doSave(Layer layer) {
+        if (layer == null)
+            return false;
+        if ( !(layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer))
+            return false;
         if (!checkSaveConditions(layer))
             return false;
-
 
         File file = getFile(layer);
@@ -263,3 +270,36 @@
         return true;
     }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        boolean check = Main.main != null
+        && Main.map != null
+        && Main.map.mapView !=null
+        && Main.map.mapView.getActiveLayer() != null;
+        if(!check) {
+            setEnabled(false);
+            return;
+        }
+        Layer layer = Main.map.mapView.getActiveLayer();
+        setEnabled(layer instanceof OsmDataLayer || layer instanceof GpxLayer);
+    }
+
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/SaveAsAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SaveAsAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/SaveAsAction.java	(revision 1808)
@@ -21,7 +21,7 @@
      * @param layer Save this layer.
      */
-    public SaveAsAction(Layer layer) {
+    public SaveAsAction() {
         super(tr("Save As..."), "save_as", tr("Save the current data to a new file."),
-        Shortcut.registerShortcut("system:saveas", tr("File: {0}", tr("Save As...")), KeyEvent.VK_S, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), layer);
+                Shortcut.registerShortcut("system:saveas", tr("File: {0}", tr("Save As...")), KeyEvent.VK_S, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT));
     }
 
Index: /trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java	(revision 1808)
@@ -8,15 +8,47 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class SelectAllAction extends JosmAction {
+public class SelectAllAction extends JosmAction implements LayerChangeListener{
 
     public SelectAllAction() {
         super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."),
-        Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
+                Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
+        Layer.listeners.add(this);
+        refreshEnabled();
     }
 
     public void actionPerformed(ActionEvent e) {
+        if (!isEnabled())
+            return;
         Main.ds.setSelected(Main.ds.allNonDeletedCompletePrimitives());
     }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+        );
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java	(revision 1808)
@@ -9,11 +9,13 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class UnselectAllAction extends JosmAction {
+public class UnselectAllAction extends JosmAction implements LayerChangeListener {
 
     public UnselectAllAction() {
         super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
-        Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
+                Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
         // this is not really GROUP_EDIT, but users really would complain if the yhad to reconfigure because we put
         // the correct group in
@@ -21,7 +23,7 @@
         // Add extra shortcut C-S-a
         Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
-        Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
-        KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
-        tr("Unselect All"));
+                Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
+                        KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
+                        tr("Unselect All"));
 
         // Add extra shortcut ESCAPE
@@ -32,11 +34,40 @@
          */
         Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
-        Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
-        KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
-        tr("Unselect All"));
+                Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
+                        KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
+                        tr("Unselect All"));
+        Layer.listeners.add(this);
+        refreshEnabled();
     }
 
     public void actionPerformed(ActionEvent e) {
+        if (!isEnabled())
+            return;
         Main.ds.setSelected();
     }
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+        );
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java	(revision 1808)
@@ -15,7 +15,9 @@
 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
 import org.openstreetmap.josm.data.osm.DataSource;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class UpdateDataAction extends JosmAction {
+public class UpdateDataAction extends JosmAction implements LayerChangeListener{
     public UpdateDataAction() {
         super(tr("Update Data"),
@@ -27,7 +29,23 @@
                         Shortcut.GROUP_HOTKEY),
                         true);
+        refreshEnabled();
+        Layer.listeners.add(this);
+    }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.main != null
+                && Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+        );
     }
 
     public void actionPerformed(ActionEvent e) {
+        if (! isEnabled())
+            return;
         int bboxCount = 0;
         List<Area> areas = new ArrayList<Area>();
@@ -71,3 +89,18 @@
         new DownloadOsmTaskList().download(false, areas);
     }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java	(revision 1808)
@@ -15,7 +15,10 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.SelectionChangedListener;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.io.MultiFetchServerObjectReader;
 import org.openstreetmap.josm.io.OsmApi;
@@ -29,5 +32,5 @@
  *
  */
-public class UpdateSelectionAction extends JosmAction {
+public class UpdateSelectionAction extends JosmAction implements SelectionChangedListener, LayerChangeListener {
 
     /**
@@ -48,4 +51,5 @@
         Main.map.mapView.getEditLayer().mergeFrom(ds);
     }
+
 
     /**
@@ -191,4 +195,20 @@
                         Shortcut.GROUP_HOTKEY + Shortcut.GROUPS_ALT2),
                         true);
+        refreshEnabled();
+        Layer.listeners.add(this);
+        DataSet.selListeners.add(this);
+    }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.main != null
+                && Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+                && ! Main.map.mapView.getEditLayer().data.getSelected().isEmpty()
+        );
     }
 
@@ -197,4 +217,6 @@
      */
     public void actionPerformed(ActionEvent e) {
+        if (! isEnabled())
+            return;
         Collection<OsmPrimitive> selection = Main.ds.getSelected();
         if (selection.size() == 0) {
@@ -209,3 +231,19 @@
         updatePrimitives(selection);
     }
+
+    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
+        refreshEnabled();
+    }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/UploadAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/UploadAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/UploadAction.java	(revision 1808)
@@ -29,4 +29,6 @@
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.io.OsmApiException;
@@ -48,5 +50,5 @@
  * @author imi
  */
-public class UploadAction extends JosmAction {
+public class UploadAction extends JosmAction implements LayerChangeListener{
     static private Logger logger = Logger.getLogger(UploadAction.class.getName());
 
@@ -152,4 +154,19 @@
             }
         });
+
+        Layer.listeners.add(this);
+        refreshEnabled();
+    }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.main != null
+                && Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+        );
     }
 
@@ -582,3 +599,18 @@
         e.printStackTrace();
     }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
+    }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 1808)
@@ -23,8 +23,10 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class SearchAction extends JosmAction {
+public class SearchAction extends JosmAction implements LayerChangeListener{
 
     public static final int SEARCH_HISTORY_SIZE = 10;
@@ -40,8 +42,12 @@
     public SearchAction() {
         super(tr("Search..."), "dialogs/search", tr("Search for objects."),
-        Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true);
+                Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true);
+        Layer.listeners.add(this);
+        refreshEnabled();
     }
 
     public void actionPerformed(ActionEvent e) {
+        if (!isEnabled())
+            return;
         if (Main.map == null) {
             JOptionPane.showMessageDialog(Main.parent, tr("No data loaded."));
@@ -49,6 +55,7 @@
         }
         SearchSetting s = lastSearch;
-        if (s == null)
+        if (s == null) {
             s = new SearchSetting("", false, false, SearchMode.replace);
+        }
         showSearchDialog(s);
     }
@@ -81,27 +88,27 @@
         JPanel right = new JPanel();
         JLabel description =
-        new JLabel("<html><ul>"
-                + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>"
-                + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>"
-                + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>"
-                + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>"
-                + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>"
-                + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>"
-                + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>"
-                + "<li>"+tr("<u>Special targets:</u>")+"</li>"
-                + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>"
-                + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"
-                + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>"
-                + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
-                + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
-                + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
-                + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"
-                + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>"
-                + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"
-                + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>"
-                + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>"
-                + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>"
-                + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"
-                + "</ul></html>");
+            new JLabel("<html><ul>"
+                    + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>"
+                    + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>"
+                    + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>"
+                    + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>"
+                    + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>"
+                    + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>"
+                    + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>"
+                    + "<li>"+tr("<u>Special targets:</u>")+"</li>"
+                    + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>"
+                    + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"
+                    + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>"
+                    + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
+                    + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
+                    + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
+                    + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"
+                    + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>"
+                    + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"
+                    + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>"
+                    + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>"
+                    + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>"
+                    + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"
+                    + "</ul></html>");
         description.setFont(description.getFont().deriveFont(Font.PLAIN));
         right.add(description);
@@ -112,8 +119,8 @@
 
         int result = new ExtendedDialog(Main.parent,
-            tr("Search"),
-            p,
-            new String[] {tr("Start Search"), tr("Cancel")},
-            new String[] {"dialogs/search.png", "cancel.png"}).getValue();
+                tr("Search"),
+                p,
+                new String[] {tr("Start Search"), tr("Cancel")},
+                new String[] {"dialogs/search.png", "cancel.png"}).getValue();
         if(result != 1) return;
 
@@ -132,8 +139,10 @@
      */
     public static void searchWithHistory(SearchSetting s) {
-        if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst()))
+        if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) {
             searchHistory.addFirst(s);
-        while (searchHistory.size() > SEARCH_HISTORY_SIZE)
+        }
+        while (searchHistory.size() > SEARCH_HISTORY_SIZE) {
             searchHistory.removeLast();
+        }
         lastSearch = s;
         search(s.text, s.mode, s.caseSensitive, s.regexSearch);
@@ -163,6 +172,7 @@
                         sel.add(osm);
                         ++foundMatches;
-                    } else
+                    } else {
                         sel.remove(osm);
+                    }
                 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) {
                     sel.add(osm);
@@ -176,14 +186,16 @@
             if (foundMatches == 0) {
                 String msg = null;
-                if (mode == SearchMode.replace)
+                if (mode == SearchMode.replace) {
                     msg = tr("No match found for ''{0}''", search);
-                else if (mode == SearchMode.add)
+                } else if (mode == SearchMode.add) {
                     msg = tr("Nothing added to selection by searching for ''{0}''", search);
-                else if (mode == SearchMode.remove)
+                } else if (mode == SearchMode.remove) {
                     msg = tr("Nothing removed from selection by searching for ''{0}''", search);
+                }
                 Main.map.statusLine.setHelpText(msg);
                 JOptionPane.showMessageDialog(Main.parent, msg);
-            } else
+            } else {
                 Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches));
+            }
         } catch (SearchCompiler.ParseError e) {
             JOptionPane.showMessageDialog(Main.parent, e.getMessage());
@@ -212,4 +224,5 @@
         }
 
+        @Override
         public boolean equals(Object other) {
             if(!(other instanceof SearchSetting))
@@ -217,8 +230,34 @@
             SearchSetting o = (SearchSetting) other;
             return (o.caseSensitive == this.caseSensitive
-                 && o.regexSearch == this.regexSearch
-                 && o.mode.equals(this.mode)
-                 && o.text.equals(this.text));
-        }
+                    && o.regexSearch == this.regexSearch
+                    && o.mode.equals(this.mode)
+                    && o.text.equals(this.text));
+        }
+    }
+
+    /**
+     * Refreshes the enabled state
+     * 
+     */
+    protected void refreshEnabled() {
+        setEnabled(Main.map != null
+                && Main.map.mapView !=null
+                && Main.map.mapView.getEditLayer() != null
+        );
+    }
+
+    /* ---------------------------------------------------------------------------------- */
+    /* Interface LayerChangeListener                                                      */
+    /* ---------------------------------------------------------------------------------- */
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerAdded(Layer newLayer) {
+        refreshEnabled();
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        refreshEnabled();
     }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/MainMenu.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 1808)
@@ -75,4 +75,6 @@
 import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
 import org.openstreetmap.josm.actions.search.SearchAction;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -91,7 +93,7 @@
     public final OpenFileAction openFile = new OpenFileAction();
     public final OpenLocationAction openLocation = new OpenLocationAction();
-    public final JosmAction save = new SaveAction(null);
-    public final JosmAction saveAs = new SaveAsAction(null);
-    public final JosmAction gpxExport = new GpxExportAction(null);
+    public final JosmAction save = new SaveAction();
+    public final JosmAction saveAs = new SaveAsAction();
+    public final JosmAction gpxExport = new GpxExportAction();
     public final DownloadAction download = new DownloadAction();
     public final JosmAction update = new UpdateDataAction();
@@ -306,4 +308,36 @@
                 Shortcut.GROUP_DIRECT).getKeyStroke());
         add(helpMenu, about);
+
+        new PresetsMenuEnabler(presetsMenu).refreshEnabled();
+    }
+
+    class PresetsMenuEnabler implements LayerChangeListener {
+        private JMenu presetsMenu;
+        public PresetsMenuEnabler(JMenu presetsMenu) {
+            Layer.listeners.add(this);
+            this.presetsMenu = presetsMenu;
+        }
+        /**
+         * Refreshes the enabled state
+         * 
+         */
+        protected void refreshEnabled() {
+            presetsMenu.setEnabled(Main.map != null
+                    && Main.map.mapView !=null
+                    && Main.map.mapView.getEditLayer() != null
+            );
+        }
+
+        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+            refreshEnabled();
+        }
+
+        public void layerAdded(Layer newLayer) {
+            refreshEnabled();
+        }
+
+        public void layerRemoved(Layer oldLayer) {
+            refreshEnabled();
+        }
     }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/MapView.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/MapView.java	(revision 1808)
@@ -210,12 +210,13 @@
      */
     public void removeLayer(Layer layer) {
+        if (layer == activeLayer) {
+            if (layer instanceof OsmDataLayer) {
+                Main.ds = null;
+            }
+            activeLayer = null;
+        }
         if (layers.remove(layer)) {
             for (Layer.LayerChangeListener l : Layer.listeners) {
                 l.layerRemoved(layer);
-            }
-        }
-        if (layer == activeLayer) {
-            if (layer instanceof OsmDataLayer) {
-                Main.ds = null;
             }
         }
@@ -419,5 +420,8 @@
         // workaround for #1461 (zoom to download bounding box instead of all data)
         // In case we already have an existing data layer ...
-        Collection<DataSource> dataSources = Main.main.createOrGetEditLayer().data.dataSources;
+        OsmDataLayer layer= getEditLayer();
+        if (layer == null)
+            return false;
+        Collection<DataSource> dataSources = layer.data.dataSources;
         // ... with bounding box[es] of data loaded from OSM or a file...
         BoundingXYVisitor bbox = new BoundingXYVisitor();
Index: /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 1808)
@@ -127,15 +127,17 @@
                 }
                 String propName = "draw.rawgps.lines.layer "+name;
-                if (Main.pref.hasKey(propName))
+                if (Main.pref.hasKey(propName)) {
                     group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true);
-                else
+                } else {
                     group.setSelected(r[0].getModel(), true);
+                }
                 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION);
                 if (answer == JOptionPane.CANCEL_OPTION)
                     return;
-                if (group.getSelection() == r[0].getModel())
+                if (group.getSelection() == r[0].getModel()) {
                     Main.pref.put(propName, null);
-                else
+                } else {
                     Main.pref.put(propName, group.getSelection() == r[1].getModel());
+                }
                 Main.map.repaint();
             }
@@ -149,5 +151,5 @@
                 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
                 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
-                JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
+                        JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
                 switch (answer) {
                 case 0:
@@ -169,9 +171,12 @@
             public void actionPerformed(ActionEvent e) {
                 GpxData namedTrackPoints = new GpxData();
-                for (GpxTrack track : data.tracks)
-                    for (Collection<WayPoint> seg : track.trackSegs)
+                for (GpxTrack track : data.tracks) {
+                    for (Collection<WayPoint> seg : track.trackSegs) {
                         for (WayPoint point : seg)
-                            if (point.attr.containsKey("name") || point.attr.containsKey("desc"))
+                            if (point.attr.containsKey("name") || point.attr.containsKey("desc")) {
                                 namedTrackPoints.waypoints.add(point);
+                            }
+                    }
+                }
 
                 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), getAssociatedFile(), me);
@@ -200,6 +205,7 @@
                 fc.setMultiSelectionEnabled(true);
                 if(fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
-                    if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir))
+                    if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) {
                         Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath());
+                    }
 
                     File sel[] = fc.getSelectedFiles();
@@ -217,16 +223,18 @@
                     String names = null;
                     for (int i = 0; i < sel.length; i++) {
-                        if(names == null)
+                        if(names == null) {
                             names = " (";
-                        else
+                        } else {
                             names += ", ";
+                        }
                         names += sel[i].getName();
                     }
-                    if(names != null)
+                    if(names != null) {
                         names += ")";
-                    else
+                    } else {
                         names = "";
+                    }
                     MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name) + names,
-                    getAssociatedFile(), me);
+                            getAssociatedFile(), me);
                     if(sel != null)
                     {
@@ -270,8 +278,9 @@
             private void addRecursiveFiles(LinkedList<File> files, File[] sel) {
                 for (File f : sel) {
-                    if (f.isDirectory())
+                    if (f.isDirectory()) {
                         addRecursiveFiles(files, f.listFiles());
-                    else if (f.getName().toLowerCase().endsWith(".jpg"))
+                    } else if (f.getName().toLowerCase().endsWith(".jpg")) {
                         files.add(f);
+                    }
                 }
             }
@@ -291,20 +300,20 @@
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
         return new Component[] {
-            new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
-            new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
-            new JSeparator(),
-            new JMenuItem(new SaveAction(this)),
-            new JMenuItem(new SaveAsAction(this)),
-            color,
-            line,
-            tagimage,
-            importAudio,
-            markersFromNamedTrackpoints,
-            new JMenuItem(new ConvertToDataLayerAction()),
-            new JMenuItem(new DownloadAlongTrackAction()),
-            new JSeparator(),
-            new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
-            new JSeparator(),
-            new JMenuItem(new LayerListPopup.InfoAction(this))};
+                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
+                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
+                new JSeparator(),
+                new JMenuItem(new LayerSaveAction(this)),
+                new JMenuItem(new LayerSaveAsAction(this)),
+                color,
+                line,
+                tagimage,
+                importAudio,
+                markersFromNamedTrackpoints,
+                new JMenuItem(new ConvertToDataLayerAction()),
+                new JMenuItem(new DownloadAlongTrackAction()),
+                new JSeparator(),
+                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
+                new JSeparator(),
+                new JMenuItem(new LayerListPopup.InfoAction(this))};
     }
 
@@ -313,13 +322,15 @@
 
         info.append(trn("{0} track, ", "{0} tracks, ",
-        data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ",
-        data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints",
-        data.waypoints.size(), data.waypoints.size())).append("<br>");
-
-        if (data.attr.containsKey("name"))
+                data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ",
+                        data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints",
+                                data.waypoints.size(), data.waypoints.size())).append("<br>");
+
+        if (data.attr.containsKey("name")) {
             info.append(tr("Name: {0}", data.attr.get(GpxData.META_NAME))).append("<br>");
-
-        if (data.attr.containsKey("desc"))
+        }
+
+        if (data.attr.containsKey("desc")) {
             info.append(tr("Description: {0}", data.attr.get(GpxData.META_DESC))).append("<br>");
+        }
 
         if(data.tracks.size() > 0){
@@ -346,5 +357,5 @@
                 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
                 info.append(tr("Timespan: ") + df.format(new Date((long)(earliest.time * 1000))) + " - "
-                + df.format(new Date((long)(latest.time * 1000))));
+                        + df.format(new Date((long)(latest.time * 1000))));
                 int diff = (int)(latest.time - earliest.time);
                 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600)/60) + ")");
@@ -418,6 +429,7 @@
         String linesKey = "draw.rawgps.lines.layer "+name;
         // draw lines, per-layer setting
-        if (Main.pref.hasKey(linesKey))
+        if (Main.pref.hasKey(linesKey)) {
             lines = Main.pref.getBoolean(linesKey);
+        }
         // paint large dots for points
         boolean large = Main.pref.getBoolean("draw.rawgps.large");
@@ -437,8 +449,8 @@
          ****************************************************************/
         if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) ||
-                                   (!neutralColor.equals(computeCacheColorUsed)) ||
-                                   (computeCacheColored != colored) ||
-                                   (computeCacheColorTracksTune != colorTracksTune))) {
-//          System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
+                (!neutralColor.equals(computeCacheColorUsed)) ||
+                (computeCacheColored != colored) ||
+                (computeCacheColorTracksTune != colorTracksTune))) {
+            //          System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
             computeCacheMaxLineLengthUsed = maxLineLength;
             computeCacheInSync = false;
@@ -468,28 +480,29 @@
 
                             switch(colored) {
-                                case velocity:
-                                    double dtime = trkPnt.time - oldWp.time;
-                                    double vel = dist/dtime;
-                                    double velColor = vel/colorTracksTune*255;
-                                    // Bad case first
-                                    if (dtime <= 0 || vel < 0 || velColor > 255)
-                                        trkPnt.customColoring = colors[255];
-                                    else
-                                        trkPnt.customColoring = colors[(int) (velColor)];
-                                    break;
-
-                                case dilution:
-                                    if(trkPnt.attr.get("hdop") != null) {
-                                        float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue();
-                                        if (hdop < 0) {
-                                            hdop = 0;
-                                        }
-                                        int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
-                                        // High hdop is bad, but high values in colors are green.
-                                        // Therefore inverse the logic
-                                        int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
-                                        trkPnt.customColoring = colors[hdopcolor];
+                            case velocity:
+                                double dtime = trkPnt.time - oldWp.time;
+                                double vel = dist/dtime;
+                                double velColor = vel/colorTracksTune*255;
+                                // Bad case first
+                                if (dtime <= 0 || vel < 0 || velColor > 255) {
+                                    trkPnt.customColoring = colors[255];
+                                } else {
+                                    trkPnt.customColoring = colors[(int) (velColor)];
+                                }
+                                break;
+
+                            case dilution:
+                                if(trkPnt.attr.get("hdop") != null) {
+                                    float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue();
+                                    if (hdop < 0) {
+                                        hdop = 0;
                                     }
-                                    break;
+                                    int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25));
+                                    // High hdop is bad, but high values in colors are green.
+                                    // Therefore inverse the logic
+                                    int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl);
+                                    trkPnt.customColoring = colors[hdopcolor];
+                                }
+                                break;
                             }
 
@@ -514,12 +527,13 @@
          ****************************************************************/
         if (lines) {
-        Point old = null;
-        for (GpxTrack trk : data.tracks) {
-            for (Collection<WayPoint> segment : trk.trackSegs) {
-                for (WayPoint trkPnt : segment) {
-                    LatLon c = trkPnt.getCoor();
-                    if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
-                        continue;
-                    Point screen = mv.getPoint(trkPnt.getEastNorth());
+            Point old = null;
+            for (GpxTrack trk : data.tracks) {
+                for (Collection<WayPoint> segment : trk.trackSegs) {
+                    for (WayPoint trkPnt : segment) {
+                        LatLon c = trkPnt.getCoor();
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
+                            continue;
+                        }
+                        Point screen = mv.getPoint(trkPnt.getEastNorth());
                         if (trkPnt.drawLine) {
                             // skip points that are on the same screenposition
@@ -545,6 +559,7 @@
                     for (WayPoint trkPnt : segment) {
                         LatLon c = trkPnt.getCoor();
-                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
                             continue;
+                        }
                         if (trkPnt.drawLine) {
                             Point screen = mv.getPoint(trkPnt.getEastNorth());
@@ -554,7 +569,7 @@
                                 double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI;
                                 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y
-                                + 10*Math.sin(t-PHI)));
+                                        + 10*Math.sin(t-PHI)));
                                 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y
-                                + 10*Math.sin(t+PHI)));
+                                        + 10*Math.sin(t+PHI)));
                                 oldA = screen;
                             }
@@ -576,6 +591,7 @@
                     for (WayPoint trkPnt : segment) {
                         LatLon c = trkPnt.getCoor();
-                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
                             continue;
+                        }
                         if (trkPnt.drawLine) {
                             Point screen = mv.getPoint(trkPnt.getEastNorth());
@@ -603,6 +619,7 @@
                     for (WayPoint trkPnt : segment) {
                         LatLon c = trkPnt.getCoor();
-                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
                             continue;
+                        }
                         Point screen = mv.getPoint(trkPnt.getEastNorth());
                         g.setColor(trkPnt.customColoring);
@@ -622,10 +639,11 @@
                     for (WayPoint trkPnt : segment) {
                         LatLon c = trkPnt.getCoor();
-                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
                             continue;
+                        }
                         if (!trkPnt.drawLine) {
                             Point screen = mv.getPoint(trkPnt.getEastNorth());
-                        g.drawRect(screen.x, screen.y, 0, 0);
-                    }
+                            g.drawRect(screen.x, screen.y, 0, 0);
+                        }
                     } // end for trkpnt
                 } // end for segment
@@ -642,6 +660,7 @@
                     for (WayPoint trkPnt : segment) {
                         LatLon c = trkPnt.getCoor();
-                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon()))
+                        if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
                             continue;
+                        }
                         Point screen = mv.getPoint(trkPnt.getEastNorth());
                         g.setColor(trkPnt.customColoring);
@@ -688,10 +707,12 @@
             }
             Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name),
-                        getAssociatedFile()));
+                    getAssociatedFile()));
             Main.main.removeLayer(GpxLayer.this);
         }
     }
 
+    @Override
     public File getAssociatedFile() { return data.storageFile; }
+    @Override
     public void setAssociatedFile(File file) { data.storageFile = file; }
 
@@ -712,20 +733,21 @@
             msg.add(new JLabel(tr("Download everything within:")), GBC.eol());
             String s[] = new String[dist.length];
-            for(int i = 0; i < dist.length; ++i)
+            for(int i = 0; i < dist.length; ++i) {
                 s[i] = tr("{0} meters", dist[i]);
+            }
             JList buffer = new JList(s);
             msg.add(buffer, GBC.eol());
             msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol());
             s = new String[area.length];
-            for(int i = 0; i < area.length; ++i)
+            for(int i = 0; i < area.length; ++i) {
                 s[i] = tr("{0} sq km", area[i]);
+            }
             JList maxRect = new JList(s);
             msg.add(maxRect, GBC.eol());
 
             if (JOptionPane.showConfirmDialog(Main.parent, msg,
-                tr("Download from OSM along this track"),
-                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
+                    tr("Download from OSM along this track"),
+                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION)
                 return;
-            }
 
             /*
@@ -813,11 +835,10 @@
 
             msg.add(new JLabel(tr("<html>This action will require {0} individual<br>download requests. Do you wish<br>to continue?</html>",
-                toDownload.size())), GBC.eol());
+                    toDownload.size())), GBC.eol());
 
             if (toDownload.size() > 1 && JOptionPane.showConfirmDialog(Main.parent, msg,
-                tr("Download from OSM along this track"),
-                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
+                    tr("Download from OSM along this track"),
+                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION)
                 return;
-            }
 
             new DownloadOsmTaskList().download(false, toDownload);
@@ -874,5 +895,7 @@
         if (data.tracks != null && ! data.tracks.isEmpty()) {
             for (GpxTrack track : data.tracks) {
-                if (track.trackSegs == null) continue;
+                if (track.trackSegs == null) {
+                    continue;
+                }
                 for (Collection<WayPoint> seg : track.trackSegs) {
                     for (WayPoint w : seg) {
@@ -880,7 +903,11 @@
                         break;
                     }
-                    if (firstTime >= 0.0) break;
-                }
-                if (firstTime >= 0.0) break;
+                    if (firstTime >= 0.0) {
+                        break;
+                    }
+                }
+                if (firstTime >= 0.0) {
+                    break;
+                }
             }
         }
@@ -892,5 +919,5 @@
         // (a) try explicit timestamped waypoints - unless suppressed
         if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) &&
-            data.waypoints != null && ! data.waypoints.isEmpty())
+                data.waypoints != null && ! data.waypoints.isEmpty())
         {
             for (WayPoint w : data.waypoints) {
@@ -905,5 +932,5 @@
         // (b) try explicit waypoints without timestamps - unless suppressed
         if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) &&
-            data.waypoints != null && ! data.waypoints.isEmpty())
+                data.waypoints != null && ! data.waypoints.isEmpty())
         {
             for (WayPoint w : data.waypoints) {
@@ -913,5 +940,7 @@
                     WayPoint wc = new WayPoint(w.getCoor());
                     wc.time = wNear.time;
-                    if (w.attr.containsKey("name")) wc.attr.put("name", w.getString("name"));
+                    if (w.attr.containsKey("name")) {
+                        wc.attr.put("name", w.getString("name"));
+                    }
                     waypoints.add(wc);
                 } else {
@@ -923,8 +952,10 @@
         // (c) use explicitly named track points, again unless suppressed
         if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) &&
-            data.tracks != null && ! data.tracks.isEmpty())
+                data.tracks != null && ! data.tracks.isEmpty())
         {
             for (GpxTrack track : data.tracks) {
-                if (track.trackSegs == null) continue;
+                if (track.trackSegs == null) {
+                    continue;
+                }
                 for (Collection<WayPoint> seg : track.trackSegs) {
                     for (WayPoint w : seg) {
@@ -945,10 +976,12 @@
             double startTime = lastModified - duration;
             startTime = firstStartTime + (startTime - firstStartTime) /
-                Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
+            Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
             WayPoint w1 = null;
             WayPoint w2 = null;
 
             for (GpxTrack track : data.tracks) {
-                if (track.trackSegs == null) continue;
+                if (track.trackSegs == null) {
+                    continue;
+                }
                 for (Collection<WayPoint> seg : track.trackSegs) {
                     for (WayPoint w : seg) {
@@ -959,5 +992,7 @@
                         w1 = w;
                     }
-                    if (w2 != null) break;
+                    if (w2 != null) {
+                        break;
+                    }
                 }
             }
@@ -967,5 +1002,5 @@
             } else {
                 wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(
-                    w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time)));
+                        w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time)));
                 wayPointFromTimeStamp.time = startTime;
                 String name = wavFile.getName();
@@ -981,9 +1016,11 @@
         // (f) simply add a single marker at the start of the track
         if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) &&
-            data.tracks != null && ! data.tracks.isEmpty())
+                data.tracks != null && ! data.tracks.isEmpty())
         {
             boolean gotOne = false;
             for (GpxTrack track : data.tracks) {
-                if (track.trackSegs == null) continue;
+                if (track.trackSegs == null) {
+                    continue;
+                }
                 for (Collection<WayPoint> seg : track.trackSegs) {
                     for (WayPoint w : seg) {
@@ -995,7 +1032,11 @@
                         break;
                     }
-                    if (gotOne) break;
-                }
-                if (gotOne) break;
+                    if (gotOne) {
+                        break;
+                    }
+                }
+                if (gotOne) {
+                    break;
+                }
             }
         }
@@ -1011,13 +1052,16 @@
         firstTime = -1.0; /* this time of the first waypoint, not first trackpoint */
         for (WayPoint w : waypoints) {
-            if (firstTime < 0.0) firstTime = w.time;
+            if (firstTime < 0.0) {
+                firstTime = w.time;
+            }
             double offset = w.time - firstTime;
             String name;
-            if (w.attr.containsKey("name"))
+            if (w.attr.containsKey("name")) {
                 name = w.getString("name");
-            else if (w.attr.containsKey("desc"))
+            } else if (w.attr.containsKey("desc")) {
                 name = w.getString("desc");
-            else
+            } else {
                 name = AudioMarker.inventName(offset);
+            }
             AudioMarker am = AudioMarker.create(w.getCoor(),
                     name, uri, ml, w.time, offset);
@@ -1031,9 +1075,9 @@
         if (timedMarkersOmitted) {
             JOptionPane.showMessageDialog(Main.parent,
-            tr("Some waypoints with timestamps from before the start of the track or after the end were omitted or moved to the start."));
+                    tr("Some waypoints with timestamps from before the start of the track or after the end were omitted or moved to the start."));
         }
         if (untimedMarkersOmitted) {
             JOptionPane.showMessageDialog(Main.parent,
-            tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
+                    tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted."));
         }
     }
@@ -1089,5 +1133,7 @@
         if (data.tracks == null) return null;
         for (GpxTrack track : data.tracks) {
-            if (track.trackSegs == null) continue;
+            if (track.trackSegs == null) {
+                continue;
+            }
             for (Collection<WayPoint> seg : track.trackSegs) {
                 WayPoint R = null;
@@ -1113,5 +1159,7 @@
                         double C = - A * rx - B * ry;
                         double RSsq = A * A + B * B;
-                        if (RSsq == 0.0) continue;
+                        if (RSsq == 0.0) {
+                            continue;
+                        }
                         double PNsq = A * px + B * py + C;
                         PNsq = PNsq * PNsq / RSsq;
Index: /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 1808)
@@ -3,15 +3,23 @@
 package org.openstreetmap.josm.gui.layer;
 
+import static org.openstreetmap.josm.tools.I18n.tr;
+
 import java.awt.Component;
 import java.awt.Graphics;
+import java.awt.event.ActionEvent;
 import java.io.File;
 import java.util.Collection;
 import java.util.concurrent.CopyOnWriteArrayList;
 
+import javax.swing.AbstractAction;
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.actions.GpxExportAction;
+import org.openstreetmap.josm.actions.SaveAction;
+import org.openstreetmap.josm.actions.SaveAsAction;
 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.tools.Destroyable;
+import org.openstreetmap.josm.tools.ImageProvider;
 
 /**
@@ -133,3 +141,51 @@
         return name;
     }
+
+
+    public static class LayerSaveAction extends AbstractAction {
+        private Layer layer;
+        public LayerSaveAction(Layer layer) {
+            putValue(SMALL_ICON, ImageProvider.get("save"));
+            putValue(SHORT_DESCRIPTION, tr("Save the current data."));
+            putValue(NAME, tr("Save"));
+            setEnabled(true);
+            this.layer = layer;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            new SaveAction().doSave(layer);
+
+        }
+    }
+
+    public static class LayerSaveAsAction extends AbstractAction {
+        private Layer layer;
+        public LayerSaveAsAction(Layer layer) {
+            putValue(SMALL_ICON, ImageProvider.get("save_as"));
+            putValue(SHORT_DESCRIPTION, tr("Save the current data to a new file."));
+            putValue(NAME, tr("Save As..."));
+            setEnabled(true);
+            this.layer = layer;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            new SaveAsAction().doSave(layer);
+        }
+    }
+
+    public static class LayerGpxExportAction extends AbstractAction {
+        private Layer layer;
+        public LayerGpxExportAction(Layer layer) {
+            putValue(SMALL_ICON, ImageProvider.get("exportgpx"));
+            putValue(SHORT_DESCRIPTION, tr("Export the data to GPX file."));
+            putValue(NAME, tr("Export to GPX..."));
+            setEnabled(true);
+            this.layer = layer;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            new GpxExportAction().export(layer);
+        }
+    }
+
 }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 1808)
@@ -18,4 +18,5 @@
 import java.awt.TexturePaint;
 import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
 import java.awt.geom.Area;
 import java.awt.image.BufferedImage;
@@ -66,4 +67,5 @@
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Shortcut;
 
 /**
@@ -430,7 +432,7 @@
                 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
                 new JSeparator(),
-                new JMenuItem(new SaveAction(this)),
-                new JMenuItem(new SaveAsAction(this)),
-                new JMenuItem(new GpxExportAction(this)),
+                new JMenuItem(new LayerSaveAction(this)),
+                new JMenuItem(new LayerSaveAsAction(this)),
+                new JMenuItem(new LayerGpxExportAction(this)),
                 new JMenuItem(new ConvertToGpxLayerAction()),
                 new JSeparator(),
Index: /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 1807)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 1808)
@@ -126,18 +126,22 @@
         boolean lines = Main.pref.getBoolean("draw.rawgps.lines", true);
         String linesKey = "draw.rawgps.lines.layer "+name;
-        if (Main.pref.hasKey(linesKey))
+        if (Main.pref.hasKey(linesKey)) {
             lines = Main.pref.getBoolean(linesKey);
+        }
         boolean large = Main.pref.getBoolean("draw.rawgps.large");
         for (Collection<GpsPoint> c : data) {
-            if (!force)
+            if (!force) {
                 old = null;
+            }
             for (GpsPoint p : c) {
                 Point screen = mv.getPoint(p.eastNorth);
-                if (lines && old != null)
+                if (lines && old != null) {
                     g.drawLine(old.x, old.y, screen.x, screen.y);
-                else if (!large)
+                } else if (!large) {
                     g.drawRect(screen.x, screen.y, 0, 0);
-                if (large)
+                }
+                if (large) {
                     g.fillRect(screen.x-1, screen.y-1, 3, 3);
+                }
                 old = screen;
             }
@@ -147,11 +151,13 @@
     @Override public String getToolTipText() {
         int points = 0;
-        for (Collection<GpsPoint> c : data)
+        for (Collection<GpsPoint> c : data) {
             points += c.size();
+        }
         String tool = data.size()+" "+trn("track", "tracks", data.size())
         +" "+points+" "+trn("point", "points", points);
         File f = getAssociatedFile();
-        if (f != null)
+        if (f != null) {
             tool = "<html>"+tool+"<br>"+f.getPath()+"</html>";
+        }
         return tool;
     }
@@ -167,7 +173,9 @@
 
     @Override public void visitBoundingBox(BoundingXYVisitor v) {
-        for (Collection<GpsPoint> c : data)
-            for (GpsPoint p : c)
+        for (Collection<GpsPoint> c : data) {
+            for (GpsPoint p : c) {
                 v.visit(p.eastNorth);
+            }
+        }
     }
 
@@ -198,15 +206,17 @@
                 }
                 String propName = "draw.rawgps.lines.layer "+name;
-                if (Main.pref.hasKey(propName))
+                if (Main.pref.hasKey(propName)) {
                     group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true);
-                else
+                } else {
                     group.setSelected(r[0].getModel(), true);
+                }
                 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION);
                 if (answer == JOptionPane.CANCEL_OPTION)
                     return;
-                if (group.getSelection() == r[0].getModel())
+                if (group.getSelection() == r[0].getModel()) {
                     Main.pref.put(propName, null);
-                else
+                } else {
                     Main.pref.put(propName, group.getSelection() == r[1].getModel());
+                }
                 Main.map.repaint();
             }
@@ -219,5 +229,5 @@
                 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
                 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
-                JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
+                        JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
                 switch (answer) {
                 case 0:
@@ -250,5 +260,5 @@
                 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
                 new JSeparator(),
-                new JMenuItem(new GpxExportAction(this)),
+                new JMenuItem(new LayerGpxExportAction(this)),
                 color,
                 line,
@@ -261,6 +271,7 @@
 
     public void preferenceChanged(String key, String newValue) {
-        if (Main.map != null && (key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force")))
+        if (Main.map != null && (key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force"))) {
             Main.map.repaint();
+        }
     }
 
