Index: /applications/editors/josm/plugins/navigator/build.xml
===================================================================
--- /applications/editors/josm/plugins/navigator/build.xml	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/build.xml	(revision 3865)
@@ -9,5 +9,5 @@
 	  
 	  <!-- plugin meta data (enter new version number if anything changed!) -->
-	  <property name="plugin.version" value="0.3"/>
+	  <property name="plugin.version" value="0.3.1"/>
 	  <property name="plugin.description" value="Provides navigation/autorouting functionality (V${plugin.version})."/>
 	  <property name="plugin.stage" value="50"/>
Index: /applications/editors/josm/plugins/navigator/readme.txt
===================================================================
--- /applications/editors/josm/plugins/navigator/readme.txt	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/readme.txt	(revision 3865)
@@ -6,4 +6,7 @@
 directory as well!
 
+Use the navigator mode and click all nodes that should be navigated to.
+Use the middle mouse button to remove the selected nodes.
+
 Christof Dallermassl
 christof@dallermassl.at
Index: /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java
===================================================================
--- /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java	(revision 3865)
@@ -147,21 +147,4 @@
             endIcon.paintIcon(mv, g, screen.x, screen.y - endIcon.getIconHeight());
         }
-
-        Main.pref.hasKey(KEY_ROUTE_COLOR);
-        String selectString = Main.pref.get(KEY_ROUTE_SELECT);
-        if(selectString.length() == 0) {
-            selectString = "true";
-            Main.pref.put(KEY_ROUTE_SELECT, selectString);
-        }
-        
-        if(Boolean.parseBoolean(selectString)) {
-            List<Segment> path = navigatorNodeModel.getSegmentPath();
-            if(path != null) {
-                synchronized(path) {
-                    Main.ds.setSelected(path);
-//                  Main.map.mapView.repaint();
-                }
-            }
-        }
         
         String colorString = Main.pref.get(KEY_ROUTE_COLOR);
@@ -243,4 +226,19 @@
     public void navigate() {
         navigatorNodeModel.calculateShortesPath();
+        Main.pref.hasKey(KEY_ROUTE_COLOR);
+        String selectString = Main.pref.get(KEY_ROUTE_SELECT);
+        if(selectString.length() == 0) {
+            selectString = "true";
+            Main.pref.put(KEY_ROUTE_SELECT, selectString);
+        }
+        
+        if(Boolean.parseBoolean(selectString)) {
+            List<Segment> path = navigatorNodeModel.getSegmentPath();
+            if(path != null) {
+                synchronized(path) {
+                    Main.ds.setSelected(path);
+                }
+            }
+        }
         Main.map.repaint();        
     }
