source: josm/src/org/openstreetmap/josm/command/AddCommand.java@ 94

Last change on this file since 94 was 94, checked in by imi, 18 years ago
  • changed Add Way mode, so that ways can be modified
  • added Command Stack dialog (list the undo buffer)
  • fixed Exception in download gps data
File size: 1.4 KB
Line 
1package org.openstreetmap.josm.command;
2
3import java.util.Collection;
4
5import javax.swing.JLabel;
6import javax.swing.tree.DefaultMutableTreeNode;
7import javax.swing.tree.MutableTreeNode;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
12import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
13import 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 */
21public 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}
Note: See TracBrowser for help on using the repository browser.