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 com.sun.midp.main.*;
030: import com.sun.midp.midletsuite.*;
031: import com.sun.midp.installer.*;
032: import javax.microedition.lcdui.*;
033: import com.sun.midp.configurator.Constants;
034:
035: import com.sun.midp.log.Logging;
036: import com.sun.midp.log.LogChannels;
037: import com.sun.midp.midlet.MIDletSuite;
038:
039: /** Simple attribute storage for MIDlet suites */
040: public class RunningMIDletSuiteInfo extends MIDletSuiteInfo {
041: /** Proxy if running. It is set from AppManagerUI.java. */
042: public MIDletProxy proxy = null;
043: /** Icon for this suite. */
044: public Image icon = null;
045:
046: /**
047: * Constructs a RunningMIDletSuiteInfo object for a suite.
048: *
049: * @param theID ID the system has for this suite
050: */
051: public RunningMIDletSuiteInfo(int theID) {
052: super (theID);
053: }
054:
055: /**
056: * Constructs a RunningMIDletSuiteInfo object for a suite.
057: *
058: * @param theID ID the system has for this suite
059: * @param theMidletToRun Class name of the only midlet in the suite
060: * @param theDisplayName Name to display to the user
061: * @param isEnabled true if the suite is enabled
062: */
063: public RunningMIDletSuiteInfo(int theID, String theMidletToRun,
064: String theDisplayName, boolean isEnabled) {
065: super (theID, theMidletToRun, theDisplayName, isEnabled);
066: icon = getDefaultSingleSuiteIcon();
067: }
068:
069: /**
070: * Constructs a RunningMIDletSuiteInfo object for a suite.
071: *
072: * @param theID ID the system has for this suite
073: * @param theMidletSuite MIDletSuite information
074: * @param mss the midletSuite storage
075: */
076: public RunningMIDletSuiteInfo(int theID,
077: MIDletSuiteImpl theMidletSuite, MIDletSuiteStorage mss) {
078: super (theID, theMidletSuite);
079:
080: icon = getIcon(theID,
081: theMidletSuite.getProperty("MIDlet-Icon"), mss);
082: if (icon == null && numberOfMidlets == 1) {
083: MIDletInfo midlet = new MIDletInfo(theMidletSuite
084: .getProperty("MIDlet-1"));
085:
086: // MIDlet icons are optional, so it the icon may be null
087: icon = getIcon(theID, midlet.icon, mss);
088: }
089:
090: if (icon == null) {
091: icon = getDefaultSingleSuiteIcon();
092: }
093: }
094:
095: /**
096: * Constructs a RunningMIDletSuiteInfo from MIDletSuiteInfo.
097: *
098: * @param info MIDletSuiteInfo reference
099: * @param mss the midletSuite storage
100: */
101: public RunningMIDletSuiteInfo(MIDletSuiteInfo info,
102: MIDletSuiteStorage mss) {
103: super (info.suiteId, info.midletToRun, info.displayName,
104: info.enabled);
105:
106: storageId = info.storageId;
107: numberOfMidlets = info.numberOfMidlets;
108: trusted = info.trusted;
109: preinstalled = info.preinstalled;
110: iconName = info.iconName;
111:
112: loadIcon(mss);
113: }
114:
115: /**
116: * Loads an icon for this suite.
117: *
118: * @param mss the midletSuite storage
119: */
120: public void loadIcon(MIDletSuiteStorage mss) {
121: if (iconName != null) {
122: icon = getIcon(suiteId, iconName, mss);
123: }
124:
125: if (icon == null) {
126: if (numberOfMidlets == 1) {
127: icon = getDefaultSingleSuiteIcon();
128: } else {
129: icon = getDefaultMultiSuiteIcon();
130: }
131: }
132: }
133:
134: /**
135: * Gets suite icon either from image cache, or from the suite jar.
136: *
137: * @param theID the suite id that system has for this suite
138: * @param iconName the name of the file where the icon is
139: * stored in the JAR
140: * @param mss The midletSuite storage
141: * @return Image provided by the application with
142: * the passed in iconName
143: */
144: public static Image getIcon(int theID, String iconName,
145: MIDletSuiteStorage mss) {
146: byte[] iconBytes;
147:
148: try {
149: iconBytes = mss.getMIDletSuiteIcon(theID, iconName);
150:
151: if (iconBytes == null) {
152: if (Logging.REPORT_LEVEL <= Logging.WARNING) {
153: Logging.report(Logging.WARNING, LogChannels.LC_AMS,
154: "getIcon: iconBytes == null");
155: }
156: return null;
157: }
158:
159: return Image.createImage(iconBytes, 0, iconBytes.length);
160: } catch (Throwable t) {
161: if (Logging.REPORT_LEVEL <= Logging.WARNING) {
162: Logging.report(Logging.WARNING, LogChannels.LC_AMS,
163: "getIcon threw an " + t.getClass());
164: }
165: return null;
166: }
167: }
168:
169: /**
170: * Returns a string representation of the MIDletSuiteInfo object.
171: * For debug only.
172: */
173: public String toString() {
174: StringBuffer b = new StringBuffer();
175: b.append("id = " + suiteId);
176: b.append(", midletToRun = " + midletToRun);
177: b.append(", proxy = " + proxy);
178: return b.toString();
179: }
180:
181: /**
182: * Compares this MIDletSuiteInfo with the passed in MIDletProxy.
183: * Returns true if both belong to the same suite and
184: * if current proxy or midetToRun points to the same class as
185: * in the passed in MIDletProxy.
186: * @param midlet The MIDletProxy to compare with
187: * @return true if The MIDletSuiteInfo points to the same midlet as
188: * the MIDletProxy, false - otherwise
189: */
190: public boolean equals(MIDletProxy midlet) {
191: if (suiteId == midlet.getSuiteId()) {
192: if (proxy != null) {
193: return proxy == midlet;
194: }
195:
196: if ((numberOfMidlets == 1 || suiteId == MIDletSuite.INTERNAL_SUITE_ID)
197: && midletToRun != null) {
198: return midletToRun.equals(midlet.getClassName());
199: }
200:
201: return true;
202: }
203:
204: return false;
205: }
206:
207: /** Cache of the suite icon. */
208: private static Image multiSuiteIcon;
209:
210: /** Cache of the single suite icon. */
211: private static Image singleSuiteIcon;
212:
213: /**
214: * Gets the single MIDlet suite icon from storage.
215: *
216: * @return icon image
217: */
218: private static Image getDefaultSingleSuiteIcon() {
219: if (singleSuiteIcon == null) {
220: singleSuiteIcon = GraphicalInstaller
221: .getImageFromInternalStorage("_ch_single");
222: }
223: return singleSuiteIcon;
224: }
225:
226: /**
227: * Gets the MIDlet suite icon from storage.
228: *
229: * @return icon image
230: */
231: private static Image getDefaultMultiSuiteIcon() {
232: if (multiSuiteIcon == null) {
233: multiSuiteIcon = GraphicalInstaller
234: .getImageFromInternalStorage("_ch_suite");
235: }
236: return multiSuiteIcon;
237: }
238: }
|