NEWS
java-gnome 4.0.7 (30 Apr 2008)
Draw some.
In addition to improvements to our coverage of the GNOME libraries, this release introduces preliminary coverage of the Cairo Graphics drawing library, along with the infrastructure to make it work within a GTK program.
Drawing with Cairo

The trusty Cairo context, traditionally declared as a variable named cr in
code, is mapped as class
Context. Various Cairo types
such as different surfaces and patterns are mapped as an abstract base class
(Surface, Pattern) along with various concrete subclasses (ImageSurface,
XlibSurface, and SolidPattern, RadialPattern, etc). Error checking is
implicit: the library status is checked internally after each operation and an
Exception thrown if there is a failure.
org.freedesktop.cairo.Plumbingorg.freedesktop.cairo.Contextorg.freedesktop.cairo.ImageSurfaceorg.freedesktop.cairo.XlibSurfaceorg.freedesktop.cairo.SVGSurfaceorg.freedesktop.cairo.SolidPatternorg.freedesktop.cairo.LinearPatternorg.freedesktop.cairo.RadialPatternorg.freedesktop.cairo.SurfacePatternorg.freedesktop.cairo.Operatororg.freedesktop.cairo.Formatorg.freedesktop.cairo.Statusorg.freedesktop.bindings.FatalErrororg.freedesktop.cairo.FatalError
The gateway to custom Widgets is the
EXPOSE_EVENT signal; this
is where you can transition from the GDK Window to a Cairo Context and
then begin drawing.
org.gnome.gtk.Widget.EXPOSE_EVENTorg.gnome.gdk.EventExposeorg.gnome.gdk.Rectangleorg.gnome.gdk.EventCrossingorg.gnome.gdk.CrossingModeorg.gnome.gdk.NotifyTypeorg.gnome.gtk.Image
Thanks in particular to Carl Worth for having reviewed our API and having helped test our implementation.
New coverage and continuing improvement
The single option choice buttons in GTK are called RadioButtons and have now
been exposed. When using them you need to indicate the other buttons they are
sharing a mutually exclusive relationship with, and this is expressed by
adding them to a RadioButtonGroup.

