Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Observable.java

00001 class Observable 
00002 {
00003      protected boolean changed;
00004      protected Vector obs;
00005      
00006      public Observable()
00007      {
00008           this.changed = false;
00009           this.obs = new Vector();
00010      }
00011      
00012      public synchronized void addObserver (Observer o)
00013      {
00014           if (!this.obs.contains(o))
00015           {
00016                this.obs.addElement(o);
00017           }
00018      }
00019      
00020      protected synchronized void clearChanged ()
00021      {
00022           this.changed = false;
00023      }
00024      
00025      public synchronized int countObservers ()
00026      {
00027           return this.obs.size();
00028      }
00029      
00030      public synchronized void deleteObserver (Observer o)
00031      {
00032           this.obs.removeElement(o);
00033      }
00034      
00035      public synchronized void deleteObservers ()
00036      {
00037           this.obs.removeAllElements();
00038      }
00039      
00040      public synchronized boolean hasChanged ()
00041      {
00042           return this.changed;
00043      }
00044      
00045      public void notifyObservers ()
00046      {
00047           this.notifyObservers(null);
00048      }
00049      
00050      public void notifyObservers (java.lang.Object arg)
00051      {
00052           java.lang.Object[] arrLocal;
00053           synchronized (this)
00054           {
00055                if (!this.changed)
00056                {
00057                     return;
00058                }
00059                arrLocal = this.obs.toArray();
00060                this.changed = false;
00061           }
00062           for (int i = (arrLocal.length - 1); i >= 0; i = (i - 1))
00063           {
00064                ((Observer) arrLocal[i]).update(this,arg);
00065           }
00066      }
00067      
00068      protected synchronized void setChanged ()
00069      {
00070           this.changed = true;
00071      }
00072 }

Generated at Thu Feb 7 06:50:53 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001