01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.main;
28:
29: /**
30: * Automation API display controller
31: */
32: public class AutoDisplayController extends DisplayController {
33:
34: /** Foreground state changes listener */
35: AutoDisplayControllerListener listener;
36:
37: /**
38: * Construct a DisplayController with a reference to the ProxyList.
39: *
40: * @param midletProxyList reference to the MIDlet proxy list
41: */
42: public AutoDisplayController(MIDletProxyList midletProxyList) {
43: super (midletProxyList);
44: listener = null;
45: }
46:
47: /**
48: * Call to notify that foreground MIDlet is changing and give the
49: * display controller a chance to preempt the change.
50: * Also the last MIDlet created state will be reset.
51: * <p>
52: * If the MIDlet to get the foreground is paused, then activate it.
53: *
54: * @param midlet proxy of the MIDlet to be put in the foreground
55: *
56: * @return Proxy of the next foreground MIDlet, may be the foreground
57: * MIDlet if the foreground should not change
58: */
59: MIDletProxy foregroundMidletChanging(MIDletProxy midlet) {
60: MIDletProxy oldForeground = midletProxyList
61: .getForegroundMIDlet();
62: MIDletProxy newForeground = super
63: .foregroundMidletChanging(midlet);
64:
65: notifyListenersOfForegroundChange(oldForeground, newForeground);
66:
67: return newForeground;
68: }
69:
70: /**
71: * Sets a listener for foreground state changes.
72: *
73: * @param listener listener
74: */
75: public void setListener(AutoDisplayControllerListener listener) {
76: this .listener = listener;
77: }
78:
79: /**
80: * Notifies listener about foreground change.
81: *
82: * @param oldForeground MIDlet currently in foreground
83: * @param newForeground MIDlet getting foreground
84: */
85: private void notifyListenersOfForegroundChange(
86: MIDletProxy oldForeground, MIDletProxy newForeground) {
87:
88: if (listener != null) {
89: listener.foregroundMIDletChanged(oldForeground,
90: newForeground);
91: }
92: }
93: }
|