Index: applications/editors/josm/plugins/measurement/build.xml
===================================================================
--- applications/editors/josm/plugins/measurement/build.xml	(revision 10379)
+++ applications/editors/josm/plugins/measurement/build.xml	(revision 10379)
@@ -0,0 +1,42 @@
+<project name="measurement" default="build" basedir=".">
+
+	<!-- point to your JOSM directory -->
+	<property name="josm" location="../../../core/dist/josm-custom.jar" />
+
+
+	<target name="init">
+		<mkdir dir="build"></mkdir>
+		<mkdir dir="dist"></mkdir>
+	</target>
+
+	<target name="compile" depends="init">
+		<javac srcdir="src" classpath="${josm}" debug="true" destdir="build" target="1.5">
+			<include name="**/*.java" />
+		</javac>
+	</target>
+
+	<target name="build" depends="compile">
+		<copy todir="build/images" >
+			<fileset dir="images" />
+		</copy>
+		<jar destfile="dist/measurement.jar" basedir="build">
+			<manifest>
+				<attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.measurement.MeasurementPlugin" />
+				<attribute name="Plugin-Description" value="Provide a measurement dialog and a layer to measure length and angle of segments (there are no segments anymore, I know. Any idea how the angle should be measures now?) and create measurement paths (which also can be imported from a gps layer)" />
+				<attribute name="Plugin-Author" value="mail@raphael-mack.de" />
+				<attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
+				<attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
+			</manifest>
+		</jar>
+	</target>
+
+	<target name="clean">
+		<delete dir="build" />
+		<delete dir="dist" />
+	</target>
+
+	<target name="install" depends="build">
+		<copy file="dist/measurement.jar" todir="${user.home}/.josm/plugins"/>
+	</target>
+	
+</project>
Index: applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java
===================================================================
--- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java	(revision 10379)
+++ applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java	(revision 10379)
@@ -0,0 +1,169 @@
+package org.openstreetmap.josm.plugins.measurement;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.text.DecimalFormat;
+import java.util.Collection;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.openstreetmap.josm.data.SelectionChangedListener;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.Main;
+
+/**
+ * A small tool dialog for displaying the current measurement data.
+ *
+ * @author ramack
+ */
+public class MeasurementDialog extends ToggleDialog implements ActionListener
+{
+	private static final long serialVersionUID = 4708541586297950021L;
+
+	/** 
+     * The reset button
+     */
+    private JButton resetButton;
+    
+    /**
+     * The measurement label for the path length
+     */
+    protected JLabel pathLengthLabel;
+    
+    /**
+     * The measurement label for the currently selected segments
+     */
+    protected JLabel selectLengthLabel;
+    
+    /**
+     * The measurement label for area of the currently selected loop
+     */
+    protected JLabel selectAreaLabel;
+    
+    /**
+     * The measurement label for the segment angle, actually updated, if 2 nodes are selected
+     */
+    protected JLabel segAngleLabel;
+    
+    /**
+     * Constructor
+     */
+    public MeasurementDialog() 
+    {
+        super(tr("Measured values"), "measure", tr("Open the measurement window."), KeyEvent.VK_M, KeyEvent.ALT_DOWN_MASK);
+        
+        JPanel buttonPanel = new JPanel(new GridLayout(1,2));
+        
+		resetButton = new JButton(tr("Reset"), ImageProvider.get("mapmode/selection/select"));
+		resetButton.setActionCommand("Reset");
+		resetButton.addActionListener(this);
+		resetButton.setToolTipText(tr("Reset current measurement results and delete measurement path."));
+//		resetButton.putClientProperty("help", "Dialog/SelectionList/Reset");
+		
+        buttonPanel.add(resetButton);
+        add(buttonPanel, BorderLayout.SOUTH);
+
+        JPanel valuePanel = new JPanel(new GridLayout(0,2));
+        
+        valuePanel.add(new JLabel("Path Length"));
+        
+        pathLengthLabel = new JLabel("0 m");
+        valuePanel.add(pathLengthLabel);
+        
+        valuePanel.add(new JLabel("Selection Length"));
+        
+        selectLengthLabel = new JLabel("0 m");
+        valuePanel.add(selectLengthLabel);
+
+        valuePanel.add(new JLabel("Selection Area"));
+        
+        selectAreaLabel = new JLabel("0 m²");
+        valuePanel.add(selectAreaLabel);
+        
+        JLabel angle = new JLabel("Angle");
+        angle.setToolTipText(tr("Angle between two selected Nodes"));
+        valuePanel.add(angle);
+        
+        segAngleLabel = new JLabel("- °");
+        valuePanel.add(segAngleLabel);
+        
+        add(valuePanel, BorderLayout.CENTER);
+
+        this.setPreferredSize(new Dimension(0, 92));
+        final MeasurementDialog dlg = this;
+       //TODO: is this enough? 
+
+        Main.ds.selListeners.add(new SelectionChangedListener(){
+
+			public void selectionChanged(Collection<? extends OsmPrimitive> arg0) {
+				double length = 0.0;
+				double segAngle = 0.0;
+                                double area = 0.0;
+                                Node lastNode = null;
+				for(OsmPrimitive p:arg0){
+                                    if(p instanceof Node){
+                                        Node n =(Node)p;
+                                        if(lastNode == null){
+                                            lastNode = n;
+                                        }else{
+                                            length += MeasurementLayer.calcDistance(lastNode.coor, n.coor);
+                                            segAngle = MeasurementLayer.angleBetween(lastNode.coor, n.coor);
+                                            lastNode = n;
+                                        }
+                                    } else if(p instanceof Way){
+                                        Way w = (Way)p;
+                                        Node lastN = null;
+                                        for(Node n: w.nodes){
+                                            if(lastN != null){
+                                                length += MeasurementLayer.calcDistance(lastN.coor, n.coor);
+                                                //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
+                                                area += (MeasurementLayer.calcX(n.coor) * MeasurementLayer.calcY(lastN.coor))
+						      - (MeasurementLayer.calcY(n.coor) * MeasurementLayer.calcX(lastN.coor));
+                                            }
+                                            lastN = n;
+                                        }
+                                        if (lastN != null && lastN == w.nodes.iterator().next()){
+                                            area = Math.abs(area / 2);
+                                        }else{
+                                            area = 0;
+                                        }
+                                    }
+				}
+				dlg.selectLengthLabel.setText(new DecimalFormat("#0.00").format(length) + " m");
+
+				dlg.segAngleLabel.setText(new DecimalFormat("#0.0").format(segAngle) + " °");		
+ 				dlg.selectAreaLabel.setText(new DecimalFormat("#0.00").format(area) + " m²");
+
+			}
+        	
+        });
+    }
+
+	public void actionPerformed(ActionEvent e) 
+	{
+		String actionCommand = e.getActionCommand();
+		if( actionCommand.equals("Reset")){
+			resetValues();
+		}
+	}
+    
+	/**
+	 * Cleans the active Meausurement Layer
+	 */
+	public void resetValues(){
+		MeasurementPlugin.getCurrentLayer().reset();
+	}
+	
+}
Index: applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java
===================================================================
--- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java	(revision 10379)
+++ applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java	(revision 10379)
@@ -0,0 +1,346 @@
+package org.openstreetmap.josm.plugins.measurement;
+/// @author Raphael Mack <ramack@raphael-mack.de> 
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+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.awt.event.MouseEvent;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.swing.Box;
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JCheckBox;
+import javax.swing.JSeparator;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.UIManager;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.gpx.GpxTrack;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
+import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+
+
+/**
+ * This is a layer that draws a grid
+ */
+public class MeasurementLayer extends Layer {
+	
+    public MeasurementLayer(String arg0) {
+        super(arg0);
+    }
+
+    private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(MeasurementPlugin.class.getResource("/images/measurement.png")));	
+    private Collection<WayPoint> points = new ArrayList<WayPoint>(32);
+	
+    @Override public Icon getIcon() {
+        return icon;
+    }
+	
+    @Override public String getToolTipText() {
+        return tr("MeasurementLayer layer");
+    }
+
+    @Override public boolean isMergable(Layer other) {
+        //return other instanceof MeasurementLayer;
+        return false;
+    }
+
+    @Override public void mergeFrom(Layer from) {
+        // TODO: nyi - doubts about how this should be done are around. Ideas?
+	
+    }
+
+    @Override public void paint(Graphics g, final MapView mv) {
+        g.setColor(Color.green);
+        Point l = null;
+        for(WayPoint p:points){
+            LatLon c = p.latlon;
+            Point pnt = Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(c));
+            if (l != null){
+                g.drawLine(l.x, l.y, pnt.x, pnt.y);
+            }
+            g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4);
+            l = pnt;
+        }
+    }
+
+    @Override public void visitBoundingBox(BoundingXYVisitor v) {
+        // nothing to do here
+    }
+
+    @Override public Object getInfoComponent() {
+        return getToolTipText();
+    }
+
+    @Override public Component[] getMenuEntries() {
+        return new Component[]{
+            new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
+            // TODO: implement new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
+            new JSeparator(),
+            new JMenuItem(new GPXLayerImportAction(this)),
+            new JSeparator(),
+            new JMenuItem(new LayerListPopup.InfoAction(this))};
+    }
+	
+    public void removeLastPoint(){
+        WayPoint l = null;
+        for(WayPoint p:points) l = p;
+        if(l != null) points.remove(l);
+        recalculate();
+        Main.map.repaint();	
+    }
+	
+    public void mouseClicked(MouseEvent e){		
+        if (e.getButton() != MouseEvent.BUTTON1) return;
+
+        LatLon coor = Main.map.mapView.getLatLon(e.getX(), e.getY());		
+        points.add(new WayPoint(coor));
+
+        Main.map.repaint();
+        recalculate();
+    }
+
+    public void reset(){
+        points.clear();
+        recalculate();
+        Main.map.repaint();		
+    }
+	
+    private void recalculate(){
+        double pathLength = 0.0, segLength = 0.0; // in meters
+        WayPoint last = null;
+		
+        pathLength = 0.0;
+        for(WayPoint p : points){
+            if(last != null){
+                segLength = calcDistance(last, p);
+                pathLength += segLength;
+            }
+            last = p;
+        }
+        DecimalFormat nf = new DecimalFormat("#0.00");
+        DecimalFormat nf2 = new DecimalFormat("#0.0");
+        MeasurementPlugin.measurementDialog.pathLengthLabel.setText(pathLength < 800?nf2.format(pathLength) + " m":nf.format(pathLength/1000) + " km");
+    }
+	
+    public static double calcDistance(LatLon p1, LatLon p2){
+        double lat1, lon1, lat2, lon2;
+        double dlon, dlat;
+	    
+        lat1 = p1.lat() * Math.PI / 180.0;
+        lon1 = p1.lon() * Math.PI / 180.0;
+        lat2 = p2.lat() * Math.PI / 180.0;
+        lon2 = p2.lon() * Math.PI / 180.0;
+
+        dlon = lon2 - lon1;
+        dlat = lat2 - lat1;
+
+        double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+        return 6367000 * c;
+    }
+
+    public static double calcX(LatLon p1){
+        double lat1, lon1, lat2, lon2;
+        double dlon, dlat;
+	    
+        lat1 = p1.lat() * Math.PI / 180.0;
+        lon1 = p1.lon() * Math.PI / 180.0;
+        lat2 = lat1;
+        lon2 = 0;
+
+        dlon = lon2 - lon1;
+        dlat = lat2 - lat1;
+
+        double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+        return 6367000 * c;
+    }
+	
+    public static double calcY(LatLon p1){
+        double lat1, lon1, lat2, lon2;
+        double dlon, dlat;
+	    
+        lat1 = p1.lat() * Math.PI / 180.0;
+        lon1 = p1.lon() * Math.PI / 180.0;
+        lat2 = 0;
+        lon2 = lon1;
+
+        dlon = lon2 - lon1;
+        dlat = lat2 - lat1;
+
+        double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+        return 6367000 * c;
+    }
+	
+    public static double calcDistance(WayPoint p1, WayPoint p2){
+        return calcDistance(p1.latlon, p2.latlon);
+    }
+	
+    public static double angleBetween(WayPoint p1, WayPoint p2){
+        return angleBetween(p1.latlon, p2.latlon);
+    }
+	
+    public static double angleBetween(LatLon p1, LatLon p2){
+        double lat1, lon1, lat2, lon2;
+        double dlon;
+        double heading;
+	    
+        lat1 = p1.lat() * Math.PI / 180.0;
+        lon1 = p1.lon() * Math.PI / 180.0;
+        lat2 = p2.lat() * Math.PI / 180.0;
+        lon2 = p2.lon() * Math.PI / 180.0;
+
+        dlon = lon2 - lon1;
+        double coslat2 = Math.cos(lat2);
+        
+        return (180 * Math.atan2(coslat2 * Math.sin(dlon),
+                          (Math.cos(lat1) * Math.sin(lat2)
+                                    - 
+                           Math.sin(lat1) * coslat2 * Math.cos(dlon)))) / Math.PI;
+    }
+
+    public static double OldangleBetween(LatLon p1, LatLon p2){
+        double lat1, lon1, lat2, lon2;
+        double dlon, dlat;
+        double heading;
+	    
+        lat1 = p1.lat() * Math.PI / 180.0;
+        lon1 = p1.lon() * Math.PI / 180.0;
+        lat2 = p2.lat() * Math.PI / 180.0;
+        lon2 = p2.lon() * Math.PI / 180.0;
+
+        dlon = lon2 - lon1;
+        dlat = lat2 - lat1;
+
+        double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));
+        double d = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+        heading = Math.acos((Math.sin(lat2) - Math.sin(lat1) * Math.cos(d))
+                            / (Math.sin(d) * Math.cos(lat1)));
+        if (Math.sin(lon2 - lon1) < 0) {
+            heading = 2 * Math.PI - heading;
+        }
+ 
+        return heading * 180 / Math.PI;
+    }
+
+
+    private class GPXLayerImportAction extends AbstractAction {
+
+	private MeasurementLayer layer;
+
+	/**
+	 * The data model for the list component.
+	 */
+	private DefaultListModel model = new DefaultListModel();
+
+	/**
+	 * @param layer the targeting measurement layer
+	 */
+	public GPXLayerImportAction(MeasurementLayer layer) {
+	    super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit")); // TODO: find better image
+	    this.layer = layer;
+	}
+
+	public void actionPerformed(ActionEvent e) {
+	    Box panel = Box.createVerticalBox();
+	    final JList layerList = new JList(model);
+	    Collection<Layer> data = Main.map.mapView.getAllLayers();
+	    Layer lastLayer = null;
+	    int layerCnt = 0;
+	    
+	    for (Layer l : data){
+                if(l instanceof GpxLayer){    
+                    model.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();
+                if(dropFirst.isSelected()){
+                    points = new ArrayList<WayPoint>(32);
+                }
+	    
+                for (GpxTrack trk : gpx.data.tracks) {
+                    for (Collection<WayPoint> trkseg : trk.trackSegs) {
+                        for(WayPoint p: trkseg){
+                            points.add(p);
+                        }
+                    }
+	    	}
+                recalculate();
+                Main.parent.repaint();
+            }else{
+                // TODO: register a listener and show menu entry only if gps layers are available
+                // no gps layer
+                JOptionPane.showMessageDialog(Main.parent,tr("No GPX data layer found."));
+            }
+        }
+    }
+
+}
Index: applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java
===================================================================
--- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java	(revision 10379)
+++ applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java	(revision 10379)
@@ -0,0 +1,57 @@
+package org.openstreetmap.josm.plugins.measurement;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Cursor;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.MapFrame;
+
+public class MeasurementMode extends MapMode {
+
+	private static final long serialVersionUID = 3853830673475744263L;
+	
+	public MeasurementMode(MapFrame mapFrame, String name, String desc) {
+		super(name, "measurement.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));		
+	}
+
+	@Override public void enterMode() {
+		super.enterMode();
+		Main.map.mapView.addMouseListener(this);
+	}
+
+	@Override public void exitMode() {
+		super.exitMode();
+		Main.map.mapView.removeMouseListener(this);
+	}
+
+	/**
+	 * If user clicked with the left button, add a node at the current mouse
+	 * position.
+	 *
+	 * If in nodesegment mode, add the node to the line segment by splitting the
+	 * segment. The new created segment will be inserted in every way the segment
+	 * was part of.
+	 */
+	@Override public void mouseClicked(MouseEvent e) {
+		if (e.getButton() == MouseEvent.BUTTON3){
+			MeasurementPlugin.getCurrentLayer().removeLastPoint();
+		}else if (e.getButton() == MouseEvent.BUTTON1){
+			LatLon coor = Main.map.mapView.getLatLon(e.getX(), e.getY());
+			if (coor.isOutSideWorld()) {
+				JOptionPane.showMessageDialog(Main.parent,tr("Can not draw outside of the world."));
+				return;
+			}
+			if (MeasurementPlugin.currentLayer == null){
+				Main.main.addLayer(new MeasurementLayer("Measurement"));
+			}
+			MeasurementPlugin.currentLayer.mouseClicked(e);
+		}
+	}
+
+}
Index: applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java
===================================================================
--- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java	(revision 10379)
+++ applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java	(revision 10379)
@@ -0,0 +1,55 @@
+package org.openstreetmap.josm.plugins.measurement;
+/// @author Raphael Mack <osm@raphael-mack.de>
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.IconToggleButton;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.plugins.Plugin;
+
+public class MeasurementPlugin extends Plugin {
+
+	private IconToggleButton btn;
+	private MeasurementMode mode;
+	protected static MeasurementDialog measurementDialog;
+	protected static MeasurementLayer currentLayer;
+	
+	public MeasurementPlugin() {
+		mode = new MeasurementMode(Main.map, "measurement", tr("measurement mode"));
+		btn = new IconToggleButton(mode);
+		btn.setVisible(true);
+		measurementDialog = new MeasurementDialog();
+	}
+	
+	@Override
+	public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
+		if(newFrame != null){
+			newFrame.addToggleDialog(measurementDialog);
+		}
+		if(Main.map != null){
+			Main.map.toolBarActions.add(btn);
+			Main.map.toolGroup.add(btn);
+			
+			Main.map.mapView.addLayerChangeListener(new LayerChangeListener(){
+				public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
+					if(newLayer instanceof MeasurementLayer)
+						MeasurementPlugin.currentLayer = (MeasurementLayer)newLayer;
+				}
+				public void layerAdded(final Layer newLayer) {
+				}
+				public void layerRemoved(final Layer oldLayer) {
+				}
+			});
+		}
+	}
+
+	public static MeasurementLayer getCurrentLayer(){
+		if(currentLayer == null){
+			currentLayer = new MeasurementLayer("Measurement");
+			Main.main.addLayer(currentLayer);
+		}
+		return currentLayer;
+	}
+}
