source: josm/branch/0.5/src/org/openstreetmap/josm/command/AddCommand.java@ 341

Last change on this file since 341 was 329, checked in by framm, 17 years ago

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

File size: 2.0 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.Main;
13import org.openstreetmap.josm.data.osm.DataSet;
14import org.openstreetmap.josm.data.osm.Relation;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
17import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;
18import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
19import org.openstreetmap.josm.gui.layer.Layer;
20import org.openstreetmap.josm.gui.layer.OsmDataLayer;
21
22/**
23 * A command that adds an osm primitive to a dataset. Keys cannot be added this
24 * way. Use ChangeKeyValueCommand instead.
25 *
26 * See ChangeCommand for comments on relation back references.
27 *
28 * @author imi
29 */
30public class AddCommand extends Command {
31
32 /**
33 * The primitive to add to the dataset.
34 */
35 private final OsmPrimitive osm;
36
37 private DataSet ds;
38
39 /**
40 * Create the command and specify the element to add.
41 */
42 public AddCommand(OsmPrimitive osm) {
43 this.osm = osm;
44 this.ds = Main.main.editLayer().data;
45 }
46
47 @Override public void executeCommand() {
48 osm.visit(new AddVisitor(ds));
49 }
50
51 @Override public void undoCommand() {
52 osm.visit(new DeleteVisitor(ds));
53 }
54
55 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
56 added.add(osm);
57 }
58
59 // faster implementation
60 @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) {
61 return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds;
62 }
63
64 @Override public MutableTreeNode description() {
65 NameVisitor v = new NameVisitor();
66 osm.visit(v);
67 return new DefaultMutableTreeNode(new JLabel(tr("Add")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));
68 }
69}
Note: See TracBrowser for help on using the repository browser.