Index: applications/editors/josm/plugins/routing/build.xml
===================================================================
--- applications/editors/josm/plugins/routing/build.xml	(revision 25843)
+++ applications/editors/josm/plugins/routing/build.xml	(revision 26119)
@@ -35,9 +35,11 @@
 	<property name="plugin.build.dir"       value="build"/>
 	<property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
-	<property name="jgrapht"                value="lib/jgrapht-jdk1.5.jar"/>
-	<property name="log4j"                  value="lib/log4j-1.2.15.jar"/>
+	<property name="libdir"                 location="lib"/>
+	<property name="jgrapht"                value="${libdir}/jgrapht-jdk1.5.jar"/>
+	<property name="log4j"                  value="${libdir}/log4j-1.2.15.jar"/>
 	<property name="ant.build.javac.target" value="1.5"/>
 	<!-- Some initializations for several other targets -->
 	<target name="init">
+		<mkdir dir="${plugin.dist.dir}"/>
 		<mkdir dir="${plugin.build.dir}"/>
 	</target>
@@ -69,5 +71,5 @@
 		<jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
 			<manifest>
-				<attribute name="Author" value="Jose Vidal &lt;vidalfree@gmail.com&gt;, Juangui Jordán &lt;juangui@gmail.com&gt;"/>
+				<attribute name="Author" value="Jose Vidal &lt;vidalfree@gmail.com&gt;, Juangui Jordán &lt;juangui@gmail.com&gt;, Hassan S &lt;hassan.sabirin@gmail.com&gt;"/>
 				<attribute name="Plugin-Class" value="com.innovant.josm.plugin.routing.RoutingPlugin"/>
 				<attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
Index: applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java
===================================================================
--- applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java	(revision 25843)
+++ applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java	(revision 26119)
@@ -49,4 +49,5 @@
  * @author Juangui
  * @author Jose Vidal
+ * @author Hassan S
  */
 public class RoutingGraph {
@@ -99,4 +100,27 @@
     private RoutingGraphDelegator rgDelegator=null;
 
+    
+    /**
+     * Graph getter
+     */
+    public Graph<Node, OsmEdge> getGraph(){
+    	return graph;
+    
+    }
+    
+    
+	private void addEdgeBidirectional( Way way, Node from, Node to){
+	    addEdge(way,from,to);
+	    addEdge(way,to,from);
+	}
+	
+	private void addEdgeReverseOneway( Way way, Node from, Node to){
+	    addEdge(way,to,from);
+	}
+	
+	private void addEdgeNormalOneway( Way way, Node from, Node to){
+	    addEdge(way,from,to);
+	}
+    
     /**
      * Speeds
@@ -131,21 +155,67 @@
         // iterate all ways and segments for all nodes:
         for (Way way : data.getWays()) {
-            if (way != null && !way.isDeleted() && this.isvalidWay(way)) {
-                Node from = null;
-                for (Node to : way.getNodes()) {
-                    // Ignore the node if deleted
-                    if (!to.isDeleted()) {
-                        graph.addVertex(to);
-                        if (from != null) {
-                            addEdge(way, from, to);
-                            if (!isOneWay(way)){
-                                addEdge(way, to, from);}
-                        }
-                        from = to;
-                    }
-                }
-            }
-        }
-//      graph.vertexSet().size();
+		
+        // skip way if not suitable for routing.
+  			if (way != null && !way.isDeleted() && this.isvalidWay(way)
+  					&& way.getNodes().size() > 1) continue;
+  
+          // INIT
+  				Node from = null;
+  				Node to = null;
+  				List<Node> nodes = way.getNodes();
+  				int nodes_count = nodes.size();
+  				
+  				/*
+           * Assume node is A B C D E. The procedure should be
+           * 
+           *  case 1 - bidirectional ways:
+           *  1) Add vertex A B C D E
+           *  2) Link A<->B, B<->C, C<->D, D<->E as Edges
+           *  
+           *  case 2 - oneway reverse:
+           *  1) Add vertex A B C D E
+           *  2) Link B->A,C->B,D->C,E->D as Edges. result: A<-B<-C<-D<-E
+           *                  
+           *  case 3 - oneway normal:
+           *  1) Add vertex A B C D E
+           *  2) Link A->B, B->C, C->D, D->E as Edges. result: A->B->C->D->E
+           *  
+           *                  
+           */
+            
+  				String oneway_val = way.get("oneway");   /*   get (oneway=?) tag for this way.   */
+            
+  				from = nodes.get(0);                   /*   1st node A  */
+  				graph.addVertex(from);                 /*   add vertex A */
+  
+  				for (int i = 1; i < nodes_count; i++) { /*   loop from B until E */
+  
+  					to = nodes.get(i);                   /*   2nd node B   */
+  					
+  					if (to != null && !to.isDeleted()) {
+  						graph.addVertex(to);               /*   add vertex B */
+  						
+  				    
+  				    //this is where we link the vertices
+  						if (oneway_val == null || oneway_val == "false" || oneway_val == "no" || oneway_val == "0") {
+  						//Case 1 (bi-way): oneway=false OR oneway=unset OR oneway=0 OR oneway=no
+  						  addEdgeBidirectional(way, from, to);
+  						  
+  						} else if (oneway_val == "-1") {
+  						//Case 2 (oneway reverse): oneway=-1
+  						  addEdgeReverseOneway(way, from, to);
+  						
+  						} else if (oneway_val == "1" || oneway_val == "yes" || oneway_val == "true") {
+              //Case 3 (oneway normal): oneway=yes OR 1 OR true
+  						  addEdgeNormalOneway(way, from, to);				
+                		
+  						}
+  
+  						from = to;                         /*   we did A<->B, next loop we will do B<->C, so from=B,to=C for next loop. */
+  					}
+					
+  				} // end of looping thru nodes
+  		  } // end of looping thru ways
+		  
         logger.debug("End Create Graph");
         logger.debug("Vertex: "+graph.vertexSet().size());
