[josm-dev] [PATCH 09/24] AddNodeToWayCommand
Dave Hansen
dave at sr71.net
Sat May 3 20:15:06 BST 2008
---
core-dave/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java | 6
core-dave/src/org/openstreetmap/josm/command/AddNodeToWayCommand.java | 72 ++++++++++
2 files changed, 75 insertions(+), 3 deletions(-)
diff -puN src/org/openstreetmap/josm/actions/JoinNodeWayAction.java~AddNodeToWayCommand src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
--- core/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java~AddNodeToWayCommand 2008-05-03 12:08:41.000000000 -0700
+++ core-dave/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java 2008-05-03 12:08:41.000000000 -0700
@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.command.AddNodeToWayCommand;
import org.openstreetmap.josm.command.ChangeCommand;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.SequenceCommand;
@@ -55,11 +56,10 @@ public class JoinNodeWayAction extends J
Collection<Command> cmds = new LinkedList<Command>();
for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) {
Way w = insertPoint.getKey();
- Way wnew = new Way(w);
List<Integer> is = insertPoint.getValue();
pruneSuccsAndReverse(is);
- for (int i : is) wnew.nodes.add(i+1, node);
- cmds.add(new ChangeCommand(w, wnew));
+ for (int i : is)
+ cmds.add(new AddNodeToWayCommand(w, node, i+1));
}
Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds));
diff -puN /dev/null src/org/openstreetmap/josm/command/AddNodeToWayCommand.java
--- /dev/null 2008-02-29 08:37:01.000000000 -0800
+++ core-dave/src/org/openstreetmap/josm/command/AddNodeToWayCommand.java 2008-05-03 12:08:41.000000000 -0700
@@ -0,0 +1,72 @@
+// 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 adds a node to a way, possibly in a particular location
+ *
+ * @author daveh
+ */
+public class AddNodeToWayCommand 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 AddNodeToWayCommand(Way _way, Node _node) {
+ this.way = _way;
+ this.node = _node;
+ }
+ public AddNodeToWayCommand(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.nodes.size();
+ way.addNode(node);
+ } else
+ way.addNodeNr(location, node);
+ //Main.ds.rl.addWayToNodeMap(node, way);
+ way.modified = true;
+ return true;
+ }
+
+ @Override public void undoCommand() {
+ Node removed = way.removeNode(location);
+ if (removed != node)
+ Main.debug("removed wrong node");
+ //Main.ds.rl.removeWayFromNodeMap(removed, 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("AddNodeToWay")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
+ }
+}
_
More information about the josm-dev
mailing list