001 // License: GPL. See LICENSE file for details. 002 package org.openstreetmap.josm.command; 003 004 import static org.openstreetmap.josm.tools.I18n.tr; 005 006 import java.util.Collection; 007 import java.util.List; 008 import javax.swing.Icon; 009 010 import org.openstreetmap.josm.data.osm.Node; 011 import org.openstreetmap.josm.data.osm.Way; 012 import org.openstreetmap.josm.data.osm.OsmPrimitive; 013 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 014 import org.openstreetmap.josm.gui.DefaultNameFormatter; 015 import org.openstreetmap.josm.tools.ImageProvider; 016 017 /** 018 * Command that changes the nodes list of a way. 019 * The same can be done with ChangeCommand, but this is more 020 * efficient. (Needed for the duplicate node fixing 021 * tool of the validator plugin, when processing large data sets.) 022 * 023 * @author Imi 024 */ 025 public class ChangeNodesCommand extends Command { 026 027 private final Way way; 028 private final List<Node> newNodes; 029 030 public ChangeNodesCommand(Way way, List<Node> newNodes) { 031 super(); 032 this.way = way; 033 this.newNodes = newNodes; 034 } 035 036 @Override public boolean executeCommand() { 037 super.executeCommand(); 038 way.setNodes(newNodes); 039 way.setModified(true); 040 return true; 041 } 042 043 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 044 modified.add(way); 045 } 046 047 @Override 048 public String getDescriptionText() { 049 return tr("Changed nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance())); 050 } 051 052 @Override 053 public Icon getDescriptionIcon() { 054 return ImageProvider.get(OsmPrimitiveType.WAY); 055 } 056 }