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

Last change on this file since 22 was 22, checked in by imi, 19 years ago

starting restructure of dataset. Checkpoint is broken!

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