Source code: com/barteo/emulator/MIDletBridge.java
1 /*
2 * MicroEmulator
3 * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Contributor(s):
20 * 3GLab
21 */
22
23 package com.barteo.emulator;
24
25 import java.util.Hashtable;
26
27 import javax.microedition.midlet.MIDlet;
28 import javax.microedition.midlet.MIDletStateChangeException;
29
30
31 public class MIDletBridge
32 {
33
34 static Hashtable midletAccess = new Hashtable();
35
36 static MicroEmulator emulator = null;
37
38 static MIDlet currentMIDlet = null;
39
40
41 public static void setMicroEmulator(MicroEmulator a_emulator)
42 {
43 emulator = a_emulator;
44 }
45
46
47 public static void setAccess(MIDlet a_midlet, MIDletAccess a_midletAccess)
48 {
49 midletAccess.put(a_midlet, a_midletAccess);
50 }
51
52
53 public static MIDlet getCurrentMIDlet()
54 {
55 return currentMIDlet;
56 }
57
58
59 public static void setCurrentMIDlet(MIDlet a_midlet)
60 {
61 if (currentMIDlet != null) {
62 try {
63 MIDletBridge.getMIDletAccess(currentMIDlet).destroyApp(true);
64 } catch (MIDletStateChangeException ex) {
65 System.err.println(ex);
66 }
67 }
68 currentMIDlet = a_midlet;
69 }
70
71
72 public static MIDletAccess getMIDletAccess(MIDlet a_midlet)
73 {
74 return (MIDletAccess) midletAccess.get(a_midlet);
75 }
76
77
78 public static MIDletAccess getMIDletAccess()
79 {
80 if (currentMIDlet == null) {
81 return null;
82 }
83
84 return getMIDletAccess(currentMIDlet);
85 }
86
87
88 public static String getAppProperty(String key)
89 {
90 return emulator.getAppProperty(key);
91 }
92
93
94 public static void notifyDestroyed()
95 {
96 emulator.notifyDestroyed();
97 }
98
99 /**
100 * Pass out changes to softkeys
101 */
102 public static void notifySoftkeyLabelsChanged()
103 {
104 emulator.notifySoftkeyLabelsChanged();
105 }
106 }