|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| InteractionsEventNotifier.java | 66.7% | 66.7% | 66.7% | 66.7% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * * Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * * Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
| 14 | * names of its contributors may be used to endorse or promote products | |
| 15 | * derived from this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | * | |
| 29 | * This software is Open Source Initiative approved Open Source Software. | |
| 30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
| 31 | * | |
| 32 | * This file is part of DrJava. Download the current version of this project | |
| 33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
| 34 | * | |
| 35 | * END_COPYRIGHT_BLOCK*/ | |
| 36 | ||
| 37 | package edu.rice.cs.drjava.model.repl; | |
| 38 | ||
| 39 | import java.io.File; | |
| 40 | ||
| 41 | import edu.rice.cs.drjava.model.EventNotifier; | |
| 42 | ||
| 43 | /** Keeps track of all listeners to an InteractionsModel, and has the ability to notify them of some event. <p> | |
| 44 | * This class has a specific role of managing InteractionsListeners. Other classes with similar names use similar | |
| 45 | * code to perform the same function for other interfaces, e.g. JavadocEventNotifier and GlobalEventNotifier. | |
| 46 | * These classes implement the appropriate interface definition so that they can be used transparently as composite | |
| 47 | * packaging for a particular listener interface. <p> | |
| 48 | * Components which might otherwise manage their own list of listeners use EventNotifiers instead to simplify their | |
| 49 | * internal implementation. Notifiers should therefore be considered a private implementation detail of the | |
| 50 | * components, and should not be used directly outside of the "host" component. <p> | |
| 51 | * All methods in this class must use the synchronization methods provided by ReaderWriterLock. This ensures | |
| 52 | * that multiple notifications (reads) can occur simultaneously, but only one thread can be adding or removing | |
| 53 | * listeners (writing) at a time, and no reads can occur during a write. <p> | |
| 54 | * <i>No</i> methods on this class should be synchronized using traditional Java synchronization! <p> | |
| 55 | * @version $Id: InteractionsEventNotifier.java 5236 2010-04-27 01:43:36Z mgricken $ | |
| 56 | */ | |
| 57 | ||
| 58 | public class InteractionsEventNotifier extends EventNotifier<InteractionsListener> implements InteractionsListener { | |
| 59 | ||
| 60 | /** Called after an interaction is started by the GlobalModel. */ | |
| 61 | 35 | public void interactionStarted() { |
| 62 | 35 | _lock.startRead(); |
| 63 | 35 | try { |
| 64 | 35 | int size = _listeners.size(); |
| 65 | 105 | for (int i = 0; i < size; i++) _listeners.get(i).interactionStarted(); |
| 66 | } | |
| 67 | 35 | finally { _lock.endRead(); } |
| 68 | } | |
| 69 | ||
| 70 | /** Called when an interaction has finished running. */ | |
| 71 | 33 | public void interactionEnded() { |
| 72 | 33 | _lock.startRead(); |
| 73 | 33 | try { |
| 74 | 33 | int size = _listeners.size(); |
| 75 | 99 | for (int i = 0; i < size; i++) _listeners.get(i).interactionEnded(); |
| 76 | } | |
| 77 | 33 | finally { _lock.endRead(); } |
| 78 | } | |
| 79 | ||
| 80 | /** Called when the interactions window generates a syntax error. | |
| 81 | * @param offset the error's offset into the InteractionsDocument | |
| 82 | * @param length the length of the error | |
| 83 | */ | |
| 84 | 0 | public void interactionErrorOccurred(int offset, int length) { |
| 85 | 0 | _lock.startRead(); |
| 86 | 0 | try { |
| 87 | 0 | int size = _listeners.size(); |
| 88 | 0 | for (int i = 0; i < size; i++) _listeners.get(i).interactionErrorOccurred(offset, length); |
| 89 | } | |
| 90 | 0 | finally { _lock.endRead(); } |
| 91 | } | |
| 92 | ||
| 93 | /** Called when the interactionsJVM has begun resetting. */ | |
| 94 | 21 | public void interpreterResetting() { |
| 95 | 21 | _lock.startRead(); |
| 96 | 21 | try { |
| 97 | 21 | int size = _listeners.size(); |
| 98 | // Utilities.showDebug("InteractionsEventNotifier: interpreterResetting called on " + size + " listeners"); | |
| 99 | 64 | for (int i = 0; i < size; i++) _listeners.get(i).interpreterResetting(); |
| 100 | } | |
| 101 | 21 | finally { _lock.endRead(); } |
| 102 | } | |
| 103 | ||
| 104 | /** Called when the interactions window is reset. */ | |
| 105 | 25 | public void interpreterReady(File wd) { |
| 106 | 25 | _lock.startRead(); |
| 107 | 25 | try { |
| 108 | 25 | int size = _listeners.size(); |
| 109 | 77 | for (int i = 0; i < size; i++) _listeners.get(i).interpreterReady(wd); |
| 110 | } | |
| 111 | 25 | finally { _lock.endRead(); } |
| 112 | } | |
| 113 | ||
| 114 | /** Called if the interpreter reset failed. | |
| 115 | * @param t Throwable explaining why the reset failed. (Subclasses must maintain listeners.) | |
| 116 | */ | |
| 117 | 0 | public void interpreterResetFailed(final Throwable t) { |
| 118 | 0 | _lock.startRead(); |
| 119 | 0 | try { |
| 120 | 0 | int size = _listeners.size(); |
| 121 | 0 | for (int i = 0; i < size; i++) _listeners.get(i).interpreterResetFailed(t); |
| 122 | } | |
| 123 | 0 | finally { _lock.endRead(); } |
| 124 | } | |
| 125 | ||
| 126 | /** Called when the interactions JVM was closed by System.exit or by being aborted. Immediately after this the | |
| 127 | * interactions will be reset. | |
| 128 | * @param status the exit code | |
| 129 | */ | |
| 130 | 1 | public void interpreterExited(int status) { |
| 131 | 1 | _lock.startRead(); |
| 132 | 1 | try { |
| 133 | 1 | int size = _listeners.size(); |
| 134 | 3 | for (int i = 0; i < size; i++) { _listeners.get(i).interpreterExited(status); } |
| 135 | } | |
| 136 | 1 | finally { _lock.endRead(); } |
| 137 | } | |
| 138 | ||
| 139 | /** Called when the active interpreter is changed. | |
| 140 | * @param inProgress Whether the new interpreter is currently in progress with an interaction (ie. whether an | |
| 141 | * interactionEnded event will be fired) | |
| 142 | */ | |
| 143 | 1 | public void interpreterChanged(boolean inProgress) { |
| 144 | 1 | _lock.startRead(); |
| 145 | 1 | try { |
| 146 | 1 | int size = _listeners.size(); |
| 147 | 3 | for (int i = 0; i < size; i++) _listeners.get(i).interpreterChanged(inProgress); |
| 148 | } | |
| 149 | 1 | finally { _lock.endRead(); } |
| 150 | } | |
| 151 | ||
| 152 | /** Notifies the view that the current interaction is incomplete. */ | |
| 153 | 0 | public void interactionIncomplete() { |
| 154 | 0 | _lock.startRead(); |
| 155 | 0 | try { |
| 156 | 0 | int size = _listeners.size(); |
| 157 | 0 | for (int i = 0; i < size; i++) _listeners.get(i).interactionIncomplete(); |
| 158 | } | |
| 159 | 0 | finally { _lock.endRead(); } |
| 160 | } | |
| 161 | ||
| 162 | } |
|
||||||||||