Here is a new patch for this problem. We went ahead and implemented the
listener idea proposed in the last email. It appears to be the simplest
(and best) fix. It does not break anything else.

Roman suggested we use a HierarchyBoundsListener, but we need a
Component Listener for the componentShown/componentHidden functions. 
The listener is attached to the parent of the heavyweight components.
Therefore, the parent whose peer is an instanceof LightweightPeer. This
was a more intuitive/simple approach.

The listener is a fix for all heavyweights in lightweights. It positions
them properly, by calling peer.setBounds, peer.show, peer.hide.

There are some mauve tests showing this problem. It is now passing, the
MegaMek issue is fixed, the swing demo still works, and other test cases
are still ok :)

Committed.
Thanks,
Lillian

2006-02-24  Lillian Angel  <[EMAIL PROTECTED]>

        * java/awt/Component.java
        (reshape): Reverted last patch. Should have check here.
        (addNotify): Added check. If parent is lightweight, then
        initialize listener on the parent.
        (HeavyweightInLightweightListener): New class.



On Fri, 2006-02-24 at 13:00 -0500, Lillian Angel wrote:
> On Fri, 2006-02-24 at 12:45 -0500, Thomas Fitzsimmons wrote:
> > On Fri, 2006-02-24 at 10:20 -0500, Lillian Angel wrote:
> > > On Thu, 2006-02-23 at 20:51 -0500, Thomas Fitzsimmons wrote:
> > > 
> > > > Lillian's gnu.testlet.java.awt.Container.LightweightContainer should
> > > > demonstrate the problem but it doesn't at the moment (see my comments on
> > > > mauve-patches).
> > > > 
> > > 
> > > I updated the mauve test. It appears we still have not fixed our
> > > problem. 
> > 
> > Check MegaMek -- is the BoardView not fixed with the patch I posted?
> 
> It is, but the mauve test is not working with it.
> 
> Lillian
> 
> 
Index: java/awt/Component.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.102
diff -u -r1.102 Component.java
--- java/awt/Component.java	23 Feb 2006 19:22:24 -0000	1.102
+++ java/awt/Component.java	24 Feb 2006 18:39:29 -0000
@@ -1391,7 +1391,11 @@
     int oldwidth = this.width;
     int oldheight = this.height;
     
-   invalidate ();
+    if (this.x == x && this.y == y && this.width == width
+        && this.height == height)
+      return;
+
+    invalidate();
     
     this.x = x;
     this.y = y;
@@ -3434,6 +3438,8 @@
   {
     if (peer == null)
       peer = getToolkit().createComponent(this);
+    else if (parent != null && parent.isLightweight())
+      new HeavyweightInLightweightListener(parent);
     /* Now that all the children has gotten their peers, we should
        have the event mask needed for this component and its
        lightweight subcomponents. */
@@ -5129,6 +5135,73 @@
   // Nested classes.
   
   /**
+   * This class fixes the bounds for a Heavyweight component that
+   * is placed inside a Lightweight container. When the lightweight is
+   * moved or resized, setBounds for the lightweight peer does nothing.
+   * Therefore, it was never moved on the screen. This class is 
+   * attached to the lightweight, and it adjusts the position and size
+   * of the peer when notified.
+   * This is the same for show and hide.
+   */
+  class HeavyweightInLightweightListener
+      implements ComponentListener
+  {
+    
+    /**
+     * Constructor. Adds component listener to lightweight parent.
+     * 
+     * @param parent - the lightweight container.
+     */
+    public HeavyweightInLightweightListener(Container parent)
+    {
+      parent.addComponentListener(this);
+    }
+    
+    /**
+     * This method is called when the component is resized.
+     * 
+     * @param event the <code>ComponentEvent</code> indicating the resize
+     */
+    public void componentResized(ComponentEvent event)
+    {
+      // Nothing to do here, componentMoved will be called.
+    }
+
+    /**
+     * This method is called when the component is moved.
+     * 
+     * @param event the <code>ComponentEvent</code> indicating the move
+     */
+    public void componentMoved(ComponentEvent event)
+    {
+      if (peer != null)
+        peer.setBounds(x, y, width, height);
+    }
+
+    /**
+     * This method is called when the component is made visible.
+     * 
+     * @param event the <code>ComponentEvent</code> indicating the visibility
+     */
+    public void componentShown(ComponentEvent event)
+    {
+      if (isShowing())
+        peer.show();
+    }
+
+    /**
+     * This method is called when the component is hidden.
+     * 
+     * @param event the <code>ComponentEvent</code> indicating the visibility
+     */
+    public void componentHidden(ComponentEvent event)
+    {
+      if (!isShowing())
+        peer.hide();
+    }
+  }
+  
+  /**
    * This class provides accessibility support for subclasses of container.
    *
    * @author Eric Blake ([EMAIL PROTECTED])
Index: java/awt/TextField.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/TextField.java,v
retrieving revision 1.16
diff -u -r1.16 TextField.java
--- java/awt/TextField.java	20 Sep 2005 01:05:28 -0000	1.16
+++ java/awt/TextField.java	24 Feb 2006 18:39:29 -0000
@@ -397,6 +397,7 @@
     return;
 
   setPeer((ComponentPeer)getToolkit().createTextField(this));
+  super.addNotify();
 }
 
 /*************************************************************************/

Reply via email to