classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] Patch: adding to top-level containers


From: Roman Kennke
Subject: Re: [cp-patches] Patch: adding to top-level containers
Date: Fri, 17 Jun 2005 13:55:28 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Hi,

this is cool, thank you. Generally I would prefer to go for 1.4 compatibility and completeness first, and add 1.5 stuff later, but in this case it really does not hurt.

Again, some suggestions:

- comments should have the following form:
/**
* Sentence start with capital letter and end with dot.
*/

- specification notices should be written as @specnote annotation:

/**
* @specnote Implemented this way to comply with JDKX.Y
*/

- variable and field names should be written like variableName instead of variable_name
- insert spaces around = and other operators.
- avoid TABs like the pest :-)

More on our coding style guidelines is available here:
http://www.gnu.org/software/classpath/docs/hacking.html#SEC7

I committed the slightly modified patch, which is attached.

2005-06-13  Anthony Balkissoon  <address@hidden>

        * javax/swing/JApplet.java,
        javax/swing/JDialog.java,
        javax/swing/JFrame.java,
        javax/swing/JInternalFrame.java,
        javax/swing/JWindow.java: Added support for adding and setting
        layout managers directly for these top-level containers tocomply
        with J2SE 5.0.  Added private boolean init_stage_done.
Initialized rootPaneCheckingEnabled to false.
        (JDialog.dialogInit): Set init_stage_done to true.
        (JApplet.JApplet): Set init_stage_done to true.
        (JFrame.frameInit) : Set init_stage_done to true.
        (JInternalFrame.JInternalFrame): Set init_state_done to true.
        (JWindow.windowInit): Set init_stage_done to true.
        (addImpl): Added check for direct adds (J2SE 5.0) and directed
        them to getContentPane().add.
        (setLayout): Added check for direct calls to setLayout.
        (remove): Added check for direct calls to remove.

/Roman

Index: javax/swing/JApplet.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JApplet.java,v
retrieving revision 1.15
diff -u -r1.15 JApplet.java
--- javax/swing/JApplet.java    25 Jan 2005 07:07:25 -0000      1.15
+++ javax/swing/JApplet.java    17 Jun 2005 11:48:45 -0000
@@ -55,12 +55,24 @@
   private static final long serialVersionUID = 7269359214497372587L;
   
   protected JRootPane rootPane;
-  protected boolean rootPaneCheckingEnabled;
+
+  /**
+   * @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;
 
   public JApplet()
   {
     super.setLayout(new BorderLayout(1, 1));
-    getRootPane(); // will do set/create
+    getRootPane(); // Will do set/create.
+    initStageDone = true; // Init stage is now over.
   }
 
   public Dimension getPreferredSize()
@@ -70,7 +82,17 @@
 
   public void setLayout(LayoutManager manager)
   {
-    super.setLayout(manager);
+    // 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);
+      }
+    else
+      super.setLayout(manager);
   }
 
   public void setLayeredPane(JLayeredPane layeredPane)
@@ -126,7 +148,17 @@
 
   protected void addImpl(Component comp, Object constraints, int index)
   {
-    super.addImpl(comp, constraints, index);
+    // If we're adding the rootPane (initialization stages) use super.add.
+    // Otherwise pass the add onto the content pane.
+    if (comp == rootPane)
+      super.addImpl(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);
+      }
   }
 
   public AccessibleContext getAccessibleContext()
@@ -156,7 +188,12 @@
   
   public void remove(Component comp)
   {
-    getContentPane().remove(comp);
+    // If we're removing the root pane, use super.remove. Otherwise
+    // pass it on to the content pane instead
+    if (comp == rootPane)
+      super.remove(rootPane);
+    else
+      getContentPane().remove(comp);
   }
 
   protected boolean isRootPaneCheckingEnabled()
Index: javax/swing/JDialog.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JDialog.java,v
retrieving revision 1.12
diff -u -r1.12 JDialog.java
--- javax/swing/JDialog.java    13 May 2005 14:06:11 -0000      1.12
+++ javax/swing/JDialog.java    17 Jun 2005 11:48:45 -0000
@@ -69,8 +69,12 @@
   /** The single RootPane in the Dialog. */
   protected JRootPane rootPane;
 
