Source Code Cross Referenced for MIDletSelector.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » appmanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.appmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.midp.appmanager;
027:
028:        import javax.microedition.lcdui.*;
029:
030:        import com.sun.midp.i18n.Resource;
031:        import com.sun.midp.i18n.ResourceConstants;
032:
033:        import com.sun.midp.main.MIDletSuiteLoader;
034:
035:        import com.sun.midp.midlet.MIDletSuite;
036:
037:        import com.sun.midp.midletsuite.*;
038:
039:        import com.sun.midp.log.Logging;
040:        import com.sun.midp.log.LogChannels;
041:
042:        /**
043:         * Selector provides a simple user interface to select MIDlets to run.
044:         * It extracts the list of MIDlets from the attributes in the
045:         * descriptor file and presents them to the user using the MIDlet-<n>
046:         * name and icon if any. When the user selects a MIDlet an instance
047:         * of the class indicated by MIDlet-<n> classname is created.
048:         */
049:        final class MIDletSelector implements  CommandListener {
050:            /**
051:             * The List of all the MIDlets.
052:             */
053:            private List mlist;
054:            /**
055:             * Information needed to display a list of MIDlets.
056:             */
057:            private RunningMIDletSuiteInfo suiteInfo;
058:            /**
059:             * The Display.
060:             */
061:            private Display display;
062:            /**
063:             * The parent's display able.
064:             */
065:            private Displayable parentDisplayable;
066:            /**
067:             * Parent app manager.
068:             */
069:            ApplicationManager manager;
070:            /**
071:             * Number of midlets in minfo.
072:             */
073:            private int mcount;
074:            /**
075:             * MIDlet information, class, name, icon; one per MIDlet.
076:             */
077:            private MIDletInfo[] minfo;
078:            /**
079:             * the Command object to exit back to the MIDlet Suite Manager
080:             */
081:            private Command backCmd = new Command(Resource
082:                    .getString(ResourceConstants.BACK), Command.BACK, 2);
083:            /**
084:             * the Command object for "Launch".
085:             */
086:            private Command launchCmd = new Command(Resource
087:                    .getString(ResourceConstants.LAUNCH), Command.ITEM, 1);
088:            /**
089:             * Index of the selected MIDlet, starts at -1 for non-selected.
090:             */
091:            private int selectedMidlet = -1;
092:
093:            /**
094:             * Create and initialize a new Selector MIDlet.
095:             * The Display is retrieved and the list of MIDlets read
096:             * from the descriptor file.
097:             *
098:             * @param theSuiteInfo information needed to display a list of MIDlets
099:             * @param theDisplay the Display
100:             * @param theParentDisplayable the parent's displayable
101:             * @param theManager the parent application manager
102:             */
103:            MIDletSelector(RunningMIDletSuiteInfo theSuiteInfo,
104:                    Display theDisplay, Displayable theParentDisplayable,
105:                    ApplicationManager theManager) throws Throwable {
106:
107:                MIDletSuiteStorage mss;
108:
109:                suiteInfo = theSuiteInfo;
110:                display = theDisplay;
111:                parentDisplayable = theParentDisplayable;
112:                manager = theManager;
113:                mcount = 0;
114:                minfo = new MIDletInfo[20];
115:
116:                mss = MIDletSuiteStorage.getMIDletSuiteStorage();
117:
118:                readMIDletInfo(mss);
119:                setupList(mss);
120:
121:                mlist.addCommand(launchCmd);
122:                mlist.addCommand(backCmd);
123:
124:                mlist.setCommandListener(this ); // Listen for the selection
125:
126:                display.setCurrent(mlist);
127:            }
128:
129:            /**
130:             * Respond to a command issued on any Screen.
131:             * The commands on list is Select and About.
132:             * Select triggers the creation of the MIDlet of the same name.
133:             * About puts up the copyright notice.
134:             *
135:             * @param c command activated by the user
136:             * @param s the Displayable the command was on.
137:             */
138:            public void commandAction(Command c, Displayable s) {
139:                if ((s == mlist && c == List.SELECT_COMMAND)
140:                        || (c == launchCmd)) {
141:                    synchronized (this ) {
142:                        if (selectedMidlet != -1) {
143:                            // the previous selected MIDlet is being launched
144:                            return;
145:                        }
146:
147:                        selectedMidlet = mlist.getSelectedIndex();
148:                    }
149:
150:                    manager.launchSuite(suiteInfo,
151:                            minfo[selectedMidlet].classname);
152:                    display.setCurrent(parentDisplayable);
153:                    return;
154:                }
155:
156:                if (c == backCmd) {
157:                    display.setCurrent(parentDisplayable);
158:                    return;
159:                }
160:            }
161:
162:            /**
163:             * Read the set of MIDlet names, icons and classes
164:             * Fill in the list.
165:             *
166:             * @param mss the midlet suite storage
167:             */
168:            private void setupList(MIDletSuiteStorage mss) {
169:                if (mlist == null) {
170:                    mlist = new List(
171:                            Resource
172:                                    .getString(ResourceConstants.AMS_SELECTOR_SEL_TO_LAUNCH),
173:                            Choice.IMPLICIT);
174:
175:                    // Add each midlet
176:                    for (int i = 0; i < mcount; i++) {
177:                        Image icon = null;
178:                        if (minfo[i].icon != null) {
179:                            icon = RunningMIDletSuiteInfo.getIcon(
180:                                    suiteInfo.suiteId, minfo[i].icon, mss);
181:                        }
182:
183:                        mlist.append(minfo[i].name, icon);
184:                    }
185:                }
186:            }
187:
188:            /**
189:             * Read in and create a MIDletInfo for each MIDlet-&lt;n&gt;
190:             *
191:             * @param mss the midlet suite storage
192:             */
193:            private void readMIDletInfo(MIDletSuiteStorage mss)
194:                    throws Throwable {
195:                try {
196:                    MIDletSuite midletSuite = mss.getMIDletSuite(
197:                            suiteInfo.suiteId, false);
198:
199:                    if (midletSuite == null) {
200:                        return;
201:                    }
202:
203:                    try {
204:                        for (int n = 1; n < 100; n++) {
205:                            String nth = "MIDlet-" + n;
206:                            String attr = midletSuite.getProperty(nth);
207:                            if (attr == null || attr.length() == 0)
208:                                break;
209:
210:                            addMIDlet(new MIDletInfo(attr));
211:                        }
212:                    } finally {
213:                        midletSuite.close();
214:                    }
215:                } catch (Throwable t) {
216:                    throw t;
217:                }
218:            }
219:
220:            /**
221:             * Add a MIDlet to the list.
222:             * @param info MIDlet information to add to MIDlet
223:             */
224:            private void addMIDlet(MIDletInfo info) {
225:                if (mcount >= minfo.length) {
226:                    MIDletInfo[] n = new MIDletInfo[mcount + 4];
227:                    System.arraycopy(minfo, 0, n, 0, mcount);
228:                    minfo = n;
229:                }
230:
231:                minfo[mcount++] = info;
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.