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.main;
028:
029: import javax.microedition.lcdui.*;
030:
031: import com.sun.midp.configurator.Constants;
032:
033: import com.sun.midp.i18n.Resource;
034: import com.sun.midp.i18n.ResourceConstants;
035:
036: /**
037: * HeadlessAlert is shown when a user selects a MIDlet to bring to the
038: * foreground that has not requested the foreground at least once by
039: * call Display.setCurrent(Displayable).
040: */
041: class HeadlessAlert extends Alert implements CommandListener {
042:
043: /** Cached reference to the MIDletControllerEventProducer. */
044: private MIDletControllerEventProducer midletControllerEventProducer;
045:
046: /** ID of the parent display */
047: private int displayId;
048:
049: /** Command to bring a headless midlet into the background */
050: private Command backgroundCommand;
051:
052: /** Command to terminate a headless midlet */
053: private Command exitCommand;
054:
055: /**
056: * Initialize this headless alert.
057: *
058: * @param theDisplayId ID of the parent display
059: * @param theMidletControllerEventProducer reference to an event producer
060: */
061: HeadlessAlert(
062: int theDisplayId,
063: MIDletControllerEventProducer theMidletControllerEventProducer) {
064: super (null, Resource
065: .getString(ResourceConstants.LCDUI_DISPLAY_HEADLESS),
066: null, AlertType.INFO);
067:
068: displayId = theDisplayId;
069: midletControllerEventProducer = theMidletControllerEventProducer;
070:
071: setTimeout(Alert.FOREVER);
072:
073: // Don't put the background command on the main display's alert
074: if (!MIDletSuiteUtils.isAmsIsolate()) {
075: backgroundCommand = new Command(Resource
076: .getString(ResourceConstants.OK), Command.OK, 2);
077: addCommand(backgroundCommand);
078: }
079:
080: exitCommand = new Command(Resource
081: .getString(ResourceConstants.EXIT), Command.EXIT, 1);
082:
083: addCommand(exitCommand);
084:
085: setCommandListener(this );
086: }
087:
088: /**
089: * Process commands for this alert. "OK" will dismiss the
090: * alert with no action. "Exit" will destroy the MIDlet.
091: *
092: * @param c command the user pressed
093: * @param d this displayable(not used)
094: */
095: public void commandAction(Command c, Displayable d) {
096: if (c == exitCommand) {
097: /**
098: * We need to destroy current midlet -
099: * the owner of this alert:
100: * to generate MIDLET_DESTROY_REQUEST
101: * event for a given midlet to MIDlet Controller
102: * in AMS Isolate.
103: */
104: midletControllerEventProducer
105: .sendMIDletDestroyRequestEvent(displayId);
106: } else if (c == backgroundCommand) {
107: midletControllerEventProducer
108: .sendDisplayBackgroundRequestEvent(displayId);
109: }
110: }
111: }
|