Possible awt patches
Boehm, Hans
hans_boehm@hp.com
Sun Feb 9 06:03:00 GMT 2003
I've been trying to get the GUI version of my constructive reals calculator to work with gcj. I made a brief attempt at using the xlib peers and then switched to the gtk peers. I'm still not there, but I found the following changes useful. I have little confidence that these are really correct. If someone can verify that I'm not just covering up other problems, I'll be happy to add ChangeLog entries and check them in:
1) setVisible calls didn't seem to invoke the right overridden show calls. The comments seemed to imply that the current code was incorrect. Possible patch:
Index: libjava/java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.22
diff -u -r1.22 Component.java
--- libjava/java/awt/Component.java 28 Jan 2003 23:49:46 -0000 1.22
+++ libjava/java/awt/Component.java 9 Feb 2003 05:16:37 -0000
@@ -844,9 +844,10 @@
// Inspection by subclassing shows that Sun's implementation calls
// show(boolean) which then calls show() or hide(). It is the show()
// method that is overriden in subclasses like Window.
- if (peer != null)
- peer.setVisible(b);
- this.visible = b;
+ if (b)
+ show();
+ else
+ hide();
}
/**
@@ -856,7 +857,9 @@
*/
public void show()
{
- setVisible(true);
+ if (peer != null)
+ peer.setVisible(true);
+ this.visible = true;
}
/**
@@ -877,7 +880,9 @@
*/
public void hide()
{
- setVisible(false);
+ if (peer != null)
+ peer.setVisible(false);
+ this.visible = false;
}
/**
2) Gtk peers for parent-less widgets seem to end up with explicit NULL "parent" attribute, which nothing is prepared for. Possible patch:
Index: libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.1
diff -u -r1.1 GtkComponentPeer.java
--- libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java 31 Jan 2003 17:54:13 -0000 1.1
+++ libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java 9 Feb 2003 05:16:36 -0000
@@ -352,7 +352,8 @@
p = component.getPeer ();
} while (p instanceof java.awt.peer.LightweightPeer);
- args.add ("parent", p);
+ if (p != null)
+ args.add ("parent", p);
}
native void set (String name, String value);
3) The xlib peers can access defaultConfig before it's set. Patch:
Index: libjava/gnu/awt/xlib/XToolkit.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/awt/xlib/XToolkit.java,v
retrieving revision 1.4
diff -u -r1.4 XToolkit.java
--- libjava/gnu/awt/xlib/XToolkit.java 15 Jan 2003 23:18:58 -0000 1.4
+++ libjava/gnu/awt/xlib/XToolkit.java 9 Feb 2003 05:16:36 -0000
@@ -183,7 +183,7 @@
public FontMetrics getFontMetrics(Font font)
{
- return defaultConfig.getXFontMetrics(font);
+ return getDefaultXGraphicsConfiguration().getXFontMetrics(font);
}
public void sync()
4) Both TextField.getPreferredSize and TextArea.getPreferredSize are apparently easily called before peers exist, and they basically give up in that case. I added code to guess instead, which gets me further, but is clearly wrong. Suggestions for a real fix would be appreciated.
Hans
More information about the Java
mailing list