[gui][PATCH] JWindow without an owner
Olga Rodimina
rodimina@redhat.com
Wed Jun 30 20:21:00 GMT 2004
Hi,
This patch makes JWindow() without an owner to work again. It might not
be the best way to fix this, but it does fix the problem. With this
patch one can create JWindow with no parent and also HeavyWeightMenu's
work again because they are dependent on JWindow.
Please let me know if there is a better way to fix this. Any comments
are greatly appreciated.
I'll be committing this patch to java-gui-branch later in the day.
Thanks,
Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? package-list
? patch
? resources
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.236
diff -c -p -u -r1.2660.2.236 ChangeLog
--- ChangeLog 30 Jun 2004 16:33:03 -0000 1.2660.2.236
+++ ChangeLog 30 Jun 2004 19:46:02 -0000
@@ -1,5 +1,21 @@
2004-06-30 Olga Rodimina <rodimina@redhat.com>
+ * java/awt/Window.java: Changed constructors to use new
+ method that is described below. Constructors call this
+ methods only if newly created window should have an owner.
+ (setWindowOwner): New method. Implementation for
+ this method is moved from this(owner,configuration).
+ * javax/swing/JWindow.java:
+ (JWindow): Reimplement to use SwingUtilities.ownerFrame
+ instead of owner.
+ * javax/swing/SwingUtilities.java:
+ (ownerFrame): Change type of this field to OwnerFrame.
+ (getOwnerFrame): Changed to return object of type OwnerFrame.
+ (SwingUtilities.OwnerFrame): New class. Represents owner
+ of a Window that is not provided with one.
+
+2004-06-30 Olga Rodimina <rodimina@redhat.com>
+
* javax/swing/AbstractButton.java:
(configurePropertiesFromAction): Set action command
to button's text by default if action command is not
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.32.12.5
diff -c -p -u -r1.32.12.5 Window.java
--- java/awt/Window.java 24 Jun 2004 05:30:16 -0000 1.32.12.5
+++ java/awt/Window.java 30 Jun 2004 19:46:03 -0000
@@ -53,6 +53,7 @@ import java.util.ResourceBundle;
import java.util.Vector;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
+import javax.swing.SwingUtilities;
/**
* This class represents a top-level window with no decorations.
@@ -118,7 +119,11 @@ public class Window extends Container im
*/
public Window(Frame owner)
{
- this (owner, owner.getGraphicsConfiguration ());
+ this();
+
+ // Construct a Window with no parent if owner is of type OwnerFrame.
+ if (!(owner instanceof SwingUtilities.OwnerFrame))
+ setWindowOwner (owner, owner.getGraphicsConfiguration ());
}
/**
@@ -133,7 +138,7 @@ public class Window extends Container im
*/
public Window(Window owner)
{
- this (owner, owner.getGraphicsConfiguration ());
+ setWindowOwner(owner, owner.getGraphicsConfiguration ());
}
/**
@@ -149,14 +154,20 @@ public class Window extends Container im
public Window(Window owner, GraphicsConfiguration gc)
{
this ();
-
+ setWindowOwner(owner, owner.getGraphicsConfiguration ());
+ }
+
+
+ private void setWindowOwner (Window owner, GraphicsConfiguration gc)
+ {
synchronized (getTreeLock())
{
if (owner == null)
throw new IllegalArgumentException ("owner must not be null");
-
- parent = owner;
- owner.ownedWindows.add(new WeakReference(this));
+
+ parent = owner;
+ owner.ownedWindows.add(new WeakReference(this));
+
}
// FIXME: make this text visible in the window.
@@ -174,9 +185,10 @@ public class Window extends Container im
// .getDefaultScreenDevice()
// .getDefaultConfiguration();
// else
- graphicsConfiguration = gc;
+ graphicsConfiguration = gc;
+
}
-
+
GraphicsConfiguration getGraphicsConfigurationImpl()
{
if (graphicsConfiguration != null)
Index: javax/swing/JWindow.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JWindow.java,v
retrieving revision 1.3.18.6
diff -c -p -u -r1.3.18.6 JWindow.java
--- javax/swing/JWindow.java 24 Jun 2004 05:31:32 -0000 1.3.18.6
+++ javax/swing/JWindow.java 30 Jun 2004 19:46:03 -0000
@@ -82,7 +82,7 @@ public class JWindow extends Window impl
public JWindow()
{
- super(null); // FIXME: This throws an exception.
+ super(SwingUtilities.getOwnerFrame());
}
// huuu ?
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/SwingUtilities.java,v
retrieving revision 1.6.2.9
diff -c -p -u -r1.6.2.9 SwingUtilities.java
--- javax/swing/SwingUtilities.java 24 Jun 2004 05:31:32 -0000 1.6.2.9
+++ javax/swing/SwingUtilities.java 30 Jun 2004 19:46:04 -0000
@@ -65,8 +65,11 @@ import java.lang.reflect.InvocationTarge
*/
public class SwingUtilities implements SwingConstants
{
-
- private static Frame ownerFrame;
+ /**
+ * This frame should be used as parent for JWindow or JDialog
+ * that doesn't an owner
+ */
+ private static OwnerFrame ownerFrame;
/**
* Calculates the portion of the base rectangle which is inside the
@@ -836,15 +839,15 @@ public class SwingUtilities implements S
}
/**
- * This method returns the common Frame owner used in JDialogs
- * when no owner is provided.
+ * This method returns the common Frame owner used in JDialogs or
+ * JWindow when no owner is provided.
*
* @return The common Frame
*/
static Frame getOwnerFrame()
{
if (ownerFrame == null)
- ownerFrame = new Frame();
+ ownerFrame = new OwnerFrame();
return ownerFrame;
}
@@ -886,4 +889,16 @@ public class SwingUtilities implements S
return ((event.getModifiers() & InputEvent.BUTTON3_DOWN_MASK)
== InputEvent.BUTTON3_DOWN_MASK);
}
+
+ /**
+ * This frame should be used when constructing a Window/JDialog without
+ * a parent. In this case, we are forced to use this frame as a window's
+ * parent, because we simply cannot pass null instead of parent to Window
+ * constructor, since doing it will result in NullPointerException.
+ */
+ private class OwnerFrame extends Frame{
+ public OwnerFrame(){
+ super();
+ }
+}
}
More information about the Java-patches
mailing list