Hi,

I fixed some things in JComponent. Most importantly I added some support
for AncestorEvents.

2005-10-07  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/JComponent.java
        (paint): Call paintBorder before paintChildren.
        (reshape): Fire AncestorEvent if position has changed.
        (fireAncestorMoved): New method. Fires AncestorEvents to this
        component and all of it's children.


/Roman
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.64
diff -u -r1.64 JComponent.java
--- javax/swing/JComponent.java	27 Sep 2005 14:03:25 -0000	1.64
+++ javax/swing/JComponent.java	7 Oct 2005 11:20:49 -0000
@@ -1473,8 +1473,8 @@
         if (g.getClip() == null)
           g.setClip(0, 0, getWidth(), getHeight());
         paintComponent(g);
-        paintChildren(g);
         paintBorder(g);
+        paintChildren(g);
       }
   }
 
@@ -2869,6 +2869,53 @@
    */
   public void reshape(int x, int y, int w, int h)
   {
+    int oldX = getX();
+    int oldY = getY();
     super.reshape(x, y, w, h);
+    // Notify AncestorListeners.
+    if (oldX != getX() || oldY != getY())
+      fireAncestorEvent(this, AncestorEvent.ANCESTOR_MOVED);
+  }
+
+  /**
+   * Fires an AncestorEvent to this component's and all of its child
+   * component's AncestorListeners.
+   *
+   * @param ancestor the component that triggered the event
+   * @param id the kind of ancestor event that should be fired
+   */
+  void fireAncestorEvent(JComponent ancestor, int id)
+  {
+    // Fire event for registered ancestor listeners of this component.
+    AncestorListener[] listeners = getAncestorListeners();
+    if (listeners.length > 0)
+      {
+        AncestorEvent ev = new AncestorEvent(this, id,
+                                             ancestor, ancestor.getParent());
+        for (int i = 0; i < listeners.length; i++)
+          {
+            switch (id)
+              {
+              case AncestorEvent.ANCESTOR_MOVED:
+                listeners[i].ancestorMoved(ev);
+                break;
+              case AncestorEvent.ANCESTOR_ADDED:
+                listeners[i].ancestorAdded(ev);
+                break;
+              case AncestorEvent.ANCESTOR_REMOVED:
+                listeners[i].ancestorRemoved(ev);
+                break;
+              }
+          }
+      }
+    // Dispatch event to all children.
+    Component[] children = getComponents();
+    for (int i = 0; i < children.length; i++)
+      {
+        if (!(children[i] instanceof JComponent))
+          continue;
+        JComponent jc = (JComponent) children[i];
+        jc.fireAncestorEvent(ancestor, id);
+      }
   }
 }
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to