pxletmanager.java

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

JAVA
431
字号
/* * @(#)PXletManager.java	1.26 06/10/10 * * Copyright  1990-2008 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 sun.mtask.xlet;// Standard classes used by xlets.import javax.microedition.xlet.*;// For Inter-Xlet Communication (IXC).import javax.microedition.xlet.ixc.*;// Provides graphic representations and event support for xlets.import java.awt.Container;import java.awt.Frame;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;// Utility classes for saving information about xlets.import java.util.Hashtable;import java.util.Vector;//For loading xlets.import java.io.IOException;import java.io.File;import java.net.URL;import java.net.MalformedURLException;import java.lang.reflect.Constructor;import java.rmi.AccessException;import java.security.AccessController;import java.security.PrivilegedAction;import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;import sun.misc.CDCAppClassLoader;import com.sun.xlet.XletLifecycleHandler;/* * Xlet Manager implementation. * * The main purpose of this class is to initiate the xlet抯 state change based  * on the request coming in from the PXletStateQueue and to keep track of  * the xlet抯 current state. It also loads and destroys xlets. * * Static data is shared across all xlets. Every instance of an * XletManager manages one xlet. The XletManager runs a thread for * every xlet, which waits until the xlet is destroyed, then performs * the cleanup. The actual state change can be done either by * posting the request through XletLifecycleHandler (which inserts the * request into XletEventQueue), or through XletContext (which notifies the * XletManager that the xlet already changed its state). */public class PXletManager implements XletLifecycleHandler {    private static final int DEFAULT_XLET_WIDTH = 300;    private static final int DEFAULT_XLET_HEIGHT = 300;        // The root frame of this xlet    private XletFrame xletFrame;     // The XletContext which this instance of PXletManager is managing.    private PXletContextImpl context;     // The xlet class instance.    private Class xletClass;      // The xlet itself.    private Xlet xlet;      // This xlet抯 state queue. The state change request is usually posted     // to the XletEventQueue.     private PXletStateQueue xletQueue;      // This xlet抯 thread group (Package private).    ThreadGroup threadGroup;      // To synchronize the state change.    // Synchronize the existing current state and desired state with a new    // current state or desired state during a state transition.     private Object stateGuard = new Object();    // The current state of the xlet that this instance of XletManager is     // managing. The XletManager is always trying to move the Xlet from the    // current state to the desired state. The first state transition would be     // from unloaded to loaded.    private XletState currentState = XletState.UNLOADED;    private static boolean verbose = (System.getProperty("pxletmanager.verbose") != null) &&        (System.getProperty("pxletmanager.verbose").toLowerCase().equals("true"));    // Load the xlet class instance with a ClassLoader.    // mainClass is the main class of the Xlet.    // args contains the command-line arguments supplied with the arg option.    // They will be stored in the XletContext.    protected PXletManager(ClassLoader xletClassLoader,			   String laf,			   String lafTheme,			   String mainClass,			   String[] args) throws ClassNotFoundException {       xletClass = xletClassLoader.loadClass(mainClass);                if (xletClass == null || (!(Xlet.class).isAssignableFrom(xletClass))) {          throw new IllegalArgumentException(             "Attempt to run a non-Xlet class: " + mainClass);       }       // Create the XletContext for this xlet.       context = new PXletContextImpl(mainClass, args, this);       this.xletClass = xletClass;             // Create a root Frame for all xlets. Every time a new xlet is       // added, it gets its own container inside this Frame. The XletManager       // sets a default size and location, adds a menu bar and window       // listener, and leaves the Frame invisible.       xletFrame = new XletFrame("Xlet Frame: " + mainClass, this,				 laf, lafTheme);               // Create a thread group that all the threads used by this xlet       // would be a part of. This is necessary for providing a separate       // EventQueue per xlet.       threadGroup = new ThreadGroup(Thread.currentThread().getThreadGroup(),				     "Xlet Thread Group ");              // Create a state queue that holds this xlet抯 state change requests.       xletQueue = new PXletStateQueue(this);              // Now that the setup is complete, enter a request to move this xlet       // from UNLOADED to LOADED.       xletQueue.push(XletState.LOADED);    }    // Return a container for this xlet.    // This will be called at most once, by PXletContextImpl.getContainer()    public Container getContainer() {	return xletFrame.getContainer();    }    //private Listener listener = null;        // The following four methods are implementations of XletLifecycleHandler    // methods. They allow a third party to request an xlet state change.    // They request a state change through the xlet state queue (which holds    // an xlet抯 state change requests).    public void postInitXlet() {        xletQueue.push(DesiredXletState.INITIALIZE);    }    public void postStartXlet() {        xletQueue.push(XletState.ACTIVE);    }    public void postPauseXlet() {        xletQueue.push(XletState.PAUSED);    }     //    // The xletDestroy() from the appmanager is best effort.    // The appmanager inspects state. If it discovers that this jvm    // has not exited, it can use Client.kill() to forcibly get rid of it.    //    public void postDestroyXlet(boolean unconditional) {        if (!unconditional) {            xletQueue.push(DesiredXletState.CONDITIONAL_DESTROY);        } else {            xletQueue.push(XletState.DESTROYED);        }    }    // Set the state of the xlet. If the current state is destroyed, don抰    // bother to set the state. If the target state is destroyed,    // exit this vm instance.    public void setState(XletState state) {         synchronized (stateGuard) {            if (currentState == XletState.DESTROYED)                 return;            currentState = state;            stateGuard.notifyAll();        }	// 	// If we are requesting a state change into DESTROYED, we want to	// go away. So don't linger, get rid of the enclosing JVM instance	// 	if (state == XletState.DESTROYED) {            if (verbose) {                System.err.println("@@PXletManager setting xlet state to DESTROYED");            }            System.exit(0);

⌨️ 快捷键说明

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