A new fine-grain command to replace a node in a way.  Much
safer and easier to use than the old ChangeCommand.

---

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

diff -puN 
src/org/openstreetmap/josm/command/RemoveNodeInWayCommand.java~RemoveNodeInWay 
src/org/openstreetmap/josm/command/RemoveNodeInWayCommand.java
--- 
core/src/org/openstreetmap/josm/command/RemoveNodeInWayCommand.java~RemoveNodeInWay
 2008-04-28 18:59:28.000000000 -0700
+++ core-dave/src/org/openstreetmap/josm/command/RemoveNodeInWayCommand.java    
2008-04-28 18:59:28.000000000 -0700
@@ -0,0 +1,80 @@
+// License: GPL. Copyright 2007 by Immanuel Scholz 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.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.Node;
+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 RemoveNodeInWayCommand extends Command {
+
+       // container object in which to replace a sub object
+       private final Way way;
+
+       // the sub-object to be replaced
+       private final Node node;
+       // its replacement
+       private int location = -1;
+
+       public RemoveNodeInWayCommand(Way _way, Node _node) {
+               this.way = _way;
+               this.node = _node;
+    }
+       public RemoveNodeInWayCommand(Way _way, Node _node, int _location) {
+               this.way = _way;
+               this.node = _node;
+               location = _location;
+       }
+
+       @Override public boolean executeCommand() {
+               super.executeCommand();
+               if (location == -1) {
+                       location = way.removeNode(node);
+                       if (location == -1 ) {
+                               return false;
+                       }
+               } else {
+                       Node removed = way.removeNode(location);
+                       //Main.debug("attempted to remove node: " + node.id + " 
at location: "
+                       //              + location + " and got: " + removed.id);
+                       if (removed != node) {
+                               way.addNodeNr(location, node);
+                               return false;
+                       }
+               }
+               Main.ds.rl.removeWayFromNodeMap(node, way);
+           way.modified = true;
+               return true;
+    }
+
+       @Override public void undoCommand() {
+               way.addNodeNr(location, node);
+               Main.ds.rl.addWayToNodeMap(node, way);
+               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("RemoveNodeInWay")+" "+tr(v.className)+" "+v.name, v.icon, 
JLabel.HORIZONTAL));
+    }
+}
_

_______________________________________________
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/josm-dev

Reply via email to