Index: applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java
===================================================================
--- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java	(revision 21468)
+++ applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java	(revision 21468)
@@ -0,0 +1,88 @@
+package org.openstreetmap.josm.plugins.videomapping;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+
+//for GPS play control secure stepping througt list
+public class GpsPlayer {
+	private List<WayPoint> ls;
+	private WayPoint prev,curr,next;
+	
+
+	public WayPoint getPrev() {
+		return prev;
+	}
+
+	public WayPoint getCurr() {
+		return curr;
+	}
+
+	public WayPoint getNext() {
+		return next;
+	}
+
+	public GpsPlayer(List<WayPoint> l) {
+		super();
+		this.ls = l;
+		prev=null;
+		curr=ls.get(0);
+		next=ls.get(1);
+	}
+	
+	public void next() {		
+		if(ls.indexOf(curr)+1<ls.size())
+		{
+			prev=curr;
+			curr=next;
+			if(ls.indexOf(curr)+1==ls.size()) next=null;
+			else next=ls.get(ls.indexOf(curr)+1);
+		}
+		else next=null;
+		
+	}
+	
+	public void prev()
+	{
+		if(ls.indexOf(curr)>0)
+		{			
+			next =curr;
+			curr=prev;
+			prev=ls.get(ls.indexOf(curr)-1);;
+		}
+		else prev=null;		
+	}
+	
+	public void jump(WayPoint p)
+	{
+		if(ls.contains(p))
+		{
+			curr=p;
+			if(ls.indexOf(curr)>0)
+			{
+				prev=ls.get(ls.indexOf(curr)-1);
+			}
+			else prev=null;
+			if(ls.indexOf(curr)<ls.size())
+			{
+				next=ls.get(ls.indexOf(curr)+1);
+			}
+			else next=null;
+			
+		}
+	}
+	
+	public void jump(int t)
+	{
+		if ((ls.indexOf(curr)+t>0)&&(ls.indexOf(curr)<ls.size()))
+		{
+			jump(ls.get(ls.indexOf(curr)+t));
+		}		
+	}
+	
+
+}
Index: applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
===================================================================
--- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java	(revision 21350)
+++ applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java	(revision 21468)
@@ -6,4 +6,5 @@
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -11,4 +12,5 @@
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
@@ -20,4 +22,5 @@
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
 
 import javax.swing.*;
@@ -38,41 +41,47 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 
-public class PositionLayer extends Layer implements MouseListener, KeyListener {
+public class PositionLayer extends Layer implements MouseListener,MouseMotionListener, KeyListener {
 	private List<WayPoint> ls;
+	private GpsPlayer l;
 	private Collection<WayPoint> selected;
-	private WayPoint sel;
-	private Iterator<WayPoint> it;
+	private TimerTask ani;
+	private boolean dragIcon=false; //do we move the icon by hand?
+	private Point mouse;
+	private ImageIcon icon;
 		
 	public PositionLayer(String name, final List<WayPoint> ls) {
-		super(name);		
-		this.ls = ls;
+		super(name);
+		this.ls=ls;
+		l= new GpsPlayer(ls);
+		selected = new ArrayList<WayPoint>();
+		icon=ImageProvider.get("videomapping.png");
 		Action a = new AbstractAction() {
 			public void actionPerformed(ActionEvent e) {
 				// TODO Auto-generated method stub
 				System.err.println("!!!boom!!!");
-			}};
-		selected = new ArrayList<WayPoint>();
+			}};		
 		Main.map.mapView.addMouseListener(this);
+		Main.map.mapView.addMouseMotionListener(this);
 		
 		//Main.panel.addKeyListener(this);
-		//Main.map.mapView.addKeyListener(this);
-		Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed");
-		Main.contentPane.getActionMap().put("pressed",a);
+		Main.map.mapView.addKeyListener(this);
+		//Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed");
+		//Main.contentPane.getActionMap().put("pressed",a);
 
 		//Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,0),a);
 		//Main.contentPane.getActionMap().put("doSomething",a);
 						
-		it=ls.iterator();
-		Timer t  = new Timer();		
-		t.schedule(new TimerTask() {
+		TimerTask ani=new TimerTask() {
 			
 			@Override
-			public void run() {
-				// TODO Auto-generated method stub
-				sel=it.next();
-				System.out.println(sel.getTime());
+			//some cheap animation stuff
+			public void run() {				
+				l.next();
 				Main.map.mapView.repaint();
 			}
-		},100,100);
+		};
+		Timer t= new Timer();
+		//t.schedule(ani,2000,2000);
+		l.next();l.next();
 		
 	}
@@ -80,5 +89,5 @@
 	@Override
 	public Icon getIcon() {
-		return ImageProvider.get("videomapping.png");
+		return icon;
 	}
 
@@ -97,6 +106,5 @@
                 //TODO here my stuff
                 new JSeparator(),
-                new JMenuItem(new LayerListPopup.InfoAction(this))
-         };
+                new JMenuItem(new LayerListPopup.InfoAction(this))};//TODO here infos about the linked videos
 	}
 	  