@@ -225,18 +295,4 @@
 
     /**
-     * Check is One Way.
-     *
-     * @param way
-     *            the way.
-     * @return <code>true</code> is a one way. <code>false</code> is not a one
-     *         way.
-     */
-    private boolean isOneWay(Way way) {
-        // FIXME: oneway=-1 is ignored for the moment!
-        return way.get("oneway") != null
-                || "motorway".equals(way.get("highway"));
-    }
-
-    /**
      * Check if a Way is correct.
      *
@@ -246,14 +302,10 @@
      */
     public boolean isvalidWay(Way way) {
-        if (!way.isTagged())
-            return false;
+        //if (!way.isTagged())            <---not needed me thinks
+        //    return false;
 
         return way.get("highway") != null || way.get("junction") != null
                 || way.get("service") != null;
 
-    }
-
-    public boolean isvalidNode(Node node) {
-        return true;
     }
 
@@ -295,5 +347,5 @@
             DijkstraShortestPath<Node, OsmEdge> routingk = null;
             for (int index = 1; index < nodes.size(); ++index) {
-                routingk = new DijkstraShortestPath<Node, OsmEdge>(rgDelegator, nodes
+                routingk = new DijkstraShortestPath<Node, OsmEdge>(g, nodes
                         .get(index - 1), nodes.get(index));
                 if (routingk.getPathEdgeList() == null) {
Index: applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java
===================================================================
--- applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java	(revision 25843)
+++ applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java	(revision 26119)
@@ -33,8 +33,10 @@
 import java.awt.Graphics2D;
 import java.awt.Point;
+import java.awt.RenderingHints;
 import java.awt.Stroke;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 import javax.swing.Action;
@@ -106,4 +108,8 @@
         this.routingModel = new RoutingModel(dataLayer.data);
         logger.debug("Routing Layer created.");
+        
+
+        this.routingModel.routingGraph.createGraph();	/* construct the graph right after we we create the layer */
+        Main.map.repaint();							/* update MapView */
     }
 
@@ -139,5 +145,5 @@
 
                 Point P = Main.map.mapView.getPoint(n);
-                double dist = p.distanceSq(P);
+                double dist = p.distance(P);
                 if (dist < snapDistance) {
                     if ((nearest == null) || (dist < minDist)) {
@@ -231,8 +237,4 @@
         // Get routing nodes (start, middle, end)
         List<Node> nodes = routingModel.getSelectedNodes();
-        if(nodes == null || nodes.size() == 0) {
-            logger.debug("no nodes selected");
-            return;
-        }
 
         // Get path stroke color from preferences
@@ -259,9 +261,29 @@
         String widthString = Main.pref.get(PreferencesKeys.KEY_ROUTE_WIDTH.key);
         if (widthString.length() == 0) {
-            widthString = "8";
+            widthString = "2";						/* I think 2 is better  */
             // FIXME add after good width is found: Main.pref.put(KEY_ROUTE_WIDTH, widthString);
         }
         int width = Integer.parseInt(widthString);
-
+        
+        
+        // draw our graph
+        if (isActiveLayer) {
+        	if(routingModel != null) {
+        		if(routingModel.routingGraph != null && routingModel.routingGraph.getGraph() != null) {
+        	    	Color color2 = ColorHelper.html2color("#00ff00");		/* just green for now  */
+        	        Set<OsmEdge> graphEdges =  routingModel.routingGraph.getGraph().edgeSet();
+        	        OsmEdge firstedge = (OsmEdge) graphEdges.toArray()[0];
+        	        Point from = mv.getPoint(firstedge.fromEastNorth());
+        	        g.drawRect(from.x-4, from.y+4, from.x+4, from.y-4);
+        	        for(OsmEdge edge : graphEdges) {
+        	        	drawGraph(g, mv, edge, color2, width);
+        	        }
+        	     }
+        	 }
+        }
+        	        
+        
+        if(nodes == null || nodes.size() == 0) return;
+        
         // Paint routing path
         List<OsmEdge> routeEdges = routingModel.getRouteEdges();
@@ -327,7 +349,8 @@
 
             Graphics2D g2d = (Graphics2D)g;
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Anti-alias!
             Stroke oldStroke = g2d.getStroke();
             g2d.setStroke(new BasicStroke(width)); // thickness
-            g.drawLine(from.x, from.y, to.x, to.y);
+            g2d.drawLine(from.x, from.y, to.x, to.y);
             if (showDirection) {
                 double t = Math.atan2(to.y-from.y, to.x-from.x) + Math.PI;
@@ -337,4 +360,20 @@
             g2d.setStroke(oldStroke);
     }
-
+    private void drawGraph(Graphics g, MapView mv, OsmEdge edge, Color col, int width) {
+        g.setColor(col);
+        Point from;
+        Point to;
+        from = mv.getPoint(edge.fromEastNorth());
+        to = mv.getPoint(edge.toEastNorth());
+        
+            Graphics2D g2d = (Graphics2D)g;
+            Stroke oldStroke = g2d.getStroke();
+            g2d.setStroke(new BasicStroke(width)); // thickness
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);  // Anti-alias!
+            g2d.drawLine(from.x, from.y, to.x, to.y);
+            g2d.drawRect(to.x- 4, to.y+4, 4, 4);
+
+            g2d.setStroke(oldStroke);
+	 }
+		
 }
Index: applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingPlugin.java
===================================================================
--- applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingPlugin.java	(revision 25843)
+++ applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingPlugin.java	(revision 26119)
@@ -35,4 +35,12 @@
 import org.apache.log4j.xml.DOMConfigurator;
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
+import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent.DatasetEventType;
+import org.openstreetmap.josm.data.osm.event.DataSetListener;
+import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
+import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
+import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
 import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.MapFrame;
@@ -60,5 +68,5 @@
  * @version 0.3
  */
-public class RoutingPlugin extends Plugin implements LayerChangeListener {
+public class RoutingPlugin extends Plugin implements LayerChangeListener,DataSetListenerAdapter.Listener {
     /**
      * Logger
@@ -123,4 +131,6 @@
      */
     private static RoutingPlugin plugin;
+    
+    private DataSetListenerAdapter datasetAdapter;
 
     /**
@@ -129,4 +139,6 @@
     public RoutingPlugin(PluginInformation info) {
         super(info);
+        
+        datasetAdapter = new DataSetListenerAdapter(this);
         plugin = this; // Assign reference to the plugin class
         DOMConfigurator.configure("log4j.xml");
@@ -141,4 +153,5 @@
         // Register this class as LayerChangeListener
         MapView.addLayerChangeListener(this);
+        DatasetEventManager.getInstance().addDatasetListener(datasetAdapter, FireMode.IN_EDT_CONSOLIDATED);
         logger.debug("Finished loading plugin");
     }
@@ -203,5 +216,19 @@
      */
     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
-        routingDialog.refresh();
+    	   	
+    	   	if (newLayer instanceof RoutingLayer) {			/*   show Routing toolbar and dialog window  */
+    	   		addRouteNodeButton.setVisible(true);
+    		    removeRouteNodeButton.setVisible(true);
+    		    moveRouteNodeButton.setVisible(true);
+    		    menu.enableRestOfItems();    		
+    		    routingDialog.showDialog();
+    		    routingDialog.refresh();
+    	   	}else{											/*   hide Routing toolbar and dialog window  */
+    	   		addRouteNodeButton.setVisible(false);
+    		    removeRouteNodeButton.setVisible(false);
+    		    moveRouteNodeButton.setVisible(false);
+    		    menu.disableRestOfItems();
+    		    routingDialog.hideDialog();
+    	   	}
     }
 
@@ -254,5 +281,9 @@
         routingDialog.refresh();
     }
-
+    
+    public void processDatasetEvent(AbstractDatasetChangedEvent event){
+    	
+    	
+    }
     /* (non-Javadoc)
      * @see org.openstreetmap.josm.plugins.Plugin#getPreferenceSetting()
Index: applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java
===================================================================
--- applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java	(revision 25843)
+++ applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java	(revision 26119)
@@ -67,4 +67,5 @@
     private JMenuItem reverseMI;
     private JMenuItem clearMI;
+    private JMenuItem regraphMI;
     private JMenu criteriaM;
     private JMenu menu;
@@ -166,4 +167,20 @@
         });
         menu.add(clearMI);
+        
+        regraphMI = new JMenuItem(tr("Reconstruct Graph"));
+        regraphMI.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+            	
+            	if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) {
+                    RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer();
+                    RoutingModel routingModel = layer.getRoutingModel();
+            	routingModel.routingGraph.resetGraph();
+            	routingModel.routingGraph.createGraph();
+            	}
+
+            }
+        });
+        menu.add(regraphMI);
+        
 
         // Initially disabled
