KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > repl > InteractionsEventNotifier


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32 END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.repl;
35
36 import java.io.File JavaDoc;
37
38 import edu.rice.cs.drjava.model.EventNotifier;
39
40 /** Keeps track of all listeners to an InteractionsModel, and has the ability to notify them of some event. <p>
41  * This class has a specific role of managing InteractionsListeners. Other classes with similar names use similar
42  * code to perform the same function for other interfaces, e.g. JavadocEventNotifier and GlobalEventNotifier.
43  * These classes implement the appropriate interface definition so that they can be used transparently as composite
44  * packaging for a particular listener interface. <p>
45  * Components which might otherwise manage their own list of listeners use EventNotifiers instead to simplify their
46  * internal implementation. Notifiers should therefore be considered a private implementation detail of the
47  * components, and should not be used directly outside of the "host" component. <p>
48  * All methods in this class must use the synchronization methods provided by ReaderWriterLock. This ensures
49  * that multiple notifications (reads) can occur simultaneously, but only one thread can be adding or removing
50  * listeners (writing) at a time, and no reads can occur during a write. <p>
51  * <i>No</i> methods on this class should be synchronized using traditional Java synchronization! <p>
52  * @version $Id: InteractionsEventNotifier.java 3592 2006-03-14 18:50:21Z rcartwright $
53  */

54
55 public class InteractionsEventNotifier extends EventNotifier<InteractionsListener> implements InteractionsListener {
56
57   /** Called after an interaction is started by the GlobalModel. */
58   public void interactionStarted() {
59     _lock.startRead();
60     try {
61       int size = _listeners.size();
62       for (int i = 0; i < size; i++) _listeners.get(i).interactionStarted();
63     }
64     finally { _lock.endRead(); }
65   }
66
67   /** Called when an interaction has finished running. */
68   public void interactionEnded() {
69     _lock.startRead();
70     try {
71       int size = _listeners.size();
72       for (int i = 0; i < size; i++) _listeners.get(i).interactionEnded();
73     }
74     finally { _lock.endRead(); }
75   }
76
77   /** Called when the interactions window generates a syntax error.
78    * @param offset the error's offset into the InteractionsDocument
79    * @param length the length of the error
80    */

81   public void interactionErrorOccurred(int offset, int length) {
82     _lock.startRead();
83     try {
84       int size = _listeners.size();
85       for (int i = 0; i < size; i++) _listeners.get(i).interactionErrorOccurred(offset, length);
86     }
87     finally { _lock.endRead(); }
88   }
89
90   /** Called when the interactionsJVM has begun resetting. */
91   public void interpreterResetting() {
92     _lock.startRead();
93     try {
94       int size = _listeners.size();
95 // Utilities.showDebug("InteractionsEventNotifier: interpreterResetting called on " + size + " listeners");
96
for (int i = 0; i < size; i++) _listeners.get(i).interpreterResetting();
97     }
98     finally { _lock.endRead(); }
99   }
100
101   /** Called when the interactions window is reset. */
102   public void interpreterReady(File JavaDoc wd) {
103     _lock.startRead();
104     try {
105       int size = _listeners.size();
106       for (int i = 0; i < size; i++) _listeners.get(i).interpreterReady(wd);
107     }
108     finally { _lock.endRead(); }
109   }
110
111   /** Called if the interpreter reset failed.
112    * @param t Throwable explaining why the reset failed. (Subclasses must maintain listeners.)
113    */

114   public void interpreterResetFailed(final Throwable JavaDoc t) {
115     _lock.startRead();
116     try {
117       int size = _listeners.size();
118       for (int i = 0; i < size; i++) _listeners.get(i).interpreterResetFailed(t);
119     }
120     finally { _lock.endRead(); }
121   }
122
123   /** Called when the interactions JVM was closed by System.exit or by being aborted. Immediately after this the
124    * interactions will be reset.
125    * @param status the exit code
126    */

127   public void interpreterExited(int status) {
128     _lock.startRead();
129     try {
130       int size = _listeners.size();
131       for (int i = 0; i < size; i++) { _listeners.get(i).interpreterExited(status); }
132     }
133     finally { _lock.endRead(); }
134   }
135
136   /** Called when the active interpreter is changed.
137    * @param inProgress Whether the new interpreter is currently in progress with an interaction (ie. whether an
138    * interactionEnded event will be fired)
139    */

140   public void interpreterChanged(boolean inProgress) {
141     _lock.startRead();
142     try {
143       int size = _listeners.size();
144       for (int i = 0; i < size; i++) _listeners.get(i).interpreterChanged(inProgress);
145     }
146     finally { _lock.endRead(); }
147   }
148
149   /** Notifies the view that the current interaction is incomplete. */
150   public void interactionIncomplete() {
151     _lock.startRead();
152     try {
153       int size = _listeners.size();
154       for (int i = 0; i < size; i++) _listeners.get(i).interactionIncomplete();
155     }
156     finally { _lock.endRead(); }
157   }
158   
159   /** Notifies listeners that the slaveJVM has been used. */
160   public void slaveJVMUsed() {
161     _lock.startRead();
162     try {
163       int size = _listeners.size();
164       for (int i = 0; i < size; i++) _listeners.get(i).slaveJVMUsed();
165     }
166     finally { _lock.endRead(); }
167   }
168 }
169
Popular Tags