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

Last change on this file since 1826 was 1814, checked in by Gubaer, 15 years ago

removed dependencies to Main.ds, removed Main.ds
removed AddVisitor, NameVisitor, DeleteVisitor - unnecessary double dispatching for these simple cases

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JLabel;
9import javax.swing.tree.DefaultMutableTreeNode;
10import javax.swing.tree.MutableTreeNode;
11
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * A command that adds an osm primitive to a dataset. Keys cannot be added this
19 * way.
20 *
21 * See {@see ChangeCommand} for comments on relation back references.
22 *
23 * @author imi
24 */
25public class AddCommand extends Command {
26
27 /**
28 * The primitive to add to the dataset.
29 */
30 private final OsmPrimitive osm;
31
32 /**
33 * Create the command and specify the element to add.
34 */
35 public AddCommand(OsmPrimitive osm) {
36 super();
37 this.osm = osm;
38 }
39
40 @Override public boolean executeCommand() {
41 getLayer().data.addPrimitive(osm);
42 return true;
43 }
44
45 @Override public void undoCommand() {
46 getLayer().data.removePrimitive(osm);
47 }
48
49 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
50 added.add(osm);
51 }
52
53 @Override public MutableTreeNode description() {
54 return new DefaultMutableTreeNode(
55 new JLabel(
56 tr("Add {0} {1}",
57 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
58 new PrimitiveNameFormatter().getName(osm)
59 ),
60 ImageProvider.get(OsmPrimitiveType.from(osm)),
61 JLabel.HORIZONTAL
62 )
63 );
64 }
65}
Note: See TracBrowser for help on using the repository browser.