diff options
Diffstat (limited to 'libjava/java/awt/Frame.java')
-rw-r--r-- | libjava/java/awt/Frame.java | 124 |
1 files changed, 110 insertions, 14 deletions
diff --git a/libjava/java/awt/Frame.java b/libjava/java/awt/Frame.java index 80d2c99ae4d..d180984ab9d 100644 --- a/libjava/java/awt/Frame.java +++ b/libjava/java/awt/Frame.java @@ -1,5 +1,5 @@ /* Frame.java -- AWT toplevel window - Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,8 +39,16 @@ exception statement from your version. */ package java.awt; import java.awt.peer.FramePeer; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Iterator; import java.util.Vector; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; + /** * This class is a top-level window with a title bar and window * decorations. @@ -196,7 +204,7 @@ private String title = ""; */ private boolean undecorated = false; -/* + /* * The number used to generate the name returned by getName. */ private static transient long next_frame_number; @@ -209,6 +217,7 @@ public Frame() { this(""); + noteFrame(this); } /** @@ -224,6 +233,7 @@ Frame(String title) this.title = title; // Top-level frames are initially invisible. visible = false; + noteFrame(this); } public @@ -231,6 +241,7 @@ Frame(GraphicsConfiguration gc) { super(gc); visible = false; + noteFrame(this); } public @@ -239,6 +250,7 @@ Frame(String title, GraphicsConfiguration gc) super(gc); setTitle(title); visible = false; + noteFrame(this); } /** @@ -391,6 +403,17 @@ remove(MenuComponent menu) /** * Notifies this frame that it should create its native peer. */ +private static void fireDummyEvent() +{ + EventQueue.invokeLater(new Runnable() + { + public void run() + { + // Do nothing here. + } + }); +} + public void addNotify() { @@ -398,6 +421,12 @@ addNotify() menuBar.addNotify(); if (peer == null) peer = getToolkit ().createFrame (this); + + // We now know there's a Frame (us) with a live peer, so we can start the + // fundamental queue and dispatch thread, by inserting a dummy event. + if (parent != null && parent.isDisplayable()) + fireDummyEvent(); + super.addNotify(); } @@ -406,15 +435,21 @@ public void removeNotify() if (menuBar != null) menuBar.removeNotify(); super.removeNotify(); + + // By now we've been disconnected from the peer, and the peer set to + // null. This is formally the same as saying "we just became + // un-displayable", so we wake up the event queue with a dummy event to + // see if it's time to shut down. + fireDummyEvent(); } -/** - * Returns a debugging string describing this window. - * - * @return A debugging string describing this window. - */ + /** + * Returns a debugging string describing this window. + * + * @return A debugging string describing this window. + */ protected String paramString () -{ + { String title = getTitle (); String resizable = ""; @@ -442,15 +477,43 @@ public void removeNotify() } return super.paramString () + ",title=" + title + resizable + state; + } + +private static ArrayList weakFrames = new ArrayList(); + +private static void noteFrame(Frame f) +{ + weakFrames.add(new WeakReference(f)); } -public static Frame[] -getFrames() +public static Frame[] getFrames() { - //Frame[] array = new Frames[frames.size()]; - //return frames.toArray(array); - String msg = "FIXME: can't be implemented without weak references"; - throw new UnsupportedOperationException(msg); + int n = 0; + synchronized (weakFrames) + { + Iterator i = weakFrames.iterator(); + while (i.hasNext()) + { + WeakReference wr = (WeakReference) i.next(); + if (wr.get() != null) + ++n; + } + if (n == 0) + return new Frame[0]; + else + { + Frame[] frames = new Frame[n]; + n = 0; + i = weakFrames.iterator(); + while (i.hasNext()) + { + WeakReference wr = (WeakReference) i.next(); + if (wr.get() != null) + frames[n++] = (Frame) wr.get(); + } + return frames; + } + } } public void setState (int state) @@ -549,4 +612,37 @@ getFrames() { return next_frame_number++; } + + protected class AccessibleAWTFrame extends AccessibleAWTWindow + { + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.FRAME; + } + + public AccessibleStateSet getAccessibleState() + { + AccessibleStateSet states = super.getAccessibleStateSet(); + if (isResizable()) + states.add(AccessibleState.RESIZABLE); + if ((state & ICONIFIED) != 0) + states.add(AccessibleState.ICONIFIED); + return states; + } + } + + /** + * Gets the AccessibleContext associated with this <code>Frame</code>. + * The context is created, if necessary. + * + * @return the associated context + */ + public AccessibleContext getAccessibleContext() + { + /* Create the context if this is the first request */ + if (accessibleContext == null) + accessibleContext = new AccessibleAWTFrame(); + return accessibleContext; + } + } |