-
Notifications
You must be signed in to change notification settings - Fork 2
/
Document.java
51 lines (43 loc) · 1.28 KB
/
Document.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.github.stippi.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Document {
private final Map<String, Property> fProperties;
private final List<DocumentListener> fListeners;
public Document() {
fProperties = new HashMap<>();
fListeners = new ArrayList<>();
}
public void setValue(String name, String value) {
Property p = fProperties.get(name);
if (p == null) {
p = new Property();
fProperties.put(name, p);
}
p.setValue(value);
notifyValueChanged(name, p);
}
public String getValue(String name) {
Property p = fProperties.get(name);
if (p != null) {
return p.getValue();
}
return "";
}
public void addListener(DocumentListener l) {
if (!fListeners.contains(l)) {
fListeners.add(l);
}
}
public void removeListener(DocumentListener l) {
fListeners.remove(l);
}
private void notifyValueChanged(String name, Property p) {
List<DocumentListener> listeners = new ArrayList<>(fListeners);
for (DocumentListener l : listeners) {
l.propertyChanged(name, p.getValue());
}
}
}