1 /*
2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javax.swing;
26
27
28 import java.util.*;
29 import java.awt.*;
30 import java.awt.event.*;
31 import java.applet.*;
32 import java.beans.*;
33 import javax.swing.event.*;
34 import sun.awt.EmbeddedFrame;
35
36 /**
37 * The KeyboardManager class is used to help dispatch keyboard actions for the
38 * WHEN_IN_FOCUSED_WINDOW style actions. Actions with other conditions are handled
39 * directly in JComponent.
40 *
41 * Here's a description of the symantics of how keyboard dispatching should work
42 * atleast as I understand it.
43 *
44 * KeyEvents are dispatched to the focused component. The focus manager gets first
45 * crack at processing this event. If the focus manager doesn't want it, then
46 * the JComponent calls super.processKeyEvent() this allows listeners a chance
47 * to process the event.
48 *
49 * If none of the listeners "consumes" the event then the keybindings get a shot.
50 * This is where things start to get interesting. First, KeyStokes defined with the
51 * WHEN_FOCUSED condition get a chance. If none of these want the event, then the component
52 * walks though it's parents looked for actions of type WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.
53 *
54 * If no one has taken it yet, then it winds up here. We then look for components registered
55 * for WHEN_IN_FOCUSED_WINDOW events and fire to them. Note that if none of those are found
56 * then we pass the event to the menubars and let them have a crack at it. They're handled differently.
57 *
58 * Lastly, we check if we're looking at an internal frame. If we are and no one wanted the event
59 * then we move up to the InternalFrame's creator and see if anyone wants the event (and so on and so on).
60 *
61 *
62 * @see InputMap
63 */
64 class KeyboardManager {
65
66 static KeyboardManager currentManager = new KeyboardManager();
67
68 /**
69 * maps top-level containers to a sub-hashtable full of keystrokes
70 */
71 Hashtable containerMap = new Hashtable();
72
73 /**
74 * Maps component/keystroke pairs to a topLevel container
75 * This is mainly used for fast unregister operations
76 */
77 Hashtable componentKeyStrokeMap = new Hashtable();
78
79 public static KeyboardManager getCurrentManager() {
80 return currentManager;
81 }
82
83 public static void setCurrentManager(KeyboardManager km) {
84 currentManager = km;
85 }
86
87 /**
88 * register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW
89 * case.
90 * Other types of keystrokes will be handled by walking the hierarchy
91 * That simplifies some potentially hairy stuff.
92 */
93 public void registerKeyStroke(KeyStroke k, JComponent c) {
94 Container topContainer = getTopAncestor(c);
95 if (topContainer == null) {
96 return;
97 }
98 Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
99
100 if (keyMap == null) { // lazy evaluate one
101 keyMap = registerNewTopContainer(topContainer);
102 }
103
104 Object tmp = keyMap.get(k);
105 if (tmp == null) {
106 keyMap.put(k,c);
107 } else if (tmp instanceof Vector) { // if there's a Vector there then add to it.
108 Vector v = (Vector)tmp;
109 if (!v.contains(c)) { // only add if this keystroke isn't registered for this component
110 v.addElement(c);
111 }
112 } else if (tmp instanceof JComponent) {
113 // if a JComponent is there then remove it and replace it with a vector
114 // Then add the old compoennt and the new compoent to the vector
115 // then insert the vector in the table
116 if (tmp != c) { // this means this is already registered for this component, no need to dup
117 Vector v = new Vector();
118 v.addElement(tmp);
119 v.addElement(c);
120 keyMap.put(k, v);
121 }
122 } else {
123 System.out.println("Unexpected condition in registerKeyStroke");
124 Thread.dumpStack();
125 }
126
127 componentKeyStrokeMap.put(new ComponentKeyStrokePair(c,k), topContainer);
128
129 // Check for EmbeddedFrame case, they know how to process accelerators even
130 // when focus is not in Java
131 if (topContainer instanceof EmbeddedFrame) {
132 ((EmbeddedFrame)topContainer).registerAccelerator(k);
133 }
134 }
135
136 /**
137 * Find the top focusable Window, Applet, or InternalFrame
138 */
139 private static Container getTopAncestor(JComponent c) {
140 for(Container p = c.getParent(); p != null; p = p.getParent()) {
141 if (p instanceof Window && ((Window)p).isFocusableWindow() ||
142 p instanceof Applet || p instanceof JInternalFrame) {
143
144 return p;
145 }
146 }
147 return null;
148 }
149
150 public void unregisterKeyStroke(KeyStroke ks, JComponent c) {
151
152 // component may have already been removed from the hierarchy, we
153 // need to look up the container using the componentKeyStrokeMap.
154
155 ComponentKeyStrokePair ckp = new ComponentKeyStrokePair(c,ks);
156
157 Object topContainer = componentKeyStrokeMap.get(ckp);
158
159 if (topContainer == null) { // never heard of this pairing, so bail
160 return;
161 }
162
163 Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
164 if (keyMap == null) { // this should never happen, but I'm being safe
165 Thread.dumpStack();
166 return;
167 }
168
169 Object tmp = keyMap.get(ks);
170 if (tmp == null) { // this should never happen, but I'm being safe
171 Thread.dumpStack();
172 return;
173 }
174
175 if (tmp instanceof JComponent && tmp == c) {
176 keyMap.remove(ks); // remove the KeyStroke from the Map
177 //System.out.println("removed a stroke" + ks);
178 } else if (tmp instanceof Vector ) { // this means there is more than one component reg for this key
179 Vector v = (Vector)tmp;
180 v.removeElement(c);
181 if ( v.isEmpty() ) {
182 keyMap.remove(ks); // remove the KeyStroke from the Map
183 //System.out.println("removed a ks vector");
195 // when focus is not in Java
196 if (topContainer instanceof EmbeddedFrame) {
197 ((EmbeddedFrame)topContainer).unregisterAccelerator(ks);
198 }
199 }
200
201 /**
202 * This method is called when the focused component (and none of
203 * its ancestors) want the key event. This will look up the keystroke
204 * to see if any chidren (or subchildren) of the specified container
205 * want a crack at the event.
206 * If one of them wants it, then it will "DO-THE-RIGHT-THING"
207 */
208 public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) {
209
210 if (e.isConsumed()) {
211 System.out.println("Aquired pre-used event!");
212 Thread.dumpStack();
213 }
214
215 KeyStroke ks;
216
217
218 if(e.getID() == KeyEvent.KEY_TYPED) {
219 ks=KeyStroke.getKeyStroke(e.getKeyChar());
220 } else {
221 ks=KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed);
222 }
223
224 Hashtable keyMap = (Hashtable)containerMap.get(topAncestor);
225 if (keyMap != null) { // this container isn't registered, so bail
226
227 Object tmp = keyMap.get(ks);
228
229 if (tmp == null) {
230 // don't do anything
231 } else if ( tmp instanceof JComponent) {
232 JComponent c = (JComponent)tmp;
233 if ( c.isShowing() && c.isEnabled() ) { // only give it out if enabled and visible
234 fireBinding(c, ks, e, pressed);
235 }
236 } else if ( tmp instanceof Vector) { //more than one comp registered for this
237 Vector v = (Vector)tmp;
238 // There is no well defined order for WHEN_IN_FOCUSED_WINDOW
239 // bindings, but we give precedence to those bindings just
240 // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW
241 // bindings are accessed before those of the JRootPane (they
242 // both have a WHEN_IN_FOCUSED_WINDOW binding for enter).
243 for (int counter = v.size() - 1; counter >= 0; counter--) {
244 JComponent c = (JComponent)v.elementAt(counter);
245 //System.out.println("Trying collision: " + c + " vector = "+ v.size());
246 if ( c.isShowing() && c.isEnabled() ) { // don't want to give these out
247 fireBinding(c, ks, e, pressed);
252 } else {
253 System.out.println( "Unexpected condition in fireKeyboardAction " + tmp);
254 // This means that tmp wasn't null, a JComponent, or a Vector. What is it?
255 Thread.dumpStack();
256 }
257 }
258
259 if (e.isConsumed()) {
260 return true;
261 }
262 // if no one else handled it, then give the menus a crack
263 // The're handled differently. The key is to let any JMenuBars
264 // process the event
265 if ( keyMap != null) {
266 Vector v = (Vector)keyMap.get(JMenuBar.class);
267 if (v != null) {
268 Enumeration iter = v.elements();
269 while (iter.hasMoreElements()) {
270 JMenuBar mb = (JMenuBar)iter.nextElement();
271 if ( mb.isShowing() && mb.isEnabled() ) { // don't want to give these out
272 fireBinding(mb, ks, e, pressed);
273 if (e.isConsumed()) {
274 return true;
275 }
276 }
277 }
278 }
279 }
280
281 return e.isConsumed();
282 }
283
284 void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed) {
285 if (c.processKeyBinding(ks, e, JComponent.WHEN_IN_FOCUSED_WINDOW,
286 pressed)) {
287 e.consume();
288 }
289 }
290
291 public void registerMenuBar(JMenuBar mb) {
292 Container top = getTopAncestor(mb);
293 if (top == null) {
294 return;
295 }
296 Hashtable keyMap = (Hashtable)containerMap.get(top);
297
298 if (keyMap == null) { // lazy evaluate one
299 keyMap = registerNewTopContainer(top);
300 }
301 // use the menubar class as the key
302 Vector menuBars = (Vector)keyMap.get(JMenuBar.class);
303
304 if (menuBars == null) { // if we don't have a list of menubars,
305 // then make one.
306 menuBars = new Vector();
307 keyMap.put(JMenuBar.class, menuBars);
308 }
309
310 if (!menuBars.contains(mb)) {
311 menuBars.addElement(mb);
312 }
313 }
314
315
316 public void unregisterMenuBar(JMenuBar mb) {
317 Object topContainer = getTopAncestor(mb);
318 if (topContainer == null) {
319 return;
320 }
321 Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
322 if (keyMap!=null) {
323 Vector v = (Vector)keyMap.get(JMenuBar.class);
324 if (v != null) {
325 v.removeElement(mb);
326 if (v.isEmpty()) {
327 keyMap.remove(JMenuBar.class);
328 if (keyMap.isEmpty()) {
329 // remove table to enable GC
330 containerMap.remove(topContainer);
331 }
332 }
333 }
334 }
335 }
336 protected Hashtable registerNewTopContainer(Container topContainer) {
337 Hashtable keyMap = new Hashtable();
338 containerMap.put(topContainer, keyMap);
339 return keyMap;
340 }
341
|
1 /*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javax.swing;
26
27
28 import java.util.*;
29 import java.awt.*;
30 import java.awt.event.*;
31 import java.applet.*;
32 import java.beans.*;
33 import javax.swing.event.*;
34 import sun.awt.AWTAccessor;
35 import sun.awt.EmbeddedFrame;
36
37 /**
38 * The KeyboardManager class is used to help dispatch keyboard actions for the
39 * WHEN_IN_FOCUSED_WINDOW style actions. Actions with other conditions are handled
40 * directly in JComponent.
41 *
42 * Here's a description of the symantics of how keyboard dispatching should work
43 * atleast as I understand it.
44 *
45 * KeyEvents are dispatched to the focused component. The focus manager gets first
46 * crack at processing this event. If the focus manager doesn't want it, then
47 * the JComponent calls super.processKeyEvent() this allows listeners a chance
48 * to process the event.
49 *
50 * If none of the listeners "consumes" the event then the keybindings get a shot.
51 * This is where things start to get interesting. First, KeyStokes defined with the
52 * WHEN_FOCUSED condition get a chance. If none of these want the event, then the component
53 * walks though it's parents looked for actions of type WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.
54 *
55 * If no one has taken it yet, then it winds up here. We then look for components registered
56 * for WHEN_IN_FOCUSED_WINDOW events and fire to them. Note that if none of those are found
57 * then we pass the event to the menubars and let them have a crack at it. They're handled differently.
58 *
59 * Lastly, we check if we're looking at an internal frame. If we are and no one wanted the event
60 * then we move up to the InternalFrame's creator and see if anyone wants the event (and so on and so on).
61 *
62 *
63 * @see InputMap
64 */
65 class KeyboardManager {
66
67 static KeyboardManager currentManager = new KeyboardManager();
68
69 /**
70 * maps top-level containers to a sub-hashtable full of keystrokes
71 */
72 Hashtable<Container, Hashtable> containerMap = new Hashtable<Container, Hashtable>();
73
74 /**
75 * Maps component/keystroke pairs to a topLevel container
76 * This is mainly used for fast unregister operations
77 */
78 Hashtable<ComponentKeyStrokePair, Container> componentKeyStrokeMap = new Hashtable<ComponentKeyStrokePair, Container>();
79
80 public static KeyboardManager getCurrentManager() {
81 return currentManager;
82 }
83
84 public static void setCurrentManager(KeyboardManager km) {
85 currentManager = km;
86 }
87
88 /**
89 * register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW
90 * case.
91 * Other types of keystrokes will be handled by walking the hierarchy
92 * That simplifies some potentially hairy stuff.
93 */
94 public void registerKeyStroke(KeyStroke k, JComponent c) {
95 Container topContainer = getTopAncestor(c);
96 if (topContainer == null) {
97 return;
98 }
99 Hashtable keyMap = containerMap.get(topContainer);
100
101 if (keyMap == null) { // lazy evaluate one
102 keyMap = registerNewTopContainer(topContainer);
103 }
104
105 Object tmp = keyMap.get(k);
106 if (tmp == null) {
107 keyMap.put(k,c);
108 } else if (tmp instanceof Vector) { // if there's a Vector there then add to it.
109 Vector v = (Vector)tmp;
110 if (!v.contains(c)) { // only add if this keystroke isn't registered for this component
111 v.addElement(c);
112 }
113 } else if (tmp instanceof JComponent) {
114 // if a JComponent is there then remove it and replace it with a vector
115 // Then add the old compoennt and the new compoent to the vector
116 // then insert the vector in the table
117 if (tmp != c) { // this means this is already registered for this component, no need to dup
118 Vector<JComponent> v = new Vector<JComponent>();
119 v.addElement((JComponent) tmp);
120 v.addElement(c);
121 keyMap.put(k, v);
122 }
123 } else {
124 System.out.println("Unexpected condition in registerKeyStroke");
125 Thread.dumpStack();
126 }
127
128 componentKeyStrokeMap.put(new ComponentKeyStrokePair(c,k), topContainer);
129
130 // Check for EmbeddedFrame case, they know how to process accelerators even
131 // when focus is not in Java
132 if (topContainer instanceof EmbeddedFrame) {
133 ((EmbeddedFrame)topContainer).registerAccelerator(k);
134 }
135 }
136
137 /**
138 * Find the top focusable Window, Applet, or InternalFrame
139 */
140 private static Container getTopAncestor(JComponent c) {
141 for(Container p = c.getParent(); p != null; p = p.getParent()) {
142 if (p instanceof Window && ((Window)p).isFocusableWindow() ||
143 p instanceof Applet || p instanceof JInternalFrame) {
144
145 return p;
146 }
147 }
148 return null;
149 }
150
151 public void unregisterKeyStroke(KeyStroke ks, JComponent c) {
152
153 // component may have already been removed from the hierarchy, we
154 // need to look up the container using the componentKeyStrokeMap.
155
156 ComponentKeyStrokePair ckp = new ComponentKeyStrokePair(c,ks);
157
158 Container topContainer = componentKeyStrokeMap.get(ckp);
159
160 if (topContainer == null) { // never heard of this pairing, so bail
161 return;
162 }
163
164 Hashtable keyMap = containerMap.get(topContainer);
165 if (keyMap == null) { // this should never happen, but I'm being safe
166 Thread.dumpStack();
167 return;
168 }
169
170 Object tmp = keyMap.get(ks);
171 if (tmp == null) { // this should never happen, but I'm being safe
172 Thread.dumpStack();
173 return;
174 }
175
176 if (tmp instanceof JComponent && tmp == c) {
177 keyMap.remove(ks); // remove the KeyStroke from the Map
178 //System.out.println("removed a stroke" + ks);
179 } else if (tmp instanceof Vector ) { // this means there is more than one component reg for this key
180 Vector v = (Vector)tmp;
181 v.removeElement(c);
182 if ( v.isEmpty() ) {
183 keyMap.remove(ks); // remove the KeyStroke from the Map
184 //System.out.println("removed a ks vector");
196 // when focus is not in Java
197 if (topContainer instanceof EmbeddedFrame) {
198 ((EmbeddedFrame)topContainer).unregisterAccelerator(ks);
199 }
200 }
201
202 /**
203 * This method is called when the focused component (and none of
204 * its ancestors) want the key event. This will look up the keystroke
205 * to see if any chidren (or subchildren) of the specified container
206 * want a crack at the event.
207 * If one of them wants it, then it will "DO-THE-RIGHT-THING"
208 */
209 public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) {
210
211 if (e.isConsumed()) {
212 System.out.println("Aquired pre-used event!");
213 Thread.dumpStack();
214 }
215
216 // There may be two keystrokes associated with a low-level key event;
217 // in this case a keystroke made of an extended key code has a priority.
218 KeyStroke ks;
219 KeyStroke ksE = null;
220
221
222 if(e.getID() == KeyEvent.KEY_TYPED) {
223 ks=KeyStroke.getKeyStroke(e.getKeyChar());
224 } else {
225 int ekc = AWTAccessor.getKeyEventAccessor().getExtendedKeyCode(e);
226 if(e.getKeyCode() != ekc) {
227 ksE=KeyStroke.getKeyStroke(ekc, e.getModifiers(), !pressed);
228 }
229 ks=KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed);
230 }
231
232 Hashtable keyMap = containerMap.get(topAncestor);
233 if (keyMap != null) { // this container isn't registered, so bail
234
235 Object tmp = null;
236 // extended code has priority
237 if( ksE != null ) {
238 tmp = keyMap.get(ksE);
239 if( tmp != null ) {
240 ks = ksE;
241 }
242 }
243 if( tmp == null ) {
244 tmp = keyMap.get(ks);
245 }
246
247 if (tmp == null) {
248 // don't do anything
249 } else if ( tmp instanceof JComponent) {
250 JComponent c = (JComponent)tmp;
251 if ( c.isShowing() && c.isEnabled() ) { // only give it out if enabled and visible
252 fireBinding(c, ks, e, pressed);
253 }
254 } else if ( tmp instanceof Vector) { //more than one comp registered for this
255 Vector v = (Vector)tmp;
256 // There is no well defined order for WHEN_IN_FOCUSED_WINDOW
257 // bindings, but we give precedence to those bindings just
258 // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW
259 // bindings are accessed before those of the JRootPane (they
260 // both have a WHEN_IN_FOCUSED_WINDOW binding for enter).
261 for (int counter = v.size() - 1; counter >= 0; counter--) {
262 JComponent c = (JComponent)v.elementAt(counter);
263 //System.out.println("Trying collision: " + c + " vector = "+ v.size());
264 if ( c.isShowing() && c.isEnabled() ) { // don't want to give these out
265 fireBinding(c, ks, e, pressed);
270 } else {
271 System.out.println( "Unexpected condition in fireKeyboardAction " + tmp);
272 // This means that tmp wasn't null, a JComponent, or a Vector. What is it?
273 Thread.dumpStack();
274 }
275 }
276
277 if (e.isConsumed()) {
278 return true;
279 }
280 // if no one else handled it, then give the menus a crack
281 // The're handled differently. The key is to let any JMenuBars
282 // process the event
283 if ( keyMap != null) {
284 Vector v = (Vector)keyMap.get(JMenuBar.class);
285 if (v != null) {
286 Enumeration iter = v.elements();
287 while (iter.hasMoreElements()) {
288 JMenuBar mb = (JMenuBar)iter.nextElement();
289 if ( mb.isShowing() && mb.isEnabled() ) { // don't want to give these out
290 if( !(ks.equals(ksE)) ) {
291 fireBinding(mb, ksE, e, pressed);
292 }
293 if(ks.equals(ksE) || !e.isConsumed()) {
294 fireBinding(mb, ks, e, pressed);
295 }
296 if (e.isConsumed()) {
297 return true;
298 }
299 }
300 }
301 }
302 }
303
304 return e.isConsumed();
305 }
306
307 void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed) {
308 if (c.processKeyBinding(ks, e, JComponent.WHEN_IN_FOCUSED_WINDOW,
309 pressed)) {
310 e.consume();
311 }
312 }
313
314 public void registerMenuBar(JMenuBar mb) {
315 Container top = getTopAncestor(mb);
316 if (top == null) {
317 return;
318 }
319 Hashtable keyMap = containerMap.get(top);
320
321 if (keyMap == null) { // lazy evaluate one
322 keyMap = registerNewTopContainer(top);
323 }
324 // use the menubar class as the key
325 Vector menuBars = (Vector)keyMap.get(JMenuBar.class);
326
327 if (menuBars == null) { // if we don't have a list of menubars,
328 // then make one.
329 menuBars = new Vector();
330 keyMap.put(JMenuBar.class, menuBars);
331 }
332
333 if (!menuBars.contains(mb)) {
334 menuBars.addElement(mb);
335 }
336 }
337
338
339 public void unregisterMenuBar(JMenuBar mb) {
340 Container topContainer = getTopAncestor(mb);
341 if (topContainer == null) {
342 return;
343 }
344 Hashtable keyMap = containerMap.get(topContainer);
345 if (keyMap!=null) {
346 Vector v = (Vector)keyMap.get(JMenuBar.class);
347 if (v != null) {
348 v.removeElement(mb);
349 if (v.isEmpty()) {
350 keyMap.remove(JMenuBar.class);
351 if (keyMap.isEmpty()) {
352 // remove table to enable GC
353 containerMap.remove(topContainer);
354 }
355 }
356 }
357 }
358 }
359 protected Hashtable registerNewTopContainer(Container topContainer) {
360 Hashtable keyMap = new Hashtable();
361 containerMap.put(topContainer, keyMap);
362 return keyMap;
363 }
364
|