Changeset 2341 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-10-28T19:33:49+01:00 (14 years ago)
Author:
Gubaer
Message:

applied #3798: patch by bastiK: Merge nodes tool - respect selection order

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r2333 r2341  
    33
    44import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing;
    76import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing;
     
    1413import java.util.Collection;
    1514import java.util.HashSet;
     15import java.util.LinkedHashSet;
    1616import java.util.LinkedList;
    1717import java.util.List;
     
    5454            return;
    5555        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    56         Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
     56        LinkedHashSet<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
    5757        if (selectedNodes.size() < 2) {
    5858            JOptionPane.showMessageDialog(
     
    7474
    7575    /**
    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      *
     76     * Find which node to merge into (i.e. which one will be left)
     77     * The last selected node will become the target node the remaining
     78     * nodes are merged to.
     79     * 
    7980     * @param candidates the collection of candidate nodes
    8081     * @return the selected target node
    8182     */
    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.)  :-(
     83    public static Node selectTargetNode(LinkedHashSet<Node> candidates) {
    9484        Node targetNode = null;
    95         for (Node n: candidates) {
    96             if (!n.isNew()) {
    97                 targetNode = n;
    98                 break;
    99             }
    100         }
    101         if (targetNode == null) {
    102             // an arbitrary node
    103             targetNode = candidates.iterator().next();
     85        for (Node n : candidates) { // pick last one
     86            targetNode = n;
    10487        }
    10588        return targetNode;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2309 r2341  
    1111import java.util.HashMap;
    1212import java.util.HashSet;
     13import java.util.LinkedHashSet;
    1314import java.util.LinkedList;
    1415import java.util.List;
     
    8384     * @return the sub-set of OSM primitives of type <code>type</code>
    8485     */
    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                }
    9193            }
    9294        }
Note: See TracChangeset for help on using the changeset viewer.