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.HashSet;
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.Set;
|
---|
10 |
|
---|
11 | import javax.swing.Icon;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
17 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
18 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Command that removes a set of nodes from a way.
|
---|
22 | * The same can be done with ChangeNodesCommand, but this is more
|
---|
23 | * efficient. (Needed for the tool to disconnect nodes from ways.)
|
---|
24 | *
|
---|
25 | * @author Giuseppe Bilotta
|
---|
26 | */
|
---|
27 | public class RemoveNodesCommand extends Command {
|
---|
28 |
|
---|
29 | private final Way way;
|
---|
30 | private final Set<Node> rmNodes;
|
---|
31 |
|
---|
32 | public RemoveNodesCommand(Way way, List<Node> rmNodes) {
|
---|
33 | super();
|
---|
34 | this.way = way;
|
---|
35 | this.rmNodes = new HashSet<Node>(rmNodes);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override public boolean executeCommand() {
|
---|
39 | super.executeCommand();
|
---|
40 | way.removeNodes(rmNodes);
|
---|
41 | way.setModified(true);
|
---|
42 | return true;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
46 | modified.add(way);
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public String getDescriptionText() {
|
---|
51 | return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public Icon getDescriptionIcon() {
|
---|
56 | return ImageProvider.get(OsmPrimitiveType.WAY);
|
---|
57 | }
|
---|
58 | }
|
---|