MIDletSelectorpublic final class MIDletSelector extends Object implements CommandListenerSelector provides a simple user interface to select MIDlets to run.
It extracts the list of MIDlets from the attributes in the
descriptor file and presents them to the user using the MIDlet-<n>
name and icon if any. When the user selects a MIDlet an instance
of the class indicated by MIDlet-<n> classname is created. |
Fields Summary |
---|
private List | mlistThe List of all the MIDlets. | private RunningMIDletSuiteInfo | suiteInfoInformation needed to display a list of MIDlets. | private Display | displayThe Display. | private Displayable | parentDisplayableThe parent's display able. | ApplicationManager | managerParent app manager. | private int | mcountNumber of midlets in minfo. | private MIDletInfo[] | minfoMIDlet information, class, name, icon; one per MIDlet. | private Command | backCmdthe Command object to exit back to the MIDlet Suite Manager | private Command | launchCmdthe Command object for "Launch". | private int | selectedMidletIndex of the selected MIDlet, starts at -1 for non-selected. |
Constructors Summary |
---|
MIDletSelector(RunningMIDletSuiteInfo theSuiteInfo, Display theDisplay, Displayable theParentDisplayable, ApplicationManager theManager)Create and initialize a new Selector MIDlet.
The Display is retrieved and the list of MIDlets read
from the descriptor file.
MIDletSuiteStorage mss;
suiteInfo = theSuiteInfo;
display = theDisplay;
parentDisplayable = theParentDisplayable;
manager = theManager;
mcount = 0;
minfo = new MIDletInfo[20];
mss = MIDletSuiteStorage.getMIDletSuiteStorage();
readMIDletInfo(mss);
setupList(mss);
mlist.addCommand(launchCmd);
mlist.addCommand(backCmd);
mlist.setCommandListener(this); // Listen for the selection
display.setCurrent(mlist);
|
Methods Summary |
---|
private void | addMIDlet(MIDletInfo info)Add a MIDlet to the list.
if (mcount >= minfo.length) {
MIDletInfo[] n = new MIDletInfo[mcount+4];
System.arraycopy(minfo, 0, n, 0, mcount);
minfo = n;
}
minfo[mcount++] = info;
| public void | commandAction(Command c, Displayable s)Respond to a command issued on any Screen.
The commands on list is Select and About.
Select triggers the creation of the MIDlet of the same name.
About puts up the copyright notice.
if ((s == mlist && c == List.SELECT_COMMAND) || (c == launchCmd)) {
synchronized (this) {
if (selectedMidlet != -1) {
// the previous selected MIDlet is being launched
return;
}
selectedMidlet = mlist.getSelectedIndex();
}
manager.launchSuite(suiteInfo, minfo[selectedMidlet].classname);
display.setCurrent(parentDisplayable);
return;
}
if (c == backCmd) {
display.setCurrent(parentDisplayable);
return;
}
| private void | readMIDletInfo(MIDletSuiteStorage mss)Read in and create a MIDletInfo for each MIDlet-<n>
try {
MIDletSuite midletSuite =
mss.getMIDletSuite(suiteInfo.suiteId, false);
if (midletSuite == null) {
return;
}
try {
for (int n = 1; n < 100; n++) {
String nth = "MIDlet-"+ n;
String attr = midletSuite.getProperty(nth);
if (attr == null || attr.length() == 0)
break;
addMIDlet(new MIDletInfo(attr));
}
} finally {
midletSuite.close();
}
} catch (Throwable t) {
throw t;
}
| private void | setupList(MIDletSuiteStorage mss)Read the set of MIDlet names, icons and classes
Fill in the list.
if (mlist == null) {
mlist = new List(Resource.getString
(ResourceConstants.AMS_SELECTOR_SEL_TO_LAUNCH),
Choice.IMPLICIT);
// Add each midlet
for (int i = 0; i < mcount; i++) {
Image icon = null;
if (minfo[i].icon != null) {
icon = RunningMIDletSuiteInfo.getIcon(suiteInfo.suiteId,
minfo[i].icon, mss);
}
mlist.append(minfo[i].name, icon);
}
}
|
|