📄 manager.java
字号:
/* * @(#)Manager.java 1.26 01/09/04 * * Copyright (c) 2001 Sun Microsystems, Inc., 901 San Antonio Road, * Palo Alto, CA 94303, U.S.A. All Rights Reserved. * * Sun Microsystems, Inc. has intellectual property rights relating * to the technology embodied in this software. In particular, and * without limitation, these intellectual property rights may include * one or more U.S. patents, foreign patents, or pending * applications. Sun, Sun Microsystems, the Sun logo, Java, KJava, * and all Sun-based and Java-based marks are trademarks or * registered trademarks of Sun Microsystems, Inc. in the United * States and other countries. * * This software is distributed under licenses restricting its use, * copying, distribution, and decompilation. No part of this * software may be reproduced in any form by any means without prior * written authorization of Sun and its licensors, if any. * * FEDERAL ACQUISITIONS: Commercial Software -- Government Users * Subject to Standard License Terms and Conditions */package com.sun.midp.dev;import javax.microedition.io.*;import java.util.*;import java.io.*;import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.*;import javax.microedition.rms.*;import com.sun.midp.lcdui.Resource;import com.sun.midp.midlet.MIDletInfo;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midlet.Scheduler;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midletsuite.*;import com.sun.midp.security.SecurityDomain;import com.sun.midp.security.Actions;import com.sun.midp.Configuration;import javax.microedition.io.*;import com.sun.midp.io.j2me.storage.*;/** * The Graphical MIDlet suite manager. * <p> * Starts with a selector that provides a list of MIDlet suites and * a set of commands to perform. It displays the MIDlet names for a suite * under the MIDlet suite name, except if there is only one suite then * instead of display the suite name, MIDlet-1 name and icon are used. * <p> * The commands are:</p> * <ul> * <li><b>Install</b>: Let the user install a suite from a list suites * obtained using an HTML URL given by the user. This list is derived by * extracting the links with hrefs that are in quotes and end with ".jad" from * the HTML page. An href in an extracted link is assumed to be an absolute * URL for a MIDP application descriptor.</li> * <li><b>Launch</b>: Launch the suite the user selected. * <li><b>Remove</b>: Remove the suite (with confirmation) the user selected. * </li> * <li><b>Update</b>: Update the suite the user selected.</li> * <li><b>Info</b>: Show the user general information of the selected suite. * <li><b>Settings</b>: Let the user change the manager's settings. * </ul> */public class Manager extends MIDlet implements CommandListener { /** Standard timeout for our alerts. */ private static final int ALERT_TIMEOUT = 1500; /** Standard name for the settings record store. */ private static final String SETTINGS_STORE = "settings"; /** This class has a different security domain than the MIDlet suite. */ private static SecurityDomain classSecurityDomain; /** Cache of the suite icon. */ private static Image suiteIcon; /** Cache of the empty icon. */ private static Image emptyIcon; /** Cache of the single suite icon. */ private static Image singleSuiteIcon; /** So the static method can know if there is a color display. */ private static boolean colorDisplay; /** The installer that is being used to install or update a suite. */ private Installer installer; /** List of all the MIDlet suites. */ private List mlist; /** True until startApp is called the first time. */ private static boolean first = true; /** Display for this MIDlet. */ private Display display; /** Number of midlets in minfo. */ private int mcount; /** MIDlet suite information, class, name, icon; one per MIDlet suite. */ private MIDletSuiteInfo[] minfo; /** Currently selected suite. */ private int selectedSuite; /** Contains the new default URL the user typed in. */ private TextBox settingsTextBox; /** Contains the default URL for the install list. */ private String defaultInstallListUrl = "http://"; /** Contains the URL the user typed in. */ private TextBox urlTextBox; /** Lets the enter a password and username. */ private Form passwordForm; /** Contains the username for installing. */ private TextField usernameField; /** Contains the password for installing. */ private TextField passwordField; /** Background installer that holds state for the current install. */ private BackgroundInstaller backgroundInstaller; /** Displays the progress of the install. */ private Form conForm; /** Keeps track of when the display last changed. UCT in millseconds. */ private long lastDisplayChange; /** What to display to the user when the current action is cancelled. */ private String cancelledMessage; /** What to display to the user when the current action is finishing. */ private String finishingMessage; /** Displays a list of suites to install to the user. */ private List installListBox; /** Contains a list of suites to install. */ private Vector installList; /** Command object for "Launch". */ private Command launchCmd = new Command(Resource.getString("Launch"), Command.ITEM, 1); /** Command object for "Info". */ private Command infoCmd = new Command(Resource.getString("Info"), Command.ITEM, 2); /** Command object for "Remove". */ private Command removeCmd = new Command(Resource.getString("Remove"), Command.ITEM, 3); /** Command object for "Update". */ private Command updateCmd = new Command(Resource.getString("Update"), Command.ITEM, 4); /** Command object for "Install". */ private Command installCmd = new Command(Resource.getString("Install"), Command.SCREEN, 1); /** Command object for "Cancel" command for the remove form. */ private Command cancelInstallCmd = new Command( Resource.getString("Cancel"), Command.CANCEL, 1); /** Command object for "Settings". */ private Command settingsCmd = new Command(Resource.getString("Settings"), Command.SCREEN, 2); /** Command object for "About". */ private Command aboutCmd = new Command(Resource.getString("About"), Command.SCREEN, 3); /** Command object for settings screen to save the settings. */ private Command saveSettingsCmd = new Command(Resource.getString("Save"), Command.SCREEN, 1); /** Command object for URL screen to go and get URL's for suites. */ private Command selectSuiteCmd = new Command(Resource.getString("Go"), Command.SCREEN, 1); /** Command object for "Back" command for the info form. */ private Command backCmd = new Command(Resource.getString("Back"), Command.BACK, 1); /** Command object for "Cancel" command for the remove form. */ private Command cancelCmd = new Command(Resource.getString("Cancel"), Command.CANCEL, 1); /** Command object for "Remove" command for the remove form. */ private Command removeOkCmd = new Command(Resource.getString("Remove"), Command.SCREEN, 1); /** Command object for "Stop" command for update and install forms. */ private Command stopCmd = new Command(Resource.getString("Stop"), Command.STOP, 1); /** Command object for "Next" command for password form. */ private Command nextCmd = new Command(Resource.getString("Next"), Command.SCREEN, 1); /** Command object for "OK" command for warning form. */ private Command okCmd = new Command(Resource.getString("OK"), Command.OK, 1); /** Translated small copyright string. */ private static final String SMALL_COPYRIGHT = Resource.getString( "Copyright 2000-2001 Sun Microsystems Inc. All Rights Reserved."); /** Translated long copyright string. */ private static final String COPYRIGHT = Resource.getString( "Copyright 2000-2001 Sun Microsystems Inc. All Rights Reserved.\n" + "Sun, Sun Microsystems, the Sun logo, Java, and all Sun-based and " + "Java-based marks are trademarks or registered trademarks of Sun " + "Microsystems, Inc. in the United States and other countries.\n" + "\n" + "This product meets the Wireless Profile Compatible designation " + "requirement, containing tested and compatible Wireless Profile " + "software from Sun Microsystems, Inc.\n" + "\n" + "Use is subject to license terms and limited to demonstration only. " + "Sun Microsystems, Inc. has intellectual property rights relating " + "to the technology embodied in this software. In particular, and " + "without limitation, these intellectual property rights may include " + "one or more U.S. patents, foreign patents, or pending applications.\n" + "U.S. Government approval required when exporting the product.\n" + "\n" + "FEDERAL ACQUISITIONS\n" + "Commercial Software -- Government Users Subject to Standard " + "License Terms and Conditions."); /** * Initializes the security domain for this class, so it can * perform actions that a normal MIDlet Suite cannot. * * @param theDomain SecurityDomain for this class. */ public static void initSecurityDomain(SecurityDomain theDomain) { if (classSecurityDomain != null) { return; } classSecurityDomain = theDomain; } /** * Set up the initial state for the Manager. * * @param logoDisplayed true if the logo has been displayed */ public static void initialize(boolean logoDisplayed) { first = !logoDisplayed; } /** * Translate an InvalidJadException into a message for the user. * * @param exception exception to translate * @param name name of the MIDlet suite to insert into the message * @param jadUrl URL of a JAD, can be null * * @return message to display to the user */ private static String translateJadException( InvalidJadException exception, String name, String jadUrl) { String[] values = {name, jadUrl, exception.getExtraData()}; String key; switch (exception.getReason()) { case InvalidJadException.MISSING_PROVIDER_CERT: case InvalidJadException.MISSING_SUITE_NAME: case InvalidJadException.MISSING_VENDOR: case InvalidJadException.MISSING_VERSION: case InvalidJadException.MISSING_JAR_URL: case InvalidJadException.MISSING_JAR_SIZE: case InvalidJadException.MISSING_JAR_DIGEST: key = "%1 cannot be installed because critical information is " + "missing from the application file (.jad)."; break; case InvalidJadException.MISSING_CONFIGURATION: case InvalidJadException.MISSING_PROFILE: key = "%1 cannot be installed because critical information is " + "missing from the archive file (.jar)."; break; case InvalidJadException.SUITE_NAME_MISMATCH: case InvalidJadException.VERSION_MISMATCH: case InvalidJadException.VENDOR_MISMATCH: case InvalidJadException.JAR_SIZE_MISMATCH: key = "%1 cannot be installed because critical information " + "between the website and the application file does not " + "match."; break; case InvalidJadException.OLD_VERSION: key = "A newer version of %1 is already installed on this " + "device."; break; case InvalidJadException.NEW_VERSION: key = "An older version of %1 is already installed on this " + "device. Do you want to update the older version?"; break; case InvalidJadException.ALREADY_INSTALLED: key = "The same version of %1 is already installed on this " + "device. Do you want to update the existing version?"; break; case InvalidJadException.JAD_SERVER_NOT_FOUND: case InvalidJadException.JAD_NOT_FOUND: key = "%1 cannot be found at this URL. " + "Contact the application provider for more information."; break; case InvalidJadException.JAR_SERVER_NOT_FOUND: case InvalidJadException.JAR_NOT_FOUND: key = "The archive file (.jar) for %1 cannot be found at its " + "URL. Contact the application provider for more " + "information."; break; case InvalidJadException.INVALID_KEY: case InvalidJadException.INVALID_VALUE: case InvalidJadException.INVALID_VERSION: key = "%1 cannot be installed because critical " + "information is not formatted correctly and is invalid."; break; case InvalidJadException.INSUFFICIENT_STORAGE: key = "There is not enough room to install %1 (%3K is needed " + "for installation.). Try removing other items to free " + "up space."; break; case InvalidJadException.INVALID_JAR_TYPE: key = "The archive file (.jar) for %1 does not appear to be " + "the correct type. Contact the application provider " + "for more information."; break; case InvalidJadException.INVALID_JAD_TYPE: key = "The application file (.jad) for %1 does not appear to be " + "the correct type. Contact the application provider " + "for more information."; break; case InvalidJadException.CORRUPT_JAR: key = "The archive file (.jar) for %1 appears to be corrupt. " + "Contact the application provider " + "for more information."; break; case InvalidJadException.JAD_MOVED: key = "The new version of %1 is not from the same provider " + "as the old version. The download URLs do not match. " + "Do you want to install the new version?" + "\n\nOld URL: %3\nNew URL: %2"; break; case InvalidJadException.CANNOT_AUTH: key = "The server has requested an authentication of the user " + "with a scheme that this device does not support."; break; case InvalidJadException.DEVICE_INCOMPATIBLE: key = "%1 is not designed to work with this device and cannot " + "be installed."; break; default: return exception.getMessage(); } return Resource.getString(key, values); } /** * Gets the MIDlet suite icon from storage. * * @return icon image */ private static Image getSuiteIcon() { if (suiteIcon != null) { return suiteIcon; } suiteIcon = getIconFromStorage( (colorDisplay ? "_suite_8.png" : "_suite_2.png")); return suiteIcon; } /** * Gets the empty icon from storage. * * @return icon image */ private static Image getEmptyIcon() { if (emptyIcon != null) { return emptyIcon; } emptyIcon = getIconFromStorage("_empty.png"); return emptyIcon; } /** * Gets the single MIDlet suite icon from storage. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -