Index: applications/editors/josm/plugins/terracer/build.xml
===================================================================
--- applications/editors/josm/plugins/terracer/build.xml	(revision 23191)
+++ applications/editors/josm/plugins/terracer/build.xml	(revision 24697)
@@ -32,6 +32,6 @@
 
 
-    <property name="commit.message" value="adapt to latest josm" />
-    <property name="plugin.main.version" value="3348" />
+    <property name="commit.message" value="select a single node to fix the direction of numbering (Merkaartor style)" />
+    <property name="plugin.main.version" value="3711" />
 
 
Index: applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java	(revision 23191)
+++ applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java	(revision 24697)
@@ -97,5 +97,7 @@
         getJContentPane();
         initialize();
+        setDefaultButton(1);
         setupDialog();
+        getRootPane().setDefaultButton(defaultButton);
         setVisible(true);
         lo.requestFocus();
Index: applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java	(revision 23191)
+++ applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java	(revision 24697)
@@ -28,4 +28,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.data.osm.Node;
 
 /**
@@ -42,4 +43,5 @@
     private TerracerAction terracerAction;
     private Way outline, street;
+    private Node init;
     private Relation associatedStreet;
     public HouseNumberInputDialog dialog;
@@ -50,4 +52,5 @@
      * @param terracerAction the terracer action
      * @param outline the closed, quadrilateral way to terrace.
+     * @param init The node that hints at which side to start the numbering
      * @param street the street, the buildings belong to (may be null)
      * @param associatedStreet a relation where we can add the houses (may be null)
@@ -55,8 +58,9 @@
      */
     public HouseNumberInputHandler(final TerracerAction terracerAction,
-            final Way outline, final Way street, final Relation associatedStreet,
+            final Way outline, final Node init, final Way street, final Relation associatedStreet,
             final String title) {
         this.terracerAction = terracerAction;
         this.outline = outline;
+        this.init = init;
         this.street = street;
         this.associatedStreet = associatedStreet;
@@ -272,5 +276,5 @@
         if (e.getSource() instanceof JButton) {
             JButton button = (JButton) e.getSource();
-            if ("OK".equals(button.getActionCommand()) & button.isEnabled()) {
+            if (tr("OK").equals(button.getActionCommand()) & button.isEnabled()) {
                 if (validateInput()) {
                     saveValues();
@@ -278,4 +282,5 @@
                     terracerAction.terraceBuilding(
                         outline,
+                        init,
                         street,
                         associatedStreet,
Index: applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 23191)
+++ applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 24697)
@@ -16,5 +16,4 @@
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -30,5 +29,4 @@
 import org.openstreetmap.josm.command.DeleteCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
-import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -37,4 +35,5 @@
 import org.openstreetmap.josm.data.osm.TagCollection;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.tools.Pair;
 import org.openstreetmap.josm.tools.Shortcut;
@@ -74,8 +73,8 @@
      */
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet()
-                .getSelected();
+        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
         Way outline = null;
         Way street = null;
+        Node init = null;
 
         class InvalidUserInputException extends Exception {
@@ -89,31 +88,27 @@
 
         try {
-            if (sel.size() == 2) {
-                Iterator<OsmPrimitive> it = sel.iterator();
-                OsmPrimitive prim1 = it.next();
-                OsmPrimitive prim2 = it.next();
-                if (!(prim1 instanceof Way && prim2 instanceof Way))
-                    throw new InvalidUserInputException();
-                Way way1 = (Way) prim1;
-                Way way2 = (Way) prim2;
-                if (way2.get("highway") != null) {
-                    street = way2;
-                    outline = way1;
-                } else if (way1.get("highway") != null) {
-                    street = way1;
-                    outline = way2;
-                } else
-                    throw new InvalidUserInputException();
-                if (street.get("name") == null)
-                    throw new InvalidUserInputException();
-
-            } else if (sel.size() == 1) {
-                OsmPrimitive prim = sel.iterator().next();
-
-                if (!(prim instanceof Way))
-                    throw new InvalidUserInputException();
-
-                outline = (Way)prim;
-            } else
+            for (OsmPrimitive osm : sel) {
+                if (osm instanceof Node) {
+                    if (init != null)
+                        throw new InvalidUserInputException();
+                    init = (Node) osm;
+                } else if (osm instanceof Way) {
+                    if (osm.hasKey("highway")) {
+                        if (street != null)
+                            throw new InvalidUserInputException();
+                        street = (Way) osm;
+                        if (!street.hasKey("name"))
+                            throw new InvalidUserInputException();
+                    } else {
+                        if (outline != null)
+                            throw new InvalidUserInputException();
+                        outline = (Way) osm;
+                    }
+                }
+            }
+            if (outline == null)
+                throw new InvalidUserInputException();
+            
+            if (init != null && !init.getReferrers().contains(outline))
                 throw new InvalidUserInputException();
 
@@ -124,6 +119,10 @@
                 throw new InvalidUserInputException();
         } catch (InvalidUserInputException ex) {
-            JOptionPane.showMessageDialog(Main.parent,
-                    tr("Select a single, closed way of at least four nodes."));
+            new ExtendedDialog(Main.parent, tr("Invalid selection"), new String[] {"OK"})
+                .setButtonIcons(new String[] {"ok"}).setIcon(JOptionPane.INFORMATION_MESSAGE)
+                .setContent(tr("Select a single, closed way of at least four nodes. " +
+                    "(Optionally you can also select a street for the addr:street tag " +
+                    "and a node to mark the start of numbering.)"))
+                .showDialog();
             return;
         }
@@ -149,5 +148,5 @@
         String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size());
         // show input dialog.
-        new HouseNumberInputHandler(this, outline, street, associatedStreet, title);
+        new HouseNumberInputHandler(this, outline, init, street, associatedStreet, title);
     }
 
@@ -169,4 +168,5 @@
      *
      * @param outline The closed, quadrilateral way to terrace.
+     * @param init The node that hints at which side to start the numbering
      * @param street The street, the buildings belong to (may be null)
      * @param associatedStreet
@@ -178,4 +178,5 @@
      */
     public void terraceBuilding(Way outline,
+                Node init,
                 Way street,
                 Relation associatedStreet,
@@ -217,10 +218,18 @@
             Pair<Way, Way> interp = findFrontAndBack(outline);
 
+            boolean swap = false;
+            if (init != null) {
+                if (interp.a.lastNode().equals(init) || interp.b.lastNode().equals(init)) {
+                    swap = true;
+                }
+            }
+
             final double frontLength = wayLength(interp.a);
             final double backLength = wayLength(interp.b);
 
             for (int i = 0; i <= nb; ++i) {
-                new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i / nb);
-                new_nodes[1][i] = interpolateAlong(interp.b, backLength * i / nb);
+                int i_dir = swap ? nb - i : i;
+                new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb);
+                new_nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb);
                 this.commands.add(new AddCommand(new_nodes[0][i]));
                 this.commands.add(new AddCommand(new_nodes[1][i]));
@@ -230,7 +239,4 @@
             for (int i = 0; i < nb; ++i) {
                 Way terr = new Way();
-                // Using Way.nodes.add rather than Way.addNode because the latter
-                // doesn't
-                // exist in older versions of JOSM.
                 terr.addNode(new_nodes[0][i]);
                 terr.addNode(new_nodes[0][i + 1]);
