001// License: GPL. See LICENSE file for details. 002package org.openstreetmap.josm.command; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Collection; 007import java.util.HashSet; 008import java.util.List; 009import java.util.Set; 010 011import javax.swing.Icon; 012 013import org.openstreetmap.josm.data.osm.Node; 014import org.openstreetmap.josm.data.osm.OsmPrimitive; 015import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 016import org.openstreetmap.josm.data.osm.Way; 017import org.openstreetmap.josm.gui.DefaultNameFormatter; 018import org.openstreetmap.josm.tools.ImageProvider; 019 020/** 021 * Command that removes a set of nodes from a way. 022 * The same can be done with ChangeNodesCommand, but this is more 023 * efficient. (Needed for the tool to disconnect nodes from ways.) 024 * 025 * @author Giuseppe Bilotta 026 */ 027public class RemoveNodesCommand extends Command { 028 029 private final Way way; 030 private final Set<Node> rmNodes; 031 032 /** 033 * Constructs a new {@code RemoveNodesCommand}. 034 * @param way The way to modify 035 * @param rmNodes The list of nodes to remove 036 */ 037 public RemoveNodesCommand(Way way, List<Node> rmNodes) { 038 this.way = way; 039 this.rmNodes = new HashSet<>(rmNodes); 040 } 041 042 @Override 043 public boolean executeCommand() { 044 super.executeCommand(); 045 way.removeNodes(rmNodes); 046 way.setModified(true); 047 return true; 048 } 049 050 @Override 051 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 052 modified.add(way); 053 } 054 055 @Override 056 public String getDescriptionText() { 057 return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance())); 058 } 059 060 @Override 061 public Icon getDescriptionIcon() { 062 return ImageProvider.get(OsmPrimitiveType.WAY); 063 } 064}