source: josm/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java@ 23

Last change on this file since 23 was 23, checked in by imi, 19 years ago
  • added commands to support undo later
  • added Edit-Layer concept
  • painting of deleted objects
File size: 2.3 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Map;
4
5import org.openstreetmap.josm.Main;
6import org.openstreetmap.josm.data.osm.visitor.Visitor;
7
8
9/**
10 * An OSM primitive can be associated with a key/value pair. It can be created, deleted
11 * and updated within the OSM-Server.
12 *
13 * @author imi
14 */
15abstract public class OsmPrimitive {
16
17 /**
18 * The key/value list for this primitive.
19 */
20 public Map<Key, String> keys;
21
22 /**
23 * Unique identifier in OSM. This is used to reidentify objects in the server.
24 * An id of 0 means an unknown id. The object has not been uploaded yet to
25 * know what id it will get.
26 */
27 public long id = 0;
28
29 /**
30 * If set to true, this object has been modified in the current session.
31 */
32 transient public boolean modified = false;
33
34 /**
35 * If set to true, this object is currently selected.
36 */
37 transient private boolean selected = false;
38
39 /**
40 * Implementation of the visitor scheme. Subclases have to call the correct
41 * visitor function.
42 * @param visitor The visitor from which the visit() function must be called.
43 */
44 abstract public void visit(Visitor visitor);
45
46 /**
47 * Return <code>true</code>, if either <code>this.keys</code> and
48 * <code>other.keys</code> is <code>null</code> or if they do not share Keys
49 * with different values.
50 *
51 * @param other The second key-set to compare with.
52 * @return True, if the keysets are mergable
53 */
54 public boolean keyPropertiesMergable(OsmPrimitive other) {
55 if ((keys == null) != (other.keys == null))
56 return false;
57
58 if (keys != null) {
59 for (Key k : keys.keySet())
60 if (other.keys.containsKey(k) && !keys.get(k).equals(other.keys.get(k)))
61 return false;
62 for (Key k : other.keys.keySet())
63 if (keys.containsKey(k) && !other.keys.get(k).equals(keys.get(k)))
64 return false;
65 }
66 return true;
67 }
68
69 /**
70 * Mark the primitive as selected or not selected and fires a selection
71 * changed later, if the value actualy changed.
72 * @param selected Whether the primitive should be selected or not.
73 */
74 public void setSelected(boolean selected) {
75 if (selected != this.selected)
76 Main.main.ds.fireSelectionChanged();
77 this.selected = selected;
78 }
79
80 /**
81 * @return Return whether the primitive is selected on screen.
82 */
83 public boolean isSelected() {
84 return selected;
85 }
86}
Note: See TracBrowser for help on using the repository browser.