junit.extensions.jfcunit
Class WindowMonitor

java.lang.Object
  extended byjunit.extensions.jfcunit.WindowMonitor
All Implemented Interfaces:
java.awt.event.AWTEventListener, java.util.EventListener

public final class WindowMonitor
extends java.lang.Object
implements java.awt.event.AWTEventListener

The WindowMonitor class is used to monitor for windows that might not show up in Frame.getFrames(). So we must watch for these windows to be opened.

Author:
Kevin Wilson, Vijay Aravamudhan : ThoughtWorks Inc.

Nested Class Summary
private  class WindowMonitor.DispatchThread
          Handle all Component events in a separate thread.
private static class WindowMonitor.WindowEventItem
          WindowEventItem is the basic type that handles the queue for queueWindowEvent and the DispatchThread.
 
Field Summary
private static java.lang.Object QLOCK
          Lock for the event queue and dispatch thread.
private static WindowMonitor.DispatchThread s_dt
          The dispatch thread used to process the event queue.
private static boolean s_running
          Flag used to shutdown the window monitor.
private static WindowMonitor s_singleton
          A handle to this class instance.
private static WindowMonitor.WindowEventItem s_windowEventQueue
          Event queue item or null if no pending items.
private static java.util.ArrayList WINDOWS
          All Non-Popup Windows which have been found.
 
Constructor Summary
private WindowMonitor()
          Constructor.
 
Method Summary
private  boolean containsKey(java.awt.Window key)
          Check to see if the key is in the current list.
 void eventDispatched(java.awt.AWTEvent theEvent)
          Event dispatch implementation.
private static void flushAWT()
          Flush the AWT Event Queue.
private static WindowMonitor getSingleton()
          return the singleton instance.
static java.awt.Window[] getWindows()
          Get all of the windows which are open.
private static void populateWindows(java.awt.Window w)
          Populate frames.
private static void processEvent(java.awt.AWTEvent theEvent)
          Processes the events by adding the event onto the event queue to be processed by the dispatch thread.
private static void queueWindowEvent(java.awt.event.WindowEvent we)
          Queue the event.
private  java.lang.Object remove(java.awt.Window key)
          Remove the window from the list.
static void start()
          Start the monitor.
static void stop()
          Stop the monitor.
private  void stopInternal()
          Stop the window monitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_singleton

private static WindowMonitor s_singleton
A handle to this class instance.


s_dt

private static WindowMonitor.DispatchThread s_dt
The dispatch thread used to process the event queue.


s_running

private static volatile boolean s_running
Flag used to shutdown the window monitor.


s_windowEventQueue

private static WindowMonitor.WindowEventItem s_windowEventQueue
Event queue item or null if no pending items. The event queue is a linked list.


QLOCK

private static final java.lang.Object QLOCK
Lock for the event queue and dispatch thread.


WINDOWS

private static final java.util.ArrayList WINDOWS
All Non-Popup Windows which have been found.

Constructor Detail

WindowMonitor

private WindowMonitor()
Constructor. Private use the static start() method.

Method Detail

getWindows

public static java.awt.Window[] getWindows()
Get all of the windows which are open.

Returns:
Window[] containing all of the windows which have been instantiated.

start

public static void start()
Start the monitor.


stop

public static void stop()
Stop the monitor.


eventDispatched

public void eventDispatched(java.awt.AWTEvent theEvent)
Event dispatch implementation.

Specified by:
eventDispatched in interface java.awt.event.AWTEventListener
Parameters:
theEvent - AWTEvent which is to be processed.

getSingleton

private static WindowMonitor getSingleton()
return the singleton instance. If the singleton has not been created, then create one.

Returns:
WindowMonitor singleton instance.

flushAWT

private static void flushAWT()
Flush the AWT Event Queue.


populateWindows

private static void populateWindows(java.awt.Window w)
Populate frames.

Parameters:
w - Frame to be traversed.

processEvent

private static void processEvent(java.awt.AWTEvent theEvent)
Processes the events by adding the event onto the event queue to be processed by the dispatch thread.

Parameters:
theEvent - The event to be processed.

queueWindowEvent

private static void queueWindowEvent(java.awt.event.WindowEvent we)
Queue the event.

Parameters:
we - WindowEvent to be queued.

stopInternal

private void stopInternal()
Stop the window monitor.


containsKey

private boolean containsKey(java.awt.Window key)
Check to see if the key is in the current list.

Parameters:
key - Window to search for.
Returns:
boolean true if the window is in the list.

remove

private java.lang.Object remove(java.awt.Window key)
Remove the window from the list.

Parameters:
key - Window to be removed.
Returns:
Object Window which was removed.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999