@@ -108,5 +116,5 @@
 	}
 
-	// no merging nescesarry
+	// no merging necessary
 	@Override
 	public boolean isMergable(Layer arg0) {
@@ -125,44 +133,58 @@
 	public void paint(Graphics2D g, MapView map, Bounds bound) {
 		Point p;
-		g.setColor(Color.green);
+		//TODO Source out redundant calculations
+		//TODO make icon transparent
+		//draw all GPS points
+		g.setColor(Color.GREEN);
 		for(WayPoint n: ls) {
 			p = Main.map.mapView.getPoint(n.getEastNorth());
-			g.drawOval(p.x - 2, p.y - 2, 4, 4); // small circles
-			}
-		g.setColor(Color.red);
+			g.drawOval(p.x - 2, p.y - 2, 4, 4);
+			}
+		g.setColor(Color.RED);
+		//draw selected GPS points
 		for(WayPoint n:selected)
 		{
 			p = Main.map.mapView.getPoint(n.getEastNorth());
-			g.drawOval(p.x - 2, p.y - 2, 4, 4); // small circles
-		}
-		if (sel!=null){
-			p=Main.map.mapView.getPoint(sel.getEastNorth());
-			//TODO Source out redundant calculations
-			//TODO make icon transparent
-			ImageProvider.get("videomapping.png").paintIcon(null, g, p.x-ImageProvider.get("videomapping.png").getIconWidth()/2, p.y-ImageProvider.get("videomapping.png").getIconHeight()/2);					
-		};
-	}
-
-	@Override
-	public void visitBoundingBox(BoundingXYVisitor arg0) {
-		// TODO dunno what to do here
-
-	}
-
-	//jump to the right position in video
-	public void mouseClicked(MouseEvent e) {		
-		//only on leftclicks of our layer
-		if(e.getButton() == MouseEvent.BUTTON1) {
-			//JOptionPane.showMessageDialog(Main.parent,"test");
-			getNearestNode(e.getPoint());
-			Main.map.mapView.repaint();
-		}
-		
-	}
-
-	//finds the corresponding timecode in GPXtrack by given screen coordinates
-	private void getNearestNode(Point mouse) {
-		Point p;
-		Rectangle rect = new Rectangle(mouse, new Dimension(30, 30));		
+			g.drawOval(p.x - 2, p.y - 2, 4, 4);
+		}
+		//draw surrounding points
+		g.setColor(Color.YELLOW);
+		if(l.getPrev()!=null)
+		{
+			p = Main.map.mapView.getPoint(l.getPrev().getEastNorth());
+			g.drawOval(p.x - 2, p.y - 2, 4, 4);
+			Point p2 = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
+			g.drawLine(p.x, p.y, p2.x, p2.y);
+		}
+		if(l.getNext()!=null)
+		{
+			p = Main.map.mapView.getPoint(l.getNext().getEastNorth());
+			g.drawOval(p.x - 2, p.y - 2, 4, 4);
+			Point p2 = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
+			g.drawLine(p.x, p.y, p2.x, p2.y);
+		}
+		//draw cam icon
+		if(dragIcon)
+		{
+			if(mouse!=null)
+			{
+				p=mouse;
+				icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2);
+			}
+		}
+		else
+		{
+			if (l.getCurr()!=null){
+			p=Main.map.mapView.getPoint(l.getCurr().getEastNorth());
+			icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2);
+			g.drawString(l.getCurr().getTime().toString(), p.x, p.y);
+			}
+		}
+	}
+
+	private void markNearestNode(Point mouse) {
+		final int MAX=10; 
+		Point p;		
+		Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,mouse.x+MAX/2,mouse.y+MAX/2);
 		//iterate through all possible notes
 		for(WayPoint n : ls)
