FileDocCategorySizeDatePackage
DisplayEventHandlerImpl.javaAPI DocphoneME MR2 API (J2ME)9224Wed May 02 18:00:22 BST 2007javax.microedition.lcdui

DisplayEventHandlerImpl

public class DisplayEventHandlerImpl extends Object implements com.sun.midp.lcdui.ItemEventConsumer, com.sun.midp.lcdui.DisplayEventHandler
This 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
displayContainer
Cached reference to Active Displays Container.
private com.sun.midp.lcdui.ForegroundController
foregroundController
Cached reference to the ForegroundController.
private com.sun.midp.lcdui.DisplayAccess
preemptingDisplay
The preempting display.
private boolean
preemptionDoneCalled
If request to end preemption was called
Constructors Summary
DisplayEventHandlerImpl()
Package private constructor restrict creation to LCDUI package.


             
     
    
Methods Summary
public voiddonePreempting(java.lang.Object preemptToken)
Display the displayable that was being displayed before preemptDisplay was called. DisplayEventHandler I/F method.

param
preemptToken the token returned from preemptDisplay

        /**
         * 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 voidhandleItemSizeRefreshEvent(CustomItem ci)
Called by event delivery to refresh a CustomItem's size information. ItemEventConsumer I/F method.

param
ci the custom item whose size information has to be changed

        ci.customItemLF.uCallSizeRefresh();
    
public voidhandleItemStateChangeEvent(Item item)
Called by event delivery to process an Item state change. ItemEventConsumer I/F method.

param
item the Item which has changed state

        if (item.owner != null) {
            item.owner.uCallItemStateChanged(item);
        }
    
public voidinitDisplayEventHandler(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.

param
theDisplayEventProducer producer for display events
param
theForegroundController controls which display has the foreground
param
theRepaintEventProducer producer for repaint events events
param
theDisplayContainer container for display objects


        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 voidinitSuiteData(boolean drawTrustedIcon)
Initialize per suite data of the display event handler. DisplayEventHandler I/F method.

param
drawTrustedIcon true, to draw the trusted icon in the upper status bar for every display of this suite

        Display.initSuiteData(drawTrustedIcon);
    
public voidonDisplayBackgroundProcessed(int displayId)
Called by Display to notify DisplayEventHandler that Display has been sent to the background to finish preempt process if any.

param
displayId id of Display


        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.ObjectpreemptDisplay(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.

param
d displayable to show the user
param
waitForDisplay if true this method will wait if the screen is being preempted by another thread, however if this is called in the event dispatch thread this method will return null regardless of the value of waitForDisplay
return
an preempt token object to pass to donePreempting done if prempt will happen, else null
exception
InterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.

        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;
        }