[josm-dev] [PATCH 20/26] ReverseWayCommand

Dave Hansen dave at sr71.net
Tue Apr 29 03:03:02 BST 2008



---

 core-dave/src/org/openstreetmap/josm/command/ReverseWayCommand.java |   59 ++++++++++
 1 file changed, 59 insertions(+)

diff -puN src/org/openstreetmap/josm/command/ReverseWayCommand.java~core-ReverseWayCommand src/org/openstreetmap/josm/command/ReverseWayCommand.java
--- core/src/org/openstreetmap/josm/command/ReverseWayCommand.java~core-ReverseWayCommand	2008-04-28 18:59:30.000000000 -0700
+++ core-dave/src/org/openstreetmap/josm/command/ReverseWayCommand.java	2008-04-28 18:59:30.000000000 -0700
@@ -0,0 +1,59 @@
+// License: GPL. Copyright 2007 by Dave Hansen and others
+package org.openstreetmap.josm.command;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.util.Collection;
+
+import javax.swing.JLabel;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.MutableTreeNode;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
+
+/**
+ * Command that basically replaces one OSM primitive by another of the
+ * same type.
+ *
+ * @author daveh
+ */
+public class ReverseWayCommand extends Command {
+
+	// way to reverse;
+	private final Way way;
+
+	public ReverseWayCommand(Way way) {
+		this.way = way;
+    }
+
+	@Override public boolean executeCommand() {
+	    super.executeCommand();
+	    for (Node n : way.nodes)
+	    	Main.debug("before way " + way.id + "node: " + n.id);
+		way.reverseNodes();
+	    for (Node n : way.nodes)
+	    	Main.debug("after way " + way.id + "node: " + n.id);
+	    //stem.out.println("ReverseWay: " + way.id);
+	    way.modified = true;
+		return true;
+    }
+
+	@Override public void undoCommand() {
+		way.reverseNodes();
+	    way.modified = this.getOrig(way).modified;
+    }
+
+	@Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
+		modified.add(way);
+	}
+
+	@Override public MutableTreeNode description() {
+		NameVisitor v = new NameVisitor();
+		way.visit(v);
+		return new DefaultMutableTreeNode(new JLabel(tr("ReverseWay")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+    }
+}
_




More information about the josm-dev mailing list