My favorites | Sign in
Project Logo
                
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package petrieditor.util;

import java.util.Vector;

/**
* @author wiktor
*/
public class Observable<S extends Observable<S, O, A>, O extends Observer<S, O, A>, A> {
private transient boolean changed = false;
private transient Vector<O> obs = new Vector<O>();

public synchronized void addObserver(O o) {
if (o == null)
throw new NullPointerException();
if (!obs.contains(o))
obs.addElement(o);
}

public synchronized void deleteObserver(O o) {
obs.removeElement(o);
}

public void setChangedAndNotifyObservers() {
setChanged();
notifyObservers();
}

public void setChangedAndNotifyObservers(A arg) {
setChanged();
notifyObservers(arg);
}

public void notifyObservers() {
notifyObservers(null);
}

public void notifyObservers(A arg) {
Vector<O> obsLocal = new Vector<O>();

synchronized (this) {
if (!changed)
return;
copy(obsLocal, obs);
obs.toArray();
clearChanged();
}

for (O o : obsLocal)
o.update(this, arg);
}

private static <O> void copy(Vector<O> dest, Vector<O> src) {
for (O o : src)
dest.add(o);
}

public synchronized void deleteObservers() {
obs.removeAllElements();
}

protected synchronized void setChanged() {
changed = true;
}

protected synchronized void clearChanged() {
changed = false;
}

public synchronized boolean hasChanged() {
return changed;
}

public synchronized int countObservers() {
return obs.size();
}

/**
* Metoda jest wolana podczas deserializacji ze wzgledu na to, ze changed i obs sa transient.
* @return Referencje do samego siebie.
*/
@SuppressWarnings({"UnusedDeclaration"})
private Object readResolve() {
changed = false;
obs = new Vector<O>();
return this;
}

}
Show details Hide details

Change log

r20 by uj.code on Apr 22, 2007   Diff
Gotowa czesc wizualna. Brakuje na razie
symulacji i modulow :)
Go to: 
Project members, sign in to write a code review

Older revisions

r9 by uj.code on Apr 16, 2007   Diff
[No log message]
r3 by uj.code on Apr 14, 2007   Diff
[No log message]
All revisions of this file

File info

Size: 2113 bytes, 88 lines
Hosted by Google Code