author | aghaisas |
Mon, 10 Jul 2017 14:55:29 +0530 | |
changeset 47151 | 362dcbee0613 |
parent 43722 | 25ba19c20260 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21591
diff
changeset
|
2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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 |
*/ |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
71 |
Hashtable<Container, Hashtable<Object, Object>> containerMap = new Hashtable<>(); |
2 | 72 |
|
73 |
/** |
|
74 |
* Maps component/keystroke pairs to a topLevel container |
|
75 |
* This is mainly used for fast unregister operations |
|
76 |
*/ |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
77 |
Hashtable<ComponentKeyStrokePair, Container> componentKeyStrokeMap = new Hashtable<>(); |
2 | 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 |
} |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
98 |
Hashtable<Object, Object> keyMap = containerMap.get(topContainer); |
2 | 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. |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
108 |
@SuppressWarnings("unchecked") |
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
109 |
Vector<Object> v = (Vector)tmp; |
2 | 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 |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
118 |
Vector<JComponent> v = new Vector<>(); |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
119 |
v.addElement((JComponent) tmp); |
2 | 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 |
*/ |
|
42198
6ff366cc096b
8168316: Suppress deprecation warnings for Applet classes in java.desktop
prr
parents:
25859
diff
changeset
|
140 |
@SuppressWarnings("deprecation") |
2 | 141 |
private static Container getTopAncestor(JComponent c) { |
142 |
for(Container p = c.getParent(); p != null; p = p.getParent()) { |
|
143 |
if (p instanceof Window && ((Window)p).isFocusableWindow() || |
|
144 |
p instanceof Applet || p instanceof JInternalFrame) { |
|
145 |
||
146 |
return p; |
|
147 |
} |
|
148 |
} |
|
149 |
return null; |
|
150 |
} |
|
151 |
||
152 |
public void unregisterKeyStroke(KeyStroke ks, JComponent c) { |
|
153 |
||
154 |
// component may have already been removed from the hierarchy, we |
|
155 |
// need to look up the container using the componentKeyStrokeMap. |
|
156 |
||
157 |
ComponentKeyStrokePair ckp = new ComponentKeyStrokePair(c,ks); |
|
158 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
159 |
Container topContainer = componentKeyStrokeMap.get(ckp); |
2 | 160 |
|
161 |
if (topContainer == null) { // never heard of this pairing, so bail |
|
162 |
return; |
|
163 |
} |
|
164 |
||
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
165 |
Hashtable<Object, Object> keyMap = containerMap.get(topContainer); |
2 | 166 |
if (keyMap == null) { // this should never happen, but I'm being safe |
167 |
Thread.dumpStack(); |
|
168 |
return; |
|
169 |
} |
|
170 |
||
171 |
Object tmp = keyMap.get(ks); |
|
172 |
if (tmp == null) { // this should never happen, but I'm being safe |
|
173 |
Thread.dumpStack(); |
|
174 |
return; |
|
175 |
} |
|
176 |
||
177 |
if (tmp instanceof JComponent && tmp == c) { |
|
178 |
keyMap.remove(ks); // remove the KeyStroke from the Map |
|
179 |
//System.out.println("removed a stroke" + ks); |
|
180 |
} else if (tmp instanceof Vector ) { // this means there is more than one component reg for this key |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
181 |
Vector<?> v = (Vector)tmp; |
2 | 182 |
v.removeElement(c); |
183 |
if ( v.isEmpty() ) { |
|
184 |
keyMap.remove(ks); // remove the KeyStroke from the Map |
|
185 |
//System.out.println("removed a ks vector"); |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
if ( keyMap.isEmpty() ) { // if no more bindings in this table |
|
190 |
containerMap.remove(topContainer); // remove table to enable GC |
|
191 |
//System.out.println("removed a container"); |
|
192 |
} |
|
193 |
||
194 |
componentKeyStrokeMap.remove(ckp); |
|
195 |
||
196 |
// Check for EmbeddedFrame case, they know how to process accelerators even |
|
197 |
// when focus is not in Java |
|
198 |
if (topContainer instanceof EmbeddedFrame) { |
|
199 |
((EmbeddedFrame)topContainer).unregisterAccelerator(ks); |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
/** |
|
204 |
* This method is called when the focused component (and none of |
|
205 |
* its ancestors) want the key event. This will look up the keystroke |
|
206 |
* to see if any chidren (or subchildren) of the specified container |
|
207 |
* want a crack at the event. |
|
208 |
* If one of them wants it, then it will "DO-THE-RIGHT-THING" |
|
209 |
*/ |
|
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
42198
diff
changeset
|
210 |
@SuppressWarnings("deprecation") |
2 | 211 |
public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) { |
212 |
||
213 |
if (e.isConsumed()) { |
|
21591 | 214 |
System.out.println("Acquired pre-used event!"); |
2 | 215 |
Thread.dumpStack(); |
216 |
} |
|
217 |
||
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
218 |
// There may be two keystrokes associated with a low-level key event; |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
219 |
// in this case a keystroke made of an extended key code has a priority. |
2 | 220 |
KeyStroke ks; |
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
221 |
KeyStroke ksE = null; |
2 | 222 |
|
223 |
||
224 |
if(e.getID() == KeyEvent.KEY_TYPED) { |
|
225 |
ks=KeyStroke.getKeyStroke(e.getKeyChar()); |
|
226 |
} else { |
|
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
227 |
if(e.getKeyCode() != e.getExtendedKeyCode()) { |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
228 |
ksE=KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed); |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
229 |
} |
2 | 230 |
ks=KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed); |
231 |
} |
|
232 |
||
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
233 |
Hashtable<Object, Object> keyMap = containerMap.get(topAncestor); |
2 | 234 |
if (keyMap != null) { // this container isn't registered, so bail |
235 |
||
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
236 |
Object tmp = null; |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
237 |
// extended code has priority |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
238 |
if( ksE != null ) { |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
239 |
tmp = keyMap.get(ksE); |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
240 |
if( tmp != null ) { |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
241 |
ks = ksE; |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
242 |
} |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
243 |
} |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
244 |
if( tmp == null ) { |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
245 |
tmp = keyMap.get(ks); |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
246 |
} |
2 | 247 |
|
248 |
if (tmp == null) { |
|
249 |
// don't do anything |
|
250 |
} else if ( tmp instanceof JComponent) { |
|
251 |
JComponent c = (JComponent)tmp; |
|
252 |
if ( c.isShowing() && c.isEnabled() ) { // only give it out if enabled and visible |
|
253 |
fireBinding(c, ks, e, pressed); |
|
254 |
} |
|
255 |
} else if ( tmp instanceof Vector) { //more than one comp registered for this |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
256 |
Vector<?> v = (Vector)tmp; |
2 | 257 |
// There is no well defined order for WHEN_IN_FOCUSED_WINDOW |
258 |
// bindings, but we give precedence to those bindings just |
|
259 |
// added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW |
|
260 |
// bindings are accessed before those of the JRootPane (they |
|
261 |
// both have a WHEN_IN_FOCUSED_WINDOW binding for enter). |
|
262 |
for (int counter = v.size() - 1; counter >= 0; counter--) { |
|
263 |
JComponent c = (JComponent)v.elementAt(counter); |
|
264 |
//System.out.println("Trying collision: " + c + " vector = "+ v.size()); |
|
265 |
if ( c.isShowing() && c.isEnabled() ) { // don't want to give these out |
|
266 |
fireBinding(c, ks, e, pressed); |
|
267 |
if (e.isConsumed()) |
|
268 |
return true; |
|
269 |
} |
|
270 |
} |
|
271 |
} else { |
|
272 |
System.out.println( "Unexpected condition in fireKeyboardAction " + tmp); |
|
273 |
// This means that tmp wasn't null, a JComponent, or a Vector. What is it? |
|
274 |
Thread.dumpStack(); |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
if (e.isConsumed()) { |
|
279 |
return true; |
|
280 |
} |
|
281 |
// if no one else handled it, then give the menus a crack |
|
282 |
// The're handled differently. The key is to let any JMenuBars |
|
283 |
// process the event |
|
284 |
if ( keyMap != null) { |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
285 |
@SuppressWarnings("unchecked") |
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
286 |
Vector<JMenuBar> v = (Vector)keyMap.get(JMenuBar.class); |
2 | 287 |
if (v != null) { |
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
288 |
Enumeration<JMenuBar> iter = v.elements(); |
2 | 289 |
while (iter.hasMoreElements()) { |
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
290 |
JMenuBar mb = iter.nextElement(); |
2 | 291 |
if ( mb.isShowing() && mb.isEnabled() ) { // don't want to give these out |
17906
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
5506
diff
changeset
|
292 |
boolean extended = (ksE != null) && !ksE.equals(ks); |
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
5506
diff
changeset
|
293 |
if (extended) { |
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
294 |
fireBinding(mb, ksE, e, pressed); |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
295 |
} |
17906
d1e3eb73fb05
8013370: Null pointer exception when adding more than 9 accelators to a JMenuBar
malenkov
parents:
5506
diff
changeset
|
296 |
if (!extended || !e.isConsumed()) { |
2473
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
297 |
fireBinding(mb, ks, e, pressed); |
3f4bbd3be2f1
6680988: KeyEvent is still missing VK values for many keyboards
yan
parents:
1639
diff
changeset
|
298 |
} |
2 | 299 |
if (e.isConsumed()) { |
300 |
return true; |
|
301 |
} |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
return e.isConsumed(); |
|
308 |
} |
|
309 |
||
310 |
void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed) { |
|
311 |
if (c.processKeyBinding(ks, e, JComponent.WHEN_IN_FOCUSED_WINDOW, |
|
312 |
pressed)) { |
|
313 |
e.consume(); |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
public void registerMenuBar(JMenuBar mb) { |
|
318 |
Container top = getTopAncestor(mb); |
|
319 |
if (top == null) { |
|
320 |
return; |
|
321 |
} |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
322 |
Hashtable<Object, Object> keyMap = containerMap.get(top); |
2 | 323 |
|
324 |
if (keyMap == null) { // lazy evaluate one |
|
325 |
keyMap = registerNewTopContainer(top); |
|
326 |
} |
|
327 |
// use the menubar class as the key |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
328 |
@SuppressWarnings("unchecked") |
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
329 |
Vector<Object> menuBars = (Vector)keyMap.get(JMenuBar.class); |
2 | 330 |
|
331 |
if (menuBars == null) { // if we don't have a list of menubars, |
|
332 |
// then make one. |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
333 |
menuBars = new Vector<>(); |
2 | 334 |
keyMap.put(JMenuBar.class, menuBars); |
335 |
} |
|
336 |
||
337 |
if (!menuBars.contains(mb)) { |
|
338 |
menuBars.addElement(mb); |
|
339 |
} |
|
340 |
} |
|
341 |
||
342 |
||
343 |
public void unregisterMenuBar(JMenuBar mb) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
344 |
Container topContainer = getTopAncestor(mb); |
2 | 345 |
if (topContainer == null) { |
346 |
return; |
|
347 |
} |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
348 |
Hashtable<Object, Object> keyMap = containerMap.get(topContainer); |
2 | 349 |
if (keyMap!=null) { |
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
350 |
Vector<?> v = (Vector)keyMap.get(JMenuBar.class); |
2 | 351 |
if (v != null) { |
352 |
v.removeElement(mb); |
|
353 |
if (v.isEmpty()) { |
|
354 |
keyMap.remove(JMenuBar.class); |
|
355 |
if (keyMap.isEmpty()) { |
|
356 |
// remove table to enable GC |
|
357 |
containerMap.remove(topContainer); |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
363 |
protected Hashtable<Object, Object> registerNewTopContainer(Container topContainer) { |
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23010
diff
changeset
|
364 |
Hashtable<Object, Object> keyMap = new Hashtable<>(); |
2 | 365 |
containerMap.put(topContainer, keyMap); |
366 |
return keyMap; |
|
367 |
} |
|
368 |
||
369 |
/** |
|
370 |
* This class is used to create keys for a hashtable |
|
371 |
* which looks up topContainers based on component, keystroke pairs |
|
372 |
* This is used to make unregistering KeyStrokes fast |
|
373 |
*/ |
|
374 |
class ComponentKeyStrokePair { |
|
375 |
Object component; |
|
376 |
Object keyStroke; |
|
377 |
||
378 |
public ComponentKeyStrokePair(Object comp, Object key) { |
|
379 |
component = comp; |
|
380 |
keyStroke = key; |
|
381 |
} |
|
382 |
||
383 |
public boolean equals(Object o) { |
|
384 |
if ( !(o instanceof ComponentKeyStrokePair)) { |
|
385 |
return false; |
|
386 |
} |
|
387 |
ComponentKeyStrokePair ckp = (ComponentKeyStrokePair)o; |
|
388 |
return ((component.equals(ckp.component)) && (keyStroke.equals(ckp.keyStroke))); |
|
389 |
} |
|
390 |
||
391 |
public int hashCode() { |
|
392 |
return component.hashCode() * keyStroke.hashCode(); |
|
393 |
} |
|
394 |
||
395 |
} |
|
396 |
||
397 |
} // end KeyboardManager |