Index: /applications/editors/josm/plugins/build.xml
===================================================================
--- /applications/editors/josm/plugins/build.xml	(revision 14220)
+++ /applications/editors/josm/plugins/build.xml	(revision 14221)
@@ -11,4 +11,5 @@
         <ant antfile="build.xml" target="dist" dir="colorscheme"/>
         <ant antfile="build.xml" target="dist" dir="DirectUpload"/>
+        <ant antfile="build.xml" target="dist" dir="editgpx"/>
         <ant antfile="build.xml" target="dist" dir="globalsat"/>
         <ant antfile="build.xml" target="dist" dir="imagewaypoint"/>
@@ -44,4 +45,5 @@
         <ant antfile="build.xml" target="clean" dir="DirectUpload"/>
         <ant antfile="build.xml" target="clean" dir="duplicateway"/>
+        <ant antfile="build.xml" target="clean" dir="editgpx"/>
         <ant antfile="build.xml" target="clean" dir="globalsat"/>
         <ant antfile="build.xml" target="clean" dir="grid"/>
Index: /applications/editors/josm/plugins/editgpx/.classpath
===================================================================
--- /applications/editors/josm/plugins/editgpx/.classpath	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/.classpath	(revision 14221)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="src-common"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
Index: /applications/editors/josm/plugins/editgpx/.project
===================================================================
--- /applications/editors/josm/plugins/editgpx/.project	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/.project	(revision 14221)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>editgpx</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+	<linkedResources>
+		<link>
+			<name>src-common</name>
+			<type>2</type>
+			<location>/Users/leo/dev/josm/core/src</location>
+		</link>
+	</linkedResources>
+</projectDescription>
Index: /applications/editors/josm/plugins/editgpx/build.xml
===================================================================
--- /applications/editors/josm/plugins/editgpx/build.xml	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/build.xml	(revision 14221)
@@ -0,0 +1,55 @@
+<project name="editgpx" default="dist" basedir=".">
+    <property name="josm"                   location="../../core/dist/josm-custom.jar"/>
+    <property name="plugin.dist.dir"        value="../../dist"/>
+    <property name="plugin.build.dir"       value="build"/>
+    <property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
+    <property name="ant.build.javac.target" value="1.5"/>
+    <target name="init">
+        <mkdir dir="${plugin.build.dir}"/>
+    </target>
+    <target name="compile" depends="init">
+        <echo message="creating ${plugin.jar}"/>
+        <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}">
+            <compilerarg value="-Xlint:deprecation"/>
+            <compilerarg value="-Xlint:unchecked"/>
+        </javac>
+    </target>
+    <target name="dist" depends="compile,revision">
+        <copy todir="${plugin.build.dir}/images">
+            <fileset dir="images"/>
+        </copy>
+        <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
+            <manifest>
+                <attribute name="Plugin-Author" value="Martin Garbe" />
+                <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.editgpx.EditGpxPlugin" />
+                <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
+                <attribute name="Plugin-Description" value="Provides an editable GPX track layer. Only deletion of points is supported. This plugin can be used to prepare tracks for upload to OSM eg. deleting uninteresting parts of track." />
+                <attribute name="Plugin-Mainversion" value="1000" />
+                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
+            </manifest>
+        </jar>
+    </target>
+    <target name="revision">
+        <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false">
+            <env key="LANG" value="C"/>
+            <arg value="info"/>
+            <arg value="--xml"/>
+            <arg value="."/>
+        </exec>
+        <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/>
+        <delete file="REVISION"/>
+    </target>
+    <target name="clean">
+        <delete dir="${plugin.build.dir}"/>
+        <delete file="${plugin.jar}"/>
+    </target>
+    <target name="install" depends="dist">
+        <property environment="env"/>
+        <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
+            <and>
+                <os family="windows"/>
+            </and>
+        </condition>
+        <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
+    </target>
+</project>
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java	(revision 14221)
@@ -0,0 +1,228 @@
+/**
+ * License: GPL. Copyright 2008. Martin Garbe (leo at running-sheep dot com)
+ */
+package org.openstreetmap.josm.plugins.editgpx;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JSeparator;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.gpx.GpxTrack;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
+import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.tools.ImageProvider;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+
+public class EditGpxLayer extends Layer {
+
+	private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png")));
+	private DataSet dataSet;
+	private GPXLayerImportAction layerImport;
+	
+	public EditGpxLayer(String str, DataSet ds) {
+		super(str);
+		dataSet = ds;
+		layerImport = new GPXLayerImportAction(dataSet);
+	}
+	
+	/**
+	 * check if dataSet is empty
+	 * if so show import dialog to user
+	 */
+	public void initializeImport() {
+		try { 
+			if(dataSet.nodes.isEmpty() ) {
+				layerImport.activateImport();
+			}
+		} catch (Exception e) {
+			System.out.println(e.getMessage());
+			e.printStackTrace();
+		}
+	}
+	
+
+	@Override
+	public Icon getIcon() {
+		return icon;
+	}
+
+
+	@Override
+	public Object getInfoComponent() {
+		return getToolTipText();
+	}
+
+
+	@Override
+	public Component[] getMenuEntries() {
+		return new Component[] {
+			new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
+			new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
+			new JSeparator(),
+			new JMenuItem(layerImport),
+			new JMenuItem(new ConvertToGpxLayerAction()),
+			new JMenuItem(new ConvertToAnonTimeGpxLayerAction()),
+			new JSeparator(),
+			new JMenuItem(new LayerListPopup.InfoAction(this))};
+	}
+
+
+	@Override
+	public String getToolTipText() {
+		return tr("Layer for editing GPX tracks");
+	}
+
+
+	@Override
+	public boolean isMergable(Layer other) {
+		// TODO 
+		return false;
+	}
+
+
+	@Override
+	public void mergeFrom(Layer from) {
+		// TODO 
+	}
+
+
+	@Override
+	public void paint(Graphics g, MapView mv) {
+		g.setColor(Color.yellow);
+
+		//don't iterate through dataSet whiling making changes
+		synchronized(layerImport.importing) {
+			for(Node n: dataSet.nodes) {
+				if (!n.deleted) {
+		            LatLon c = n.coor;
+		            Point pnt = Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(c));
+		            g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4);
+	        	}
+	        }
+		}
+	}
+	
+
+    public void reset(){
+        //TODO implement a reset
+    }
+	
+
+	@Override
+	public void visitBoundingBox(BoundingXYVisitor v) {
+		// TODO Auto-generated method stub
+	}
+	
+	
+	/**
+	 * convert a DataSet to GPX
+	 * 
+	 * @param boolean anonTime If true set all time and date in GPX to 01/01/1970 00:00 ?
+	 * @return GPXData
+	 */
+	private GpxData toGpxData(boolean anonTime) {
+        GpxData gpxData = new GpxData();
+        HashSet<Node> doneNodes = new HashSet<Node>();
+        //add all ways
+        for (Way w : dataSet.ways) {
+            if (w.incomplete || w.deleted) continue;
+            GpxTrack trk = new GpxTrack();
+            gpxData.tracks.add(trk);
+
+            if (w.get("name") != null)
+                trk.attr.put("name", w.get("name"));
+
+            ArrayList<WayPoint> trkseg = null;
+            for (Node n : w.nodes) {
+                if (n.incomplete || n.deleted) {
+                    trkseg = null;
+                    continue;
+                }
+                if (trkseg == null) {
+                    trkseg = new ArrayList<WayPoint>();
+                    trk.trackSegs.add(trkseg);
+                }
+                if (!n.isTagged()) {
+                    doneNodes.add(n);
+                }
+                WayPoint wpt = new WayPoint(n.coor);
+                if (!n.isTimestampEmpty())
+                {
+                    if (anonTime) {
+                    	wpt.attr.put("time", "1970-01-01T00:00:00");
+                    } else {
+                    	wpt.attr.put("time", n.getTimestamp());
+                    	System.out.println("timestamp: "+n.getTimestamp());
+                    }
+                    wpt.setTime();
+                }
+                trkseg.add(wpt);
+            }
+        }
+
+        // add nodes as waypoints
+        for (Node n : dataSet.nodes) {
+            if (n.incomplete || n.deleted || doneNodes.contains(n)) continue;
+            WayPoint wpt = new WayPoint(n.coor);
+            if (!n.isTimestampEmpty()) {
+            	if (anonTime) {
+            		wpt.attr.put("time", "1970-01-01T00:00:00");
+            	} else {
+            		wpt.attr.put("time", n.getTimestamp());
+            	}
+                wpt.setTime();
+            }
+            if (n.keys != null && n.keys.containsKey("name")) {
+                wpt.attr.put("name", n.keys.get("name"));
+            }
+            gpxData.waypoints.add(wpt);
+        }
+        return gpxData;
+    }
+	
+	//context item "Convert to GPX layer"
+	public class ConvertToGpxLayerAction extends AbstractAction {
+        public ConvertToGpxLayerAction() {
+            super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx"));
+        }
+        public void actionPerformed(ActionEvent e) {
+            Main.main.addLayer(new GpxLayer(toGpxData(false), tr("Converted from: {0}", name)));
+            Main.main.removeLayer(EditGpxLayer.this);
+        }
+    }
+
+	//context item "Convert to GPX layer with anonymised time"
+	public class ConvertToAnonTimeGpxLayerAction extends AbstractAction {
+        public ConvertToAnonTimeGpxLayerAction() {
+            super(tr("Convert to GPX layer with anonymised time"), ImageProvider.get("converttogpx"));
+        }
+        public void actionPerformed(ActionEvent e) {
+            Main.main.addLayer(new GpxLayer(toGpxData(true), tr("Converted from: {0}", name)));
+            Main.main.removeLayer(EditGpxLayer.this);
+        }
+    }
+}
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 14221)
@@ -0,0 +1,152 @@
+/**
+ * License: GPL. Copyright 2008. Martin Garbe (leo at running-sheep dot com)
+ */
+package org.openstreetmap.josm.plugins.editgpx;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.MouseEvent;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.gui.MapFrame;
+
+
+public class EditGpxMode extends MapMode {
+
+	private static final long serialVersionUID = 7940589057093872411L;
+	Point pointPressed;
+	DataSet dataSet;
+	MapFrame mapFrame;
+	Rectangle oldRect;
+	MapFrame frame;
+	
+	public EditGpxMode(MapFrame mapFrame, String name, String desc, DataSet ds) {
+		super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
+		dataSet = ds;
+	}
+	
+	@Override public void enterMode() {
+        super.enterMode();
+        Main.map.mapView.addMouseListener(this);
+        Main.map.mapView.addMouseMotionListener(this);
+    }
+
+    @Override public void exitMode() {
+        super.exitMode();
+        Main.map.mapView.removeMouseListener(this);
+        Main.map.mapView.removeMouseMotionListener(this);
+    }
+    
+    
+    @Override public void mousePressed(MouseEvent e) {
+    	pointPressed = new Point(e.getPoint());
+    }
+    
+    
+    @Override public void mouseDragged(MouseEvent e) {
+    	if ( (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) ==  MouseEvent.BUTTON1_DOWN_MASK) {
+    		//if button1 is hold, draw the rectangle.
+    		paintRect(pointPressed, e.getPoint());
+    	}
+    }
+    
+    
+    @Override public void mouseReleased(MouseEvent e) {
+        if (e.getButton() != MouseEvent.BUTTON1) {
+        	return;
+        } else {
+        	Point pointReleased = e.getPoint();
+        	
+        	//prepare vars
+            EastNorth en;
+    		double scale = Main.map.mapView.getScale();
+    	    EastNorth center = Main.map.mapView.getCenter(); //Center n/e coordinate of the desired screen center.
+    	    int width = Main.map.mapView.getWidth();
+    	    int height = Main.map.mapView.getHeight();
+    	    Rectangle r = createRect(pointReleased, pointPressed);
+    	    
+			//go through nodes and mark the ones in the selection rect as deleted
+    	    for (Node n: dataSet.nodes) {
+        		en = n.eastNorth;
+                //calculate point on screen from node n
+        		double x = (en.east()-center.east())/scale + width/2;
+                double y = (center.north()-en.north())/scale + height/2;
+                Point p = new Point((int)x,(int)y);
+                if (r.contains(p)) {
+                	n.deleted = true; //only set as deleted. this makes reset to beginning possible
+                }
+            }
+        	oldRect = null;
+        	Main.map.mapView.repaint();
+            
+        }
+    	
+    }
+
+    /**
+     * create rectangle out of two given corners
+     */
+    public Rectangle createRect(Point p1, Point p2) {
+    	int x,y,w,h;
+    	if (p1.x == p2.x && p1.y == p2.y) {
+    		//if p1 and p2 same points draw a small rectangle around them
+    		x = p1.x -1;
+    		y = p1.y -1;
+    		w = 3;
+    		h = 3;
+    	} else {
+	    	if (p1.x < p2.x){
+	    		x = p1.x;
+	    		w = p2.x-p1.x;
+	    	} else {
+	    		x = p2.x;
+	    		w = p1.x-p2.x;
+	    	}
+	    	if (p1.y < p2.y) {
+	    		y = p1.y;
+	    		h = p2.y-p1.y;
+	    	} else {
+	    		y = p2.y;
+	    		h = p1.y-p2.y;
+	    	}
+    	}
+    	return new Rectangle(x,y,w,h);
+    }
+  
+    
+    /**
+     * Draw a selection rectangle on screen.
+     */
+    private void paintRect(Point p1, Point p2) {
+    	Graphics g = frame.getGraphics();//Main.map.mapView.getGraphics();
+    	
+    	Rectangle r = oldRect;
+    	if (r != null) {
+    		//overwrite old rct
+        	g.setXORMode(Color.BLACK);
+    		g.setColor(Color.WHITE);
+	        g.drawRect(r.x,r.y,r.width,r.height);
+	    }
+	        
+        g.setXORMode(Color.BLACK);
+    	g.setColor(Color.WHITE);        
+        r = createRect(p1,p2);
+        g.drawRect(r.x,r.y,r.width,r.height);
+        oldRect = r;
+     
+    }
+    
+
+    public void setFrame(MapFrame mapFrame) {
+    	frame = mapFrame;
+    }
+    
+
+}
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 14221)
@@ -0,0 +1,121 @@
+/**
+ * License: GPL. Copyright 2008. Martin Garbe (leo at running-sheep dot com)
+ */
+package org.openstreetmap.josm.plugins.editgpx;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.gui.IconToggleButton;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
+import org.openstreetmap.josm.plugins.Plugin;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+/**
+ * Provides an editable GPX layer. Editable layer here means the deletion of points is supported. 
+ * This plugin can be used to prepare tracks for upload to OSM eg. delete uninteresting parts
+ * of the track. 
+ * Additionally while converting the track back to a normal GPX layer the time can be made 
+ * anonymous. This feature sets all time stamps to 1970-01-01 00:00. 
+ * 
+ * TODO:
+ * - TODO s durchschauen
+ * - write docu
+ * - upload beta of plugin
+ * - BUG: when importing eGpxLayer is shown as RawGpxLayer??
+ * - BUG: after deletion of layer not all data is deleted (eg dataset)
+ * - implement reset if user made mistake while marking
+ * 
+ * 
+ */
+public class EditGpxPlugin extends Plugin {
+
+	private IconToggleButton btn;
+	private EditGpxMode mode;
+	protected static EditGpxLayer eGpxLayer;
+	protected static DataSet dataSet;
+	public static boolean active = false;
+	
+	public EditGpxPlugin() {
+		dataSet = new DataSet();
+		mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"), dataSet);
+		
+        btn = new IconToggleButton(mode);
+        btn.setVisible(true);
+	}
+	
+	
+	/**
+	 * initialize button. if button is pressed create new layer.
+	 */
+	@Override
+    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
+		if(oldFrame == null && newFrame != null) {
+            mode.setFrame(newFrame);
+		
+	        if(Main.map != null)
+	            Main.map.addMapMode(btn);
+			
+	        active = btn.isSelected();
+	        
+	        btn.addActionListener(new ActionListener() {
+	        	public void actionPerformed(ActionEvent e) {
+	        		active = btn.isSelected();
+	        		if (active) {
+	        			Main.worker.execute(new Runnable() {
+	        				public void run() {
+	        					updateLayer();
+	        				}
+	        			});
+	        		}
+	        	}
+	        });
+        }
+    }
+	
+	/**
+	 * create new layer, add listeners and try importing gpx data.
+	 */
+	private void updateLayer() {
+        if(eGpxLayer == null) {
+        	eGpxLayer = new EditGpxLayer(tr("EditGpx"), dataSet);
+            Main.main.addLayer(eGpxLayer);
+            Layer.listeners.add(new LayerChangeListener(){
+            	
+                public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
+                    if(newLayer instanceof EditGpxLayer)
+                    	EditGpxPlugin.eGpxLayer = (EditGpxLayer)newLayer;
+                }
+                
+                public void layerAdded(final Layer newLayer) {
+                }
+                
+                public void layerRemoved(final Layer oldLayer) {
+                	if(oldLayer == eGpxLayer) {
+                        eGpxLayer = null;
+                        //dataSet = new DataSet();
+                        
+                    }
+                }
+            });
+            
+            eGpxLayer.initializeImport();
+        } 
+        Main.map.mapView.repaint();
+    }
+    
+    
+    public static ImageIcon loadIcon(String name) {
+        URL url = EditGpxPlugin.class.getResource("/images/editgpx.png");
+        return new ImageIcon(url);
+    }
+
+}
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java	(revision 14221)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java	(revision 14221)
@@ -0,0 +1,149 @@
+/**
+ * License: GPL. Copyright 2008. Martin Garbe (leo at running-sheep dot com)
+ *
+ * other source from mesurement plugin written by Raphael Mack
+ * 
+ */
+package org.openstreetmap.josm.plugins.editgpx;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.util.Collection;
+
+import javax.swing.AbstractAction;
+import javax.swing.Box;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.Icon;
+import javax.swing.JCheckBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.gpx.GpxTrack;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.tools.DateUtils;
+import org.openstreetmap.josm.tools.ImageProvider;
+
+/**
+ * Import GPX data from available layers
+ * 
+ *
+ */
+class GPXLayerImportAction extends AbstractAction {
+	
+	
+	private static final long serialVersionUID = 5794897888911798168L;
+	private DataSet dataSet;
+	public Object importing = new Object(); //used for synchronization
+	
+	public GPXLayerImportAction(DataSet ds) {
+		//TODO what is icon at the end?
+		super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit"));
+        this.dataSet = ds;
+	}
+	
+	/**
+	 * shows a list of GPX layers. if user selects one the data from this layer is
+	 * imported.
+	 */
+	public void activateImport() {
+		Box panel = Box.createVerticalBox();
+		DefaultListModel dModel= new DefaultListModel();
+
+		final JList layerList = new JList(dModel);
+        Collection<Layer> data = Main.map.mapView.getAllLayers();
+        Layer lastLayer = null;
+        int layerCnt = 0;
+
+        for (Layer l : data){
+                if(l instanceof GpxLayer){
+                    dModel.addElement(l);
+                    lastLayer = l;
+                    layerCnt++;
+                }
+        }
+        if(layerCnt == 1){
+                layerList.setSelectedValue(lastLayer, true);
+        }
+        if(layerCnt > 0){
+            layerList.setCellRenderer(new DefaultListCellRenderer(){
+                    @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+                        Layer layer = (Layer)value;
+                        JLabel label = (JLabel)super.getListCellRendererComponent(list,
+                                                                                  layer.name, index, isSelected, cellHasFocus);
+                        Icon icon = layer.getIcon();
+                        label.setIcon(icon);
+                        label.setToolTipText(layer.getToolTipText());
+                        return label;
+                    }
+                });
+
+            JCheckBox dropFirst = new JCheckBox(tr("Drop existing path"));
+
+            panel.add(layerList);
+            panel.add(dropFirst);
+
+            final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
+                    @Override public void selectInitialValue() {
+                        layerList.requestFocusInWindow();
+                    }
+                };
+            final JDialog dlg = optionPane.createDialog(Main.parent, tr("Import path from GPX layer"));
+            dlg.setVisible(true);
+
+            Object answer = optionPane.getValue();
+            if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE ||
+                (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) {
+                return;
+            }
+
+            GpxLayer gpx = (GpxLayer)layerList.getSelectedValue();
+
+            synchronized(importing) {
+	            for (GpxTrack trk : gpx.data.tracks) {
+	                for (Collection<WayPoint> segment : trk.trackSegs) {
+	                    Way w = new Way();
+	                    for (WayPoint p : segment) {
+	                        Node n = new Node(p.latlon);
+	                        String timestr = p.getString("time");
+	                        if(timestr != null)
+	                        {
+	                            timestr = timestr.replace("Z","+00:00");
+	                            n.setTimestamp(DateUtils.fromString(timestr));
+	                        }
+	                        dataSet.nodes.add(n);
+	                        w.nodes.add(n); //TODO what to do with these while deletion
+	                    }
+	                    dataSet.ways.add(w);
+	                }
+	            }
+            }
+            Main.map.mapView.repaint();
+
+        } else { 
+            // no gps layer
+            JOptionPane.showMessageDialog(Main.parent,tr("No GPX data layer found."));
+        }
+	
+	}
+
+	/**
+	 * called when pressing "Import.." from context menu of EditGpx layer
+	 * 
+	 */
+	public void actionPerformed(ActionEvent arg0) {
+		activateImport();
+	}
+		
+
+}
