162 |
{ |
{ |
163 |
Component target = (Component) e.getSource (); |
Component target = (Component) e.getSource (); |
164 |
|
|
165 |
if (e.id == FocusEvent.FOCUS_GAINED |
if (e.id == FocusEvent.FOCUS_GAINED) |
|
&& !(target instanceof Window)) |
|
166 |
{ |
{ |
167 |
if (((FocusEvent) e).isTemporary ()) |
if (((FocusEvent) e).isTemporary ()) |
168 |
setGlobalFocusOwner (target); |
setGlobalFocusOwner (target); |
169 |
else |
else |
170 |
setGlobalPermanentFocusOwner (target); |
setGlobalPermanentFocusOwner (target); |
171 |
} |
} |
172 |
|
else if (e.id == FocusEvent.FOCUS_LOST) |
173 |
|
{ |
174 |
|
// We need to set the window's focus owner here; we can't |
175 |
|
// set it when the window loses focus because by that time |
176 |
|
// the previous focus owner has already lost focus |
177 |
|
// (FOCUS_LOST events are delivered before |
178 |
|
// WINDOW_LOST_FOCUS events). |
179 |
|
|
180 |
|
// Find the target Component's top-level ancestor. |
181 |
|
Container parent = target.getParent (); |
182 |
|
|
183 |
|
while (parent != null |
184 |
|
&& !(parent instanceof Window)) |
185 |
|
parent = parent.getParent (); |
186 |
|
|
187 |
|
Window toplevel = parent == null ? |
188 |
|
(Window) target : (Window) parent; |
189 |
|
|
190 |
|
Component focusOwner = getFocusOwner (); |
191 |
|
if (focusOwner != null) |
192 |
|
toplevel.setFocusOwner (focusOwner); |
193 |
|
|
194 |
|
if (((FocusEvent) e).isTemporary ()) |
195 |
|
setGlobalFocusOwner (null); |
196 |
|
else |
197 |
|
setGlobalPermanentFocusOwner (null); |
198 |
|
} |
199 |
|
|
|
if (!(target instanceof Window)) |
|
200 |
target.dispatchEvent (e); |
target.dispatchEvent (e); |
201 |
|
|
202 |
return true; |
return true; |
217 |
// processKeyEvent checks if this event represents a focus |
// processKeyEvent checks if this event represents a focus |
218 |
// traversal key stroke. |
// traversal key stroke. |
219 |
Component focusOwner = getGlobalPermanentFocusOwner (); |
Component focusOwner = getGlobalPermanentFocusOwner (); |
220 |
|
|
221 |
|
if (focusOwner != null) |
222 |
processKeyEvent (focusOwner, (KeyEvent) e); |
processKeyEvent (focusOwner, (KeyEvent) e); |
223 |
|
|
224 |
if (e.isConsumed ()) |
if (e.isConsumed ()) |
257 |
{ |
{ |
258 |
Component focusOwner = getGlobalPermanentFocusOwner (); |
Component focusOwner = getGlobalPermanentFocusOwner (); |
259 |
|
|
260 |
|
if (focusOwner != null) |
261 |
focusOwner.dispatchEvent (e); |
focusOwner.dispatchEvent (e); |
262 |
|
|
263 |
// Loop through all registered KeyEventPostProcessors, giving |
// Loop through all registered KeyEventPostProcessors, giving |