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

Last change on this file since 2284 was 1990, checked in by Gubaer, 15 years ago

fixed #3261: Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists
new: new checkbox in LAF preferences for enabling/disabling localized names for primitives

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