View Javadoc

1   package fr.ove.applet;
2   
3   import java.util.*;
4   import fr.ove.applet.AppletLoadingChecked;
5   import fr.ove.applet.ListenableApplet;
6   import fr.ove.applet.events.AppletListener;
7   import fr.ove.applet.events.AppletEvent;
8   
9   /***
10  * This is an implementation of the <CODE>ListenableApplet</CODE> interface.<BR>
11  * This applet takes as argument a parameter named <CODE>name</CODE> which
12  * represents the name the instance to identify it for futher treatments and
13  * for registration.<BR>
14  * Maintains a list of listeners (<CODE>AppletListener</CODE>) of the instance
15  * and fires to them an event (<CODE>AppletEvent</CODE>) for each change.
16  * <P>
17  * This class is an final class, so it can't be overloaded.
18  *
19  * @author © 1999 DIRAT Laurent
20  * @version 1.0  30/04/99
21  */
22  public final class AListenableApplet extends AppletLoadingChecked implements ListenableApplet {
23      /***
24      * The name of the applet.<BR>
25      * We need to identify the instance for further treatments
26      */
27      private String name;
28  
29      /***
30      * The list of listeners of the instance.
31      */
32      private Vector listeners = new Vector();
33  
34      public void init() {
35          super.init();
36          name = getParameter("name");
37      }
38  
39      /***
40      * Sets the name of the applet.
41      * @param name the name of the applet.
42      */
43      public void setName(String name) {
44          this.name = name;
45      }
46  
47      /***
48      * Returns the name of the applet.
49      */
50      public String getName() {
51          return name;
52      }
53  
54      /***
55      * Registers a listener of the instance.
56      */
57      public void addAppletListener(AppletListener appletListener) {
58          if (!listeners.contains(appletListener))
59              listeners.addElement(appletListener);
60      }
61  
62      /***
63      * Unregisters the specified listener of the instance.
64      * @param appletListener the listener to remove.
65      */
66      public void removeAppletListener(AppletListener appletListener) {
67          listeners.removeElement(appletListener);
68      }
69  
70      /***
71      * Fires an event to all the registered listeners of the instance.
72      * @param appletEvent the event to fire.
73      */
74      public void fireAppletEvent(AppletEvent appletEvent) {
75          for (int i = 0; i < listeners.size(); i++)
76            ((AppletListener) listeners.elementAt(i)).consumeAppletEvent(appletEvent);
77      }
78  }