FileDocCategorySizeDatePackage
DisplayEventListener.javaAPI DocphoneME MR2 API (J2ME)5865Wed May 02 18:00:24 BST 2007com.sun.midp.lcdui

DisplayEventListener

public class DisplayEventListener extends Object implements com.sun.midp.events.EventListener
Listener for LCDUI events (user inputs, etc).

Fields Summary
private com.sun.midp.lcdui.DisplayContainer
displayContainer
Active displays.
private com.sun.midp.events.EventQueue
eventQueue
Cached reference to the MIDP event queue.
Constructors Summary
public DisplayEventListener(com.sun.midp.events.EventQueue theEventQueue, com.sun.midp.lcdui.DisplayContainer theDisplayContainer)
The constructor for the default event handler for LCDUI.

param
theEventQueue the event queue
param
theDisplayContainer container for display objects

            
        eventQueue = theEventQueue;
        displayContainer = theDisplayContainer;

        /*
         * All events handled by this object are of NativeEventClass
         * and are instance specific events assosiated with some display Id.
         * So this listener is able to find an appropriate DisplayEventConsumer
         * associated with the displayId field of NativeEvent and 
         * to call methods of found consumer.
         */
        eventQueue.registerEventListener(EventTypes.KEY_EVENT, this);
        eventQueue.registerEventListener(EventTypes.PEN_EVENT, this);
        eventQueue.registerEventListener(EventTypes.COMMAND_EVENT, this);
        eventQueue.registerEventListener(EventTypes.PEER_CHANGED_EVENT, this);
        eventQueue.registerEventListener(EventTypes.ROTATION_EVENT,this);
    
Methods Summary
public booleanpreprocess(com.sun.midp.events.Event event, com.sun.midp.events.Event waitingEvent)
Preprocess an event that is being posted to the event queue.

param
event event being posted
param
waitingEvent previous event of this type waiting in the queue to be processed
return
true to allow the post to continue, false to not post the event to the queue

        return true;
    
public voidprocess(com.sun.midp.events.Event event)
Process an event.

param
event event to process

        NativeEvent nativeEvent = (NativeEvent)event;

        /*
         * Find DisplayEventConsumer instance by nativeEvent.intParam4
         * and (if not null) call DisplayEventConsumer methods ...
         */
        DisplayEventConsumer dc =
            displayContainer.findDisplayEventConsumer(nativeEvent.intParam4);

        if (dc != null) {
            switch (event.getType()) {
            case EventTypes.KEY_EVENT:
                if (nativeEvent.intParam1 == EventConstants.IME) {
                    dc.handleInputMethodEvent(nativeEvent.stringParam1);
                } if (Logging.REPORT_LEVEL < Constants.LOG_DISABLED && 
                      nativeEvent.intParam2 == EventConstants.DEBUG_TRACE1) {
                    // This is a special VM hook to print all stacks
                    if (nativeEvent.intParam1 == EventConstants.PRESSED) {
                      System.getProperty("__debug.only.pss");
                    }
                } else {
                    dc.handleKeyEvent(
                        nativeEvent.intParam1, 
                        nativeEvent.intParam2);
                }
                return;

            case EventTypes.PEN_EVENT:
                dc.handlePointerEvent(
                    nativeEvent.intParam1,
                    nativeEvent.intParam2, 
                    nativeEvent.intParam3);
                return;

            case EventTypes.COMMAND_EVENT:
                dc.handleCommandEvent(
                    /* nativeEvent.intParamX - will contain screenId */
                    nativeEvent.intParam1);
                return;

            case EventTypes.PEER_CHANGED_EVENT:
                dc.handlePeerStateChangeEvent(
                    nativeEvent.intParam1,
                    nativeEvent.intParam2,
                    nativeEvent.intParam3);

                return;

            case EventTypes.ROTATION_EVENT:
                dc.handleRotationEvent();
                return;

            default:
                if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                    Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                                   "unknown system event (" +
                                   event.getType() + ")");
                }
            }
        }