Index: /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModeAction.java
===================================================================
--- /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModeAction.java	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModeAction.java	(revision 3865)
@@ -26,5 +26,5 @@
     
     public NavigatorModeAction(MapFrame mapFrame, NavigatorModel navigatorModel, NavigatorLayer navigationLayer) {
-        super(tr("Navigator"), "navigation", tr("Set start/end for autorouting"), KeyEvent.VK_F, mapFrame, ImageProvider.getCursor("crosshair", "selection"));
+        super(tr("Navigator"), "navigation", tr("Set start/end for autorouting. Middle Mouse button to reset."), KeyEvent.VK_F, mapFrame, ImageProvider.getCursor("crosshair", "selection"));
         this.navigatorModel = navigatorModel;
         this.navigatorLayer = navigationLayer;
Index: /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java
===================================================================
--- /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java	(revision 3865)
@@ -6,6 +6,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import org.jgrapht.Graph;
@@ -24,12 +26,23 @@
  */
 public class NavigatorModel {
-    private Graph graph;
+    private Graph<Node, SegmentEdge> graph;
     private List<Node> nodes;
-    private int selectionChangedCalls;
-    List<Segment> segmentPath;
-    List<SegmentEdge> edgePath;
+    private List<Segment> segmentPath;
+    private List<SegmentEdge> edgePath;
+    private Map<String, Double> highwayWeight;
 
     public NavigatorModel() {
         nodes = new ArrayList<Node>();
+        highwayWeight = new HashMap<String, Double>();
+    }
+    
+    /**
+     * Set the weight for the given highway type. The higher the weight is,
+     * the more it is preferred in routing.
+     * @param type the type of the highway.
+     * @param weigth the weight.
+     */
+    public void setHighwayTypeWeight(String type, double weigth) {
+        highwayWeight.put(type, weigth);
     }
     
@@ -45,4 +58,7 @@
         if (graph == null) {
             OsmGraphCreator graphCreator = new OsmGraphCreator();
+            for(String type : highwayWeight.keySet()) {
+                graphCreator.setHighwayTypeWeight(type, highwayWeight.get(type));
+            }
             // graph = graphCreator.createGraph();
             graph = graphCreator.createSegmentGraph();
@@ -80,5 +96,5 @@
         edgePath.addAll(fullPath);
         
-        System.out.println("shortest path found: " + fullPath + " weight: " + fullWeight);
+        System.out.println("shortest path found: " + fullPath + "\nweight: " + fullWeight);
         System.out.println(getPathDescription());
 //        double weight2 = 0;
@@ -121,18 +137,41 @@
         Way oldWay = null;
         Way way = null;
-        for(SegmentEdge edge : edgePath) {
+        
+        SegmentEdge edge;
+        for(int segIndex = 0; segIndex < edgePath.size(); ++segIndex) {
+            edge = edgePath.get(segIndex);
             way = edge.getWay();
+            if(way == null) {
+                System.out.println("way is null!");
+            }
             length += edge.getLengthInM();
-            if(oldWay != null && !oldWay.equals(way)) {
-                description = new PathDescription(oldWay, length);
+            // if way changes or it is the last way add the description:
+            if(oldWay != null && !way.equals(oldWay)) {
+                description = new PathDescription(oldWay, length); // add finished way
                 pathDescriptions.add(description);
-                length = 0;
+                length = 0;                
+            }
+            if(segIndex == edgePath.size() - 1) {
+                description = new PathDescription(way, length);
+                pathDescriptions.add(description);                
             }
             oldWay = way;
         }
-        if(way != null) {
-            description = new PathDescription(way, length);
-            pathDescriptions.add(description);
-        }
+        
+        
+//        for(SegmentEdge edge : edgePath) {
+//            way = edge.getWay();
+//            length += edge.getLengthInM();
+//            if(oldWay != null && !oldWay.equals(way)) {
+//                description = new PathDescription(oldWay, length);
+//                pathDescriptions.add(description);
+//                length = 0;
+//            }
+//            oldWay = way;
+//        }
+//        if(way != null) {
+//            description = new PathDescription(way, length);
+//            pathDescriptions.add(description);
+//        }
         return pathDescriptions;
     }
Index: /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java
===================================================================
--- /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java	(revision 3865)
@@ -8,20 +8,13 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Map;
 
-import javax.swing.AbstractButton;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 
-import org.jgrapht.Graph;
-import org.jgrapht.alg.DijkstraShortestPath;
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.Segment;
 import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
 import org.openstreetmap.josm.plugins.Plugin;
 
@@ -33,4 +26,5 @@
  */
 public class NavigatorPlugin extends Plugin {
+    private static final String KEY_HIGHWAY_WEIGHT_PREFIX = "navigator.weight.";
     private NavigatorLayer navigatorLayer;
     private NavigatorModel navigatorModel;
@@ -41,6 +35,7 @@
     public NavigatorPlugin() {
         super();
-        
+        checkWeights();
         navigatorModel = new NavigatorModel();
+        setHighwayTypeWeights();
         navigatorLayer = new NavigatorLayer(tr("Navigation"));
         navigatorLayer.setNavigatorNodeModel(navigatorModel);
@@ -54,8 +49,46 @@
             public void actionPerformed(ActionEvent e) {
                 navigatorModel.resetGraph();
+                setHighwayTypeWeights();
             }
         });
         navigatorMenu.add(resetMenuItem);
         menu.add(navigatorMenu);
+    }
+    
+    /**
+     * Reads the weight values for the different highway types from the preferences.
+     */
+    private void setHighwayTypeWeights() {
+        Map<String, String> weightMap = Main.pref.getAllPrefix(KEY_HIGHWAY_WEIGHT_PREFIX);
+        String type;
+        double weight;
+        String value;
+        for(String typeKey : weightMap.keySet()) {
+            type = typeKey.substring(KEY_HIGHWAY_WEIGHT_PREFIX.length());
+            weight = Double.parseDouble(weightMap.get(typeKey));
+            navigatorModel.setHighwayTypeWeight(type, weight);
+        }
+    }
+    
+    /**
+     * Checks if there are any highway weights set in the preferences. If not, default 
+     * values are used.
+     */
+    private void checkWeights() {
+        setDefaultWeight("motorway", 100.0);
+        setDefaultWeight("primary", 80.0);
+        setDefaultWeight("secondary", 70.0);
+        setDefaultWeight("tertiary", 60.0);
+        setDefaultWeight("unclassified", 60.0);
+        setDefaultWeight("residential", 40.0);
+        setDefaultWeight("pedestrian", 0.0);
+        setDefaultWeight("cycleway", 0.0);
+        setDefaultWeight("footway", 0.0);
+    }
+    
+    private void setDefaultWeight(String type, double value) {
+        if(!Main.pref.hasKey(KEY_HIGHWAY_WEIGHT_PREFIX + type)) {
+            Main.pref.put(KEY_HIGHWAY_WEIGHT_PREFIX + type, String.valueOf(value));
+        }
     }
     
Index: /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java
===================================================================
--- /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java	(revision 3864)
+++ /applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java	(revision 3865)
@@ -33,18 +33,24 @@
 
     private Map<String, Double> highwayWeight;
-    private static final double DEFAULT_WEIGHT = Double.MAX_VALUE;
+    private static final double DEFAULT_WEIGHT = 0.0;
 
     public OsmGraphCreator() {
         highwayWeight = new HashMap<String, Double>();
-        highwayWeight.put("motorway", 130.0);
-        highwayWeight.put("primary", 100.0);
-        highwayWeight.put("secondary", 70.0);
-        highwayWeight.put("unclassified", 50.0);
-        highwayWeight.put("residential", 40.0);
-        highwayWeight.put("footway", 1.0);
+    }
+    
+    /**
+     * Set the weight for the given highway type. The higher the weight is,
+     * the more it is preferred in routing.
+     * @param type the type of the highway.
+     * @param weigth the weight.
+     */
+    public void setHighwayTypeWeight(String type, double weigth) {
+        highwayWeight.put(type, weigth);
+        System.out.println("set " + type + " to " + weigth);
     }
 
     public Graph<Node, SegmentEdge> createSegmentGraph() {
-        SimpleDirectedWeightedGraph<Node, SegmentEdge> graph = new SimpleDirectedWeightedGraph<Node, SegmentEdge>(SegmentEdge.class);
+        DirectedWeightedMultigraph<Node, SegmentEdge> graph = new DirectedWeightedMultigraph<Node, SegmentEdge>(SegmentEdge.class);
+        // SimpleDirectedWeightedGraph<Node, SegmentEdge> graph = new SimpleDirectedWeightedGraph<Node, SegmentEdge>(SegmentEdge.class);
         // SimpleGraph<Node, SegmentEdge> graph = new SimpleGraph<Node, SegmentEdge>(SegmentEdge.class);
         SegmentEdge edge;
@@ -81,6 +87,5 @@
     /**
      * Returns the weight for the given segment depending on the highway type and the length of the
-     * segment.
-     * 
+     * segment. The higher the value, the less it is used in routing.
      * @param way
      * @param segment
@@ -90,5 +95,5 @@
         String type = way.get("highway");
         if (type == null) {
-            return 0.0d;
+            return Double.MAX_VALUE;
         }
         Double weightValue = highwayWeight.get(type);
@@ -99,10 +104,10 @@
             weight = weightValue.doubleValue();
         }
-        double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; // deg
-                                                                                            // to m
-                                                                                            // (at
-                                                                                            // equator
-                                                                                            // :-)
-        return distance; // weight;
+        // deg to m (at equator :-):
+        double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; 
+        if(weight == 0.0) {
+            weight = 1E-20;
+        }
+        return distance / weight;
     }
 
