Hi,
I fixed the handling of the rootPaneCheckingEnabled property in Swing's
toplevel containers. The situation before was that this property was
only used to decide if an exception should be thrown or not if an
attempt was made to add a component to (or set the layout for) a
toplevel swing container. We had a private boolean field that indicated
if we are in the init phase or not which was used to decide if adds and
setLayout go to the container directly or to its contentPane.
I observed that the JDK1.5 (in which this property was introduced) never
throws an Exception when add or setLayout is called, and actually used
the rootPaneCheckingEnabled property to decide where the add and
setLayout should go. I checked in a couple of Mauve tests for this and
here comes the fix.
This contains some more fixlets for JInternalFrame, most notably we need
to switch to init mode in the setUI and updateUI methods so that the UI
initialization can work on the JInternalFrame directly and not on its
contentPane. And yes, we need to do this in both methods, since
subclasses commonly override one of these two, but not necessarily both.
2005-11-07 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JApplet.java
(initStageDone): Removed unnecessary field.
(JApplet): Use rootPaneCheckingEnabled property instead of
initStageDone field.
(setLayout): Likewise.
(addImpl): Likewise.
* javax/swing/JDialog.java
(initStageDone): Removed unnecessary field.
(dialogInit): Use rootPaneCheckingEnabled property instead of
initStageDone field.
(setLayout): Likewise.
(addImpl): Likewise.
* javax/swing/JFrame.java
(initStageDone): Removed unnecessary field.
(frameInit): Use rootPaneCheckingEnabled property instead of
initStageDone field.
(setLayout): Likewise.
(addImpl): Likewise.
* javax/swing/JWindow.java
(initStageDone): Removed unnecessary field.
(windowInit): Use rootPaneCheckingEnabled property instead of
initStageDone field.
(setLayout): Likewise.
(addImpl): Likewise.
* javax/swing/JInternalFrame.java
(initStageDone): Removed unnecessary field.
(JInternalFrame): Use rootPaneCheckingEnabled property instead of
initStageDone field.
(setLayout): Likewise.
(addImpl): Likewise.
(paramString): Return superclass paramstring.
(reshape): Call revalidate() instead of invalidate() and
doLayout().
(setUI): Temporarily go into init mode, so that the UI can
manipulate the frame directly.
(updateUI): Likewise.
/Roman
Index: javax/swing/JApplet.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JApplet.java,v
retrieving revision 1.21
diff -u -r1.21 JApplet.java
--- javax/swing/JApplet.java 22 Sep 2005 14:48:05 -0000 1.21
+++ javax/swing/JApplet.java 7 Nov 2005 21:03:30 -0000
@@ -85,20 +85,13 @@
/**
* @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
*/
- protected boolean rootPaneCheckingEnabled=false;
-
- /**
- * Tells us if we're in the initialization stage.
- * If so, adds go to top-level Container, otherwise they go
- * to the content pane for this container
- */
- private boolean initStageDone = false;
+ protected boolean rootPaneCheckingEnabled = false;
public JApplet()
{
super.setLayout(new BorderLayout(1, 1));
getRootPane(); // Will do set/create.
- initStageDone = true; // Init stage is now over.
+ setRootPaneCheckingEnabled(true); // Init stage is now over.
}
public Dimension getPreferredSize()
@@ -110,13 +103,8 @@
{
// Check if we're in initialization stage. If so, call super.setLayout
// otherwise, valid calls go to the content pane
- if (initStageDone)
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Cannot set layout. Use getContentPane().setLayout()"
- + "instead.");
- getContentPane().setLayout(manager);
- }
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
else
super.setLayout(manager);
}
@@ -176,15 +164,10 @@
{
// If we're adding in the initialization stage use super.add.
// Otherwise pass the add onto the content pane.
- if (!initStageDone)
- super.addImpl(comp, constraints, index);
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp, constraints, index);
else
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Do not use add() on JApplet directly. Use "
- + "getContentPane().add() instead");
- getContentPane().add(comp, constraints, index);
- }
+ super.addImpl(comp, constraints, index);
}
public AccessibleContext getAccessibleContext()
Index: javax/swing/JDialog.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JDialog.java,v
retrieving revision 1.18
diff -u -r1.18 JDialog.java
--- javax/swing/JDialog.java 7 Sep 2005 16:05:14 -0000 1.18
+++ javax/swing/JDialog.java 7 Nov 2005 21:03:31 -0000
@@ -102,13 +102,6 @@
/** Whether JDialogs are decorated by the Look and Feel. */
private static boolean decorated;
- /**
- * Whether we're in the init stage or not.
- * If so, adds and layouts are for top-level, otherwise they're for the
- * content pane
- */
- private boolean initStageDone = false;
-
/* Creates a new non-modal JDialog with no title
* using a shared Frame as the owner.
*/
@@ -259,7 +252,7 @@
invalidate();
// Now that initStageDone is true, adds and layouts apply to contentPane,
// not top-level.
- initStageDone = true;
+ setRootPaneCheckingEnabled(true);
}
/**
@@ -330,13 +323,8 @@
{
// Check if we're in initialization stage. If so, call super.setLayout
// otherwise, valid calls go to the content pane.
- if (initStageDone)
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Cannot set top-level layout. Use"
- + " getConentPane().setLayout instead.");
- getContentPane().setLayout(manager);
- }
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
else
super.setLayout(manager);
}
@@ -460,15 +448,10 @@
{
// If we're adding in the initialization stage use super.add.
// Otherwise pass the add onto the content pane.
- if (!initStageDone)
- super.addImpl(comp, constraints, index);
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp, constraints, index);
else
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Do not add directly to JDialog."
- + " Use getContentPane().add instead.");
- getContentPane().add(comp, constraints, index);
- }
+ super.addImpl(comp, constraints, index);
}
/**
Index: javax/swing/JFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JFrame.java,v
retrieving revision 1.30
diff -u -r1.30 JFrame.java
--- javax/swing/JFrame.java 30 Sep 2005 14:52:05 -0000 1.30
+++ javax/swing/JFrame.java 7 Nov 2005 21:03:31 -0000
@@ -102,13 +102,6 @@
*/
protected boolean rootPaneCheckingEnabled = false;
- /**
- * Tells us if we're in the initialization stage.
- * If so, adds go to top-level Container, otherwise they go
- * to the content pane for this container.
- */
- private boolean initStageDone = false;
-
public JFrame()
{
super("JFrame");
@@ -158,7 +151,7 @@
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
getRootPane(); // will do set/create
// We're now done the init stage.
- initStageDone = true;
+ setRootPaneCheckingEnabled(true);
}
public Dimension getPreferredSize()
@@ -180,13 +173,8 @@
{
// Check if we're in initialization stage. If so, call super.setLayout
// otherwise, valid calls go to the content pane.
- if (initStageDone)
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Cannot set layout. Use getContentPane().setLayout()"
- + " instead.");
- getContentPane().setLayout(manager);
- }
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
else
super.setLayout(manager);
}
@@ -246,15 +234,10 @@
{
// If we're adding in the initialization stage use super.add.
// Otherwise pass the add onto the content pane.
- if (!initStageDone)
- super.addImpl(comp, constraints, index);
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp,constraints,index);
else
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("rootPaneChecking is enabled - adding components "
- + "disallowed.");
- getContentPane().add(comp,constraints,index);
- }
+ super.addImpl(comp, constraints, index);
}
public void remove(Component comp)
Index: javax/swing/JInternalFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JInternalFrame.java,v
retrieving revision 1.21
diff -u -r1.21 JInternalFrame.java
--- javax/swing/JInternalFrame.java 11 Jul 2005 20:55:44 -0000 1.21
+++ javax/swing/JInternalFrame.java 7 Nov 2005 21:03:31 -0000
@@ -437,13 +437,6 @@
*/
protected boolean rootPaneCheckingEnabled = false;
- /**
- * Tells us if we're in the initialization stage.
- * If so, adds go to top-level Container, otherwise they go
- * to the content pane for this container.
- */
- private boolean initStageDone = false;
-
/** Whether the JInternalFrame is resizable. */
protected boolean resizable;
@@ -567,7 +560,7 @@
storedBounds = new Rectangle();
setRootPane(createRootPane());
updateUI();
- initStageDone = true; // Done the init stage, now adds go to content pane.
+ setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
}
/**
@@ -587,15 +580,10 @@
// If we're in the initialization stage use super.add. Here we add the
// rootPane as well as the title bar and other stuff.
// Otherwise pass the add onto the content pane.
- if (!initStageDone)
- super.addImpl(comp,constraints, index);
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp, constraints, index);
else
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Do not use add() on JInternalFrame directly. Use "
- + "getContentPane().add() instead");
- getContentPane().add(comp, constraints, index);
- }
+ super.addImpl(comp,constraints, index);
}
/**
@@ -1187,7 +1175,7 @@
*/
protected String paramString()
{
- return "JInternalFrame";
+ return super.paramString();
}
/**
@@ -1227,8 +1215,7 @@
public void reshape(int x, int y, int width, int height)
{
super.reshape(x, y, width, height);
- invalidate();
- doLayout();
+ revalidate();
}
/**
@@ -1489,13 +1476,8 @@
{
// Check if we're in initialization stage. If so, call super.setLayout
// otherwise, valid calls go to the content pane.
- if (initStageDone)
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Cannot set layout. Use getContentPane().setLayout()"
- + " instead.");
- getContentPane().setLayout(manager);
- }
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
else
super.setLayout(manager);
}
@@ -1678,7 +1660,12 @@
*/
public void setUI(InternalFrameUI ui)
{
+ // We must temporarily go into init mode so that the UI can directly
+ // manipulate the JInternalFrame.
+ boolean old = isRootPaneCheckingEnabled();
+ setRootPaneCheckingEnabled(false);
super.setUI(ui);
+ setRootPaneCheckingEnabled(old);
}
/**
@@ -1704,7 +1691,13 @@
*/
public void updateUI()
{
+ // We must go into the init stage when updating the UI, so the UI can
+ // set layout and components directly on the internal frame, not its
+ // content pane.
+ boolean old = isRootPaneCheckingEnabled();
+ setRootPaneCheckingEnabled(false);
setUI((InternalFrameUI) UIManager.getUI(this));
+ setRootPaneCheckingEnabled(old);
}
/**
Index: javax/swing/JWindow.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JWindow.java,v
retrieving revision 1.21
diff -u -r1.21 JWindow.java
--- javax/swing/JWindow.java 7 Sep 2005 16:05:14 -0000 1.21
+++ javax/swing/JWindow.java 7 Nov 2005 21:03:31 -0000
@@ -86,13 +86,6 @@
protected AccessibleContext accessibleContext;
- /**
- * Tells us if we're in the initialization stage.
- * If so, adds go to top-level Container, otherwise they go
- * to the content pane for this container.
- */
- private boolean initStageDone = false;
-
public JWindow()
{
super(SwingUtilities.getOwnerFrame());
@@ -128,7 +121,7 @@
super.setLayout(new BorderLayout(1, 1));
getRootPane(); // will do set/create
// Now we're done init stage, adds and layouts go to content pane.
- initStageDone = true;
+ setRootPaneCheckingEnabled(true);
}
public Dimension getPreferredSize()
@@ -140,13 +133,8 @@
{
// Check if we're in initialization stage. If so, call super.setLayout
// otherwise, valid calls go to the content pane.
- if (initStageDone)
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Cannot set layout. Use getContentPane().setLayout()"
- + " instead.");
- getContentPane().setLayout(manager);
- }
+ if (isRootPaneCheckingEnabled())
+ getContentPane().setLayout(manager);
else
super.setLayout(manager);
}
@@ -207,15 +195,10 @@
{
// If we're adding in the initialization stage use super.add.
// otherwise pass the add onto the content pane.
- if (!initStageDone)
- super.addImpl(comp, constraints, index);
+ if (isRootPaneCheckingEnabled())
+ getContentPane().add(comp, constraints, index);
else
- {
- if (isRootPaneCheckingEnabled())
- throw new Error("Do not use add() on JWindow directly. Use "
- + "getContentPane().add() instead");
- getContentPane().add(comp, constraints, index);
- }
+ super.addImpl(comp, constraints, index);
}
public void remove(Component comp)
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches