classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: fixes for JLayeredPane and JInternalFrame


From: Roman Kennke
Subject: [cp-patches] FYI: fixes for JLayeredPane and JInternalFrame
Date: Wed, 25 May 2005 11:00:29 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

Hi,

Micheal discovered that my implementation for the _static_ method getLayer() in javax.swing.JLayeredPane is not calling the instance method getLayer() but instead the static method. This is of course wrong and here comes the fix to that problem.
Also included is a new method for JLayeredPane.

2005-05-25  Roman Kennke  <address@hidden>

       * javax/swing/JLayeredPane.java
       (static getLayer): Add cast to force a call to the instance method
       getLayer().
       (getLayeredPaneAbove): Added and implemented method.
       * javax/swing/JInternalFrame.java
       (getLayer): Add cast to force a call to the instance method
       getLayer() of JLayeredPane.

/Roman
Index: javax/swing/JLayeredPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JLayeredPane.java,v
retrieving revision 1.19
diff -u -r1.19 JLayeredPane.java
--- javax/swing/JLayeredPane.java       23 May 2005 13:37:43 -0000      1.19
+++ javax/swing/JLayeredPane.java       25 May 2005 08:57:39 -0000
@@ -146,7 +146,29 @@
     if (lp == null)
       return 0;
     else
-      return lp.getLayer(comp);
+      // The cast here forces the call to the instance method getLayer()
+      // instead of the static method (this would lead to infinite
+      // recursion).
+      return lp.getLayer((Component) comp);
+  }
+
+  /**
+   * Returns the first JLayeredPane that contains the Component
+   * <code>comp</code> or <code>null</code> if <code>comp</code> is
+   * not contained in a JLayeredPane.
+   *
+   * @param comp the component for which we are searching the JLayeredPane
+   *     ancestor
+   *
+   * @return the first JLayeredPane that contains the Component
+   *     <code>comp</code> or <code>null</code> if <code>comp</code> is
+   *     not contained in a JLayeredPane
+   */
+  public static JLayeredPane getLayeredPaneAbove(Component comp)
+  {
+    JLayeredPane lp = (JLayeredPane) SwingUtilities.getAncestorOfClass
+      (JLayeredPane.class, comp);
+    return lp;
   }
 
   /**
Index: javax/swing/JInternalFrame.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JInternalFrame.java,v
retrieving revision 1.14
diff -u -r1.14 JInternalFrame.java
--- javax/swing/JInternalFrame.java     25 Jan 2005 07:07:25 -0000      1.14
+++ javax/swing/JInternalFrame.java     25 May 2005 08:57:39 -0000
@@ -862,7 +862,10 @@
   {
     JDesktopPane pane = getDesktopPane();
     if (pane != null)
-      return pane.getLayer(this);
+      // The cast here forces the call to the instance method getLayer()
+      // instead of the static method (this would lead to infinite
+      // recursion).
+      return pane.getLayer((Component) this);
     return -1;
   }
 

reply via email to

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