001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.catching;
025:
026: import jacareto.eventmask.WindowEventMask;
027: import jacareto.system.Environment;
028: import jacareto.toolkit.PriorityList;
029:
030: import java.awt.Window;
031: import java.awt.event.WindowEvent;
032:
033: import java.util.EventObject;
034: import java.util.Iterator;
035:
036: /**
037: * This class listens for windows activations.
038: *
039: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
040: * @version 1.01
041: */
042: public class WindowActivationCatcher extends Catcher {
043: /** List of all instances which are waiting for a window activation. */
044: private PriorityList waitingInstances;
045:
046: /**
047: * Creates a new WindowActivationCatcher with a specified env.
048: *
049: * @param env the environment
050: */
051: public WindowActivationCatcher(Environment env) {
052: super (env);
053: waitingInstances = new PriorityList();
054:
055: // just "window opened" events
056: WindowEventMask eventMask = new WindowEventMask(env,
057: WindowEventMask.ALL_EXCLUDED);
058: eventMask.setIncluded(WindowEvent.WINDOW_ACTIVATED, true);
059: setAWTEventMask(eventMask);
060: }
061:
062: /**
063: * This method is called when a window pops up. All registered instances which wait for
064: * activations will be notified of that event.
065: *
066: * @param event the dispatched (window) event
067: *
068: * @return <code>true</code> (all other catchers are allowed to handle the event, too)
069: */
070: public boolean handleEvent(EventObject event) {
071: Window window = ((WindowEvent) event).getWindow();
072: Iterator i = waitingInstances.iterator();
073:
074: while (i.hasNext()) {
075: ((WindowActivationCatcherObserver) i.next())
076: .handleActivation(window);
077: }
078:
079: return true;
080: }
081:
082: /**
083: * Registers an instance which is waiting for window activations with the specified priority. A
084: * greater value of priority symbolizes a higher priority.
085: *
086: * @param waitingInstance the waiting instance to add
087: * @param priority the priority
088: */
089: public void addWaitingInstance(
090: WindowActivationCatcherObserver waitingInstance,
091: int priority) {
092: if (priority >= 0) {
093: waitingInstances.add(waitingInstance, priority);
094: } else {
095: waitingInstances.add(waitingInstance);
096: }
097: }
098:
099: /**
100: * Registers an instance which is waiting for window activations with the lowest priority.
101: *
102: * @param waitingInstance the waiting instance to add
103: */
104: public void addWaitingInstance(
105: WindowActivationCatcherObserver waitingInstance) {
106: addWaitingInstance(waitingInstance, -1);
107: }
108: }
|