home *** CD-ROM | disk | FTP | other *** search
- package java.util;
-
- public class Observable {
- private boolean changed = false;
- private Object obs;
-
- public synchronized void addObserver(Observer o) {
- if (this.obs != null) {
- if (this.obs instanceof ObserverList) {
- if (!((ObserverList)this.obs).contains(o)) {
- ((ObserverList)this.obs).addElement(o);
- return;
- }
-
- return;
- }
-
- if (this.obs != o) {
- ObserverList tmp = new ObserverList();
- ((Vector)tmp).addElement(this.obs);
- ((Vector)tmp).addElement(o);
- this.obs = tmp;
- return;
- }
- } else {
- this.obs = o;
- }
-
- }
-
- public synchronized void deleteObserver(Observer o) {
- if (this.obs == o) {
- this.obs = null;
- } else {
- if (this.obs != null && this.obs instanceof ObserverList) {
- ((ObserverList)this.obs).removeElement(o);
- }
-
- }
- }
-
- public void notifyObservers() {
- this.notifyObservers((Object)null);
- }
-
- public synchronized void notifyObservers(Object arg) {
- if (this.hasChanged()) {
- if (this.obs != null) {
- if (this.obs instanceof ObserverList) {
- ((ObserverList)this.obs).notifyObservers(this, arg);
- } else {
- ((Observer)this.obs).update(this, arg);
- }
- }
-
- this.clearChanged();
- }
-
- }
-
- public synchronized void deleteObservers() {
- this.obs = null;
- }
-
- protected synchronized void setChanged() {
- this.changed = true;
- }
-
- protected synchronized void clearChanged() {
- this.changed = false;
- }
-
- public synchronized boolean hasChanged() {
- return this.changed;
- }
-
- public synchronized int countObservers() {
- if (this.obs != null) {
- return this.obs instanceof ObserverList ? ((ObserverList)this.obs).size() : 1;
- } else {
- return 0;
- }
- }
- }
-