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

SMMDisplayController

public class SMMDisplayController 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 automatically selects the next foreground if needed.

From the user perspective when the last MIDlet the user launched is created, 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 int
lastMidletSuiteId
Suite ID of the last MIDlet in foreground.
private String
lastMidletClassName
Class name of the last MIDlet in foreground.
private MIDletProxy
lastMidletInForeground
This MIDlet should only get the foreground if it is the last MIDlet.
Constructors Summary
public SMMDisplayController(MIDletProxyList theMIDletProxyList, int suiteId, String classname)
Construct a DisplayController with a reference to the ProxyList.

param
theMIDletProxyList reference to the MIDlet proxy list
param
suiteId the suiteId of the last MIDlet in the foreground
param
classname classname of the last MIDlet in the foreground

        super(theMIDletProxyList);
        midletProxyList = theMIDletProxyList;
        lastMidletSuiteId = suiteId;
        lastMidletClassName = classname;
    
Methods Summary
MIDletProxybackgroundRequest(MIDletProxy midlet)
Handles MIDlet background requests.

If the MIDlet requesting to be put in the background is the foreground MIDlet, then find a MIDlet to bring to the foreground (see the findNextForeground method).

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

        return findNextForegroundMIDlet();
    
private MIDletProxyfindNextForegroundMIDlet()
Find a MIDlet that wants the foreground. If none wants the foreground then find one that is not paused, if no find one that is paused and wants the foreground, then find one that is paused. Only return the "last MIDlet to have the foreground" if there are not other MIDlets.

return
new foreground task or null

        Enumeration midlets;

        // find the first task that is active and wants foreground
        midlets = midletProxyList.getMIDlets();
        while (midlets.hasMoreElements()) {
            MIDletProxy current = (MIDletProxy)midlets.nextElement();

            if (current.getMidletState() != MIDletProxy.MIDLET_ACTIVE) {
                continue;
            }

            if (current.wantsForeground() &&
                    current != getLastMidletInForeground()) {
                return current;
            }
        }

        // find the first task that is active
        midlets = midletProxyList.getMIDlets();
        while (midlets.hasMoreElements()) {
            MIDletProxy current = (MIDletProxy)midlets.nextElement();

            if (current.getMidletState() != MIDletProxy.MIDLET_ACTIVE &&
                    current != getLastMidletInForeground()) {
                return current;
            }
        }

        // find the first task that is paused and wants the foreground
        midlets = midletProxyList.getMIDlets();
        while (midlets.hasMoreElements()) {
            MIDletProxy current = (MIDletProxy)midlets.nextElement();

            if (current.getMidletState() != MIDletProxy.MIDLET_PAUSED &&
                    current != getLastMidletInForeground()) {
                continue;
            }

            if (current.wantsForeground() &&
                    current != getLastMidletInForeground()) {
                return current;
            }
        }

        // find the first task that is paused
        midlets = midletProxyList.getMIDlets();
        while (midlets.hasMoreElements()) {
            MIDletProxy current = (MIDletProxy)midlets.nextElement();

            if (current.getMidletState() != MIDletProxy.MIDLET_PAUSED &&
                    current != getLastMidletInForeground()) {
                return current;
            }
        }

        return getLastMidletInForeground();
    
private MIDletProxygetLastMidletInForeground()
Returns the last MIDlet to that should get the foreground.

return
last MIDlet in foreground

        if (lastMidletInForeground == null) {
            lastMidletInForeground =
                midletProxyList.findMIDletProxy(lastMidletSuiteId,
                                                lastMidletClassName);
        }

        return lastMidletInForeground;