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

Last change on this file since 1951 was 1857, checked in by Gubaer, 15 years ago

replaced JOptionDialog.show... by OptionPaneUtil.show....
improved relation editor

  • Property svn:eol-style set to native
File size: 2.1 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.gui.layer.OsmDataLayer;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * A command that adds an osm primitive to a dataset. Keys cannot be added this
20 * way.
21 *
22 * See {@see ChangeCommand} for comments on relation back references.
23 *
24 * @author imi
25 */
26public class AddCommand extends Command {
27
28 /**
29 * The primitive to add to the dataset.
30 */
31 private final OsmPrimitive osm;
32
33 /**
34 * Create the command and specify the element to add.
35 */
36 public AddCommand(OsmPrimitive osm) {
37 super();
38 this.osm = osm;
39 }
40
41 /**
42 * Create the command and specify the element to add.
43 */
44 public AddCommand(OsmDataLayer layer, OsmPrimitive osm) {
45 super(layer);
46 this.osm = osm;
47 }
48
49 @Override public boolean executeCommand() {
50 getLayer().data.addPrimitive(osm);
51 return true;
52 }
53
54 @Override public void undoCommand() {
55 getLayer().data.removePrimitive(osm);
56 }
57
58 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
59 added.add(osm);
60 }
61
62 @Override public MutableTreeNode description() {
63 return new DefaultMutableTreeNode(
64 new JLabel(
65 tr("Add {0} {1}",
66 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(),
67 new PrimitiveNameFormatter().getName(osm)
68 ),
69 ImageProvider.get(OsmPrimitiveType.from(osm)),
70 JLabel.HORIZONTAL
71 )
72 );
73 }
74}
Note: See TracBrowser for help on using the repository browser.