FileDocCategorySizeDatePackage
MVMDisplayController.javaAPI DocphoneME MR2 API (J2ME)6554Wed May 02 18:00:04 BST 2007com.sun.midp.main

MVMDisplayController

public class MVMDisplayController extends DisplayController
This class controls which MIDlet's display is in the foreground. Running only in the AMS Isolate (0) the controller consulted by the MIDlet proxy list for any foreground when various state changes occur in a MIDlet. The display controller defers the display decision to the user by choosing the foreground selector to be the next foreground.

From the user perspective when the last MIDlet the user launched sets its current displayable for the first time, that MIDlet should automatically get the foreground (see the midletCreated and foregroundRequest methods).

A MIDlet that is paused or destroyed is treated as if it has requested the background as described above.

Fields Summary
private MIDletProxy
foregroundSelector
Foreground Selector MIDlet.
Constructors Summary
public MVMDisplayController(MIDletProxyList theMIDletProxyList, MIDletProxy theForegroundSelector)
Construct a DisplayController with a reference to the ProxyList.

param
theMIDletProxyList reference to the MIDlet proxy list
param
theForegroundSelector the proxy of foreground selector

        super(theMIDletProxyList);

        foregroundSelector = theForegroundSelector;

        /*
         * Ensure the foreground selector will get the foreground
         * when requested.
         */
        lastMidletCreated = foregroundSelector;
    
Methods Summary
MIDletProxybackgroundRequest(MIDletProxy midlet)
Handles MIDlet background requests.

If the MIDlet is the foreground MIDlet, then bring the foreground selector to the foreground.

param
midlet The proxy of the MIDlet that was updated
return
Proxy of the next foreground MIDlet, may be the foreground MIDlet if the foreground should not change

        MIDletProxy foreground = midletProxyList.getForegroundMIDlet();

        if (midlet != foreground) {
            // not in the foreground, so don't change the foreground
            return foreground;
        }

        /*
         * Normal MVM mode case,
         * Let the user choose the next foreground.
         */
        return getForegroundSelector();
    
MIDletProxyforegroundRequest(MIDletProxy midlet)
Handles MIDlet foreground requests.

If proxy being updated belongs last MIDlet created in the proxy list, then put the MIDlet in the foreground.

Otherwise, the request will not be granted. Foreground will not change.

param
midlet The proxy of the MIDlet that was updated
return
Proxy of the next foreground MIDlet, may be the foreground MIDlet if the foreground should not change

        /*
         * When the last MIDlet started wants the foreground automatically
         * put in the foreground this time only.
         */
        return (midlet == lastMidletCreated) ? midlet
                    : midletProxyList.getForegroundMIDlet();
    
private MIDletProxygetForegroundSelector()
Returns the foreground selector MIDlet.

return
Proxy of the foreground selector MIDlet

        return foregroundSelector;
    
MIDletProxyselectForeground(boolean onlyFromLaunchedList)
Called to process a select foreground event. Returns the foreground selector MIDlet in the foreground.

param
onlyFromLaunchedList true if midlet should be selected from the list of already launched midlets, if false then possibility to launch midlet is needed.
return
Proxy of the next foreground MIDlet, may be the foreground MIDlet if the foreground should not change


        notifyListenersOfSelectForeground(onlyFromLaunchedList);
        return getForegroundSelector();
    
MIDletProxystartPreempting(MIDletProxy preempting)
Preempt an Isolate's displays.

param
preempting proxy of the preempting MIDlet to be put in the foreground when a preempted MIDlet gets the foreground
return
Proxy of the next foreground MIDlet, may be the foreground MIDlet if the foreground should not change

        Enumeration midlets;
        MIDletProxy preempted;
        MIDletProxy foreground;

        /*
         * Preempt all of the MIDlets in the same Isolate as the preempting
         * proxy.
         */
        midlets = midletProxyList.getMIDlets();
        while (midlets.hasMoreElements()) {
            MIDletProxy current = (MIDletProxy)midlets.nextElement();

            if (current.getIsolateId() != preempting.getIsolateId()) {
                continue;
            }

            preempting.setPreemptedMidlet(current);
            current.setPreemptingDisplay(preempting);
            midletProxyList.notifyListenersOfProxyUpdate(current, 
                MIDletProxyListListener.PREEMPTING_DISPLAY);
        }

        foreground = midletProxyList.getForegroundMIDlet();
        if (foreground == null) {
            return preempting;
        }

        if (foreground.getIsolateId() == preempting.getIsolateId()) {
            preempting.setPreemptedMidlet(foreground);
            return preempting;
        }

        return foreground;