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:
027: package com.sun.midp.appmanager;
028:
029: import javax.microedition.lcdui.*;
030:
031: import com.sun.midp.i18n.Resource;
032: import com.sun.midp.i18n.ResourceConstants;
033:
034: import com.sun.midp.main.TrustedMIDletIcon;
035:
036: import com.sun.midp.midlet.*;
037:
038: import com.sun.midp.midletsuite.*;
039:
040: import com.sun.midp.io.j2me.push.*;
041:
042: import com.sun.midp.installer.*;
043:
044: import com.sun.midp.configurator.Constants;
045:
046: /**
047: * The Graphical MIDlet suite information display.
048: * <p>
049: * The application property "arg0" will have the ID of the suite to display.
050: */
051: public class AppInfo extends Form {
052:
053: /** Cache of the suite icon. */
054: Image suiteIcon;
055: /** Cache of the single suite icon. */
056: Image singleSuiteIcon;
057:
058: /** Icon to display for the suite */
059: Image icon;
060:
061: /** MIDlet Suite storage object. */
062: MIDletSuiteStorage midletSuiteStorage;
063:
064: /** Switch to the manager when "Back" is activated */
065: ApplicationManager manager;
066:
067: /** Installation information of the suite. */
068: InstallInfo installInfo;
069: /** Number of MIDlets in the suite. */
070: int numberOfMidlets;
071: /** Display name of the suite. */
072: String displayName;
073:
074: /**
075: * Create and initialize a new Application Info MIDlet.
076: * @param suiteId - the id of the suite for
077: * which the AppInfo should be displayed
078: * @exception Exception if error occurs
079: */
080: public AppInfo(int suiteId) throws Throwable {
081:
082: super (null);
083:
084: midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();
085:
086: displaySuiteInfo(suiteId);
087: }
088:
089: /**
090: * Display the information for a suite.
091: *
092: * @param suiteId ID for suite to display
093: * @exception Exception if error occurs
094: */
095: private void displaySuiteInfo(int suiteId) throws Throwable {
096: StringBuffer label = new StringBuffer(40);
097: StringBuffer value = new StringBuffer(40);
098: Item item;
099: String[] authPath;
100: String temp;
101: MIDletSuiteImpl midletSuite = null;
102:
103: try {
104: midletSuite = midletSuiteStorage.getMIDletSuite(suiteId,
105: false);
106:
107: initMidletSuiteInfo(midletSuite);
108:
109: label.append(Resource.getString(ResourceConstants.INFO));
110: label.append(": ");
111: label.append(displayName);
112: setTitle(label.toString());
113:
114: append(new ImageItem(null, icon,
115: ImageItem.LAYOUT_NEWLINE_BEFORE
116: + ImageItem.LAYOUT_CENTER
117: + ImageItem.LAYOUT_NEWLINE_AFTER, null));
118:
119: if (!midletSuite.isEnabled()) {
120: item = new StringItem(
121: null,
122: Resource
123: .getString(ResourceConstants.AMS_SUITE_DISABLED_NOTE));
124: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
125: | Item.LAYOUT_2);
126: append(item);
127: }
128:
129: // round up the size to a Kilobyte
130: label.setLength(0);
131: label
132: .append(Resource
133: .getString(ResourceConstants.AMS_SIZE));
134: label.append(": ");
135: value.append(Integer.toString((MIDletSuiteStorage
136: .getMIDletSuiteStorage().getStorageUsed(
137: midletSuite.getID()) + 1023) / 1024));
138: value.append(" K");
139: item = new StringItem(label.toString(), value.toString());
140: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
141: append(item);
142:
143: label.setLength(0);
144: label.append(Resource
145: .getString(ResourceConstants.AMS_VERSION));
146: label.append(": ");
147: item = new StringItem(label.toString(), midletSuite
148: .getProperty(MIDletSuite.VERSION_PROP));
149: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
150: append(item);
151:
152: label.setLength(0);
153:
154: if (midletSuite.isTrusted()) {
155: temp = Resource
156: .getString(ResourceConstants.AMS_MGR_AUTH_VENDOR);
157: } else {
158: temp = Resource
159: .getString(ResourceConstants.AMS_MGR_VENDOR);
160: }
161:
162: label.append(temp);
163: label.append(": ");
164: item = new StringItem(label.toString(), midletSuite
165: .getProperty(MIDletSuite.VENDOR_PROP));
166: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
167: append(item);
168:
169: temp = midletSuite.getProperty(MIDletSuite.DESC_PROP);
170: if (temp != null) {
171: label.setLength(0);
172: label.append(Resource
173: .getString(ResourceConstants.AMS_DESCRIPTION));
174: label.append(": ");
175: item = new StringItem(label.toString(), temp);
176: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
177: | Item.LAYOUT_2);
178: append(item);
179: }
180:
181: if (numberOfMidlets != 1) {
182: label.setLength(0);
183: label.append(Resource
184: .getString(ResourceConstants.AMS_CONTENTS));
185: label.append(":");
186: item = new StringItem(label.toString(), "");
187: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
188: | Item.LAYOUT_2);
189: append(item);
190: appendMIDletsToForm(midletSuite);
191: }
192:
193: label.setLength(0);
194: label.append(Resource
195: .getString(ResourceConstants.AMS_WEBSITE));
196: label.append(": ");
197: item = new StringItem(label.toString(), installInfo
198: .getDownloadUrl());
199: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
200: append(item);
201:
202: label.setLength(0);
203: label.append(Resource
204: .getString(ResourceConstants.AMS_ADVANCED));
205: label.append(": ");
206: item = new StringItem(label.toString(), "");
207: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
208: append(item);
209:
210: if (midletSuite.isTrusted()) {
211: append(new ImageItem(null, TrustedMIDletIcon.getIcon(),
212: ImageItem.LAYOUT_DEFAULT, null));
213: temp = Resource
214: .getString(ResourceConstants.AMS_MGR_TRUSTED);
215: } else {
216: temp = Resource
217: .getString(ResourceConstants.AMS_MGR_UNTRUSTED);
218: }
219:
220: item = new StringItem(null, temp);
221: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
222: append(item);
223:
224: // Append classes verification state to advanced section
225: if (Constants.VERIFY_ONCE && midletSuite.isVerified()) {
226: item = new StringItem(
227: null,
228: Resource
229: .getString(ResourceConstants.AMS_VERIFIED_CLASSES));
230: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
231: | Item.LAYOUT_2);
232: append(item);
233:
234: }
235:
236: authPath = installInfo.getAuthPath();
237: if (authPath != null) {
238: label.setLength(0);
239: label
240: .append(Resource
241: .getString(ResourceConstants.AMS_AUTHORIZED_BY));
242: label.append(": ");
243: temp = label.toString();
244: for (int i = 0; i < authPath.length; i++) {
245: item = new StringItem(temp, authPath[i]);
246: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
247: | Item.LAYOUT_2);
248: append(item);
249: temp = null;
250: }
251: }
252:
253: temp = PushRegistryInternal.listConnections(midletSuite
254: .getID(), false);
255: if (temp != null) {
256: label.setLength(0);
257: label
258: .append(Resource
259: .getString(ResourceConstants.AMS_AUTO_START_CONN));
260: label.append(": ");
261: item = new StringItem(label.toString(), temp);
262: item.setLayout(Item.LAYOUT_NEWLINE_AFTER
263: | Item.LAYOUT_2);
264: append(item);
265: }
266: } catch (Throwable t) {
267: throw t;
268: } finally {
269: if (midletSuite != null) {
270: midletSuite.close();
271: }
272: }
273: }
274:
275: /**
276: * Initialize the MIDlet suite info fields for a given suite.
277: *
278: * @param midletSuite the MIDletSuiteImpl object instance
279: *
280: * @exception Exception if problem occurs while getting the suite info
281: */
282: private void initMidletSuiteInfo(MIDletSuiteImpl midletSuite)
283: throws Exception {
284:
285: installInfo = midletSuite.getInstallInfo();
286: numberOfMidlets = midletSuite.getNumberOfMIDlets();
287:
288: if (numberOfMidlets == 1) {
289: String value = midletSuite.getProperty("MIDlet-1");
290: MIDletInfo temp = new MIDletInfo(value);
291: displayName = temp.name;
292: icon = getSingleSuiteIcon();
293: } else {
294: displayName = midletSuite
295: .getProperty(MIDletSuiteImpl.SUITE_NAME_PROP);
296: icon = getSuiteIcon();
297: }
298: }
299:
300: /**
301: * Appends a names of all the MIDlets in a suite to a Form, one per line.
302: *
303: * @param midletSuite information of a suite of MIDlets
304: */
305: private void appendMIDletsToForm(MIDletSuiteImpl midletSuite) {
306: int numberOfMidlets;
307: MIDletInfo midletInfo;
308: StringItem item;
309:
310: numberOfMidlets = midletSuite.getNumberOfMIDlets();
311: for (int i = 1; i <= numberOfMidlets; i++) {
312: midletInfo = new MIDletInfo(midletSuite
313: .getProperty("MIDlet-" + i));
314:
315: item = new StringItem(null, midletInfo.name);
316: item.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
317: append(item);
318: }
319: }
320:
321: /**
322: * Gets the MIDlet suite icon from storage.
323: *
324: * @return icon image
325: */
326: private Image getSuiteIcon() {
327: if (suiteIcon != null) {
328: return suiteIcon;
329: }
330:
331: suiteIcon = GraphicalInstaller
332: .getImageFromInternalStorage("_suite8");
333: return suiteIcon;
334: }
335:
336: /**
337: * Gets the single MIDlet suite icon from storage.
338: *
339: * @return icon image
340: */
341: private Image getSingleSuiteIcon() {
342: if (singleSuiteIcon != null) {
343: return singleSuiteIcon;
344: }
345:
346: singleSuiteIcon = GraphicalInstaller
347: .getImageFromInternalStorage("_single8");
348: return singleSuiteIcon;
349: }
350: }
|