| 1 | // License: GPL. See LICENSE file for details.
|
|---|
| 2 | package org.openstreetmap.josm.command;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.util.Collection;
|
|---|
| 7 | import java.util.HashSet;
|
|---|
| 8 | import java.util.List;
|
|---|
| 9 | import javax.swing.Icon;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
|---|
| 15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
|---|
| 16 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Command that removes a set of nodes from a way.
|
|---|
| 20 | * The same can be done with ChangeNodesCommand, but this is more
|
|---|
| 21 | * efficient. (Needed for the tool to disconnect nodes from ways.)
|
|---|
| 22 | *
|
|---|
| 23 | * @author Giuseppe Bilotta
|
|---|
| 24 | */
|
|---|
| 25 | public class RemoveNodesCommand extends Command {
|
|---|
| 26 |
|
|---|
| 27 | private final Way way;
|
|---|
| 28 | private final HashSet<Node> rmNodes;
|
|---|
| 29 |
|
|---|
| 30 | public RemoveNodesCommand(Way way, List<Node> rmNodes) {
|
|---|
| 31 | super();
|
|---|
| 32 | this.way = way;
|
|---|
| 33 | this.rmNodes = new HashSet<Node>(rmNodes);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | @Override public boolean executeCommand() {
|
|---|
| 37 | super.executeCommand();
|
|---|
| 38 | way.removeNodes(rmNodes);
|
|---|
| 39 | way.setModified(true);
|
|---|
| 40 | return true;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
|---|
| 44 | modified.add(way);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | @Override
|
|---|
| 48 | public String getDescriptionText() {
|
|---|
| 49 | return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | @Override
|
|---|
| 53 | public Icon getDescriptionIcon() {
|
|---|
| 54 | return ImageProvider.get(OsmPrimitiveType.WAY);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|