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.lcdui;
028:
029: import com.sun.midp.events.EventTypes;
030: import com.sun.midp.events.EventQueue;
031: import com.sun.midp.events.NativeEvent;
032:
033: /**
034: * This class provides methods to send events of types
035: * handled by ForegroundEventConsumer I/F implementors.
036: * This class completely hide event construction & sending in its methods.
037: *
038: * Generic comments for all XXXEventProducers:
039: *
040: * For each supported event type there is a separate sendXXXEvent() method,
041: * that gets all needed parameters to construct an event of an approprate
042: * class.
043: * The method also performs event sending itself.
044: *
045: * If a given event type merges a set of logically different subtypes,
046: * this class shall provide separate methods for these subtypes.
047: *
048: * It is assumed that only one object instance of this class
049: * is initialized with the system event that is created at (isolate) startup.
050: *
051: * This class only operates on the event queue given to it during
052: * construction, the class does not obtain any restricted object itself,
053: * so it does not need protection.
054: *
055: * All MIDP stack subsystems that need to send events of supported types,
056: * must get a reference to an already created istance of this class.
057: * Typically, this instance should be passed as a constructor parameter.
058: *
059: * Class is NOT final to allow debug/profile/test/automation subsystems
060: * to change, substitute, complement default "event sending" functionality :
061: * Ex.
062: * class LogXXXEventProducer
063: * extends XXXEventProducer {
064: * ...
065: * void sendXXXEvent(parameters) {
066: * LOG("Event of type XXX is about to be sent ...")
067: * super.sendXXXEvent(parameters);
068: * LOG("Event of type XXX has been sent successfully !")
069: * }
070: * ...
071: * }
072: */
073: public class ForegroundEventProducer {
074:
075: /** Cached reference to the MIDP event queue. */
076: private EventQueue eventQueue;
077:
078: /**
079: * Construct a new ForegroundEventProducer.
080: *
081: * @param theEventQueue An event queue where new events will be posted.
082: */
083: public ForegroundEventProducer(EventQueue theEventQueue) {
084: eventQueue = theEventQueue;
085: }
086:
087: /**
088: * Called to process a change a display's foreground/background status.
089: *
090: * @param midletIsolateId ID of the target isolate (where to send event)
091: * @param midletDisplayId ID of the target display
092: */
093: public void sendDisplayForegroundNotifyEvent(int midletIsolateId,
094: int midletDisplayId) {
095:
096: NativeEvent event = new NativeEvent(
097: EventTypes.FOREGROUND_NOTIFY_EVENT);
098:
099: event.intParam4 = midletDisplayId;
100:
101: eventQueue.sendNativeEventToIsolate(event, midletIsolateId);
102: }
103:
104: /**
105: * Called to process a change a display's foreground/background status.
106: *
107: * @param midletIsolateId ID of the target isolate (where to send event)
108: * @param midletDisplayId ID of the target display
109: */
110: public void sendDisplayBackgroundNotifyEvent(int midletIsolateId,
111: int midletDisplayId) {
112: NativeEvent event = new NativeEvent(
113: EventTypes.BACKGROUND_NOTIFY_EVENT);
114:
115: event.intParam4 = midletDisplayId;
116:
117: eventQueue.sendNativeEventToIsolate(event, midletIsolateId);
118: }
119: }
|