source: josm/src/org/openstreetmap/josm/command/DeleteCommand.java@ 104

Last change on this file since 104 was 104, checked in by imi, 18 years ago
  • started i18n
  • started "download incomplete ways" action
  • added straight line selection mode
File size: 1.9 KB
Line 
1package org.openstreetmap.josm.command;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4import static org.openstreetmap.josm.tools.I18n.trn;
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.visitor.NameVisitor;
14import org.openstreetmap.josm.tools.ImageProvider;
15
16/**
17 * A command to delete a number of primitives from the dataset.
18 * @author imi
19 */
20public class DeleteCommand extends Command {
21
22 /**
23 * The primitive that get deleted.
24 */
25 private final Collection<OsmPrimitive> data;
26
27 public DeleteCommand(Collection<OsmPrimitive> data) {
28 this.data = data;
29 }
30
31 @Override public void executeCommand() {
32 super.executeCommand();
33 for (OsmPrimitive osm : data)
34 osm.delete(true);
35 }
36
37 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
38 deleted.addAll(data);
39 }
40
41 @Override public MutableTreeNode description() {
42 NameVisitor v = new NameVisitor();
43
44 if (data.size() == 1) {
45 data.iterator().next().visit(v);
46 return new DefaultMutableTreeNode(new JLabel(tr("Delete"+" "+v.className+" "+v.name), v.icon, JLabel.HORIZONTAL));
47 }
48
49 String cname = null;
50 for (OsmPrimitive osm : data) {
51 osm.visit(v);
52 if (cname == null)
53 cname = v.className;
54 else if (!cname.equals(v.className))
55 cname = "primitive";
56 }
57 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(
58 tr("Delete")+" "+data.size()+" "+trn(cname, cname+"s", data.size()), ImageProvider.get("data", cname), JLabel.HORIZONTAL));
59 for (OsmPrimitive osm : data) {
60 osm.visit(v);
61 root.add(new DefaultMutableTreeNode(v.toLabel()));
62 }
63 return root;
64 }
65}
Note: See TracBrowser for help on using the repository browser.