---
core-dave/src/org/openstreetmap/josm/command/ReplaceNodeInWayCommand.java |
94 ++++++++++
1 file changed, 94 insertions(+)
diff -puN
src/org/openstreetmap/josm/command/ReplaceNodeInWayCommand.java~ReplaceNodeInWayCommand
src/org/openstreetmap/josm/command/ReplaceNodeInWayCommand.java
---
core/src/org/openstreetmap/josm/command/ReplaceNodeInWayCommand.java~ReplaceNodeInWayCommand
2008-05-03 12:08:41.000000000 -0700
+++ core-dave/src/org/openstreetmap/josm/command/ReplaceNodeInWayCommand.java
2008-05-03 12:08:41.000000000 -0700
@@ -0,0 +1,94 @@
+// 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.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 node in a way
+ *
+ * @author daveh
+ */
+public class ReplaceNodeInWayCommand 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 final Node newNode;
+ private int replaced_at;
+ private int replace_at;
+
+ public ReplaceNodeInWayCommand(Way _way, Node _node, Node _newNode, int
_replace_at) {
+ this.way = _way;
+ this.node = _node;
+ this.newNode = _newNode;
+ this.replace_at = _replace_at;
+ }
+
+ public ReplaceNodeInWayCommand(Way _way, Node _node, Node _newNode) {
+ this.way = _way;
+ this.node = _node;
+ this.newNode = _newNode;
+ this.replace_at = -1;
+ }
+
+ @Override public boolean executeCommand() {
+ super.executeCommand();
+ ///ds.rl.check(node);
+ ///ds.rl.check(newNode);
+ if (replace_at != -1)
+ replaced_at = way.replaceNode(node, newNode,
replace_at);
+ else
+ replaced_at = way.replaceNode(node, newNode);
+ ///ds.rl.removeWayFromNodeMap_nocheck(node, way);
+ ///ds.rl.addWayToNodeMap_nocheck(newNode, way);
+ ///ds.rl.check(node);
+ ///ds.rl.check(newNode);
+ if (replaced_at < 0) {
+ String location = "";
+ if (replace_at != -1)
+ location = " at location";
+ Main.debug("error replacing node " + node.id +
+ location + " in way " +way.id);
+ return false;
+ }
+ way.modified = true;
+ return true;
+ }
+
+ @Override public void undoCommand() {
+ way.replaceNode(newNode, node, replaced_at);
+ ///ds.rl.removeWayFromNodeMap_nocheck(newNode, way);
+ ///ds.rl.addWayToNodeMap_nocheck(node, way);
+ ///ds.rl.check(node);
+ ///ds.rl.check(newNode);
+ Way orig_way = (Way)this.getOrig(way);
+ Main.debug("ReplaceNodeInWay() orig_way: " + orig_way);
+ way.modified = orig_way.modified;
+ }
+
+ @Override public void fillModifiedData(Collection<OsmPrimitive>
modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
+ modified.add(way);
+ deleted.add(node);
+ }
+
+ @Override public MutableTreeNode description() {
+ NameVisitor v = new NameVisitor();
+ way.visit(v);
+ return new DefaultMutableTreeNode(new
JLabel(tr("ReplaceNodeInWay")+" "+tr(v.className)+" "+v.name, v.icon,
JLabel.HORIZONTAL));
+ }
+}
_
_______________________________________________
josm-dev mailing list
[email protected]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/josm-dev