Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: gov/lanl/IDViewer/SourceSelectionNotifier.java


1   //SourceSelectionNotifier.java
2   
3   /*************************************
4    * Copyright Notice
5    * Copyright (c) 1999, Regents of the University of California. All rights reserved.
6   
7    * DISCLAIMER
8    * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
9    * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
10   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
11   * SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
13   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
14   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
15   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
16   * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
17   * DAMAGE.
18   ***************************************/
19  
20  package gov.lanl.IDViewer;
21  
22  import java.util.Vector;
23  
24  /**
25   * When an instance of the class SourceSelectionObserver receives a notification
26   * from a source selection dialog window, it passes it on to all of its
27   * registered observers.
28   * <P>
29   * Currently, the class <code>SourceSelectionNotifier</code> distinguishes between
30   * three types of events:
31   * <code>INACTIVE_SRC_SELECTION_CHANGED</code>  - the source selection in the source
32   *                                                 selection frame changed
33   * <code>ACTIVE_SRC_SELECTION_CHANGED</code>    - the source selection in the source
34   *                                                 client panel changed
35   * <code>INACTIVE_SRC_SELECTION_FINALIZED</code>- the user finished selecting source
36   *                                                 in the source selection frame
37   *
38   * @author  Torsten Staab
39   * @version 11/09/98     $Id: SourceSelectionNotifier.java,v 1.2 2002/06/09 14:26:01 dwforslund Exp $
40   *
41   */
42  class SourceSelectionNotifier {
43      public static final int INACTIVE_SRC_SELECTION_CHANGED = 1;  // notification events
44      public static final int ACTIVE_SRC_SELECTION_CHANGED = 2;
45      public static final int INACTIVE_SRC_SELECTION_FINALIZED = 3;
46  
47      /** vector that stores the current source selection in form of strings */
48      private Vector sourceSelectionVector = new Vector();
49      /** vector of source selection observers */
50      private Vector observers = new Vector();
51  
52  
53      /**
54       * adds a new observer to this object
55       *
56       * @param observer  the source selection observer to be added
57       */
58      public void addObserver(SourceSelectionObserver observer) {
59          observers.addElement((Object) observer);
60      } // end addObserver()
61  
62  
63      /**
64       * removes an observer from this object
65       *
66       * @param observer  the source selection observer to be removed
67       */
68      public void removeObserver(SourceSelectionObserver observer) {
69          observers.removeElement(observer);
70      } // end removeObserver()
71  
72  
73      /**
74       * This method is called when this object needs to pass on a
75       * notification to its registered observers.
76       *
77       * @param event                describes the type of event, such as
78       *      <code>INACTIVE_SRC_SELECTION_CHANGED</code>  - the source selection in the source
79       *                                                      selection frame changed
80       *      <code>ACTIVE_SRC_SELECTION_CHANGED</code>    - the source selection in the source
81       *                                                      client panel changed
82       *      <code>INACTIVE_SRC_SELECTION_FINALIZED</code>- the user finished selecting source
83       *                                                      in the source selection frame
84       * @param sourceSelectionVector  a vector that contains the current source selection in
85       *                             form of String objects
86       */
87      public void notifySourceSelectionObserver(int event, Vector sourceSelectionVector) {
88          // before we notify all observers copy the current source selection
89          // to a local vector
90          this.sourceSelectionVector.removeAllElements();
91          String selectedSource;
92          for (int i = 0; i < sourceSelectionVector.size(); i++) {
93              selectedSource = (String) sourceSelectionVector.elementAt(i);
94              this.sourceSelectionVector.addElement(selectedSource);
95          }
96          // now notify every observer about the change in the source selection
97          Object anObserver;
98          for (int i = 0; i < observers.size(); i++) {
99              anObserver = observers.elementAt(i);
100             if (anObserver != null)
101                 ((SourceSelectionObserver) anObserver).notifySourceSelectionObserver(event,
102                         this.sourceSelectionVector);
103         } // for()
104 
105     } // end notifySourceSelectionObserver()
106 
107 } // class SourceSelectionNotifier