componentmanager.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 462 行 · 第 1/2 页

JAVA
462
字号
/* * * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.appmanager;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.installer.DynamicComponentInstaller;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midletsuite.DynamicComponentStorage;import com.sun.midp.midletsuite.MIDletSuiteLockedException;import com.sun.midp.services.ComponentInfo;import javax.microedition.lcdui.*;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;import java.io.IOException;/** * Component Manager * * Implements a built-in MIDlet that manages the dynamically installed components. */public class ComponentManager extends MIDlet {    /**     * Constructor: launches the component view screen.     */    public ComponentManager() {        new ComponentView(MIDletSuite.INTERNAL_SUITE_ID, this, true);    }    /**     * Signals the <code>MIDlet</code> that it has entered the     * <em>Active</em> state.     * In the <em>Active</EM> state the <code>MIDlet</code> may     * hold resources.     * The method will only be called when     * the <code>MIDlet</code> is in the <em>Paused</em> state.     * <p/>     * Two kinds of failures can prevent the service from starting,     * transient and non-transient.  For transient failures the     * <code>MIDletStateChangeException</code> exception should be thrown.     * For non-transient failures the <code>notifyDestroyed</code>     * method should be called.     * <p/>     * If a Runtime exception occurs during <code>startApp</code> the     * MIDlet will be     * destroyed immediately.  Its <code>destroyApp</code> will be     * called allowing     * the MIDlet to cleanup.     *     * @throws javax.microedition.midlet.MIDletStateChangeException     *          is thrown     *          if the <code>MIDlet</code>     *          cannot start now but might be able to start at a     *          later time.     */    protected void startApp() throws MIDletStateChangeException {    }    /**     * Signals the <code>MIDlet</code> to enter     * the <em>Paused</em> state.     * In the <em>Paused</em> state the <code>MIDlet</code> must     * release shared resources     * and become quiescent. This method will only be called     * called when the <code>MIDlet</code> is in the <em>Active</em> state. <p>     * <p/>     * If a Runtime exception occurs during <code>pauseApp</code> the     * MIDlet will be destroyed immediately.  Its     * <code>destroyApp</code> will be called allowing     * the MIDlet to cleanup.     */    protected void pauseApp() {    }    /**     * Signals the <code>MIDlet</code> to terminate and enter the     * <em>Destroyed</em> state.     * In the destroyed state the <code>MIDlet</code> must release     * all resources and save any persistent state. This method may     * be called from the <em>Paused</em> or     * <em>Active</em> states. <p>     * <code>MIDlet</code>s should     * perform any operations required before being terminated, such as     * releasing resources or saving preferences or     * state. <p>     * <p/>     * <strong>Note:</strong> The <code>MIDlet</code> can request that     * it not enter the <em>Destroyed</em>     * state by throwing an <code>MIDletStateChangeException</code>. This     * is only a valid response if the <code>unconditional</code>     * flag is set to <code>false</code>. If it is <code>true</code>     * the <code>MIDlet</code> is assumed to be in the <em>Destroyed</em> state     * regardless of how this method terminates. If it is not an     * unconditional request, the <code>MIDlet</code> can signify that it     * wishes to stay in its current state by throwing the     * <code>MIDletStateChangeException</code>.     * This request may be honored and the <code>destroy()</code>     * method called again at a later time.     * <p/>     * <p>If a Runtime exception occurs during <code>destroyApp</code> then     * they are ignored and the MIDlet is put into the <em>Destroyed</em>     * state.     *     * @param unconditional If true when this method is called, the     *                      <code>MIDlet</code> must cleanup and release all resources.  If     *                      false the <code>MIDlet</code> may throw     *                      <CODE>MIDletStateChangeException</CODE> to indicate it does not     *                      want to be destroyed at this time.     * @throws javax.microedition.midlet.MIDletStateChangeException     *          is thrown     *          if the <code>MIDlet</code> wishes to continue to     *          execute (Not enter the <em>Destroyed</em> state).     *          This exception is ignored if <code>unconditional</code>     *          is equal to <code>true</code>.     */    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {    }    /**     * A screen with a list of MIDlet components.     *     * Can provide read-only or full access to the user.     * May serve as the main screen of a MIDlet (in which case the MIDlet     * will terminate when the user exits the component list screen) or     * be called from some other screen (in which case that screen will     * be shown after exiting the the component list screen).     */    static class ComponentView implements CommandListener, ItemCommandListener {        /** Command object for "Back" command in the suite list form. */        private Command backCmd = new Command(Resource.getString                                              (ResourceConstants.BACK),                                              Command.BACK, 1);        /** Command object for "Back" command in the error message form. */        private Command errorBackCmd = new Command(Resource.getString                                              (ResourceConstants.BACK),                                              Command.BACK, 1);        /** Command object for "Launch". */        private Command openCmd =            new Command(Resource.getString(ResourceConstants.OPEN),                        Command.ITEM, 1);        /** Command object for "Install" command for the suite list form. */        private Command installCmd =            new Command(Resource.getString(ResourceConstants.INSTALL),                        Command.SCREEN, 1);        /** Command object for "Back" command in the install screen. */        private Command installNoCmd = new Command(Resource.getString                                              (ResourceConstants.BACK),                                              Command.BACK, 1);        /** Command object for "Yes, Install" command for the install screen. */        private Command installYesCmd =            new Command(Resource.getString(ResourceConstants.INSTALL),                        Command.SCREEN, 1);        /** Command object for "Remove" in the suite list form. */        private Command removeCmd =            new Command(Resource.getString(ResourceConstants.REMOVE),                        Command.ITEM, 3);        /**         * The Display object corresponding to the parent MIDlet.         * If not null, the current displayable is saved in the constructor         * to be restored when the user selects the "Back" command in         * the component list Form.         */        private Display display;        /**         * If not null, the Displayable to be restored         * when the user selects the "Back" command in the component list Form.         */        private Displayable parentDisplayable;        /**         * The parent MIDlet. If not null, this MIDlet receives NotifyDestroyed()         * when the user selects the "Back" command in the component list Form.         */        private MIDlet midlet;        /** ID of the MIDlet suite whose components we are interested in. */        private int  suiteId;        /** false for read-only access, true for full access. */        private boolean mayModify;        /** The component list Form */        private Form compList = new Form(null);        /** The "install component from url" Form */        private Form installUrlForm = null;        /** the component url text field for installUrlForm */        private TextField installUrlField = null ;        /** the component name text field for installUrlForm */        private TextField nameField = null ;        /** The error message Form */        private Form errorForm = null;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?