1 | // License: GPL. For details, see LICENSE file.
|
---|
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 |
|
---|
9 | import javax.swing.Icon;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Command that changes the nodes list of a way.
|
---|
20 | * The same can be done with ChangeCommand, but this is more
|
---|
21 | * efficient. (Needed for the duplicate node fixing
|
---|
22 | * tool of the validator plugin, when processing large data sets.)
|
---|
23 | *
|
---|
24 | * @author Imi
|
---|
25 | */
|
---|
26 | public class ChangeNodesCommand extends Command {
|
---|
27 |
|
---|
28 | private final Way way;
|
---|
29 | private final List<Node> newNodes;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructs a new {@code ChangeNodesCommand}.
|
---|
33 | * @param way The way to modify
|
---|
34 | * @param newNodes The new list of nodes for the given way
|
---|
35 | */
|
---|
36 | public ChangeNodesCommand(Way way, List<Node> newNodes) {
|
---|
37 | this.way = way;
|
---|
38 | this.newNodes = newNodes;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public boolean executeCommand() {
|
---|
43 | super.executeCommand();
|
---|
44 | way.setNodes(newNodes);
|
---|
45 | way.setModified(true);
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
51 | modified.add(way);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public String getDescriptionText() {
|
---|
56 | return tr("Changed nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public Icon getDescriptionIcon() {
|
---|
61 | return ImageProvider.get(OsmPrimitiveType.WAY);
|
---|
62 | }
|
---|
63 | }
|
---|