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

Last change on this file since 4302 was 3262, checked in by bastiK, 14 years ago

extended command list dialog; added inspection panel

  • Property svn:eol-style set to native
File size: 2.3 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.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8import java.util.Collections;
9
10import javax.swing.JLabel;
11
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.gui.DefaultNameFormatter;
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 JLabel getDescription() {
63 String msg;
64 switch(OsmPrimitiveType.from(osm)) {
65 case NODE: msg = marktr("Add node {0}"); break;
66 case WAY: msg = marktr("Add way {0}"); break;
67 case RELATION: msg = marktr("Add relation {0}"); break;
68 default: /* should not happen */msg = ""; break;
69 }
70
71 return new JLabel(
72 tr(msg, osm.getDisplayName(DefaultNameFormatter.getInstance())),
73 ImageProvider.get(OsmPrimitiveType.from(osm)),
74 JLabel.HORIZONTAL);
75 }
76
77 @Override
78 public Collection<OsmPrimitive> getParticipatingPrimitives() {
79 return Collections.singleton(osm);
80 }
81}
Note: See TracBrowser for help on using the repository browser.