Ticket #3798: merge-order.patch
| File merge-order.patch, 3.9 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/MergeNodesAction.java
13 13 import java.util.ArrayList; 14 14 import java.util.Collection; 15 15 import java.util.HashSet; 16 import java.util.LinkedHashSet; 16 17 import java.util.LinkedList; 17 18 import java.util.List; 18 19 import java.util.Set; … … 53 54 if (!isEnabled()) 54 55 return; 55 56 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 56 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);57 LinkedHashSet<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 57 58 if (selectedNodes.size() < 2) { 58 59 JOptionPane.showMessageDialog( 59 60 Main.parent, … … 73 74 } 74 75 75 76 /** 76 * Selects a node out of a collection of candidate nodes. The selected 77 * node will become the target node the remaining nodes are merged to. 78 * 77 * Find which node to merge into (i.e. which one will be left) 78 * The selected node will become the target node the remaining 79 * nodes are merged to. 80 * It will be the last node in the list. 81 * 79 82 * @param candidates the collection of candidate nodes 80 83 * @return the selected target node 81 84 */ 82 public static Node selectTargetNode(Collection<Node> candidates) { 83 // Find which node to merge into (i.e. which one will be left) 84 // - this should be combined from two things: 85 // 1. It will be the first node in the list that has a 86 // positive ID number, OR the first node. 87 // 2. It will be at the position of the first node in the 88 // list. 89 // 90 // *However* - there is the problem that the selection list is 91 // _not_ in the order that the nodes were clicked on, meaning 92 // that the user doesn't know which node will be chosen (so 93 // (2) is not implemented yet.) :-( 85 public static Node selectTargetNode(LinkedHashSet<Node> candidates) { 94 86 Node targetNode = null; 95 for (Node n: candidates) { 96 if (!n.isNew()) { 97 targetNode = n; 98 break; 99 } 87 for (Node n : candidates) { // pick last one 88 targetNode = n; 100 89 } 101 if (targetNode == null) {102 // an arbitrary node103 targetNode = candidates.iterator().next();104 }105 90 return targetNode; 106 91 } 107 92 -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
10 10 import java.util.Date; 11 11 import java.util.HashMap; 12 12 import java.util.HashSet; 13 import java.util.LinkedHashSet; 13 14 import java.util.LinkedList; 14 15 import java.util.List; 15 16 import java.util.Locale; … … 82 83 * @param type the type to filter for 83 84 * @return the sub-set of OSM primitives of type <code>type</code> 84 85 */ 85 static public <T extends OsmPrimitive> Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) { 86 if (set == null) return Collections.emptySet(); 87 HashSet<T> ret = new HashSet<T>(); 88 for(OsmPrimitive p: set) { 89 if (type.isInstance(p)) { 90 ret.add(type.cast(p)); 86 static public <T extends OsmPrimitive> LinkedHashSet<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) { 87 LinkedHashSet<T> ret = new LinkedHashSet<T>(); 88 if (set != null) { 89 for(OsmPrimitive p: set) { 90 if (type.isInstance(p)) { 91 ret.add(type.cast(p)); 92 } 91 93 } 92 94 } 93 95 return ret;
