src/share/classes/java/util/Observable.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  27 
  28 /**
  29  * This class represents an observable object, or "data"
  30  * in the model-view paradigm. It can be subclassed to represent an
  31  * object that the application wants to have observed.
  32  * <p>
  33  * An observable object can have one or more observers. An observer
  34  * may be any object that implements interface <tt>Observer</tt>. After an
  35  * observable instance changes, an application calling the
  36  * <code>Observable</code>'s <code>notifyObservers</code> method
  37  * causes all of its observers to be notified of the change by a call
  38  * to their <code>update</code> method.
  39  * <p>
  40  * The order in which notifications will be delivered is unspecified.
  41  * The default implementation provided in the Observable class will
  42  * notify Observers in the order in which they registered interest, but
  43  * subclasses may change this order, use no guaranteed order, deliver
  44  * notifications on separate threads, or may guarantee that their
  45  * subclass follows this order, as they choose.
  46  * <p>
  47  * Note that this notification mechanism is has nothing to do with threads
  48  * and is completely separate from the <tt>wait</tt> and <tt>notify</tt>
  49  * mechanism of class <tt>Object</tt>.
  50  * <p>
  51  * When an observable object is newly created, its set of observers is
  52  * empty. Two observers are considered the same if and only if the
  53  * <tt>equals</tt> method returns true for them.
  54  *
  55  * @author  Chris Warth
  56  * @see     java.util.Observable#notifyObservers()
  57  * @see     java.util.Observable#notifyObservers(java.lang.Object)
  58  * @see     java.util.Observer
  59  * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
  60  * @since   JDK1.0
  61  */
  62 public class Observable {
  63     private boolean changed = false;
  64     private Vector obs;
  65 
  66     /** Construct an Observable with zero Observers. */
  67 


   1 /*
   2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  27 
  28 /**
  29  * This class represents an observable object, or "data"
  30  * in the model-view paradigm. It can be subclassed to represent an
  31  * object that the application wants to have observed.
  32  * <p>
  33  * An observable object can have one or more observers. An observer
  34  * may be any object that implements interface <tt>Observer</tt>. After an
  35  * observable instance changes, an application calling the
  36  * <code>Observable</code>'s <code>notifyObservers</code> method
  37  * causes all of its observers to be notified of the change by a call
  38  * to their <code>update</code> method.
  39  * <p>
  40  * The order in which notifications will be delivered is unspecified.
  41  * The default implementation provided in the Observable class will
  42  * notify Observers in the order in which they registered interest, but
  43  * subclasses may change this order, use no guaranteed order, deliver
  44  * notifications on separate threads, or may guarantee that their
  45  * subclass follows this order, as they choose.
  46  * <p>
  47  * Note that this notification mechanism has nothing to do with threads
  48  * and is completely separate from the <tt>wait</tt> and <tt>notify</tt>
  49  * mechanism of class <tt>Object</tt>.
  50  * <p>
  51  * When an observable object is newly created, its set of observers is
  52  * empty. Two observers are considered the same if and only if the
  53  * <tt>equals</tt> method returns true for them.
  54  *
  55  * @author  Chris Warth
  56  * @see     java.util.Observable#notifyObservers()
  57  * @see     java.util.Observable#notifyObservers(java.lang.Object)
  58  * @see     java.util.Observer
  59  * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
  60  * @since   JDK1.0
  61  */
  62 public class Observable {
  63     private boolean changed = false;
  64     private Vector obs;
  65 
  66     /** Construct an Observable with zero Observers. */
  67