LCDUIEventListenerpublic class LCDUIEventListener extends Object implements EventListenerThis is the event listener for LCDUI events. |
Fields Summary |
---|
private ItemEventConsumer | itemEventConsumerThe DisplayManager object handling the display events. | private EventQueue | eventQueueCached 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.
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 void | itemEvent(LCDUIEvent lcduiEvent)Processes event of ITEM_EVENT class
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 boolean | preprocess(Event newEvent, Event waitingEvent)Preprocess an event that is being posted to the event 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 boolean | preprocessAllowOnlyOneEvent(Event genericEvent1, Event genericEvent2)Preprocess an event to only allow one in the queue
at once.
if (genericEvent2 == null) {
// There is no other event, queue this event
return true;
}
return false;
| private boolean | preprocessScreenChangeEvent(Event genericEvent1, Event genericEvent2)Preprocess a screen change event to only allow one with the same
screen in the queue at once.
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 void | process(Event event)Process an event.
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() + ")");
}
}
|
|