39 |
package java.awt; |
package java.awt; |
40 |
|
|
41 |
import java.awt.peer.FramePeer; |
import java.awt.peer.FramePeer; |
42 |
|
import java.lang.ref.WeakReference; |
43 |
|
import java.util.ArrayList; |
44 |
|
import java.util.Iterator; |
45 |
import java.util.Vector; |
import java.util.Vector; |
46 |
|
|
47 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
217 |
Frame() |
Frame() |
218 |
{ |
{ |
219 |
this(""); |
this(""); |
220 |
|
noteFrame(this); |
221 |
} |
} |
222 |
|
|
223 |
/** |
/** |
233 |
this.title = title; |
this.title = title; |
234 |
// Top-level frames are initially invisible. |
// Top-level frames are initially invisible. |
235 |
visible = false; |
visible = false; |
236 |
|
noteFrame(this); |
237 |
} |
} |
238 |
|
|
239 |
public |
public |
241 |
{ |
{ |
242 |
super(gc); |
super(gc); |
243 |
visible = false; |
visible = false; |
244 |
|
noteFrame(this); |
245 |
} |
} |
246 |
|
|
247 |
public |
public |
250 |
super(gc); |
super(gc); |
251 |
setTitle(title); |
setTitle(title); |
252 |
visible = false; |
visible = false; |
253 |
|
noteFrame(this); |
254 |
} |
} |
255 |
|
|
256 |
/** |
/** |
403 |
/** |
/** |
404 |
* Notifies this frame that it should create its native peer. |
* Notifies this frame that it should create its native peer. |
405 |
*/ |
*/ |
406 |
|
|
407 |
|
private static void fireDummyEvent() |
408 |
|
{ |
409 |
|
EventQueue.invokeLater(new Runnable() { public void run() { } }); |
410 |
|
} |
411 |
|
|
412 |
public void |
public void |
413 |
addNotify() |
addNotify() |
414 |
{ |
{ |
416 |
menuBar.addNotify(); |
menuBar.addNotify(); |
417 |
if (peer == null) |
if (peer == null) |
418 |
peer = getToolkit ().createFrame (this); |
peer = getToolkit ().createFrame (this); |
419 |
|
|
420 |
|
// We now know there's a Frame (us) with a live peer, so we can start the |
421 |
|
// fundamental queue and dispatch thread, by inserting a dummy event. |
422 |
|
if (parent != null && parent.isDisplayable()) |
423 |
|
fireDummyEvent(); |
424 |
|
|
425 |
super.addNotify(); |
super.addNotify(); |
426 |
} |
} |
427 |
|
|
430 |
if (menuBar != null) |
if (menuBar != null) |
431 |
menuBar.removeNotify(); |
menuBar.removeNotify(); |
432 |
super.removeNotify(); |
super.removeNotify(); |
433 |
|
|
434 |
|
// By now we've been disconnected from the peer, and the peer set to |
435 |
|
// null. This is formally the same as saying "we just became |
436 |
|
// un-displayable", so we wake up the event queue with a dummy event to |
437 |
|
// see if it's time to shut down. |
438 |
|
fireDummyEvent(); |
439 |
} |
} |
440 |
|
|
441 |
/** |
/** |
474 |
return super.paramString () + ",title=" + title + resizable + state; |
return super.paramString () + ",title=" + title + resizable + state; |
475 |
} |
} |
476 |
|
|
477 |
public static Frame[] |
private static ArrayList weakFrames = new ArrayList(); |
478 |
getFrames() |
|
479 |
|
private static void noteFrame(Frame f) |
480 |
|
{ |
481 |
|
weakFrames.add(new WeakReference(f)); |
482 |
|
} |
483 |
|
|
484 |
|
public static Frame[] getFrames() |
485 |
{ |
{ |
486 |
//Frame[] array = new Frames[frames.size()]; |
int n = 0; |
487 |
//return frames.toArray(array); |
synchronized (weakFrames) |
488 |
String msg = "FIXME: can't be implemented without weak references"; |
{ |
489 |
throw new UnsupportedOperationException(msg); |
Iterator i = weakFrames.iterator(); |
490 |
|
while (i.hasNext()) |
491 |
|
{ |
492 |
|
WeakReference wr = (WeakReference) i.next(); |
493 |
|
if (wr.get() != null) |
494 |
|
++n; |
495 |
|
} |
496 |
|
if (n == 0) |
497 |
|
return new Frame[0]; |
498 |
|
else |
499 |
|
{ |
500 |
|
Frame[] frames = new Frame[n]; |
501 |
|
n = 0; |
502 |
|
i = weakFrames.iterator(); |
503 |
|
while (i.hasNext()) |
504 |
|
{ |
505 |
|
WeakReference wr = (WeakReference) i.next(); |
506 |
|
if (wr.get() != null) |
507 |
|
frames[n++] = (Frame) wr.get(); |
508 |
|
} |
509 |
|
return frames; |
510 |
|
} |
511 |
|
} |
512 |
} |
} |
513 |
|
|
514 |
public void setState (int state) |
public void setState (int state) |