1 | package org.openstreetmap.josm.command;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 |
|
---|
5 | import javax.swing.JLabel;
|
---|
6 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
7 | import javax.swing.tree.MutableTreeNode;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
11 | import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
|
---|
12 | import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * A command that adds an osm primitive to a dataset. Keys cannot be added this
|
---|
17 | * way. Use ChangeKeyValueCommand instead.
|
---|
18 | *
|
---|
19 | * @author imi
|
---|
20 | */
|
---|
21 | public class AddCommand extends Command {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * The primitive to add to the dataset.
|
---|
25 | */
|
---|
26 | private final OsmPrimitive osm;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Create the command and specify the element to add.
|
---|
30 | */
|
---|
31 | public AddCommand(OsmPrimitive osm) {
|
---|
32 | this.osm = osm;
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override public void executeCommand() {
|
---|
36 | osm.visit(new AddVisitor(Main.ds));
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override public void undoCommand() {
|
---|
40 | osm.visit(new DeleteVisitor(Main.ds));
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
44 | added.add(osm);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override public MutableTreeNode description() {
|
---|
48 | NameVisitor v = new NameVisitor();
|
---|
49 | osm.visit(v);
|
---|
50 | return new DefaultMutableTreeNode(new JLabel("Add "+v.className+" "+v.name, v.icon, JLabel.HORIZONTAL));
|
---|
51 | }
|
---|
52 | }
|
---|