DisplayEventHandlerImplpublic class DisplayEventHandlerImpl extends Object implements com.sun.midp.lcdui.ItemEventConsumer, com.sun.midp.lcdui.DisplayEventHandlerThis class has dual functiopnality:
First, it implements DisplayEventHandler I/F and thus provides access
to display objects (creation, preemption, set/get IDs and other properties).
Second, it implements ItemEventConsumer I/F and thus processes
LCDUI events that due to different reasons can't be associated with
Display instance specific DisplayEventConsumer objects,
but need to be processed by isolate-wide handler.
TBD: These are subjects for futher investigation to move them
to DisplayEventConsumer.
In addition, it implements a number of package private methods that work
with Display and are called locally by display/DisplayAccessor.
TBD: These are subjects for further investination to move them closer
to end users: Display & displayAccessor classes. |
Fields Summary |
---|
private com.sun.midp.lcdui.DisplayContainer | displayContainerCached reference to Active Displays Container. | private com.sun.midp.lcdui.ForegroundController | foregroundControllerCached reference to the ForegroundController. | private com.sun.midp.lcdui.DisplayAccess | preemptingDisplayThe preempting display. | private boolean | preemptionDoneCalledIf request to end preemption was called |
Constructors Summary |
---|
DisplayEventHandlerImpl()Package private constructor restrict creation to LCDUI package.
|
Methods Summary |
---|
public void | donePreempting(java.lang.Object preemptToken)Display the displayable that was being displayed before
preemptDisplay was called.
DisplayEventHandler I/F method.
/**
* This sync protects preempt related local fields:
* preemptingDisplay and destroyPreemptingDisplay.
*/
synchronized (this) {
if (preemptingDisplay != null &&
(preemptToken == preemptingDisplay || preemptToken == null)) {
preemptionDoneCalled = true;
foregroundController.stopPreempting(
preemptingDisplay.getDisplayId());
}
}
| public void | handleItemSizeRefreshEvent(CustomItem ci)Called by event delivery to refresh a CustomItem's size information.
ItemEventConsumer I/F method.
ci.customItemLF.uCallSizeRefresh();
| public void | handleItemStateChangeEvent(Item item)Called by event delivery to process an Item state change.
ItemEventConsumer I/F method.
if (item.owner != null) {
item.owner.uCallItemStateChanged(item);
}
| public void | initDisplayEventHandler(com.sun.midp.lcdui.DisplayEventProducer theDisplayEventProducer, com.sun.midp.lcdui.ForegroundController theForegroundController, com.sun.midp.lcdui.RepaintEventProducer theRepaintEventProducer, com.sun.midp.lcdui.DisplayContainer theDisplayContainer)Initialize Display Event Handler.
DisplayEventHandler I/F method.
foregroundController = theForegroundController;
displayContainer = theDisplayContainer;
/*
* TBD: not a good idea to call static initializer
* from non-static method ...
* Maybe to create a separate method:
* DisplayEventHandler.initDisplayClass(token,...)
* for these purposes and call it from Suite Loader's main() ?
* displayEventHandlerImpl I/F miplementor will call
* Display.initClass() from itsinitDisplayClass() method ?
*/
Display.initClass(
theForegroundController,
theDisplayEventProducer,
theRepaintEventProducer,
theDisplayContainer);
| public void | initSuiteData(boolean drawTrustedIcon)Initialize per suite data of the display event handler.
DisplayEventHandler I/F method.
Display.initSuiteData(drawTrustedIcon);
| public void | onDisplayBackgroundProcessed(int displayId)Called by Display to notify DisplayEventHandler that
Display has been sent to the background to finish
preempt process if any.
synchronized (this) {
if (preemptionDoneCalled && preemptingDisplay != null &&
preemptingDisplay.getDisplayId() == displayId) {
displayContainer.removeDisplay(
preemptingDisplay.getNameOfOwner());
preemptingDisplay = null;
preemptionDoneCalled = false;
// A midlet may be waiting to preempt
this.notify();
}
}
| public java.lang.Object | preemptDisplay(Displayable d, boolean waitForDisplay)Preempt the current displayable with
the given displayable until donePreempting is called.
To avoid dead locking the event thread his method
MUST NOT be called in the event thread.
DisplayEventHandler I/F method.
Display tempDisplay;
String title;
if (d == null) {
throw new NullPointerException(
"The displayable can't be null");
}
title = d.getTitle();
if (title == null) {
throw new NullPointerException(
"The title of the displayable can't be null");
}
if (EventQueue.isDispatchThread()) {
// Developer programming error
throw new RuntimeException(
"Blocking call performed in the event thread");
}
/**
* This sync protects preempt related local fields:
* preemptingDisplay and destroyPreemptingDisplay.
*/
synchronized (this) {
if (preemptingDisplay != null) {
if (!waitForDisplay) {
return null;
}
this.wait();
}
// This class will own the display.
tempDisplay =
new Display("com.sun.midp.lcdui.DisplayEventHandlerImpl");
foregroundController.startPreempting(tempDisplay.displayId);
tempDisplay.setCurrent(d);
preemptingDisplay = tempDisplay.accessor;
return preemptingDisplay;
}
|
|