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

LCDUIEventListener

public class LCDUIEventListener extends Object implements EventListener
This is the event listener for LCDUI events.

Fields Summary
private ItemEventConsumer
itemEventConsumer
The DisplayManager object handling the display events.
private EventQueue
eventQueue
Cached reference to the MIDP event queue.
Constructors Summary
public LCDUIEventListener(com.sun.midp.security.SecurityToken token, EventQueue theEventQueue, ItemEventConsumer theItemEventConsumer)
The constructor for the default event handler for LCDUI.

param
token security token that controls instance creation.
param
theEventQueue the event queue
param
theItemEventConsumer handler for item events

            
        token.checkIfPermissionAllowed(Permissions.MIDP);
        
        eventQueue = theEventQueue;
        itemEventConsumer = theItemEventConsumer;

        /*
         * All events handled by this object are of [ackage private 
         * LCDUIEvent class, so only this object knows how to 
         * decode their fields. 
         */
        eventQueue.registerEventListener(EventTypes.SCREEN_CHANGE_EVENT, this);
        eventQueue.registerEventListener(EventTypes.SCREEN_REPAINT_EVENT, this);
        eventQueue.registerEventListener(EventTypes.INVALIDATE_EVENT, this);
        eventQueue.registerEventListener(EventTypes.ITEM_EVENT, this);
        eventQueue.registerEventListener(EventTypes.CALL_SERIALLY_EVENT, this);
    
Methods Summary
private voiditemEvent(LCDUIEvent lcduiEvent)
Processes event of ITEM_EVENT class

param
lcduiEvent LCDUI event to be processed

        switch (lcduiEvent.minorCode) {
        case LCDUIEvent.ITEM_STATE_CHANGED:
            itemEventConsumer.handleItemStateChangeEvent(
                lcduiEvent.changedItem);
            break;
        case LCDUIEvent.ITEM_SIZE_REFRESH:
            itemEventConsumer.handleItemSizeRefreshEvent(
                (CustomItem)lcduiEvent.changedItem);
            break;
        default:
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                               "ITEM_EVENT invalid minor code (" +
                               lcduiEvent.minorCode + ")");
            }
            break;
        }
        return;
    
public booleanpreprocess(Event newEvent, Event waitingEvent)
Preprocess an event that is being posted to the event queue.

param
newEvent 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

        switch (newEvent.getType()) {
        case EventTypes.INVALIDATE_EVENT:
        case EventTypes.CALL_SERIALLY_EVENT:
            return preprocessAllowOnlyOneEvent(newEvent, waitingEvent);
        case EventTypes.SCREEN_CHANGE_EVENT:
            return preprocessScreenChangeEvent
                        (newEvent, waitingEvent);
        // case EventTypes.ITEM_EVENT: 
        default:
            return true;
        }
    
private booleanpreprocessAllowOnlyOneEvent(Event genericEvent1, Event genericEvent2)
Preprocess an event to only allow one in the queue at once.

param
genericEvent1 LCDUI event
param
genericEvent2 waiting LCDUI event
return
true if the event should be put in the queue, false if the event should not be put in the queue because it has been merged with the event currently waiting in the queue.

        if (genericEvent2 == null) {
            // There is no other event, queue this event
            return true;
        }

        return false;
    
private booleanpreprocessScreenChangeEvent(Event genericEvent1, Event genericEvent2)
Preprocess a screen change event to only allow one with the same screen in the queue at once.

param
genericEvent1 LCDUI event
param
genericEvent2 waiting LCDUI event
return
true if the event should be put in the queue, false if the event should not be put in the queue because it is duplicate of the event currently waiting in the queue.

        LCDUIEvent newEvent;
        LCDUIEvent waitingEvent;

        if (genericEvent2 == null) {
            // There is no other event, queue this event
            return true;
        }

        newEvent = (LCDUIEvent)genericEvent1;
        waitingEvent = (LCDUIEvent)genericEvent2;

        if (newEvent.nextScreen != waitingEvent.nextScreen) {
             // The events are different, queue this event
             return true;
        }

        // The events are the same event , do not queue this event
        return false;
    
public voidprocess(Event event)
Process an event.

param
event event to process

        LCDUIEvent lcduiEvent = (LCDUIEvent)event;
        
        switch (event.getType()) {
        case EventTypes.SCREEN_CHANGE_EVENT:
            /*
             * Target DisplayEventConsumer is obtained directly 
             * from event field.
             * Assumed that target consumer is not null.
             */
            lcduiEvent.display.handleScreenChangeEvent(lcduiEvent.nextScreen);
            return;

        case EventTypes.SCREEN_REPAINT_EVENT:
            /*
             * Target DisplayEventConsumer is obtained directly
             * from event field.
             * Assumed that target consumer is not null.
             */
            lcduiEvent.display.handleScreenRepaintEvent();
            return;

        case EventTypes.INVALIDATE_EVENT:
            /*
             * Target DisplayEventConsumer is obtained directly 
             * from event field.
             * Assumed that target consumer is not null.
             */
            lcduiEvent.display.handleInvalidateEvent();
            return;

        case EventTypes.ITEM_EVENT:
            /*
             * Item Events are processed by ItemEventConsumer.
             */
            itemEvent(lcduiEvent);
            return;
            
        case EventTypes.CALL_SERIALLY_EVENT:
            /*
             * Target DisplayEventConsumer is obtained directly 
             * from event field.
             * Assumed that target consumer is not null.
             */
            lcduiEvent.display.handleCallSeriallyEvent();
            return;
            
        default:
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                               "unknown system event (" +
                               event.getType() + ")");
            }
        }