I've been playing with the X peers, to see if they'll become a good choice
for embedded systems with GCJ.  Maybe they'll be easier to keep maintained
than the xlib peers, because they're part of the gnu classpath tree and
because they're pure java.  This patch fixes a few things I found, described
below.  Please consider checking it in.  Thanks.

2007-04-19  Scott Gilbertson  [EMAIL PROTECTED]

        * gnu/java/awt/peer/swing/SwingComponentPeer.java
        (handleEvent) Coalesce paint events.
        * gnu/java/awt/peer/swing/SwingComponentPeer.java
        (handleEvent) Coalesce paint events.
        * gnu/java/awt/peer/x/XGraphics.java
        (setColor) Use black as default color.
        (drawPolygon) Use passed npoints parameter.
        (fillPolygon) Use passed npoints parameter.
        * gnu/java/awt/peer/x/XLightweightPeer.java
        (XLightweightPeer) Pass null to super constructor.

SwingComponentPeer.handleEvent was sometimes failing with a null paintArea.
I noticed in the GTK peers a coalescePaintEvents, commented "Make sure that
the paintArea includes the area from the event in the case when an
application sends PaintEvents directly" and did likewise.

Programs that don't explicitly set a Component's foreground color were using
white, whereas on the JRE they use black, and the GTK peers appear to also
use black.  I changed the default color to black.

XGraphics.drawPolygon and XGraphics.fillPolygon were not using their npoints
parameter.  Instead, they used the sizes of the points arrays, which are
never less than 4.  Consequently, when I tried to draw a triangle with a
3-point Polygon, I got a 4-sided figure with an extra corner at 0,0.  With
the change, I get triangles.


XLightweightPeer wouldn't build, because it passed a Component to the
SwingContainerPeer constructor, which expects a Container.

Some other things I noticed when testing the X peers were:
 - some thrown exceptions, both in the x peers and occasionally in escher
    I'll probably have a look at those.  If not, I'll post details.
 - XImage.getGraphics and XWindowPeer.getGraphics don't return a Graphics2D,
    although I see the classes there for that
    (I think my embedded applications can work around that one if necessary)
 - very strange behavior when re-sizing with the mouse -- whatever crazy
path you
    drag the corner through gets repeated forever when you let go of the
button.
    (Won't affect full-screen embedded apps, which never re-size)

I have not yet tried running an AWT Frame on a target with no window
manager, which results in a borderless frame when the xlib peers are used.
I'm hoping the X peers do the same.
Index: gnu/java/awt/peer/swing/SwingComponentPeer.java
===================================================================
RCS file: 
/sources/classpath/classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java,v
retrieving revision 1.7
diff -u -r1.7 SwingComponentPeer.java
--- gnu/java/awt/peer/swing/SwingComponentPeer.java     29 Nov 2006 12:56:39 
-0000      1.7
+++ gnu/java/awt/peer/swing/SwingComponentPeer.java     19 Apr 2007 20:25:13 
-0000
@@ -404,6 +404,9 @@
         // because Container.paint() will grab it anyway.
         synchronized (this)
           {
+            // Make sure that the paintArea includes the area from the event
+            // in the case when an application sends PaintEvents directly.
+            coalescePaintEvent((PaintEvent)e);
             assert paintArea != null;
             if (awtComponent.isShowing())
               {
Index: gnu/java/awt/peer/x/XGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/XGraphics.java,v
retrieving revision 1.7
diff -u -r1.7 XGraphics.java
--- gnu/java/awt/peer/x/XGraphics.java  20 Jul 2006 13:08:07 -0000      1.7
+++ gnu/java/awt/peer/x/XGraphics.java  19 Apr 2007 20:25:13 -0000
@@ -171,22 +171,21 @@
    */
   public void setColor(Color c)
   {
-    if (c != null)
-      {
-        XToolkit tk = (XToolkit) Toolkit.getDefaultToolkit();
-        HashMap colorMap = tk.colorMap;
-        gnu.x11.Color col = (gnu.x11.Color) colorMap.get(c);
-        if (col == null)
-          {
-            Colormap map = xdrawable.display.default_colormap;
-            col = map.alloc_color (c.getRed() * 256,
-                                   c.getGreen() * 256,
-                                   c.getBlue() * 256);
-            colorMap.put(c, col);
-          }
-        xgc.set_foreground(col);
-        foreground = c;
+    if (c == null)
+      c = Color.BLACK;
+    XToolkit tk = (XToolkit) Toolkit.getDefaultToolkit();
+    HashMap colorMap = tk.colorMap;
+    gnu.x11.Color col = (gnu.x11.Color) colorMap.get(c);
+    if (col == null)
+      {
+        Colormap map = xdrawable.display.default_colormap;
+        col = map.alloc_color (c.getRed() * 256,
+                               c.getGreen() * 256,
+                               c.getBlue() * 256);
+        colorMap.put(c, col);
       }
+    xgc.set_foreground(col);
+    foreground = c;
   }
 
   public void setPaintMode()
@@ -496,22 +495,20 @@
 
   public void drawPolygon(int[] xPoints, int[] yPoints, int npoints)
   {
-    int numPoints = Math.min(xPoints.length, yPoints.length);
-    Point[] points = new Point[numPoints];
+    Point[] points = new Point[npoints];
     // FIXME: Improve Escher API to accept arrays to avoid creation
     // of many Point objects.
-    for (int i = 0; i < numPoints; i++)
+    for (int i = 0; i < npoints; i++)
       points[i] = new Point(xPoints[i], yPoints[i]);
     xdrawable.poly_line(xgc, points, Drawable.ORIGIN);
   }
 
   public void fillPolygon(int[] xPoints, int[] yPoints, int npoints)
   {
-    int numPoints = Math.min(xPoints.length, yPoints.length);
-    Point[] points = new Point[numPoints];
+    Point[] points = new Point[npoints];
     // FIXME: Improve Escher API to accept arrays to avoid creation
     // of many Point objects.
-    for (int i = 0; i < numPoints; i++)
+    for (int i = 0; i < npoints; i++)
       points[i] = new Point(xPoints[i], yPoints[i]);
     xdrawable.fill_poly(xgc, points, Drawable.COMPLEX, Drawable.ORIGIN);
   }
Index: gnu/java/awt/peer/x/XLightweightPeer.java
===================================================================
RCS file: 
/sources/classpath/classpath/gnu/java/awt/peer/x/XLightweightPeer.java,v
retrieving revision 1.1
diff -u -r1.1 XLightweightPeer.java
--- gnu/java/awt/peer/x/XLightweightPeer.java   29 Jun 2006 15:15:56 -0000      
1.1
+++ gnu/java/awt/peer/x/XLightweightPeer.java   19 Apr 2007 20:25:13 -0000
@@ -50,7 +50,7 @@
 
   XLightweightPeer(Component c)
   {
-    super(c);
+    super(null);
     init(c, null);
   }
 }

Reply via email to