| 1 | //License: GPL. Copyright 2007 by Immanuel Scholz and others
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.GridBagLayout;
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.awt.event.KeyEvent;
|
|---|
| 9 | import java.util.ArrayList;
|
|---|
| 10 | import java.util.Collection;
|
|---|
| 11 | import java.util.HashMap;
|
|---|
| 12 | import java.util.HashSet;
|
|---|
| 13 | import java.util.LinkedList;
|
|---|
| 14 | import java.util.Map;
|
|---|
| 15 | import java.util.Set;
|
|---|
| 16 | import java.util.TreeMap;
|
|---|
| 17 | import java.util.TreeSet;
|
|---|
| 18 | import java.util.Map.Entry;
|
|---|
| 19 |
|
|---|
| 20 | import javax.swing.Box;
|
|---|
| 21 | import javax.swing.JComboBox;
|
|---|
| 22 | import javax.swing.JLabel;
|
|---|
| 23 | import javax.swing.JOptionPane;
|
|---|
| 24 | import javax.swing.JPanel;
|
|---|
| 25 |
|
|---|
| 26 | import org.openstreetmap.josm.Main;
|
|---|
| 27 | import org.openstreetmap.josm.command.ChangeCommand;
|
|---|
| 28 | import org.openstreetmap.josm.command.Command;
|
|---|
| 29 | import org.openstreetmap.josm.command.DeleteCommand;
|
|---|
| 30 | import org.openstreetmap.josm.command.SequenceCommand;
|
|---|
| 31 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
|---|
| 32 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 33 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 34 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 35 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 36 | import org.openstreetmap.josm.data.osm.RelationMember;
|
|---|
| 37 | import org.openstreetmap.josm.data.osm.TigerUtils;
|
|---|
| 38 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 39 | import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
|
|---|
| 40 | import org.openstreetmap.josm.tools.GBC;
|
|---|
| 41 | import org.openstreetmap.josm.tools.Pair;
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | /**
|
|---|
| 45 | * Merge two or more nodes into one node - variant that uses the other node.
|
|---|
| 46 | * (based on MergeNodesAction)
|
|---|
| 47 | *
|
|---|
| 48 | * @author Henry Loenwind, based on work of Matthew Newton
|
|---|
| 49 | *
|
|---|
| 50 | */
|
|---|
| 51 | public class MergeNodes2Action extends MergeNodesAction implements SelectionChangedListener {
|
|---|
| 52 |
|
|---|
| 53 | public MergeNodes2Action() {
|
|---|
| 54 | super(tr("Merge Nodes (2)"), "mergenodes", tr("Merge nodes into the newest one."), 0, 0, true);
|
|---|
| 55 | DataSet.selListeners.add(this);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | public void actionPerformed(ActionEvent event) {
|
|---|
| 59 | Collection<OsmPrimitive> selection = Main.ds.getSelected();
|
|---|
| 60 | LinkedList<Node> selectedNodes = new LinkedList<Node>();
|
|---|
| 61 | Node useNode = null;
|
|---|
| 62 |
|
|---|
| 63 | // the selection check should stop this procedure starting if
|
|---|
| 64 | // nothing but node are selected - otherwise we don't care
|
|---|
| 65 | // anyway as long as we have at least two nodes
|
|---|
| 66 | for (OsmPrimitive osm : selection)
|
|---|
| 67 | if (osm instanceof Node){
|
|---|
| 68 | selectedNodes.add((Node)osm);
|
|---|
| 69 | useNode = (Node)osm;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | if (selectedNodes.size() < 2) {
|
|---|
| 73 | JOptionPane.showMessageDialog(Main.parent, tr("Please select at least two nodes to merge."));
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | mergeNodes(selectedNodes, useNode);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | }
|
|---|