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.mtask.midlet;
028:
029: import sun.mtask.Listener;
030: import sun.mtask.AppModelManager;
031: import com.sun.midp.main.MIDletProxy;
032: import com.sun.midp.main.MIDletProxyList;
033:
034: /**
035: * Proxy MIDlet Manager.
036: */
037: public class PMidletManager implements AppModelManager {
038: /** Current proxy list. */
039: private static MIDletProxyList proxyList = null;
040: /** Most recent foreground MIDlet. */
041: private static MIDletProxy lastForegroundMidlet = null;
042: /** Verbose debug output flag. */
043: private static boolean verbose = false;
044:
045: static {
046: PMidletManager pmm = new PMidletManager();
047: try {
048: Listener.setAppModelManager(pmm);
049: } catch (Throwable e) {
050: // The Listener is not created. Do nothing.
051: }
052: }
053:
054: /**
055: * Register this app model manager with the system.
056: */
057: public void register() {
058: }
059:
060: /**
061: * Deactivate myself.
062: */
063: public void deactivate() {
064: if (lastForegroundMidlet == null) {
065: if (proxyList == null) {
066: proxyList = MIDletProxyList.getMIDletProxyList();
067: }
068: lastForegroundMidlet = proxyList.getForegroundMIDlet();
069: }
070: proxyList.setForegroundMIDlet(null);
071: }
072:
073: /**
074: * Activate myself.
075: */
076: public void activate() {
077: if (lastForegroundMidlet != null) {
078: proxyList.setForegroundMIDlet(lastForegroundMidlet);
079: lastForegroundMidlet = null;
080: }
081: }
082:
083: /**
084: * Process incoming message for this app model
085: * @param s target application type
086: * @param messageId message identifier (currently unused)
087: * @return <code>true</code> if action was performed
088: */
089: public boolean processMessage(String s, String messageId) {
090: if (!s.startsWith("MIDLET_")) {
091: return false;
092: }
093: s = s.substring(7);
094: if (verbose) {
095: System.err.println("MIDLET MESSAGE=\"" + s + "\"");
096: }
097: if (s.startsWith("ACTIVATE")) {
098: activate();
099: } else if (s.startsWith("DEACTIVATE")) {
100: deactivate();
101: } else {
102: return false;
103: }
104: return true;
105: }
106: }
|