org.gnome.gtk.RadioButtonorg.gnome.gtk.RadioButtonGroup
The usual steady refinements to our coverage of the GtkTreeView API continue.
There’s a new DataColumn type for Stock icons, and TreeModelSort is now
implemented.
org.gnome.gtk.TreeModelSortorg.gnome.gtk.DataColumnPixbuforg.gnome.gtk.DataColumnStockorg.gnome.gtk.CellRendererPixbuforg.gnome.gtk.TreeVieworg.gnome.gtk.TreeModelorg.gnome.gtk.ListStoreorg.gnome.gtk.TreeStore
and minor changes to various other miscellaneous classes:
org.freedesktop.bindings.Environmentorg.gnome.gtk.Expanderorg.gnome.gtk.Frameorg.gnome.gtk.Panedorg.gnome.gtk.HPanedorg.gnome.gtk.VPanedorg.gnome.gtk.Widgetorg.gnome.gtk.ProgressBarorg.gnome.gtk.Action
Considerable internal optimizations have been done, especially relating to
ensuring proper memory management, with notable refinements to make use of
“caller owns return” information available in the .defs data. This fixes a
number of bugs. Thanks to Vreixo Formoso for having driven these improvements.
Error handling has been improved for GLib based libraries as well. If an
ERROR or CRITICAL is emitted, our internals will trap this and throw an
exception instead, allowing the developer to see a Java stack trace leading
them to the point in their code where they caused the problem.
org.gnome.glib.FatalError
Internationalization support
java-gnome now has full support for the GNOME translation and localization
infrastructure, including the standard _("Hello") idiom for marking strings
for extraction and translation. There’s a fairly detailed explanation in the
Internationalization
utility class.
org.freedesktop.bindings.Internationalization
Build changes
Note that as was advertised as forthcoming some time ago, Java 1.5 is now the minimum language level required of your tool chain and Java virtual machine in order to build and use the java-gnome library.
Thanks to Colin Walters, Manu Mahajan, Thomas Girard, Rob Taylor, and Serkan Kaba for contributing improvements allowing the library to build in more environments and for their work on packages for their distributions.
The download page has updated instructions for getting either binary packages or checking out the source code.
Documentation, examples, and testing
Refinements to the API documentation continue across the board, notably improving consistency. A large number of javadoc warnings have also been cleaned up.
While not a full blown tutorial, the number of fully explained examples is
growing. There are examples for box packing and signal connection, presenting
tabular data, and basic drawing, among others. See the description page in the
doc/examples/ section.
This code, together with the not inconsiderable number of unit tests and the code for generating snapshots of Widgets and Windows means that a large portion of the public API is tested within the library itself. The number of non-trivial applications making use of java-gnome is starting to grow, which are likewise providing for ongoing validation of the codebase.
Summary
You can see the full changes accompanying a release by grabbing a copy of the sources and running:
$ bzr diff -r tag:v4.0.6..tag:v4.0.7
Looking ahead
It’s probably unwise to predict what will be in future releases. The challenge for anyone contributing is that they need to understand what something does, when to use it (and more to the point, when not to!), and be able to explain it to others. This needs neither prior experience developing with GNOME or guru level Java knowledge, but a certain willingness to dig into details is necessary.
That said, I imagine we’ll likely see further Cairo improvements as people start to use it in anger. It shouldn’t take too long until the bulk of the functionality needed for most uses is present in java-gnome. In particular, forthcoming coverage of the Pango text drawing library will round things out nicely.
There are a number of other major feature improvements we’d like to see in java-gnome. Conceptual and design work is ongoing on for bindings of GConf, GStreamer, and even support for applets. Within GTK, there have been a number of requests made for various things to be exposed, for example, the powerful GtkTextView / GtkTextBuffer text display and editing capability. Some of these have preliminary implementations; whether or not any given piece of work is acceptable in time for any particular future release will remain to be seen and depends on the willingness of clients to fund us to review and test such work.
In the mean time, people are happily using the library to develop rich user
interfaces, which is, of course, the whole point. We’re always pleased to
welcome new faces to the community around the project. If you want to learn
more, stop by #java-gnome and say hello!
AfC
Debian packages
The java-gnome bindings suite is now available in Debian Linux as
libjava-gnome-java
If you need help installing it, see the the Debian page in the download section here.
Compliments to Manu Mahajan for having done the research to develop the Debian package, and thanks to Thomas Girard for having refined Manu’s start and for having seen through the process of getting the package uploaded.
AfC
Cairo support
Adding coverage of the Cairo Graphics library is a feature we’ve been working on for about 6 months now, and during the 4.0.7 development cycle we’ve been able to land it in java-gnome!
Cairo is a huge library, of course, but we’ve put enough coverage in place to
ensure that things are working. Cairo has lots of convenience functions and
tons of obscure uses; no surprise (and no apology) that there’s still lots
that will need doing. If you want to help make sure it has what you need, then
grab ‘mainline’ and see org.freedesktop.cairo.Context.
Huge thanks go out to Behdad Esfahbod and Carl Worth; Behdad was really critical in explaining some basic Cairo concepts to me started when we were working together at the GNOME Summit back in October in Boston, and during March at the GTK hackfest in Berlin, Carl Worth was awesome for having checked our preliminary APIs and for having helped sorted us out as we were working our way through create some examples.
AfC
java-gnome 4.0.6 (12 Feb 2008)
Finding the missing methods.
Most of our effort recently has simply been fleshing out areas of the public API. The focus for this work as been getting the coverage needed to allow us to port some of our in-house applications to java-gnome 4.0. It’s not especially glamorous — if anything it has been tedious as hell — but the result has been a large body of improvements to java-gnome as a whole which we’re pleased to release as java-gnome 4.0.6
The bulk of this development took place on the ‘missing’ branch, so named
because that’s where I was working on what was missing :).
Continuing Improvement
Notable public changes include coverage additions to enable key stroke and mouse button handling:
org.gnome.gdk.Keyvalorg.gnome.gdk.KeypadKeyvalorg.gnome.gdk.EventKeyorg.gnome.gdk.ModifierTypeorg.gnome.gdk.MouseButtonorg.gnome.gdk.EventButton
Rather than exposing the int keyvals that bubble up out of the X server, we
have wrapped these as constants of type
Keyval (thereby being consistent with the
rest of java-gnome in our working to the strengths of Java as a strongly-typed
language; MouseButton was created for the same reason, helping developers
understand just what on earth mouse button
“1” is, anyway). Along with
ModifierType, this gives enough to
deal with the KEY_PRESS_EVENT and KEY_RELEASE_EVENT signals when the
developer wishes to deal with key strokes.
We’ve finally gotten around to providing proper coverage of the box packing
model which underlies every aspect of how GTK presents user interfaces. To
understand the size-request/size-allocation process, you might start with
Widget’s
setSizeRequest().
org.gnome.gtk.Requisitionorg.gnome.gtk.Allocationorg.gnome.gtk.Widgetorg.gnome.gtk.Containerorg.gnome.gtk.SizeGrouporg.gnome.gtk.SizeGroupMode
We’ve also added coverage for SizeGroup, which, when used in concert with nested VBoxes and HBoxes, can work wonderful magic and is often far better than messing around with Table when doing complex layouts.
After dithering for several releases, we’ve settled on how we’re going to deal with ComboBox and family. The underlying GtkComboBox presents something of a nightmare as it is really two classes in one with more-or-less incompatible APIs. So, not surprisingly, we’ve presented it as two sets of classes, with the text-only convenience API spliced out of ComboBox and ComboBoxEntry into TextComboBox and TextComboBoxEntry respectively.
org.gnome.gtk.ComboBoxorg.gnome.gtk.ComboBoxEntryorg.gnome.gtk.TextComboBoxorg.gnome.gtk.TextComboBoxEntry
We’ve added a few new features in our coverage of GTK’s TreeView API, and many other classes involved have also seen improvements. The persistent reference to a row provided by TreeRowReference is now available as is model type TreeModelFilter.
org.gnome.gtk.TreeModelorg.gnome.gtk.ListStoreorg.gnome.gtk.TreeIterorg.gnome.gtk.TreePathorg.gnome.gtk.TreeVieworg.gnome.gtk.TreeViewColumnorg.gnome.gtk.TreeViewColumnSizingorg.gnome.gtk.TreeModelFilterorg.gnome.gtk.TreeRowReferenceorg.gnome.gtk.CellLayoutorg.gnome.gtk.CellRendererorg.gnome.gtk.CellRendererPixbuforg.gnome.gtk.CellRendererText
Support for the actual filtering in TreeModelFilter is notable for having been quite tricky. The underlying C library use a function pointers rather than a GObject signal emission, and we don’t have any mechanism to handle that. We do, however, have a fantastic capability to marshal signals, so we dealt with the problem by creating a custom signal and then passing a function which emits it when the TreeModelFilter wants to ask the developer whether to include a row or not.
The new classes include support for TreeModel columns storing long data as
well as setting properties of that type:
org.gnome.glib.Valueorg.gnome.gtk.Valueorg.gnome.gtk.Objectorg.gnome.gtk.DataColumnLong
It should also be noted that most of the methods taking a TreeViewColumn have been converted to taking an argument of type CellLayout (an interface implemented by TreeViewColumn). This has no change to how you use our TreeView API, but was necessary to support ComboBox properly.
Finally lots and lots of minor additions to both public APIs and internals deeper down in the GDK part of the toolkit:
org.gnome.gdk.Colororg.gnome.gdk.Cursororg.gnome.gdk.CursorTypeorg.gnome.gdk.Pixbuforg.gnome.gdk.Windoworg.gnome.gtk.AboutDialogorg.gnome.gtk.Actionorg.gnome.gtk.Boxorg.gnome.gtk.Buttonorg.gnome.gtk.Calendarorg.gnome.gtk.Editableorg.gnome.gtk.Entryorg.gnome.gtk.EventBoxorg.gnome.gtk.Imageorg.gnome.gtk.IconSizeorg.gnome.gtk.ImageMenuItemorg.gnome.gtk.Labelorg.gnome.gtk.ScrolledWindoworg.gnome.gtk.Statusbarorg.gnome.gtk.Tableorg.gnome.gtk.Window
As ever, you can see the full changes accompanying a release by grabbing a copy of the sources and running:
$ bzr diff -r tag:v4.0.5..tag:v4.0.6
Documentation
We’ve always had HTML JavaDoc for the current stable release at
doc/api/ on the java-gnome website.
We’re going to change that a bit, though. As fixes to the explanatory
documentation happen quite frequently to classes and methods all over the
place, we’ve decided to generate the JavaDoc from ‘mainline’ periodically and
upload that instead. This means that there will, of course, be descriptions of
some methods which aren’t yet available in a released version of the library,
but they will clearly identifiable by virtue of having a @since tag showing
a version number greater than the most recent release. We’ll revert back to
more traditional behaviour once we hit 4.2.0, but in the mean time we can give
people access to the best information we can online.
The idea of having up-to-date illustrations of the various Widgets has proved popular, and we’ve continued to update the suite of snapshots. Doing that is also tedious, but it does provide a good opportunity to test APIs we are exposing especially where unit tests are less suitable.

