QtAWT

What is QtAWT?

QtAWT provides a Qt based implementation of the peer classes used by the AWT components. This consists of a set of Java classes that implement the interfaces specified in java.awt.peer, and a few others such as java.awt.Toolkit. The classes are implemented in a mixture of Java code and native code, with the native methods being called via the JNI. Because it sticks to standard APIs such as the JNI QtAWT should be portable enough to work on any 1.1 JVM. Once the class and library paths have been set up correctly, the QtAWT can be used instead of the native peers provided with your JVM by setting the awt.toolkit property to point to the QtToolkit implementation. This can be achieved by adding -Dawt.toolkit=javax.org.kde.qtawt.QtToolkit to your java command line, or by editing system.properties.

Important: This is a work in progress, it is unfinished and missing almost every possible feature. Do not expect this to run your favourite applets yet.

How complete is QtAWT?

QtAWT is nowhere near complete - it only has about 6 peers started. See the
status.html file for details.

How does it work?

Each peer is a subclass of QtPeer. QtPeer is a base class that provides somewhere to store a reference to the Component for which the peer was instantiated, and also the native Qt object that is providing the implementation of the peer. Utility methods to access the native object from a jobject that refers to the QtPeer instance (or a subclass), and to get at the Toolkit instance are in util.cpp. The Toolkit instance is very important as this object is used as the point of synchronisation of QtAWT, the toolkit is locked by every native accessor to allow safe access to the underlying native objects. If you write any peer methods then don't forget to include the synchronisation code - you can pretty much cut and paste it from an existing method, just look for the bits that say 'Lock the AWT' or similar.

How can I help?

Well, basically just pick any class in the java.awt.peer package and start typing. If you don't know anything about Qt programming, but you know some Java then you could still help by writing the Java side of a peer (like the ones in the javax/org/kde/qtawt directory of the source tree). I'll try to knock together a HOWTO style document explaining how to write a peer when the mechanism has stabalised a bit. The commincation between the native code and the Java peers is handled using the JNI, so in theory this should port should work with any JVM that supports JNI and Java 1.1. If you are using a JVM other than the Blackdown JDK port, then please let me know how you get on. I have also tried the code with Japhar, but for some reason it refuses to load the toolkit correctly - I suspect this is really a bug in Japhar, but I'm not sure yet.

Notes

There are probably some more things that would be good for util.cpp.
  • A class that works like KConfigGroupSaver to provide access to jstrings.
  • Move more of the initialisation into Java code for simplicity.
  • Make constructor call init, and make init chain to superclass. Only the leaf-most peer should create a native object.
QtAWT by Richard Moore

[ Edit ]