39 |
package java.awt; |
package java.awt; |
40 |
|
|
41 |
import java.awt.event.ComponentEvent; |
import java.awt.event.ComponentEvent; |
42 |
|
import java.awt.event.FocusEvent; |
43 |
|
import java.awt.event.WindowAdapter; |
44 |
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
45 |
import java.awt.event.WindowFocusListener; |
import java.awt.event.WindowFocusListener; |
46 |
import java.awt.event.WindowListener; |
import java.awt.event.WindowListener; |
87 |
|
|
88 |
private transient boolean shown; |
private transient boolean shown; |
89 |
|
|
90 |
|
private transient Component windowFocusOwner; |
91 |
|
|
92 |
/** |
/** |
93 |
* This (package access) constructor is used by subclasses that want |
* This (package access) constructor is used by subclasses that want |
94 |
* to build windows that do not have parents. Eg. toplevel |
* to build windows that do not have parents. Eg. toplevel |
102 |
// cycle roots. |
// cycle roots. |
103 |
focusCycleRoot = true; |
focusCycleRoot = true; |
104 |
setLayout(new BorderLayout()); |
setLayout(new BorderLayout()); |
105 |
|
|
106 |
|
addWindowFocusListener (new WindowAdapter () |
107 |
|
{ |
108 |
|
public void windowGainedFocus (WindowEvent event) |
109 |
|
{ |
110 |
|
if (windowFocusOwner != null) |
111 |
|
{ |
112 |
|
// FIXME: move this section and the other similar |
113 |
|
// sections in Component into a separate method. |
114 |
|
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); |
115 |
|
synchronized (eq) |
116 |
|
{ |
117 |
|
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); |
118 |
|
Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); |
119 |
|
if (currentFocusOwner != null) |
120 |
|
{ |
121 |
|
eq.postEvent (new FocusEvent (currentFocusOwner, FocusEvent.FOCUS_LOST, |
122 |
|
false, windowFocusOwner)); |
123 |
|
eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED, |
124 |
|
false, currentFocusOwner)); |
125 |
|
} |
126 |
|
else |
127 |
|
eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED, false)); |
128 |
|
} |
129 |
|
} |
130 |
|
} |
131 |
|
}); |
132 |
} |
} |
133 |
|
|
134 |
Window(GraphicsConfiguration gc) |
Window(GraphicsConfiguration gc) |
689 |
// The currently-focused Component belongs to the active Window. |
// The currently-focused Component belongs to the active Window. |
690 |
if (activeWindow == this) |
if (activeWindow == this) |
691 |
return manager.getFocusOwner (); |
return manager.getFocusOwner (); |
692 |
|
else |
693 |
|
return windowFocusOwner; |
694 |
|
} |
695 |
|
|
696 |
return null; |
/** |
697 |
|
* Set the focus owner for this window. This method is used to |
698 |
|
* remember which component was focused when this window lost |
699 |
|
* top-level focus, so that when it regains top-level focus the same |
700 |
|
* child component can be refocused. |
701 |
|
* |
702 |
|
* @param windowFocusOwner the component in this window that owns |
703 |
|
* the focus. |
704 |
|
*/ |
705 |
|
void setFocusOwner (Component windowFocusOwner) |
706 |
|
{ |
707 |
|
this.windowFocusOwner = windowFocusOwner; |
708 |
} |
} |
709 |
|
|
710 |
/** |
/** |
716 |
*/ |
*/ |
717 |
public boolean postEvent(Event e) |
public boolean postEvent(Event e) |
718 |
{ |
{ |
719 |
// FIXME |
return handleEvent (e); |
|
return false; |
|
720 |
} |
} |
721 |
|
|
722 |
/** |
/** |