CiaoJava
Class PLEventListener

java.lang.Object
  |
  +--CiaoJava.PLEventListener

public class PLEventListener
extends java.lang.Object
implements java.awt.event.AWTEventListener

This class listens events directly from the system event queue. Keeps a list of Prolog listeners associated with objects and event Ids. A key element of this implementation is that the Prolog listeners will be evaluated when the event raises, so the arguments of the listeners will be updated correctly in the Prolog side.


Field Summary
private static float FACTOR
           
private  PLInterpreter interpreter
          Interpreter to evaluate goal arguments.
private  java.util.Hashtable objTable
          Object/event Hashtable.
private  PLConnection pl
          Prolog connection for the goals to be launched when an event occurs.
private  java.awt.EventQueue queue
          System queue
private static int STARTING_CAPACITY
          Internal constants.
 
Constructor Summary
PLEventListener(PLConnection pl, PLInterpreter interpreter)
          Creates a new event listener.
 
Method Summary
 void addListener(java.lang.Object obj, java.lang.Class ec, PLTerm goal)
          Inserts a new listener.
 void eventDispatched(java.awt.AWTEvent eventRaised)
          Method called on each event queued on the system queue.
 void removeListener(java.lang.Object obj, java.lang.Class ec, PLTerm goal)
          Removes a listener.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

STARTING_CAPACITY

private static final int STARTING_CAPACITY
Internal constants.

FACTOR

private static final float FACTOR

queue

private java.awt.EventQueue queue
System queue

objTable

private java.util.Hashtable objTable
Object/event Hashtable.

interpreter

private PLInterpreter interpreter
Interpreter to evaluate goal arguments.

pl

private PLConnection pl
Prolog connection for the goals to be launched when an event occurs.
Constructor Detail

PLEventListener

public PLEventListener(PLConnection pl,
                       PLInterpreter interpreter)
Creates a new event listener. Given a connection and a interpreter, creates the event listener and adds it to the AWTEventListener class.
Parameters:
pl - Connection to the Prolog process
interpreter - The PLInterpreter object to be used for the goal argument calculation.
Method Detail

addListener

public void addListener(java.lang.Object obj,
                        java.lang.Class ec,
                        PLTerm goal)
Inserts a new listener. Given an object, event class and goal, updates the listener list. If the object list does not contain this object (there is no listener yet), inserts it in the object list and creates the events list for that object; else inserts the event in the event list for the object. Then, inserts the goal in the goal list of the event.
Parameters:
obj - object on which the listener listens.
ec - event class that will be listened.
goal - Prolog goal that will be evaluated when the event raises.

removeListener

public void removeListener(java.lang.Object obj,
                           java.lang.Class ec,
                           PLTerm goal)
Removes a listener. Given an object and event class, updates the listener structure removing the listener to this object and event.
Parameters:
obj - object on which the listener listens.
ec - event class that is being listened.
goal - Prolog goal that will be evaluated when the event raises.

eventDispatched

public void eventDispatched(java.awt.AWTEvent eventRaised)
Method called on each event queued on the system queue. Selects and runs the goals that must be launched for the object and event raised.
Specified by:
eventDispatched in interface java.awt.event.AWTEventListener
Parameters:
ev - AWTEvent object representing the event raised.