-  /** Whether checking is enabled on the RootPane */
-  protected boolean rootPaneCheckingEnabled = true;
+  /**
+   * Whether checking is enabled on the RootPane.
+   *
+   * @specnote Should be false to comply with J2SE 5.0
+   */ 
+  protected boolean rootPaneCheckingEnabled = false;
 
   /** The default action taken when closed. */
   private int close_action = HIDE_ON_CLOSE;
@@ -79,7 +83,13 @@
   private static boolean decorated;
 
   /**
-   * Creates a new non-modal JDialog with no title 
+   * 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.
    */
   public JDialog()
@@ -224,12 +234,12 @@
   protected void dialogInit()
   {
     // FIXME: Do a check on GraphicsEnvironment.isHeadless()
-    setRootPaneCheckingEnabled(false);
-    setLocale(JComponent.getDefaultLocale());       
-    getRootPane(); // will do set/create  
-    setRootPaneCheckingEnabled(true);    
+    setLocale(JComponent.getDefaultLocale());
+    getRootPane(); // Will do set/create.
     invalidate();
-
+    // Now that initStageDone is true, adds and layouts apply to contentPane,
+    // not top-level.
+    initStageDone = true;
   }
 
   /**
@@ -298,9 +308,17 @@
    */
   public void setLayout(LayoutManager manager)
   {
-    if (isRootPaneCheckingEnabled())
-      throw new Error("rootPaneChecking is enabled - cannot set layout.");
-    super.setLayout(manager);
+    // 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);
+      }
+    else
+      super.setLayout(manager);
   }
 
   /**
@@ -420,9 +438,17 @@
    */
   protected void addImpl(Component comp, Object constraints, int index)
   {
-    if (isRootPaneCheckingEnabled())
-      throw new Error("rootPaneChecking is enabled - adding components 
disallowed.");
-    super.addImpl(comp, constraints, index);
+    // If we're adding the rootPane (initialization stages) use super.add.
+    // Otherwise pass the add onto the content pane.
+    if (comp == rootPane)
+      super.addImpl(comp, constraints, index);
+    else
+      {
+        if (isRootPaneCheckingEnabled())
+          throw new Error("Do not add directly to JDialog."
+                          + " Use getContentPane().add instead.");
+        getContentPane().add(comp, constraints, index);
+      }
   }
 
   /**
@@ -432,7 +458,8 @@
    */
   public void remove(Component comp)
   {
-    // The path changes if the component == root.
+    // If we're removing the root pane, use super.remove. Otherwise
+    // pass it on to the content pane instead.
     if (comp == rootPane)
       super.remove(rootPane);
     else 
Index: javax/swing/JFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JFrame.java,v
retrieving revision 1.22
diff -u -r1.22 JFrame.java
--- javax/swing/JFrame.java     6 Jun 2005 12:53:44 -0000       1.22
+++ javax/swing/JFrame.java     17 Jun 2005 11:48:45 -0000
@@ -66,7 +66,18 @@
   private int close_action = HIDE_ON_CLOSE;
   protected AccessibleContext accessibleContext;
   protected JRootPane rootPane;
-  protected boolean rootPaneCheckingEnabled;
+  
+  /**
+   * @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;
 
   public JFrame()
   {
@@ -116,6 +127,8 @@
     super.setLayout(new BorderLayout(1, 1));
     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
     getRootPane(); // will do set/create
+    // We're now done the init stage.
+    initStageDone = true;
   }
 
   public Dimension getPreferredSize()
@@ -135,7 +148,17 @@
 
   public void setLayout(LayoutManager manager)
   {
-    super.setLayout(manager);
+    // 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);
+      }
+    else
+      super.setLayout(manager);
   }
 
   public void setLayeredPane(JLayeredPane layeredPane)
@@ -191,12 +214,27 @@
 
   protected void addImpl(Component comp, Object constraints, int index)
   {
-    super.addImpl(comp, constraints, index);
+    // If we're adding the rootPane (initialization stages) use super.add.
+    // Otherwise pass the add onto the content pane.
+    if (comp==rootPane)
+      super.addImpl(comp, constraints, index);
+    else
+      {
+        if (isRootPaneCheckingEnabled())
+          throw new Error("rootPaneChecking is enabled - adding components "
+                           + "disallowed.");
+        getContentPane().add(comp,constraints,index);
+      }
   }
 
   public void remove(Component comp)
   {
-    getContentPane().remove(comp);
+    // If we're removing the root pane, use super.remove. Otherwise
+    // pass it on to the content pane instead.
+    if (comp==rootPane)
+      super.remove(rootPane);
+    else
+      getContentPane().remove(comp);
   }
 
   protected boolean isRootPaneCheckingEnabled()
Index: javax/swing/JInternalFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JInternalFrame.java,v
retrieving revision 1.16
diff -u -r1.16 JInternalFrame.java
--- javax/swing/JInternalFrame.java     27 May 2005 21:12:46 -0000      1.16
+++ javax/swing/JInternalFrame.java     17 Jun 2005 11:48:46 -0000
@@ -430,8 +430,19 @@
   /** Whether the JInternalFrame can be maximized. */
   protected boolean maximizable;
 
-  /** Whether the JInternalFrame has rootPaneChecking enabled. */
-  protected boolean rootPaneCheckingEnabled = true;
+  /**
+   * Whether the JInternalFrame has rootPaneChecking enabled.
+   *
+   * @specnote Should be 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;
 
   /** Whether the JInternalFrame is resizable. */
   protected boolean resizable;
@@ -554,12 +565,9 @@
     this.maximizable = maximizable;
     this.iconable = iconifiable;
     storedBounds = new Rectangle();
-
-    setRootPaneCheckingEnabled(false);
     setRootPane(createRootPane());
-
     updateUI();
-    setRootPaneCheckingEnabled(true);
+    initStageDone = true; // Done the init stage, now adds go to content pane.
   }
 
   /**
@@ -576,10 +584,17 @@
    */
   protected void addImpl(Component comp, Object constraints, int index)
   {
-    if (isRootPaneCheckingEnabled())
-      throw new Error("Do not use add() on JInternalPane directly. Use 
getContentPane().add() instead");
-
-    super.addImpl(comp, constraints, index);
+    // If we're adding the rootPane (initialization stages) use super.add.
+    // otherwise pass the add onto the content pane.
+    if (comp==rootPane)
+      super.addImpl(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);
+      }
   }
 
   /**
@@ -1181,7 +1196,12 @@
    */
   public void remove(Component comp)
   {
-    super.remove(comp);
+    // If we're removing the root pane, use super.remove.  Otherwise
+    // pass it on to the content pane instead.
+    if (comp==rootPane)
+      super.remove(comp);
+    else
+      getContentPane().remove(comp);
   }
 
   /**
@@ -1466,9 +1486,17 @@
    */
   public void setLayout(LayoutManager manager)
   {
-    if (isRootPaneCheckingEnabled())
-      throw new Error("Cannot set layout. Use getContentPane().setLayout() 
instead.");
-    super.setLayout(manager);
+    // 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);
+      }
+    else
+      super.setLayout(manager);
   }
 
   /**
Index: javax/swing/JWindow.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JWindow.java,v
retrieving revision 1.17
diff -u -r1.17 JWindow.java
--- javax/swing/JWindow.java    25 Jan 2005 07:07:25 -0000      1.17
+++ javax/swing/JWindow.java    17 Jun 2005 11:48:46 -0000
@@ -63,9 +63,21 @@
   private static final long serialVersionUID = 5420698392125238833L;
   
   protected JRootPane rootPane;
-  protected boolean rootPaneCheckingEnabled;
+
+  /**
+   * @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
+   */
+  protected boolean rootPaneCheckingEnabled = false;
+
   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());
@@ -100,6 +112,8 @@
   {
     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;
   }
 
   public Dimension getPreferredSize()
@@ -109,7 +123,17 @@
 
   public void setLayout(LayoutManager manager)
   {
-    super.setLayout(manager);
+    // 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);
+      }
+    else
+      super.setLayout(manager);
   }
 
   public void setLayeredPane(JLayeredPane layeredPane)
@@ -163,14 +187,30 @@
     getRootPane().setGlassPane(glassPane);
   }
 
+
   protected void addImpl(Component comp, Object constraints, int index)
   {
-    super.addImpl(comp, constraints, index);
+    // If we're adding the rootPane (initialization stages) use super.add.
+    // otherwise pass the add onto the content pane.
+    if (comp == rootPane)
+      super.addImpl(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);
+      }
   }
 
   public void remove(Component comp)
   {
-    getContentPane().remove(comp);
+    // If we're removing the root pane, use super.remove.  Otherwise
+    // pass it on to the content pane instead.
+    if (comp == rootPane)
+      super.remove(rootPane);
+    else
+      getContentPane().remove(comp);
   }
 
   protected boolean isRootPaneCheckingEnabled()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]