source: josm/src/org/openstreetmap/josm/command/ChangePropertyCommand.java@ 106

Last change on this file since 106 was 106, checked in by imi, 18 years ago
  • fixed import from GPX (time not read somtimes)
  • fixed delete mode does not join line segments
  • fixed incomplete segments not occour in segment list (=does not get updated on merge)
  • added josm/ignore will ignore the object on uploads
File size: 2.6 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;
7import java.util.LinkedList;
8import java.util.List;
9
10import javax.swing.JLabel;
11import javax.swing.tree.DefaultMutableTreeNode;
12import javax.swing.tree.MutableTreeNode;
13
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * Command that manipulate the key/value structure of several objects. Manages deletion,
20 * adding and modify of values and keys.
21 *
22 * @author imi
23 */
24public class ChangePropertyCommand extends Command {
25 /**
26 * All primitives, that are affected with this command.
27 */
28 private final List<OsmPrimitive> objects;
29 /**
30 * The key that is subject to change.
31 */
32 private final String key;
33 /**
34 * The key value. If it is <code>null</code>, delete all key references with the given
35 * key. Else, change the properties of all objects to the given value or create keys of
36 * those objects that do not have the key yet.
37 */
38 private final String value;
39
40 public ChangePropertyCommand(Collection<OsmPrimitive> objects, String key, String value) {
41 this.objects = new LinkedList<OsmPrimitive>(objects);
42 this.key = key;
43 this.value = value;
44 }
45
46 @Override public void executeCommand() {
47 super.executeCommand(); // save old
48 if (value == null) {
49 for (OsmPrimitive osm : objects) {
50 osm.modified = true;
51 osm.remove(key);
52 }
53 } else {
54 for (OsmPrimitive osm : objects) {
55 osm.modified = true;
56 osm.put(key, value);
57 }
58 }
59 }
60
61 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
62 modified.addAll(objects);
63 }
64
65 @Override public MutableTreeNode description() {
66 String text = value == null ? tr( "Remove \"{0}\" for", key) : tr("Set {0}={1} for",key,value);
67 if (objects.size() == 1) {
68 NameVisitor v = new NameVisitor();
69 objects.iterator().next().visit(v);
70 text += " "+v.className+" "+v.name;
71 } else
72 text += objects.size()+trn("object","objects",objects.size());
73 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(text, ImageProvider.get("data", "key"), JLabel.HORIZONTAL));
74 if (objects.size() == 1)
75 return root;
76 NameVisitor v = new NameVisitor();
77 for (OsmPrimitive osm : objects) {
78 osm.visit(v);
79 root.add(new DefaultMutableTreeNode(v.toLabel()));
80 }
81 return root;
82 }
83}
Note: See TracBrowser for help on using the repository browser.