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.Way;
015import org.openstreetmap.josm.data.osm.OsmPrimitive;
016import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
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    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
033        super();
034        this.way = way;
035        this.rmNodes = new HashSet<Node>(rmNodes);
036    }
037
038    @Override public boolean executeCommand() {
039        super.executeCommand();
040        way.removeNodes(rmNodes);
041        way.setModified(true);
042        return true;
043    }
044
045    @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
046        modified.add(way);
047    }
048
049    @Override
050    public String getDescriptionText() {
051        return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
052    }
053
054    @Override
055    public Icon getDescriptionIcon() {
056        return ImageProvider.get(OsmPrimitiveType.WAY);
057    }
058}