FileDocCategorySizeDatePackage
MIDletSwitcher.javaAPI DocphoneME MR2 API (J2ME)4838Wed May 02 18:00:06 BST 2007com.sun.midp.appmanager

MIDletSwitcher

public class MIDletSwitcher extends javax.microedition.lcdui.List implements CommandListener
The Graphical MIDlet swicher. Switcher provides a simple user interface to select MIDlets to bring into foreground from the list of running midlets.

Fields Summary
private int
mcount
Number of midlets in minfo.
private RunningMIDletSuiteInfo[]
minfo
MIDlet information, class, name, icon; one per MIDlet.
private final int
pitch
Number of reserved elements in minfo array.
ApplicationManager
manager
Application Manager.
AppManagerUI
managerUI
Application Manager main form.
Display
display
Display for the Manager MIDlet.
private Command
fgCmd
Command object for "Bring to foreground".
Constructors Summary
MIDletSwitcher(AppManagerUI managerUI, ApplicationManager manager, Display display)
Create and initialize a new MIDlet Switcher.

param
managerUI the aplication manager main form
param
manager the parent application manager
param
display the Display

                                 
       
                     
        super("", Choice.IMPLICIT);
        this.manager = manager;
        this.managerUI = managerUI;
        this.display = display;
        mcount = 0;
        minfo = new RunningMIDletSuiteInfo[Constants.MAX_ISOLATES];

        setSelectCommand(fgCmd);
        setFitPolicy(TEXT_WRAP_OFF);
        setCommandListener(this); // Listen for the selection
    
Methods Summary
synchronized voidappend(RunningMIDletSuiteInfo msi)
Append launched suite info to the list.

        checkInfoArraySize();
        minfo[mcount++] = msi;
        append(msi.displayName, msi.icon);
    
private voidcheckInfoArraySize()
Ensures that info array has enough capacity.

        if ((mcount+pitch < minfo.length) || (mcount >= minfo.length)) { 
            RunningMIDletSuiteInfo[] n =
                new RunningMIDletSuiteInfo[mcount+pitch];
            System.arraycopy(minfo, 0, n, 0, mcount);
            minfo = n;
        }
    
public synchronized voidcommandAction(Command c, Displayable s)
Respond to a command issued on any Screen.

param
c command activated by the user
param
s the Displayable the command was on.

        if (c == fgCmd) {
            //bring to foreground appropriate midlet
            int ind = getSelectedIndex();
            if (ind != -1) {
                manager.moveToForeground(minfo[ind]);
            }
            display.setCurrent(managerUI);
        }
    
synchronized booleanhasItems()
If switcher hase any items. equivalent statement - if there is any launched MIDlet

        return (mcount > 0);
    
synchronized voidremove(MIDletSuiteInfo msi)
Remove suite info from the list.

        int pos = -1;
        for (int i = 0; i < mcount; i++) {
            if (minfo[i] == msi) {
                pos = i;
                break;
            }
        }
        if (pos >= 0) {
            for (int i = pos+1; i < mcount; i++) {
                minfo[i-1] = minfo[i];
            }
            mcount--;
            checkInfoArraySize();
            delete(pos);
        }