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.List;
|
---|
8 | import javax.swing.Icon;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.osm.Node;
|
---|
11 | import org.openstreetmap.josm.data.osm.Way;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
14 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Command that changes the nodes list of a way.
|
---|
19 | * The same can be done with ChangeCommand, but this is more
|
---|
20 | * efficient. (Needed for the duplicate node fixing
|
---|
21 | * tool of the validator plugin, when processing large data sets.)
|
---|
22 | *
|
---|
23 | * @author Imi
|
---|
24 | */
|
---|
25 | public class ChangeNodesCommand extends Command {
|
---|
26 |
|
---|
27 | private final Way way;
|
---|
28 | private final List<Node> newNodes;
|
---|
29 |
|
---|
30 | public ChangeNodesCommand(Way way, List<Node> newNodes) {
|
---|
31 | super();
|
---|
32 | this.way = way;
|
---|
33 | this.newNodes = newNodes;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override public boolean executeCommand() {
|
---|
37 | super.executeCommand();
|
---|
38 | way.setNodes(newNodes);
|
---|
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("Changed nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public Icon getDescriptionIcon() {
|
---|
54 | return ImageProvider.get(OsmPrimitiveType.WAY);
|
---|
55 | }
|
---|
56 | }
|
---|