// file: $ISIP_IFC/class/java/ConnectionManager/DemoEventProcessor.java
// version: $Id: DemoEventProcessor.java 10231 2005-09-13 14:29:38Z stanley $
// import necessary java libraries
//
import java.awt.*;
import java.util.*;
/**
* This class allows AWTEvent s to be added to its event
* list and then processes the events by calling the
* handleEvent method of the passed
* DemoEventProcessable object.
*/
public class DemoEventProcessor {
//-------------------------------------------------------------------------
//
// public constants
//
//-------------------------------------------------------------------------
//------------------------------------------------------------------------
//
// protected data
//
//-----------------------------------------------------------------------
/**
* Linked list for events needed to handle
*/
protected LinkedList event_list_d;
/**
* Event handler
*/
protected DemoEventProcessable handler_d;
//-------------------------------------------------------------------------
//
// public methods
//
//-------------------------------------------------------------------------
/**
* Creates a new LinkedList to hold events.
*
* @param handler_a the DemoEventProcessable that will
* handle events.
*
*/
public DemoEventProcessor(DemoEventProcessable handler_a) {
// create a linked list to hold the events
//
event_list_d = new LinkedList();
// holder the handler
//
this.handler_d = handler_a;
}
/**
* Add an AWT event to the event list.
*
* @param event_a an event to be added to the event list.
*
* @return a boolean value indicating status
*/
public boolean addEvent(AWTEvent event_a) {
synchronized(event_list_d) {
event_list_d.add(event_a);
}
// exit gracefully
//
return true;
}
/**
* Removes the first event from the event list and sends the event
* to the DemoEventProcessable object through its
* handleEvent() method.
*
* @return a boolean value indicating status.
*/
public boolean processEventList() {
// local variables
//
AWTEvent event;
// loop all event list
//
while (event_list_d.size() > 0) {
synchronized(event_list_d) {
event = (AWTEvent) event_list_d.removeFirst();
}
// handle the event
//
handler_d.handleEvent(event);
}
// exit gracefully
//
return true;
}
}