43 |
import java.awt.event.WindowListener; |
import java.awt.event.WindowListener; |
44 |
import java.awt.event.WindowStateListener; |
import java.awt.event.WindowStateListener; |
45 |
import java.awt.peer.WindowPeer; |
import java.awt.peer.WindowPeer; |
46 |
|
import java.lang.ref.Reference; |
47 |
|
import java.lang.ref.WeakReference; |
48 |
|
import java.util.Iterator; |
49 |
import java.util.EventListener; |
import java.util.EventListener; |
50 |
import java.util.Locale; |
import java.util.Locale; |
51 |
import java.util.ResourceBundle; |
import java.util.ResourceBundle; |
52 |
|
import java.util.Vector; |
53 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
54 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
55 |
|
|
73 |
/** @since 1.4 */ |
/** @since 1.4 */ |
74 |
private boolean focusableWindowState = true; |
private boolean focusableWindowState = true; |
75 |
|
|
76 |
|
// A list of other top-level windows owned by this window. |
77 |
|
private transient Vector ownedWindows = new Vector(); |
78 |
|
|
79 |
private transient WindowListener windowListener; |
private transient WindowListener windowListener; |
80 |
private transient WindowFocusListener windowFocusListener; |
private transient WindowFocusListener windowFocusListener; |
81 |
private transient WindowStateListener windowStateListener; |
private transient WindowStateListener windowStateListener; |
146 |
if (owner == null) |
if (owner == null) |
147 |
throw new IllegalArgumentException ("owner must not be null"); |
throw new IllegalArgumentException ("owner must not be null"); |
148 |
|
|
149 |
this.parent = owner; |
parent = owner; |
150 |
|
|
151 |
// FIXME: add to owner's "owned window" list |
synchronized (owner.ownedWindows) |
152 |
//owner.owned.add(this); // this should be a weak reference |
{ |
153 |
|
owner.ownedWindows.add(new WeakReference(this)); |
154 |
|
} |
155 |
|
|
156 |
// FIXME: make this text visible in the window. |
// FIXME: make this text visible in the window. |
157 |
SecurityManager s = System.getSecurityManager(); |
SecurityManager s = System.getSecurityManager(); |
158 |
if (s != null && ! s.checkTopLevelWindow(this)) |
if (s != null && ! s.checkTopLevelWindow(this)) |
180 |
} |
} |
181 |
|
|
182 |
/** |
/** |
|
* Disposes of the input methods and context, and removes the WeakReference |
|
|
* which formerly pointed to this Window from the parent's owned Window list. |
|
|
* |
|
|
* @exception Throwable The Exception raised by this method. |
|
|
*/ |
|
|
protected void finalize() throws Throwable |
|
|
{ |
|
|
// FIXME: remove from owner's "owned window" list (Weak References) |
|
|
super.finalize(); |
|
|
} |
|
|
|
|
|
/** |
|
183 |
* Creates the native peer for this window. |
* Creates the native peer for this window. |
184 |
*/ |
*/ |
185 |
public void addNotify() |
public void addNotify() |
224 |
|
|
225 |
public void hide() |
public void hide() |
226 |
{ |
{ |
227 |
// FIXME: call hide() on any "owned" children here. |
synchronized (ownedWindows) |
228 |
|
{ |
229 |
|
Iterator e = ownedWindows.iterator(); |
230 |
|
while(e.hasNext()) |
231 |
|
{ |
232 |
|
Window w = (Window)(((Reference) e.next()).get()); |
233 |
|
if (w != null) |
234 |
|
w.hide(); |
235 |
|
else |
236 |
|
// Remove null weak reference from ownedWindows. |
237 |
|
// Unfortunately this can't be done in the Window's |
238 |
|
// finalize method because there is no way to guarantee |
239 |
|
// synchronous access to ownedWindows there. |
240 |
|
e.remove(); |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
super.hide(); |
super.hide(); |
245 |
} |
} |
246 |
|
|
252 |
} |
} |
253 |
|
|
254 |
/** |
/** |
255 |
* Called to free any resource associated with this window. |
* Destroys any resources associated with this window. This includes |
256 |
|
* all components in the window and all owned top-level windows. |
257 |
*/ |
*/ |
258 |
public void dispose() |
public void dispose() |
259 |
{ |
{ |
260 |
hide(); |
hide(); |
261 |
|
|
262 |
Window[] list = getOwnedWindows(); |
synchronized (ownedWindows) |
263 |
for (int i=0; i<list.length; i++) |
{ |
264 |
list[i].dispose(); |
Iterator e = ownedWindows.iterator(); |
265 |
|
while(e.hasNext()) |
266 |
|
{ |
267 |
|
Window w = (Window)(((Reference) e.next()).get()); |
268 |
|
if (w != null) |
269 |
|
w.dispose(); |
270 |
|
else |
271 |
|
// Remove null weak reference from ownedWindows. |
272 |
|
e.remove(); |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
for (int i = 0; i < ncomponents; ++i) |
for (int i = 0; i < ncomponents; ++i) |
277 |
component[i].removeNotify(); |
component[i].removeNotify(); |
364 |
/** @since 1.2 */ |
/** @since 1.2 */ |
365 |
public Window[] getOwnedWindows() |
public Window[] getOwnedWindows() |
366 |
{ |
{ |
367 |
// FIXME: return array containing all the windows this window currently |
Window [] trimmedList; |
368 |
// owns. |
synchronized (ownedWindows) |
369 |
return new Window[0]; |
{ |
370 |
|
// Windows with non-null weak references in ownedWindows. |
371 |
|
Window [] validList = new Window [ownedWindows.size()]; |
372 |
|
|
373 |
|
Iterator e = ownedWindows.iterator(); |
374 |
|
int numValid = 0; |
375 |
|
while (e.hasNext()) |
376 |
|
{ |
377 |
|
Window w = (Window)(((Reference) e.next()).get()); |
378 |
|
if (w != null) |
379 |
|
validList[numValid++] = w; |
380 |
|
else |
381 |
|
// Remove null weak reference from ownedWindows. |
382 |
|
e.remove(); |
383 |
|
} |
384 |
|
|
385 |
|
if (numValid != validList.length) |
386 |
|
{ |
387 |
|
trimmedList = new Window [numValid]; |
388 |
|
System.arraycopy (validList, 0, trimmedList, 0, numValid); |
389 |
|
} |
390 |
|
else |
391 |
|
trimmedList = validList; |
392 |
|
} |
393 |
|
return trimmedList; |
394 |
} |
} |
395 |
|
|
396 |
/** |
/** |