Index: applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java	(revision 26885)
+++ applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java	(revision 27318)
@@ -43,4 +43,5 @@
     JMenuItem selModifiedWays;
     JMenuItem selectHighway;
+    JMenuItem selectAreaBoundary;
     
     JMenuItem selectURL;
@@ -79,4 +80,5 @@
         undoSelection = MainMenu.add(selectionMenu, new UndoSelectionAction());
         selectHighway = MainMenu.add(selectionMenu, new SelectHighwayAction());
+        selectAreaBoundary = MainMenu.add(selectionMenu, new SelectBoundaryAction());
         
         selectURL = MainMenu.add(toolsMenu, new ChooseURLAction());
Index: applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java	(revision 26885)
+++ applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java	(revision 27318)
@@ -268,6 +268,78 @@
             }
     }
-
     
+    static boolean addAreaBoundary(Way firstWay, Set<Way> newWays, boolean goingLeft) {
+        Way w=firstWay;
+        Node curNode = w.lastNode();
+        Node prevNode = w.getNode(w.getNodes().size()-2);
+        Set<Way> newestWays = new HashSet<Way>();
+        while(true) {
+
+            Node nextNode, endNode, otherEnd, preLast;
+            Way nextWay;
+
+            EastNorth en;
+            double startHeading,bestAngle;
+
+            en = curNode.getEastNorth();
+            startHeading = prevNode.getEastNorth().heading( en );
+
+            bestAngle = goingLeft ? -1e5 : 1e5 ;
+            otherEnd=null; nextWay=null;
+            
+            for (OsmPrimitive ref : curNode.getReferrers()) {
+                if (ref instanceof Way && ref!=w && ref.isSelectable()) {
+                    //
+                    Way w2 = (Way) ref;
+                    //  -----[prevNode]-(curNode)-[nextNode]------[preLast]-(endNode)
+                    //          w           |              w2
+                    if (w2.getNodesCount()<2 || w2.isClosed()) continue;
+
+
+                    if (curNode == w2.firstNode()) {
+                        nextNode = w2.getNode(1);
+                        preLast = w2.getNode(w2.getNodesCount()-2);
+                        endNode = w2.lastNode();
+                    } // forward direction
+                    else if (curNode == w2.lastNode()) {
+                        nextNode = w2.getNode(w2.getNodesCount()-2);
+                        preLast = w2.getNode(1);
+                        endNode = w2.firstNode();
+                    } // backward direction
+                        else continue; // we came to some way middle node
+
+                    double angle = startHeading -Math.PI - en.heading(nextNode.getEastNorth());
+                    while (angle<0) angle+=2*Math.PI;
+                    
+                    if (angle < bestAngle ^ goingLeft) {
+                        bestAngle = angle;
+                        otherEnd = endNode;
+                        prevNode = preLast;
+                        nextWay = w2;
+                    }
+                }
+            }
+            if (firstWay == nextWay ) {
+                //we came to starting way, but not not the right end 
+                if (otherEnd==firstWay.firstNode()) return false;
+                newWays.addAll(newestWays);
+                return true; // correct loop found 
+            }
+            if (newestWays.contains(nextWay)) {
+                // P - like loop found
+                return false;
+            }
+            if (nextWay != null) { 
+                newestWays.add(nextWay);
+                curNode = otherEnd;
+                w = nextWay;
+                // next way found, continuing
+            } else {
+                // no closed loop found
+                return false;
+            } 
+        }
+    }
+
     static void addAllInsideMultipolygon(DataSet data, Relation rel, Set<Way> newWays, Set<Node> newNodes) {
         if (!rel.isMultipolygon()) return;
Index: applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectAllInsideAction.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectAllInsideAction.java	(revision 26885)
+++ applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectAllInsideAction.java	(revision 27318)
@@ -35,5 +35,4 @@
     public void actionPerformed(ActionEvent e) {
         long t=System.currentTimeMillis();
-        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
         Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Way.class);
         Set<Relation> selectedRels = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Relation.class);
