While working on the X11 based AWT peers, I noticed some glitches in the
Swing peers:

2006-04-18  Roman Kennke  <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/swing/SwingComponentPeer.java
        (setBounds): Call reshape().
        * gnu/java/awt/peer/swing/SwingContainerPeer.java
        (SwingContainerPeer): Changed argument to be a Component
        instead a Container.
        (getInsets): Call insets().
        (handleMouseEvent): Added null check to avoid NPE.
        (handleMouseMotionEvent): Added null check to avoid NPE.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: gnu/java/awt/peer/swing/SwingComponentPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java,v
retrieving revision 1.2
diff -u -1 -0 -r1.2 SwingComponentPeer.java
--- gnu/java/awt/peer/swing/SwingComponentPeer.java	27 Jan 2006 09:41:16 -0000	1.2
+++ gnu/java/awt/peer/swing/SwingComponentPeer.java	18 Apr 2006 12:23:19 -0000
@@ -583,22 +583,21 @@
    *
    * This is implemented to call setBounds() on the Swing component.
    *
    * @param x the X coordinate of the upper left corner of the component
    * @param y the Y coordinate of the upper left corner of the component
    * @param width the width of the component
    * @param height the height of the component
    */
   public void setBounds(int x, int y, int width, int height)
   {
-    if (swingComponent != null)
-      swingComponent.getJComponent().setBounds(x, y, width, height);
+    reshape(x, y, width, height);
   }
 
   /**
    * Sets the cursor of the component. This is called by
    * [EMAIL PROTECTED] Component#setCursor(Cursor)}.
    *
    * This is implemented to call setCursor() on the Swing component.
    *
    * @specnote Part of the earlier 1.1 API, apparently no longer needed.
    */
Index: gnu/java/awt/peer/swing/SwingContainerPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java,v
retrieving revision 1.1
diff -u -1 -0 -r1.1 SwingContainerPeer.java
--- gnu/java/awt/peer/swing/SwingContainerPeer.java	14 Jan 2006 00:26:26 -0000	1.1
+++ gnu/java/awt/peer/swing/SwingContainerPeer.java	18 Apr 2006 12:23:19 -0000
@@ -54,21 +54,21 @@
 public class SwingContainerPeer
   extends SwingComponentPeer
   implements ContainerPeer
 {
 
   /**
    * Creates a new SwingContainerPeer.
    *
    * @param awtCont
    */
-  public SwingContainerPeer(Container awtCont)
+  public SwingContainerPeer(Component awtCont)
   {
     init(awtCont, null);
   }
 
   /**
    * Returns the insets of the container.
    *
    * This is implemented to return the insets of the Swing container.
    *
    * @return the insets of the container
@@ -85,26 +85,21 @@
 
   /**
    * Returns the insets of the container.
    *
    * This is implemented to return the insets of the Swing container.
    *
    * @return the insets of the container
    */
   public Insets getInsets()
   {
-    Insets retVal;
-    if (swingComponent != null)
-      retVal = swingComponent.getJComponent().getInsets();
-    else
-      retVal = new Insets(0, 0, 0, 0);
-    return retVal;
+    return insets();
   }
 
   /**
    * Called before the validation of this containers begins.
    */
   public void beginValidate()
   {
     // Nothing to do here.
   }
 
@@ -207,35 +202,41 @@
   }
 
   /**
    * Handles mouse events by dispatching it to the correct component.
    *
    * @param ev the mouse event
    */
   protected void handleMouseEvent(MouseEvent ev)
   {
     Component comp = awtComponent.getComponentAt(ev.getPoint());
-    ComponentPeer peer = comp.getPeer();
-    if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+    if (comp != null)
       {
-        ev.translatePoint(comp.getX(), comp.getY());
-        ev.setSource(comp);
-        ((SwingComponentPeer) peer).handleMouseEvent(ev);
+        ComponentPeer peer = comp.getPeer();
+        if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+          {
+            ev.translatePoint(comp.getX(), comp.getY());
+            ev.setSource(comp);
+            ((SwingComponentPeer) peer).handleMouseEvent(ev);
+          }
       }
   }
 
   /**
    * Handles mouse events by dispatching it to the correct component.
    *
    * @param ev the mouse event
    */
   protected void handleMouseMotionEvent(MouseEvent ev)
   {
     Component comp = awtComponent.getComponentAt(ev.getPoint());
-    ComponentPeer peer = comp.getPeer();
-    if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+    if (comp != null)
       {
-        ev.translatePoint(comp.getX(), comp.getY());
-        ((SwingComponentPeer) peer).handleMouseMotionEvent(ev);
+        ComponentPeer peer = comp.getPeer();
+        if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
+          {
+            ev.translatePoint(comp.getX(), comp.getY());
+            ((SwingComponentPeer) peer).handleMouseMotionEvent(ev);
+          }
       }
   }
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to