Index: src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/OrthogonalizeAction.java	(revision 2595)
+++ src/org/openstreetmap/josm/actions/OrthogonalizeAction.java	(working copy)
@@ -10,6 +10,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -141,24 +142,41 @@
                 }
                 else if (p instanceof Way) {
                     wayDataList.add(new WayData((Way) p));
-                }
-                else {      // maybe a relation got selected...
+                } else
                     throw new InvalidUserInputException("Selection must consist only of ways and nodes.");
-                }
             }
-            if (wayDataList.isEmpty()) {
+            if (wayDataList.isEmpty())
                 throw new InvalidUserInputException("usage");
-            }
             else  {
                 if (nodeList.size() == 2) {
                     orthogonalize(wayDataList, nodeList);
                 }
                 else if (nodeList.isEmpty()) {
-                    orthogonalize(wayDataList, nodeList);
-                }
-                else {
+                    ArrayList<ArrayList<WayData>> groups = new ArrayList<ArrayList<WayData>>();
+                    for (WayData w: wayDataList) {
+                        boolean add = false;
+                        for (ArrayList<WayData> g: groups) {
+                            for (WayData groupedWay: g) {
+                                if (!Collections.disjoint(w.way.getNodes(), groupedWay.way.getNodes())) {
+                                    add = true;
+                                    break;
+                                }
+                            }
+                            if (add) {
+                                g.add(w);
+                            }
+                        }
+                        if (!add) {
+                            ArrayList<WayData> newGroup = new ArrayList<WayData>();
+                            newGroup.add(w);
+                            groups.add(newGroup);
+                        }
+                    }
+                    for (ArrayList<WayData> g: groups) {
+                        orthogonalize(g, nodeList);
+                    }
+                } else
                     throw new InvalidUserInputException("usage");
-                }
             }
         } catch (InvalidUserInputException ex) {
             if (ex.getMessage().equals("usage")) {