Index: applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectBoundaryAction.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectBoundaryAction.java	(revision 27318)
+++ applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectBoundaryAction.java	(revision 27318)
@@ -0,0 +1,146 @@
+// License: GPL. Copyright 2011 by Alexei Kasatkin
+package utilsplugin2.selection;
+
+import java.util.LinkedHashSet;
+import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.tools.Shortcut;
+
+/**
+ *    Extends current selection by selecting nodes on all touched ways
+ */
+public class SelectBoundaryAction extends JosmAction {
+    private Way lastUsedStartingWay; //used for repeated calls
+    private boolean lastUsedLeft;
+
+    public SelectBoundaryAction() {
+        super(tr("Area boundary [testing]"), "selboundary", tr("Select relation or all ways that forms area boundary"),
+                Shortcut.registerShortcut("tools:selboundary", tr("Tool: {0}","Area boundary [testing]"),
+                KeyEvent.VK_SLASH, Shortcut.GROUP_EDIT ,Shortcut.SHIFT_DEFAULT), true);
+        putValue("help", ht("/Action/SelectAreaBoundary"));
+    }
+
+    public void actionPerformed(ActionEvent e) {
+        long t=System.currentTimeMillis();
+        Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Way.class);
+        Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Node.class);
+        LinkedHashSet<Relation> selectedRelations = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Relation.class);
+        
+        Set<Way> newWays = new HashSet<Way>();
+        
+        Way w=null;
+        Relation selectedRelation=null;
+        
+        if (selectedRelations.size()==1) {
+            selectedRelation = selectedRelations.iterator().next();
+            if (selectedRelation.getMemberPrimitives().contains(lastUsedStartingWay)) {
+                w=lastUsedStartingWay; 
+                // repeated call for selected relation
+            }
+        } else if (selectedWays.isEmpty()) {
+            if (selectedNodes.size()==1 ) {
+                for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) {
+                    if (p instanceof Way && p.isSelectable()) {
+                        //if (w!=null) return; // ifwe want only one way
+                        w=(Way) p;
+                        break;
+                    }
+                }
+            }
+        } else if (selectedWays.size()==1)  {
+            w = selectedWays.iterator().next();
+        } else if (selectedWays.contains(lastUsedStartingWay)) { 
+            w=lastUsedStartingWay; //repeated call for selected way
+            lastUsedLeft = !lastUsedLeft;
+        }
+
+        
+        if (w==null) return; //no starting way found
+        if (!w.isSelectable()) return;
+        if (w.isClosed()) return;
+        if (w.getNodesCount()<2) return;
+
+        newWays.add(w);
+        lastUsedStartingWay = w;
+        
+        List<Relation> rels=new ArrayList<Relation>();
+        for (OsmPrimitive p : w.getReferrers()) {
+            if (p instanceof Relation && p.isSelectable()) {
+                rels.add((Relation) p);
+            }
+        }
+        if (selectedRelation!=null) {
+            int idx = rels.indexOf(selectedRelation); 
+            System.out.println("idx="+idx);
+            // selectedRelation has number idx in active relation list
+            if (idx>=0) {
+               // select next relation
+               if (idx+1<rels.size())
+                   getCurrentDataSet().setSelected(Arrays.asList(rels.get(idx+1)));
+               else 
+                   getCurrentDataSet().setSelected(Arrays.asList(rels.get(0))); 
+               return;
+            }
+        } else if (rels.size()>0) {
+               getCurrentDataSet().setSelected(Arrays.asList(rels.get(0)));
+               return;
+        }
+
+        
+        
+        // try going left at each turn
+        if (! NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft) ) {
+            NodeWayUtils.addAreaBoundary(w, newWays, !lastUsedLeft); // try going right at each turn
+        }
+        
+        
+        
+        if (!newWays.isEmpty() ) {
+            getCurrentDataSet().setSelected(newWays);
+        } else{
+        JOptionPane.showMessageDialog(Main.parent,
+               tr("Nothing found. Please select way that is a part of some polygon formed by connected ways"),
+               tr("Warning"), JOptionPane.WARNING_MESSAGE);
+        }
+
+    }
+
+    @Override
+    protected void updateEnabledState() {
+        if (getCurrentDataSet() == null) {
+            setEnabled(false);
+        } else {
+            updateEnabledState(getCurrentDataSet().getSelected());
+        }
+    }
+
+    @Override
+    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
+        if (selection == null) {
+            setEnabled(false);
+            return;
+        }
+        setEnabled(!selection.isEmpty());
+    }
+
+
+}