Looking ahead
Almost as complex as the TreeView/TreeModel API are GTK’s powerful TextView/TextModel classes, collectively a Widget used to display and edit large text documents. Working out the java-gnome coverage for TextView will take a fair bit of consideration, but TreeView provides a road map, and, as with the coverage in 4.0.5 and 4.0.6 (which was driven largely by existing applications we were porting), we have some significant uses of GtkTextView which will guide us on our way.
The next release will also feature significant work outside of GTK; we should
be in a position to merge our coverage of the excellent Cairo drawing library
soon, and likewise we have tentative work in place letting people store
configuration and settings data in GConf. Both the ‘cairo’ and ‘gconf’
branches need more QA and documentation work, but they’re looking good and will
definitely be featured in java-gnome 4.0.7.
AfC
java-gnome 4.0.5 (26 Nov 2007)
TreeView is here!
It’s always a great feeling when you bag a milestone, and with this release we have reached a major goal on our way to having outstanding Java bindings for the GNOME platform: coverage of GTK’s powerful yet complex TreeView & TreeModel API.
TreeView
TreeViews are a central part of almost every application. GUIs use lists for all sorts of things, and so a significant goal was to make coding TreeViews and their backing TreeModels as straight forward as possible.
The most challenging and complex part was to design the Java side API, which was no small matter. As a native library, the GtkTreeView API is complex and very much written with programming in the C language in mind, and as such our algorithmic mapping of the underlying libraries into Java doesn’t entirely fit. Long experience with the TreeViews in the previous bindings had made it clear just how nasty to use the API could be, and so the hardest part of the work was to come up with a mapping and a usage pattern that would be both faithful to GTK and be sensible to use.
The other significant challenge was to document the work effectively. Our Java side API documentation is a major feature of java-gnome, and merely exposing classes and methods is not sufficient; they need to be clearly explained in our JavaDoc as well. Introduced in this release, then, are:
org.gnome.gtk.TreeVieworg.gnome.gtk.TreeViewColumnorg.gnome.gtk.CellRendererorg.gnome.gtk.CellRendererTextorg.gnome.gtk.CellRendererPixbuforg.gnome.gtk.TreeSelectionorg.gnome.gtk.SelectionModeorg.gnome.gtk.TreeModelorg.gnome.gtk.ListStoreorg.gnome.gtk.TreeIterorg.gnome.gtk.TreePathorg.gnome.gtk.Alignment
along with numerous test cases in our unit test suite, and several comprehensively worked examples.
This was a monster patch, and the culmination of not just three months direct effort, but also where we’ve been heading since we first started the re-engineering of Java bindings for GNOME. Although largely written by Andrew Cowie, a significant contribution was made by Srichand Pendyala who not only exhaustively evaluated the design but also threw in some serious chunks of code. The work benefited from comprehensive input from Peter Miller on the modelling and design, and the comments of Bryan Clark, Owen Taylor, and Hanna Wallach were all really positive and helped us know that we’d gone in the right direction. Finally, thanks to Behdad Esfahbod and the GNOME Foundation who made it possible for us to meet in Boston at the GNOME Summit and so accomplish much of the final pulling together of this branch.
Continuing Improvement
Meanwhile, steady work continues on to the fundamental base classes, with a whack of additional signals and methods on Widget and especially Window, along with expansion of coverage in numerous other classes:
org.gnome.gtk.Widgetorg.gnome.gtk.Windoworg.gnome.gtk.StateTypeorg.gnome.gdk.Colororg.gnome.gdk.VisibilityStateorg.gnome.gdk.EventVisibility
What else? We’ve begun to get the basics of image handling in place,
org.gnome.gdk.Pixbuforg.gnome.gtk.Imageorg.gnome.gtk.ImageMenuItem
One nice piece of contributed work came from Vreixo Formoso and Thomas Schmitz
with coverage of the Dialog Window functionality in GTK. It took a bit of
doing to map the int response codes used by GTK into something suitably
strongly-typed, but all good:
org.gnome.gtk.Dialogorg.gnome.gtk.ResponseTypeorg.gnome.gtk.MessageDialogorg.gnome.gtk.MessageTypeorg.gnome.gtk.ButtonsTypeorg.gnome.gtk.FileChooserDialog
And finally, minor improvements to all sorts of stuff:
org.gnome.gtk.Containerorg.gnome.gtk.Buttonorg.gnome.gtk.Boxorg.gnome.gtk.Binorg.gnome.gtk.Menu
notably from new contributor Mario Torre. Awesome!
For further details you can always grab a copy of the sources and run
$ bzr diff -r tag:v4.0.4..tag:v4.0.5
to see the complete code delta.
Screenshots
For fun we built in a capability to
create demonstrations to be captured as screenshots to illustrate various
things. It doesn’t get more basic than the example on the
Window documentation page, but it’s a nice touch. :) We’ve
screenshots for a number of Dialog classes and one for the TreeView page. I
imagine we’ll build up a nice library of images in the next few months (yes,
dear contributors, you can add snapshots to the list of things we’ll be
expecting along with well written documentation and unit tests when submitting
additions to the public API).
Building and requirements
The library now depends on GTK >= 2.12. Those packaging java-gnome for their distributions please take note.
Looking ahead
Continuing to expand the coverage levels in the classes already exposed will continue to dominate our attention; there’s still a long way to go but we’re pleased with the progress we’ve made so far; you can definitely build real applications with java-gnome now.
The next release also ought to include preliminary coverage of GConf and Cairo. Doing each justice will again take a serious amount of work, but will continue to grow the fun things you can do with java-gnome.
AfC
Arch packages
java-gnome now builds on Arch Linux and is packaged there. Thanks to Timm Preetz for having done the legwork for this!
AfC
Trees and Branches
Lots of ongoing work.
The major focus over the last three months has been on the ‘treeview’ branch.
Andrew Cowie, backed by Srichand Pendyala, has made awesome progress in working
out the engineering necessary to support GTK’s powerful but complex
TreeView/TreeModel system and designing an appropriate public API by which
java-gnome can present it. This has taken most of September and October but is
working really well at this point. This branch should be ready for merging to
‘mainline’ in the next week or two; just need to bring the documentation up
to release quality and we’re set.
Vreixo Formoso and Thomas Schmitz have done some great work to expose the
Dialog family of classes. This work has exposed a few bugs in our internals,
but thanks to some expert help from Owen Taylor we should have that sorted out
soon. Work to fix that is taking place on the ‘delete’ branch.
Andrew Cowie, helped by Behdad Esfahbod, has begun work on a binding of the
Cairo library. This work is still experimental at this stage, but we’ll merge
this ‘cairo’ branch in so we can to at least set the tone for what will be an
exciting addition to java-gnome over the coming months.
Once we land these branches we should be able to polish things up for the release of 4.0.5, hopefully by the end of November.
AfC
java-gnome 4.0.4 (26 Sep 2007)
Coverage increasing!
Most of our work continues to be on infrastructure and architecture, improving the code generator that outputs the translation Java layer and JNI C layer which allow bindings hackers to reach the underlying native libraries. Nevertheless, there have been a number of publicly visible improvements across the board, so we wanted to push out a release highlighting these contributions!
Documentation improvements
Continuing our effort to have extensive developer friendly tutorial style documentation, there have been major additions to a number of existing classes. Of particular note is the Window class, containing the various utility methods used to ask the window manager to do things for you (we’ve also started exposing some of the deeper parts of the GTK toolkit, though only a few things that were immediately related to window management).
org.gnome.gtk.Windoworg.gnome.gtk.Widgetorg.gnome.gdk.Screenorg.gnome.gdk.Window
While the topic of thread safety was discussed at considerable length in the last release, we have added some of the more relevant information to the code documentation to reinforce its importance.
org.gnome.gdk.Gdk’slock
New coverage
Numerous people have been hard at work developing new coverage. The standards
for accepting patches which expose public API are high, so it’s awesome to see
bundles accepted for being merged to mainline from new contributors Thomas
Schmitz, Wouter Bolsterlee, and Nat Pryce.
The infrastructure for a number of areas important to supporting applications including Menus, Toolbars, and Actions has been put in place:
org.gnome.gtk.Toolbarorg.gnome.gtk.ToolItemorg.gnome.gtk.ToolButtonorg.gnome.gtk.ToggleToolButtonorg.gnome.gtk.MenuToolButtonorg.gnome.gtk.SeparatorToolItemorg.gnome.gtk.MenuItemorg.gnome.gtk.CheckMenuItemorg.gnome.gtk.SeparatorMenuItemorg.gnome.gtk.Actionorg.gnome.gtk.ActionGroup
A number of Container related Widgets have been added, though coverage is preliminary. There have, of course, also been a number of minor improvements in other existing classes, including:
org.gnome.gtk.Notebookorg.gnome.gtk.ScrolledWindoworg.gnome.gtk.Miscorg.gnome.gtk.ButtonBoxorg.gnome.gtk.HButtonBoxorg.gnome.gtk.VButtonBoxorg.gnome.gtk.Label
and even:
org.gnome.gtk.StatusIcon
Along with these goes a variety of miscellaneous constants and wrappers around the stock item identifiers:
org.gnome.gtk.Alignmentorg.gnome.gtk.ImageTypeorg.gnome.gtk.ButtonBoxStyleorg.gnome.gtk.Justificationorg.gnome.gtk.Orientationorg.gnome.gtk.Stockorg.gnome.gdk.Gravity
Internals
Vreixo Formoso carried out an important refactoring to the type database and Generator family of classes in the code generator, with the result that more of the array passing and out-parameter cases are now being handled correctly. This kind of work is usually thankless and taken for granted, but it’s hugely appreciated!
The real gains are in internal quality. A number of serious bugs and
limitations have been overcome (Glade is working again, for example). The
generated code now guards against improper use (you can’t pass a null pointer
unless it’s allowed by the underlying library). Related to this is handling of
“GError” — Java side, bindings hackers will get GlibException which they
can then re-throw as an appropriate Java Exception, say FileNotFoundException
in the case of not being able to open a file.
This all goes along with numerous build system fixes by Srichand Pendyala to make for an increasingly robust project. Thanks guys!
Looking ahead
As mentioned above, we have mostly been focused on areas other than public API, but it is expanding steadily. The hard work on infrastructure, however, is starting to pay off, and the next release should include coverage of TreeView, GTK’s powerful but complex list Widget.
AfC
Gentoo packages
The java-gnome bindings suite is now available in Gentoo
Linux. An .ebuild for 4.0.3 has been merged to
Portage in
dev-java/java-gnome
If you need help installing it, see the the Gentoo page in the download section here.
Thanks to the people who pushed this through: Xerces MC for having submitted an
initial .ebuild, Petteri Räty (Gentoo dev and Java team lead) for having
fixed it up, and Christoph Brill for testing.
AfC
java-gnome 4.0.3 (31 Jul 2007)
The code generator has landed!
Work has been underway for several months to develop the next stage of the new java-gnome: the code generator that will output the tedious translation and native layers that allow us to glue our public API to the native GNOME libraries. With this release we’re pleased to announce that the code generator is a reality!
Generated translation and JNI layers
The primary goal of the java-gnome 4.0 re-engineering effort has been to switch to an architecture whereby we could generate the bulk of the machinery necessary to take make native calls into the GNOME libraries from Java.
Extensive prototyping was done to establish the detailed design and to validate
the architecture we had developed. Releases 4.0.0 through 4.0.2 contained this
work along with mockups of the “translation” layer (the Java code that
downshifts from our Proxy objects to primitives suitable to pass over the JNI
boundary, along with the native declarations necessary in order to call
methods actually written in C) and of the “JNI layer” (the C code that
implements the methods declared in the translation layer which in turn coverts
parameters into GLib terms and then makes the actual function call into the
appropriate GNOME library).
With a solid foundation proving that our design was sound, we subsequently
began the long effort to implement a code generator which would output these
Java and C layers, allowing us to replace the mockup/ directory and at last
leave behind the shackles of entirely hand written bindings. Over the past five
months, the java-gnome hackers have been steadily working on the ‘codegen’
branch. The nature of the challenge meant that we had to have most of the code
in place before any of it would be useful — never an enviable task to be
working on. Thanks to the hard work of Andrew Cowie, Vreixo Formoso Lopes, and
Srichand Pendyala, we reached the point where the output Java code compiled in
May, and the output C code successfully compiled in by the end of June.
Tremendous.
We’ve been bug hunting and refining since then, pushing towards the point where we could merge back to ‘mainline’, at last replacing the hand written mockup code. We are today pleased to announce the culmination of that work with the release of java-gnome 4.0.3.
This post on the development of the java-gnome code generator
contains further details should you be interested; the file
5a-Architecture.txt in the doc/design/ directory of the
source code explains the rationale and origin of the engineering design.
New coverage
Although our focus has evidently been on getting the generator into working order, there have nevertheless been a few minor coverage additions along the way:
org.gnome.gtk.Entryorg.gnome.gtk.Separatororg.gnome.gtk.HSeparatororg.gnome.gtk.VSeparatororg.gnome.gtk.Frameorg.gnome.gtk.Calendarorg.gnome.gtk.Notebookorg.gnome.gtk.Imageorg.gnome.gtk.Menuorg.gnome.gtk.MenuBarorg.gnome.gtk.MenuItemorg.gnome.gtk.ToggleButtonorg.gnome.gtk.CheckButton
which are largely to the credit of Sebastian Mancke for having submitted them and Srichand Pendyala for having fixed up their JavaDoc. There have also been steady improvements to a number of other classes; notably further signals and utility methods exposed in:
org.gnome.gtk.Widgetorg.gnome.gtk.Container
along with some preliminary coverage of the lower level GDK event machinery:
org.gnome.gdk.Eventorg.gnome.gdk.EventType
As is reasonable given our focus on writing the actual translation and JNI layer generators, most of these present only one or two methods from the underlying native class. Coverage will steadily improve as people contribute their knowledge and experience in documentation form.
People upgrading from 4.0.2 will actually notice that there are stubs for all of the public API classes; this was necessary to make the generated code compile. Most of these are empty as yet.
GList and friends
GList and GSList are the native GLib data structures used to represent
lists and are the return type from quite a few methods across GTK. Vreixo
Formoso Lopes worked out how to handle and working our wrap/unwrap functions
for us to use in the JNI layer made a significant contribution to reducing our
blacklisted method count.
Flags
We’ve also worked out handling of native types that, while type defined as enums, are actually bit fields. These are used occasionally in GTK to express options; two examples now exposed are:
org.gnome.gtk.CalendarDisplayOptionsorg.gnome.gdk.WindowState
Flags subclasses present an or() function allowing you to combine individual
Flags constants into a new composite Flags object. Yes it’s a lot of machinery
to do a logical |, but being strongly typed is a hallmark of java-gnome.
Build improvements
No release would be complete without mentioning that the code builds on more systems than it did before! Thanks to Maciej Piechotka and Srichand Pendyala for fixing problems resulting from Debian and Ubuntu strangeness.
The build internally now uses an optimized script that takes into account that
even though the code generator may have run the translation and jni files may
not actually be different. This was causing problems as Make only looks at file
modification time. Instead, build/faster (great name, huh?) will only rebuild
a target when source contents have changed. This was necessary for bindings
hackers working in Eclipse; every time a file was saved Eclipse would merrily
spawn off an auto-build which sooner or later would block the IDE UI. Yuk.
Addressing this has also resulted in a faster build for everyone; all good.
The internal build script should be transparent; you still run ./configure
and make as before. If you experience problems let us know.
Thread safety
In addition to the code generator, java-gnome 4.0.3 incorporates a comprehensive thread safety strategy.
None of the major Java graphical toolkits out there let you make GUI calls from threads other than the “main” one; they’re all single threaded. Even if all you want to do is a quick worker thread to carry out some input validation in the background after the user presses “OK”, you have to jump through horrific contortions to do so safely, resulting in cumbersome, clunky code.
By contrast, the new Java bindings of GTK presented in java-gnome are transparently thread safe, the first and only graphical user interface widget toolkit for Java to be so! We integrate properly with the underlying GDK thread lock and as a result you can safely make calls to various GTK methods from worker threads! This has been a long sought after goal and we hope a significant contribution to helping developers write elegant code.
Every call made to the native libraries is protected by entering the “GDK lock”
[that’s gdk_threads_enter/leave() for those familiar with the C side of
things]. The lock used is actually a Java side synchronized monitor and
therefore reentrant; nested calls all behave properly. When in a signal handler
callback the GDK lock is already held (you’re “in” the main loop when a
callback happens), but since it just works transparently you don’t need to
worry about it. If you do find a need to take the lock into account explicitly
in your own code, see Gdk.lock in org.gnome.gdk.
It is worth noting that we have been warned that there are certain to be places in the underlying libraries that do not yet live up to the requirements of the GDK threads model — thus we will likely end up tripping over such things as we slowly add API coverage. We regard such inevitable instances as an opportunity to help contribute to improving the stability of the underlying libraries and will actively work with their maintainers to identify and resolve such issues. Nevertheless, in testing thus far our multi-threaded use of GTK has been rock solid. See these posts on GTK thread “awareness” and java-gnome’s thread strategy if you wish further details on our approach to the thread safety question.
Thanks in particular to Owen Taylor for having helped us navigate these waters!
Looking ahead
Taken together, these innovations represent the culmination of an immense amount of work towards realizing java-gnome as a viable platform for GTK and GNOME development.
Obviously with the generated translation layer in place the opportunity at last exists to start dramatically improving our coverage level, and we welcome contributions to this end. Prospective hackers are cautioned, however, that simply wrapping generated methods is insufficient — public API will only be added when it is clearly documented and meets the approachability criterion.
There are still areas where the code generator needs to be improved; we need to improve our handling for arrays, lists, and out-parameters — there are numerous permutations with all sorts of ugly corner cases.
Now that Free Java with support for generics is becoming widely available, 4.0.3 will be the last release holding the language level to Java 1.4; starting the next cycle 1.5 will be the minimum language requirement and we will be leveraging generics and other 1.5 features from here on.
Most importantly, the primary focus of the next few months will be developing a
quality binding for the backbone of many applications: the TreeView Widget
and the underlying TreeModel which powers it. The APIs in the native library
is hideously complicated and has long been the source of confusion and pain for
developers in C; it has long been a major goal amongst the java-gnome hackers
to present a public API with as friendly and usable an interface as possible.
It’ll be a good challenge.
AfC
java-gnome 4.0.2 (12 Feb 2007)
The End of the Beginning!
Major bugfixes and refactorings
Setting and getting properties on GObjects requires some tricky manoeuvring.
We implemented the code to do this early on, and it looked like our general
mechanism for getting Proxy instances for arbitrary pointers was working fine
for properties. It turns out, however, that when you call g_type_name() on a
GValue containing a GObject, it returns the name of the type that was listed
when the property specification was registered, rather than saying it is a
GValue (as you might expect) or what the object actually is (that you might
also reasonably expect).
This led to all kinds of nastiness since the type name was what we were using
in our instanceFor() mechanism to discriminate (on the Java side) what kind
of Proxy subclass to create. The example we tripped over was asking for the
parent property of a Button packed into a VBox. What g_type_name() told us
was “GtkContainer”, not “GtkVBox”! And that was a big problem, because
Container is abstract, and besides, we want to instantiate a concrete VBox
Proxy, not a Container one!
Solving the problem involved major changes to:
org.gnome.glib.Valueorg.gnome.glib.Objectorg.gnome.glib.Plumbingorg.gnome.glib.GValueorg.gnome.glib.GObject
The solution basically boiled down to having two separate code paths: one
named objectFor() [a greatly simplified version of the previous
instanceFor()] which returns normal Proxy objects for GObject subclasses
(Buttons and Labels and whatnot), and a new code path available via
valueFor() to specifically return our GValue Proxy for the cases where we
know we’re getting a GValue back. Since that occurs in limited and known
circumstances only (ie, when we’re getting properties) it’s no problem to know
which to use when.
Thanks to Davyd Madeley for extensive debugging assistance, and credit to Manish Singh, James Henstridge, and Malcolm Tredinnick for having analyzed the root cause issue and having clarified that two code paths would indeed be necessary.
As often happens when you kick a stone loose, we were able to do a number of refactorings to clean things up. This eventually led to the realization (ok, epiphany) that our treatment of the GValue mechanism was needlessly complex. Toss. We no longer have individual Value subclasses for each different fundamental type, but rather just leave them as opaque references:
-
org.gnome.glib.Fundamental -
org.gnome.glib.StringValue -
org.gnome.glib.BooleanValue -
org.gnome.glib.IntegerValue -
org.gnome.glib.EnumValue -
org.gnome.glib.ObjectValue org.gnome.glib.Valueorg.gnome.glib.Plumbing
This allowed a further simplification of the valueFor() mechanism and even
more smashing about in Plumbing with a chainsaw. Net result was a reduction
by several hundred lines of code. Yeay!
All of these changes were confined to the internals of the binding machinery and are not user visible.
Loading .glade files
User interface designers are nothing new, but one of the really cool things
about GTK has long been the existence of libglade. It’s a library which
takes the output of a one of the GNOME user interface designers (such as such
as Glade 3 or Gazpacho) and dynamically, at runtime, generates live
Windows full of Widgets!
With the arbitrary Proxy retrieval sorted out, the beginnings of a binding of
libglade was possible. None of the fancy stuff is there yet, but a .glade
file can be loaded, and Widgets retrieved from the instantiated tree.
org.gnome.glade.Gladeorg.gnome.glade.Xmlorg.gnome.glade.GladeXml
The JavaDoc for these classes clearly indicates that this is preliminary and subject to change. It may well all be blown away when GtkBuilder lands. We’ll see.
Testing framework
We’ve introduced the beginnings of a unit test framework. At the moment, this just evaluates various getters and setters without doing anything that requires the main loop. Despite this, the unit tests end up exercising the entire Proxy system discussed above; validating that the properties set and get and that the correct Proxy object is returned through a round trip is no mean feat.
You can run the suite from Eclipse, by specifying a JUnit 3 launcher on class
UnitTests in the default package in tests/java, or by running
$ make test
from the command line.
Further coverage
This release also sees the addition of:
org.gnome.gtk.FileChooserorg.gnome.gtk.FileChooserActionorg.gnome.gtk.FileChooserButton
Along with mocked up code for:
org.gnome.gtk.GtkFileChooserorg.gnome.gtk.GtkFileChooserActionorg.gnome.gtk.GtkFileChooserButton
This is significant because GtkFileChooser is an interface in GTK, and GtkFileChooserButton implements it. We’d been putting off the question of dealing with GInterface (would it work or be a major problem?) for a while now. We were delighted to find that the design implied by the re-engineered bindings handled it cleanly, elegantly, and without any fuss. Another nice validation of our new architecture.
Finally, a number of new signals were exposed on:
org.gnome.gtk.Widget
though these were mostly the result of doing live demonstrations at conferences of how easy extending the coverage of the new bindings is.
Memory management
We have successfully implemented full GObject memory management in java-gnome 4.0 using GLib’s ToggleRef mechanism.
A strongly referenced Java Proxy will not allow its GObject to be destroyed out from underneath it; meanwhile, as long as the GObject is still referenced by something other than java-gnome, an otherwise only weakly reachable Java object that Proxies it will not be finalized. When the situation does occur whereby the GObject is only referenced from java-gnome, and the Java object is no longer strongly referenced by any other Java objects, then the Java object can be garbage collected and the GObject will be unref()’d and destroyed.
You can watch the reference system in action if you set
Debug.MEMORY_MANAGEMENT to true.
Huge thanks go to Vreixo Formoso Lopes who collaborated on the design, reviewed the implementation, and contributed test case code.
Build system improvements
A better detection of jni.h is done on Ubuntu, thanks to Michael Kedzierski. This makes java-gnome more likely to build out of the box on Debian-derived systems.
On the eve of release, Srichand Pendyala noticed that if you are running such
a system, a package named libglade-dev needs to be installed. Of course, on
more modern systems all the necessary dependencies are present merely by
having GNOME installed in the first place. We’ll add a check for this Debian
specific behaviour in 4.0.3.
The VERSION and APIVERSION constants were moved to
org.gnome.gtk.Version
so that anyone working on the Gtk main class isn’t forced to do a re-configuration every time they save.
Installation and Packaging
java-gnome 4.0 now has the standard make install command, and the equally
standard --prefix option to ./configure.
$ ./configure --prefix=/usr
$ make
$ sudo make install
The install target understands the DESTDIR variable used by packagers to
install to a specified prefix within a temporary directory.
See the README file for details.
Looking ahead
The feature additions described above were done to bring java-gnome up to
speed for the GTK & GNOME tutorial given at linux.conf.au. With that
past, we’re not going to do any more manual mockups of code in what will be
the generated layers. Focus now turns to designing and implementing the tool
that will parse .defs files and output the translation code.
Once we secure funding for the project, the code generator will be our top priority and shouldn’t take more than a couple months to complete.
AfC
java-gnome 4.0.1 (05 Jan 2007)
It’s not really a prototype anymore! the design works, and so the code that is here is forming the foundation of the new Java bindings for GTK and GNOME.
While there are some significant pieces of engineering that are yet to be done, and of course a universe of coverage yet to write, we’re pleased to mark the milestone of the prototype having proved itself to be stable and the strong foundation that we need. In this release:
Project documentation
Import project documentation, initially consisting of the re-engineering
emails written by Andrew Cowie to the java-gnome-hackers mailing list, and
expanded to include top level README and
HACKING files, and a style guide for contributors to follow.
All documentation [re]formatted in Markdown syntax so as to be renderable to
web pages. See doc/design/ and
doc/style/.
Project website
Create an entirely new website for http://java-gnome.sourceforge.net/, introducing sections “About”, “Documentation”, “Download” and “Interact” to discuss the the project as a whole, to be a home for the documentation, to provide instructions on how to get java-gnome, and information about the mailing lists and IRC channel, respectively. Also include a page thanking the previous generations of maintainers for their hard work and noting that the 2.x bindings have been unmaintained for some time now and are formally deprecated.
The website is no longer a wiki but is entirely within the source code of
java-gnome itself. See the web/public/ directory; improvements welcome.
Major engineering
Quite significantly, the infrastructure to get a Proxy or Constant instance for any arbitrary C side pointer or enum is complete, involving significant work to:
org.freedestkop.bindings.Plumbingorg.freedestkop.bindings.Proxyorg.freedestkop.bindings.Constantorg.gnome.glib.Plumbingorg.gnome.glib.Valueorg.gnome.glib.GValueorg.gnome.glib.Fundamentalorg.gnome.glib.Object
Along with the corresponding C side code, especially in GValue.c
This was a necessary building block in order to complete the generalized
getProperty() mechanism that, while hidden from public view, is nevertheless
a major aspect of the GObject tool chest and is usable by bindings hackers
when necessary. The generalized instance mechanism was the last major
engineering hurdle that needed to be achieved in order to prove the new
bindings design.
New coverage
org.gnome.gtk.Labelorg.gnome.gtk.Fixedorg.gnome.gtk.Boxorg.gnome.gtk.VBoxorg.gnome.gtk.HBox
Along with
org.gnome.gtk.GtkLabelorg.gnome.gtk.GtkFixedorg.gnome.gtk.GtkBoxorg.gnome.gtk.GtkVBoxorg.gnome.gtk.GtkHBox
And corresponding [working] mockup native code.
Compliments to Srichand Pendyala from Bangalore, India for being the first
external hacker to have a patch accepted to mainline! He contributed methods
to Label and initiated the implementation of the Fixed class. In so doing, he
also helped work the bugs out of the bzr bundle submission process. Awesome.
Build improvements
java-gnome now builds on Ubuntu and OpenSolaris in addition to its home turf of Gentoo. Thanks to John Rice of Sun Microsystems who provided the guidance allowing us to port Equivalence to Solaris some months ago, and Laszlo Peter, also of Sun Ireland, for several fixes to allow configure to recognize a wider range of Solaris environments.
The tiny example program that we have been using to validate the code,
Experiment is now compiled by the build system if you so request. Try make
demo.
API documentation
Extensive attention has been paid to the JavaDoc for the few methods that are presented so as to clearly set the standard required. The canonical JavaDoc for the project is available at the website with a stable URL and can be linked to.
All source code [comments, ie JavaDoc] have been spell checked! Initial top
level overview.html and package.html files have also been written to help
round out the JavaDoc.
AfC
java-gnome 4.0.0 (26 Nov 2006)
Initial release of the java-gnome 4.0 prototype, corresponding to the first public demonstration of the new bindings done at foss.in/2006 at Bangalore, India.
The prototype is fully functional and is intended to prove the design and architecture we have arrived at as a result of the re-engineering process. It includes both real wrapper layer classes that are the seed from which our public API will grow, along with the infrastructure that the wrapper layer depends on.
Initial coverage
Wrapper layer presenting the public API to developers (publicly visible classes in bold):
org.freedesktop.bindings.Proxyorg.gnome.glib.Valueorg.gnome.glib.Objectorg.gnome.gtk.Objectorg.gnome.gtk.Widgetorg.gnome.gtk.Containerorg.gnome.gtk.Binorg.gnome.gtk.Buttonorg.gnome.gtk.Window
Along with complete translation layer implementations for each:
org.freedesktop.bindings.Plumbingorg.gnome.glib.Plumbingorg.gnome.glib.GValueorg.gnome.glib.GObjectorg.gnome.gtk.GtkObjectorg.gnome.gtk.GtkWidgetorg.gnome.gtk.GtkContainerorg.gnome.gtk.GtkBinorg.gnome.gtk.GtkButtonorg.gnome.gtk.GtkWindow
At present the bindings mock up the code that will be generated with temporarily hand written substitutes (ie, those in italics above) for both translation (Java) and native (C) layers. These will do until we receive the funding to make the code generator a reality; we certainly don’t want to be writing much more translation layer Java and C code by hand. Yuk.
Signal API
The defining aspect of GUI programming is, of course, that it is event driven. In addition to the “forward” direction of making calls to the native library and having return values bubble back up, there is the “reverse” direction of connecting callback handlers to the various signals that different Widgets offer, and having those signal events result in those handlers being invoked.
java-gnome 4.0 has an entirely new and redesigned signal connection and
callback API. This functionality was demonstrated, and coverage of
Button.CLICKED and Window.DELETE is now present and functional!
The APIs used by GNOME language bindings to achieve this are some of the most
voodoo I have ever seen. But it’s hooked up, and it works. It’s like black
magic :)
Build
java-gnome is configured and built using Andrew Cowie’s Equivalence build
scripts. It builds on Gentoo and should build on a Debian or Fedora derived
system as well. See README for further details.
At the moment, java-gnome is a single source package.
The source code is available via bzr. Again, see README.
AfC