@@ -172,54 +194,151 @@
 			{				
 				selected.add(n);
-				sel=n;
 			}
 			
 		}	
 	}
-
-	public void mouseEntered(MouseEvent arg0) {
-		// TODO Auto-generated method stub
-		
+	
+	private WayPoint getNearestPoint(Point mouse)
+	{
+		final int MAX=10;
+		Point p;
+		Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,mouse.x+MAX/2,mouse.y+MAX/2);
+		//iterate through all possible notes
+		for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP?
+		{
+			p = Main.map.mapView.getPoint(n.getEastNorth());
+			if (rect.contains(p))
+			{				
+				return n;
+			}
+			
+		}
+		return null;
+		
+	}
+	
+	@Override
+	public void visitBoundingBox(BoundingXYVisitor arg0) {
+		// TODO dunno what to do here
+
+	}
+
+	//mark selected points
+	public void mouseClicked(MouseEvent e) {		
+	}
+
+	public void mouseEntered(MouseEvent arg0) {	
 	}
 
 	public void mouseExited(MouseEvent arg0) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	public void mousePressed(MouseEvent arg0) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	public void mouseReleased(MouseEvent arg0) {
-		// TODO Auto-generated method stub
+	}
+
+	public void mousePressed(MouseEvent e) {
+		if(e.getButton() == MouseEvent.BUTTON1) {
+			//is it on the cam icon?
+			if (l.getCurr()!=null)
+			{
+				if (getIconRect().contains(e.getPoint()))
+				{
+					mouse=e.getPoint();
+					dragIcon=true;
+					//ani.cancel();
+				}
+			}
+		}
+		
+	}
+
+	public void mouseReleased(MouseEvent e) {
+		
+		//only on leftclicks of our layer
+		if(e.getButton() == MouseEvent.BUTTON1) {
+			if(dragIcon)
+			{
+				dragIcon=false;
+			}
+			else
+			{
+				//JOptionPane.showMessageDialog(Main.parent,"test");
+				markNearestNode(e.getPoint());
+				WayPoint wp = getNearestPoint(e.getPoint());
+				if(wp!=null)
+				{
+					l.jump(wp);			
+				}
+			}
+			Main.map.mapView.repaint();
+		}
+		
+	}
+	
+	//gets point on the line between
+	private Point getInterpolated(Point m)
+	{		
+		Point highest = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
+		Point smallest = Main.map.mapView.getPoint(l.getNext().getEastNorth());
+		float slope=(float)(highest.y-smallest.y) / (float)(highest.x - smallest.x);
+		
+		m.y = highest.y+Math.round(slope*(m.x-highest.x));
+		if(m.x<smallest.x)
+		{
+			m=smallest;
+		}
+		if(m.x>highest.x) m=highest;
+		System.out.println((m));
+		return m;
+	}
+	
+	public void mouseDragged(MouseEvent e) {		
+		if(dragIcon)
+		{			
+			mouse=e.getPoint();
+			//restrict to GPS track
+			mouse=getInterpolated(mouse);
+
+			Main.map.mapView.repaint();
+		}
+	}
+
+	private Rectangle getIconRect()
+	{
+		Point p = Main.map.mapView.getPoint(l.getCurr().getEastNorth());
+		return new Rectangle(p.x-icon.getIconWidth()/2,p.y-icon.getIconHeight()/2,icon.getIconWidth(),icon.getIconHeight());
+	}
+	
+	public void mouseMoved(MouseEvent e) {		
+		
+		if (l.getCurr()!=null)
+		{						
+			if (getIconRect().contains(e.getPoint()))
+			{
+				Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+			}
+			else
+			{
+				Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+			}
+		}
 		
 	}
 
 	public void keyPressed(KeyEvent e) {
+		int i;
 		System.out.println(e.getKeyCode());
 		switch(e.getKeyCode())
 		{
+			case KeyEvent.VK_RIGHT:
+				{
+					l.jump(10);
+				};break;
 			case KeyEvent.VK_LEFT:
-				{
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-					it.next();
-				}
+			{
+				l.jump(-10);
+
+			};break;
+			case KeyEvent.VK_SPACE:
+			{
+				ani.cancel();
+			}
 		}
 		
