aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/awt/Dialog.java28
-rw-r--r--libjava/java/awt/Frame.java21
-rw-r--r--libjava/java/awt/Window.java98
3 files changed, 87 insertions, 60 deletions
diff --git a/libjava/java/awt/Dialog.java b/libjava/java/awt/Dialog.java
index aba4098..eee8361 100644
--- a/libjava/java/awt/Dialog.java
+++ b/libjava/java/awt/Dialog.java
@@ -70,7 +70,7 @@ private boolean modal;
/**
* @serial Indicates whether or not this dialog box is resizable.
*/
-private boolean resizable;
+private boolean resizable = true;
/**
* @serial The title string for this dialog box, which can be
@@ -91,7 +91,7 @@ private String title;
/**
* Initializes a new instance of <code>Dialog</code> with the specified
- * parent, that is not resizable and not modal, and which has no title.
+ * parent, that is resizable and not modal, and which has no title.
*
* @param parent The parent frame of this dialog box.
*
@@ -109,7 +109,7 @@ Dialog(Frame parent)
/**
* Initializes a new instance of <code>Dialog</code> with the specified
- * parent and modality, that is not resizable and which has no title.
+ * parent and modality, that is resizable and which has no title.
*
* @param parent The parent frame of this dialog box.
* @param modal <true> if this dialog box is modal, <code>false</code>
@@ -129,7 +129,7 @@ Dialog(Frame parent, boolean modal)
/**
* Initializes a new instance of <code>Dialog</code> with the specified
- * parent, that is not resizable and not modal, and which has the specified
+ * parent, that is resizable and not modal, and which has the specified
* title.
*
* @param parent The parent frame of this dialog box.
@@ -149,7 +149,7 @@ Dialog(Frame parent, String title)
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
- * parent, title, and modality, that is not resizable.
+ * parent, title, and modality, that is resizable.
*
* @param parent The parent frame of this dialog box.
* @param title The title string for this dialog box.
@@ -168,7 +168,7 @@ Dialog(Frame parent, String title, boolean modal)
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
* parent, title, modality and <code>GraphicsConfiguration</code>,
- * that is not resizable.
+ * that is resizable.
*
* @param parent The parent frame of this dialog box.
* @param title The title string for this dialog box.
@@ -189,14 +189,14 @@ Dialog (Frame parent, String title, boolean modal, GraphicsConfiguration gc)
this.title = title;
this.modal = modal;
- resizable = false;
+ visible = false;
setLayout(new BorderLayout());
}
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
- * parent, that is not resizable.
+ * parent, that is resizable.
*
* @exception IllegalArgumentException If parent is null. This exception is
* always thrown when GraphicsEnvironment.isHeadless() returns true.
@@ -211,7 +211,7 @@ Dialog (Dialog owner)
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
- * parent and title, that is not resizable.
+ * parent and title, that is resizable.
*
* @exception IllegalArgumentException If parent is null. This exception is
* always thrown when GraphicsEnvironment.isHeadless() returns true.
@@ -226,7 +226,7 @@ Dialog (Dialog owner, String title)
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
- * parent, title and modality, that is not resizable.
+ * parent, title and modality, that is resizable.
*
* @exception IllegalArgumentException If parent is null. This exception is
* always thrown when GraphicsEnvironment.isHeadless() returns true.
@@ -242,7 +242,7 @@ Dialog (Dialog owner, String title, boolean modal)
/**
* Initializes a new instance of <code>Dialog</code> with the specified,
* parent, title, modality and <code>GraphicsConfiguration</code>,
- * that is not resizable.
+ * that is resizable.
*
* @exception IllegalArgumentException If parent is null, the
* GraphicsConfiguration is not a screen device or
@@ -255,10 +255,10 @@ Dialog (Dialog parent, String title, boolean modal, GraphicsConfiguration gc)
{
super (parent, parent.getGraphicsConfiguration ());
- this.modal = modal;
this.title = title;
- resizable = false;
-
+ this.modal = modal;
+ visible = false;
+
setLayout (new BorderLayout ());
}
diff --git a/libjava/java/awt/Frame.java b/libjava/java/awt/Frame.java
index 1df9832..b6a3427 100644
--- a/libjava/java/awt/Frame.java
+++ b/libjava/java/awt/Frame.java
@@ -438,25 +438,6 @@ addNotify()
/*************************************************************************/
/**
- * Destroys any resources associated with this frame. This includes
- * all components in the frame and all owned toplevel windows.
- */
-public void
-dispose()
-{
- Enumeration e = ownedWindows.elements();
- while(e.hasMoreElements())
- {
- Window w = (Window)e.nextElement();
- w.dispose();
- }
-
- super.dispose();
-}
-
-/*************************************************************************/
-
-/**
* Returns a debugging string describing this window.
*
* @return A debugging string describing this window.
@@ -472,8 +453,6 @@ getFrames()
{
//Frame[] array = new Frames[frames.size()];
//return frames.toArray(array);
-
- // see finalize() comment
String msg = "FIXME: can't be implemented without weak references";
throw new UnsupportedOperationException(msg);
}
diff --git a/libjava/java/awt/Window.java b/libjava/java/awt/Window.java
index 2f625aa..9f10275 100644
--- a/libjava/java/awt/Window.java
+++ b/libjava/java/awt/Window.java
@@ -43,9 +43,13 @@ import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import java.awt.peer.WindowPeer;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.Iterator;
import java.util.EventListener;
import java.util.Locale;
import java.util.ResourceBundle;
+import java.util.Vector;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
@@ -69,6 +73,9 @@ public class Window extends Container implements Accessible
/** @since 1.4 */
private boolean focusableWindowState = true;
+ // A list of other top-level windows owned by this window.
+ private transient Vector ownedWindows = new Vector();
+
private transient WindowListener windowListener;
private transient WindowFocusListener windowFocusListener;
private transient WindowStateListener windowStateListener;
@@ -139,11 +146,13 @@ public class Window extends Container implements Accessible
if (owner == null)
throw new IllegalArgumentException ("owner must not be null");
- this.parent = owner;
-
- // FIXME: add to owner's "owned window" list
- //owner.owned.add(this); // this should be a weak reference
-
+ parent = owner;
+
+ synchronized (owner.ownedWindows)
+ {
+ owner.ownedWindows.add(new WeakReference(this));
+ }
+
// FIXME: make this text visible in the window.
SecurityManager s = System.getSecurityManager();
if (s != null && ! s.checkTopLevelWindow(this))
@@ -171,18 +180,6 @@ public class Window extends Container implements Accessible
}
/**
- * 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();
- }
-
- /**
* Creates the native peer for this window.
*/
public void addNotify()
@@ -227,7 +224,23 @@ public class Window extends Container implements Accessible
public void hide()
{
- // FIXME: call hide() on any "owned" children here.
+ synchronized (ownedWindows)
+ {
+ Iterator e = ownedWindows.iterator();
+ while(e.hasNext())
+ {
+ Window w = (Window)(((Reference) e.next()).get());
+ if (w != null)
+ w.hide();
+ else
+ // Remove null weak reference from ownedWindows.
+ // Unfortunately this can't be done in the Window's
+ // finalize method because there is no way to guarantee
+ // synchronous access to ownedWindows there.
+ e.remove();
+ }
+ }
+
super.hide();
}
@@ -239,15 +252,26 @@ public class Window extends Container implements Accessible
}
/**
- * Called to free any resource associated with this window.
+ * Destroys any resources associated with this window. This includes
+ * all components in the window and all owned top-level windows.
*/
public void dispose()
{
hide();
- Window[] list = getOwnedWindows();
- for (int i=0; i<list.length; i++)
- list[i].dispose();
+ synchronized (ownedWindows)
+ {
+ Iterator e = ownedWindows.iterator();
+ while(e.hasNext())
+ {
+ Window w = (Window)(((Reference) e.next()).get());
+ if (w != null)
+ w.dispose();
+ else
+ // Remove null weak reference from ownedWindows.
+ e.remove();
+ }
+ }
for (int i = 0; i < ncomponents; ++i)
component[i].removeNotify();
@@ -340,9 +364,33 @@ public class Window extends Container implements Accessible
/** @since 1.2 */
public Window[] getOwnedWindows()
{
- // FIXME: return array containing all the windows this window currently
- // owns.
- return new Window[0];
+ Window [] trimmedList;
+ synchronized (ownedWindows)
+ {
+ // Windows with non-null weak references in ownedWindows.
+ Window [] validList = new Window [ownedWindows.size()];
+
+ Iterator e = ownedWindows.iterator();
+ int numValid = 0;
+ while (e.hasNext())
+ {
+ Window w = (Window)(((Reference) e.next()).get());
+ if (w != null)
+ validList[numValid++] = w;
+ else
+ // Remove null weak reference from ownedWindows.
+ e.remove();
+ }
+
+ if (numValid != validList.length)
+ {
+ trimmedList = new Window [numValid];
+ System.arraycopy (validList, 0, trimmedList, 0, numValid);
+ }
+ else
+ trimmedList = validList;
+ }
+ return trimmedList;
}
/**