Changeset 5080 in osm for applications
- Timestamp:
- 2007-10-19T12:47:09+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/MergeNodesAction.java
r5076 r5080 4 4 5 5 import java.util.ArrayList; 6 import java.util.HashSet; 6 7 import java.util.LinkedList; 7 8 import java.util.Collection; … … 36 37 public void actionPerformed(ActionEvent e) { 37 38 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 38 Collection<Node> nodes = new ArrayList<Node>();39 HashSet<Node> nodes = new HashSet<Node>(); 39 40 40 41 for (OsmPrimitive osm : sel) … … 59 60 60 61 Node newTarget = new Node(target); 61 cmds.add(new ChangeCommand(target, newTarget));62 62 63 63 // Don't place the merged node on one of the former nodes. … … 71 71 x / nodes.size(), y / nodes.size()); 72 72 73 nodes.remove(target);73 cmds.add(new ChangeCommand(target, newTarget)); 74 74 75 cmds.add(new DeleteCommand(nodes)); 75 HashSet<Node> delNodes = new HashSet<Node>(nodes); 76 delNodes.remove(target); 77 cmds.add(new DeleteCommand(delNodes)); 76 78 77 79 for (Way w : Main.ds.ways) { … … 87 89 if (!affected) continue; 88 90 89 // Replace the old nodes with the merged one s91 // Replace the old nodes with the merged one 90 92 Way wnew = new Way(w); 91 93 for (int i = 0; i < wnew.nodes.size(); i++) { 92 94 if (nodes.contains(wnew.nodes.get(i))) { 93 wnew.nodes.set(i, newTarget);95 wnew.nodes.set(i, target); 94 96 } 95 97 } … … 98 100 Node lastN = null; 99 101 for (int i = wnew.nodes.size() - 1; i >= 0; i--) { 100 if (lastN == wnew.nodes.get(i)) { 101 wnew.nodes.remove(i); 102 if (i < wnew.nodes.size()) i++; 103 } 102 Node n = wnew.nodes.get(i); 103 if (lastN == n) wnew.nodes.remove(i); 104 lastN = n; 104 105 } 105 106 … … 111 112 JOptionPane.showMessageDialog(Main.parent, 112 113 tr("Cannot merge nodes: " + 113 "Would have to delete way that is still used."));114 "Would have to delete a way that is still used.")); 114 115 return; 115 116 } … … 122 123 123 124 Main.main.undoRedo.add(new SequenceCommand(tr("Merge Nodes"), cmds)); 125 Main.ds.setSelected(newTarget); 124 126 Main.map.repaint(); 125 127 }
Note:
See TracChangeset
for help on using the changeset viewer.