<?xml version="1.0"?>

<rss version="2.0">
  <channel>
    <title>Andrew Cowie</title>
    <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/</link>
    <description>Blog postings by Andrew Cowie about Open Source and Software Development</description>
    <language>en</language>
    <copyright>Copyright (c) 2008 Operational Dynamics Consulting Pty Ltd. All rights reserved. Not for redistribution or attribution without permission in writing.</copyright>

    <image>
      <url>http://research.operationaldynamics.com/images/andrew_Hackergotchi.png</url>
      <title>Operational Dynamics Research</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/</link>
      <width>80</width>
      <height>86</height>
    </image>

    <lastBuildDate>Sun, 05 Oct 2008 13:05:00 GMT</lastBuildDate>

    <item>
      <title>java-gnome 4.0.8 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.8-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is an extract of the release note from the</em> <code>NEWS</code> <em>file which you can read <a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.8 (15 Aug 2008)</h1>

<p><em>Cleanups and fixups.</em></p>

<p>This release is mostly to push out bug fixes and internal improvements,
setting the stage for some major new feature development. We&#8217;ve also taken the
opportunity to introduce a major change to the way we connect handlers for
signals.</p>

<h2>New coverage and continuing improvement</h2>

<p>With thanks to new contributors Stefan Prelle and Andreas Kuehntopf we have a
number of small improvements to the TreeView/TreeModel APIs. As always, Widget and Window saw a bunch of work, with <code>Window.ConfigureEvent</code> now being available and a number of additional property setters and methods relating to window type. Widgets that scroll around a view of a broader underlying canvas have seen a fair bit of activity related to controlling that scrolling.</p>

<p>New features include refinements and new coverage of methods in a variety of
lower level classes including that further support drawing operations. Bug
fixes, debugging improvements, and defencive enhancements to our thread safety
measures have also featured largely.</p>

<h2>Signal naming change</h2>

<p>The names of the inner interfaces used to specify the prototypes of the
methods which receive signal callbacks have changed to the pattern
<code>Button.Clicked</code>, this being more appropriate to Java type naming conventions
and providing better consistency between the signal name, the method to be
implemented to receive the callback, and the method that can be used to emit
this signal.</p>

<p>API compatibility to previous releases in the 4.0 series has been preserved.
The old signal interfaces and <code>connect()</code> methods are <code>@deprecated</code>.
Developers are encouraged to migrate quickly; new coverage will of course all
follow the new pattern. Making the transition is is easy, especially in an
IDE. Most of the people we&#8217;re aware of using the library have already ported
their code. Just turn assertions on to double check.</p>

<h2>Build changes</h2>

<p>java-gnome now defines C compiler flags like <code>GTK_DISABLE_DEPRECATED</code> to
ensure we are not linking against code that will be unavailable in GTK 3.0.
Many thanks are due to new contributor Kenneth Prugh for having done some
terrific grunt work to prune deprecated classes and methods from our <code>.defs</code>
data so that java-gnome compiles without using these APIs.</p>

<p>The build system internally now ensures that multiple runs don&#8217;t occur
simultaneously, fixing a number of annoyances that cropped up when using IDEs
which tend to like trying to frequently re-run the build even if a previous
one hasn&#8217;t finished.</p>

<h2>Documentation, examples, and testing</h2>

<p>Our <a href="http://java-gnome.sourceforge.net/4.0/doc/api/overview-summary.html">API documentation</a> and the growing set of
<a href="http://java-gnome.sourceforge.net/4.0/doc/examples/START.html">example code</a> have all been updated to reflect the
new signal interface names. Doing so forced us to review a wide swath of the
documentation, and so along the way a huge number of minor improvements were
made. Given how detailed our JavaDoc is, this sort of painstaking work really
makes a genuine contribution to overall quality.</p>

<p>There has been steady growth in our test suite, which is great. When combined
with the snapshots used to illustrate our documentation, the coverage level
is substantial.</p>

<p>Error handling continues to improve. In the (hand written) public API wrapper
layer we do our best to catch  misuses of the library before they get sent to
the native code. But that&#8217;s not always possible, and in 4.0.7 we introduced a
mechanism whereby GLib error messages get translated into Java Exceptions and
thrown. As of 4.0.8, in addition to <code>ERROR</code> and <code>CRITICAL</code>, we also throw
<code>WARNING</code>s as Exceptions. Getting a stack trace this way has proved very
useful in helping developers track down where they are making mistakes in
using the library.</p>

<h2>Conclusion</h2>

<p>You can see the full changes accompanying a release by grabbing a copy of the
sources and running:</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr diff -r tag:v4.0.7..tag:v4.0.8
</pre>

<p>Because of the API changes to signal handling this release touches just about
every public class in the library and so isn&#8217;t quite as clean (as a summary)
as in previous releases &#8212; but it does show you everything that changed. <code>:)</code></p>

<h2>Looking ahead</h2>

<p>Most of the contributors to java-gnome are working on branches that didn&#8217;t
reach sufficient maturity to be merged in time for 4.0.8; that&#8217;s the way it
goes sometimes. Major effort continues on implementing coverage of GTK&#8217;s
powerful TextView/TextBuffer APIs, along with further drawing capabilities in
Cairo and Pango. There have also been a surprising level of interest on other
areas of the GNOME stack, with new contributors working on adding support to
java-gnome for Nautilus, GStreamer, and even WebKit. Exciting stuff!</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> &#8216;<code>mainline</code>&#8217; <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr checkout bzr://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 18 Aug 2008 23:01:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.8-release</guid>
    </item>

    <item>
      <title>Using Eclipse&#8217;s source code formatter from the command line</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/eclipse-code-format-from-command-line.html</link>
      <description><![CDATA[<p>One of the many wonderful capabilities built into the side of Eclipse is a powerful code formatter. Adjusting source code to match one&#8217;s particular preferences is nothing terribly new; what makes Eclipse&#8217;s so excellent is the degree of configurability and the preview of the effect each setting will have.</p>

<p>An Eclipse project has several metadata files:</p>

<pre>
.project
.classpath
.settings/org.eclipse.cdt.core.prefs
.settings/org.eclipse.jdt.core.prefs
<b>.settings/org.eclipse.jdt.ui.prefs</b>
</pre>

<p>Which seems a bit of a mess, but whatever. The <code>.settings/</code> stuff gets written down when you decide to tell a Project to have settings custom that override the user&#8217;s defaults. It goes without saying that for a collaboratively developed project like the Java bindings we have the Eclipse project metadata for compiler warnings tuned, the code formatter settings, how to invoke the build system etc all stored in Bazaar along side the real sources.</p>

<p>Anyway, this&#8217;s all fine and nice for people working on my software in Eclipse, but what about people wishing to use a different editor?</p>

<p>For a few versions now, Eclipse has exposed the the ability to run its code formatter from the command line; the work was done by Ben Konrath, someone I met a few years ago at a java-gnome hackfest. Since I use Eclipse I hadn&#8217;t needed to bother to figure out how to use whatever it was that he&#8217;d done. Since becoming maintainer of java-gnome, though, I&#8217;ve noticed a bit of unnecessary formatting churn in the contributions we receive. We do have a <a href="http://java-gnome.sourceforge.net/4.0/doc/style/">style guide</a>, but it is secondary to the fact that Eclipse just normalizes the code every time I save something (nice). But for people not using Eclipse I thought I might have a look.</p>

<p>A bit of searching around turned up this blog post by one <a href="http://www.peterfriese.de/formatting-your-code-using-the-eclipse-code-formatter/">Peter Friese</a>. It included two important points that are non-trivial. Firstly, that configuration the code formatter from command line will use can be controlled by the pointing it at the <code>.settings/org.eclipse.jdt.ui.prefs</code> file which in turn can be created by the &#8220;Enable project specific settings&#8221; described above (we&#8217;d already done that, so no problem, but how on earth would anyone have guessed this?). Secondly, the command line that one has to incant to make it go is pretty voodoo, so I&#8217;m pretty thankful that he described what he&#8217;d done.</p>

<p>In our environment, this works out to:</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ /opt/local/eclipse/<b>eclipse -nosplash
    -application org.eclipse.jdt.core.JavaCodeFormatter
    -verbose
    -config .settings/org.eclipse.jdt.core.prefs</b>
    src/ tests/ doc/examples/
</pre>

<p>Gah!</p>

<p>For a brief moment I wondered if it would be easier just to run the Java class in question. So I interrupted the process and had a look in the process table.</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
/usr/lib/jvm/sun-jdk-1.6/bin/java
    -Dosgi.requiredJavaVersion=1.5
    -client
    -Xms40m
    -Xmx256m
    -jar /opt/local/eclipse/plugins org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar
    -os linux
    -ws gtk
    -arch x86
    -launcher /opt/local/eclipse/<b>eclipse</b>
    -name Eclipse
    --launcher.library /opt/local/eclipse/plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.0.2.R331_v20071019/eclipse_1021.so
    -startup /opt/local/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar
    -exitdata 84001b
    <b>-application org.eclipse.jdt.core.JavaCodeFormatter
    -verbose
    -config .settings/org.eclipse.jdt.core.prefs</b>
    src/ tests/ doc/examples/
    -vm /usr/bin/java
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -client
    -Xms40m
    -Xmx256m
    -jar /opt/local/eclipse/plugins/org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar
</pre>

<p>Good Lord. What the hell is all that? I mean, I know Java environments tend to get a bit unwieldy because there is still no link-to-binary facility, and I know Eclipse is an OSGi framework and what not, but that is pathetic. I guess running the command as described at the top isn&#8217;t such a bad idea after all.</p>

<p>I&#8217;ve got an even better idea: how about a convenience target in our <code>Makefile</code> front end. Yup. So I&#8217;ve added  a <code>format</code> target:</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ make format
</pre>

<p>(or</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ ECLIPSE=/opt/local/eclipse/eclipse make format
</pre>

<p>in my case). Running that before committing will do the trick quite nicely.</p>

<p>I agree with the bug mentioned by one <a href="http://www.nirving.com/2007/06/01/batch-code-formatting-using-eclipse-code-formatter-but-without-eclipse/">Nicholas Irving</a> in his post on the topic: it is somewhat asinine that this bit of Eclipse bumps the modification time of every file it formats; it would be nice if it only changed files in which it actually found something it needed to alter. Fortunately our internal build system is actually md5 hash (not Make) based, so it doesn&#8217;t hurt us. </p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Sun, 06 Jul 2008 03:23:00 GMT</pubDate>
      <guid isPermaLink="false">eclipse-code-format-from-command-line</guid>
    </item>

    <item>
      <title>java-gnome 4.0.7 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.7-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is an extract of the release note from the</em> <code>NEWS</code> <em>file which you can read <a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.7 (30 Apr 2008)</h1>

<p><em>Draw some.</em></p>

<p>In addition to the usual 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.</p>

<h2>Drawing with Cairo</h2>

<p><img src="http://java-gnome.sourceforge.net/4.0/doc/examples/cairo/ExampleCairoDrawingBlends.png" alt="Example"/></p>

<p>The trusty Cairo context, traditionally declared as a variable named <code>cr</code> in
code, is mapped as class
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/freedesktop/cairo/Context.html"><code>Context</code></a>. Various Cairo types
such as different surfaces and patterns are mapped as an abstract base class
(<code>Surface</code>, <code>Pattern</code>) along with various concrete subclasses (<code>ImageSurface</code>,
<code>XlibSurface</code>, and <code>SolidPattern</code>, <code>RadialPattern</code>, etc). Error checking is
implicit: the library status is checked internally after each operation and an
Exception thrown if there is a failure.</p>

<p>Thanks in particular to Carl Worth for having reviewed our API and having
helped test our implementation.</p>

<h2>New coverage and continuing improvement</h2>

<p>The single option choice buttons in GTK are called <code>RadioButton</code>s 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 <code>RadioButtonGroup</code>.</p>

<p><img src="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/RadioButton.png" alt="RadioButton" title=""/></p>

<p>The usual steady refinements to our coverage of the GtkTreeView API continue.
There&#8217;s a new <code>DataColumn</code> type for Stock icons, and <code>TreeModelSort</code> is now
implemented, along with minor changes to various other miscellaneous classes.</p>

<p>Considerable internal optimizations have been done, especially relating to
ensuring proper memory management, with notable refinements to make use  of
&#8220;caller owns return&#8221; information available in the <code>.defs</code> data. This fixes a
number of bugs. Thanks to Vreixo Formoso for having driven these improvements.</p>

<p>Error handling has been improved for GLib based libraries as well. If an
<code>ERROR</code> or <code>CRITICAL</code> 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.</p>

<h2>Internationalization support</h2>

<p>java-gnome now has full support for the GNOME translation and localization
infrastructure, including the standard <code>_("Hello")</code> idiom for marking strings
for extraction and translation, but combined with some of the powerful support for positional parameters available from Java&#8217;s <code>MessageFormat</code> as well. There&#8217;s a fairly detailed explanation in the
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/freedesktop/bindings/Internationalization.html"><code>Internationalization</code></a>
utility class.</p>

<h2>Build changes</h2>

<p>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.</p>

<p>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.</p>

<p>The <a href="http://java-gnome.sourceforge.net/4.0/get/">download</a> page has updated instructions for getting either binary
packages or checking out the source code.</p>

<h2>Documentation, examples, and testing</h2>

<p>Refinements to the API documentation continue across the board, notably
improving consistency. A large number of javadoc warnings have also been
cleaned up.</p>

<p>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
<a href="http://java-gnome.sourceforge.net/4.0/doc/examples/START.html"><code>doc/examples/</code></a> section.</p>

<p>This code, together with the not inconsiderable number of unit tests and the
code for generating snapshots of <code>Widget</code>s and <code>Window</code>s 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.</p>

<h2>Summary</h2>

<p>You can see the full changes accompanying a release by grabbing a copy of the
sources and running:</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr diff -r tag:v4.0.6..tag:v4.0.7
</pre>

<h2>Looking ahead</h2>

<p>It&#8217;s probably unwise to predict what will be in future releases. The challenge
for anyone contributing is that they need to understand <em>what</em> something does,
<em>when</em> to use it (and more to the point, when not to!), and be able to
<em>explain</em> it to others. This needs neither prior experience developing with
GNOME or guru level Java knowledge, but a certain willingness to dig into
details <em>is</em> necessary.</p>

<p>That said, I imagine we&#8217;ll likely see further Cairo improvements as people
start to use it in anger. It shouldn&#8217;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.</p>

<p>There are a number of other major feature improvements we&#8217;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.</p>

<p>In the mean time, people are happily <em>using</em> the library to develop rich user
interfaces, which is, of course, the whole point. We&#8217;re always pleased to
welcome new faces to the community around the project. If you want to learn
more, stop by <code>#java-gnome</code> and say hello!</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> &#8216;<code>mainline</code>&#8217; <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr clone bzr://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 05 May 2008 08:19:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.7-release</guid>
    </item>

    <item>
      <title>Cairo drawing from java-gnome</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/cairo-drawing.html</link>
      <description><![CDATA[<p>We&#8217;ve added support for the amazing <a href="http://www.cairographics.org/">Cairo Graphics</a> library to the <a href="http://java-gnome.sourceforge.net/4.0/objectives.php">Java bindings for GTK and GNOME</a>.</p>

<p>Adding Cairo is a feature we&#8217;ve been working on for about 6 months now, and so I&#8217;m pretty pleased that during the 4.0.7 development cycle we&#8217;ve been able to land it. Cairo is a huge library, of course, but we&#8217;ve put enough coverage in place to ensure that things are working.</p>

<p>Cairo has lots of convenience functions and tons of obscure uses; no surprise (and no apology) that there&#8217;s still lots that will need doing. If you want to help make sure it has what you need, then
grab &#8216;<code>mainline</code>&#8217; and see <code>org.freedesktop.cairo.</code><a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/freedesktop/cairo/Context.html"><code>Context</code></a> and <a href="http://java-gnome.sourceforge.net/4.0/doc/examples/cairo/ExampleDrawingInExposeEvent.html"><code>ExampleCairoDrawingInExposeEvent</code></a>.</p>

<p>Huge thanks go out to Behdad Esfahbod and Carl Worth; Behdad was really critical in explaining some basic Cairo concepts to get me started when we were working together at the GNOME Summit back in October in Boston, and at the GTK hackfest in Berlin in March, Carl Worth checked our preliminary APIs and helped sort me out as we were working our way through to create some examples. Awesome!</p>

<p><img src="/blogs/andrew/software/java-gnome/ExampleCairoDrawingBlends.png" alt="example" title=""/></p>

<p>java-gnome 4.0.7 should be out in the next week or two, depending on how long it takes to finish up testing, QA, and to do the release engineering.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Sat, 05 Apr 2008 23:58:00 GMT</pubDate>
      <guid isPermaLink="false">cairo-drawing</guid>
    </item>

    <item>
      <title>java-gnome 4.0.6 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.6-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read
<a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.6 (12 Feb 2008)</h1>

<p><em>Finding the missing methods.</em></p>

<p>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&#8217;s not
especially glamorous &#8212; if anything it has been tedious as hell &#8212; but the
result has been a large body of improvements to java-gnome as a whole which
we&#8217;re pleased to release as java-gnome 4.0.6</p>

<p>The bulk of this development took place on the &#8216;<code>missing</code>&#8217; branch, so named
because that&#8217;s where I was working on what was missing <code>:)</code>.</p>

<h2>Continuing Improvement</h2>

<p>Notable public changes include coverage additions to enable key stroke and
mouse button handling</p>

<p>Rather than exposing the <code>int</code> keyvals that bubble up out of the X server, we
have wrapped these as  constants of type
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gdk/Keyval.html">Keyval</a> (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
&#8220;<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gdk/MouseButton#LEFT">1</a>&#8221; is, anyway). Along with
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gdk/ModifierType.html">ModifierType</a>, this gives enough to
deal with the <code>KEY_PRESS_EVENT</code> and <code>KEY_RELEASE_EVENT</code> signals when the
developer wishes to deal with key strokes.</p>

<p>We&#8217;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&#8217;s
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Widget.html#setSizeRequest(int,%20int)"><code>setSizeRequest()</code></a>.</p>

<p>We&#8217;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.</p>

<p>After dithering for several releases, we&#8217;ve settled on how we&#8217;re going to deal
with <a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/ComboBox.html">ComboBox</a> 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&#8217;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.</p>

<p>We&#8217;ve added a few new features in our coverage of GTK&#8217;s <a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/TreeView.html">TreeView</a> / <a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/TreeModel.html">TreeModel</a> 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.</p>

<p>Support for the actual filtering in <a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/TreeModelFilter.html">TreeModelFilter</a> is notable for having been
quite tricky. The underlying C library use a function pointers rather than a
GObject signal emission, and we don&#8217;t have any mechanism to handle that. We
<em>do</em>, 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.</p>

<p>The new classes include support for TreeModel columns storing <code>long</code> data as
well as setting properties of that type.</p>

<p>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.</p>

<p>Finally lots and lots of minor additions to both public APIs and internals
deeper down in the GDK part of the toolkit.</p>

<p>As ever, you can see the full changes accompanying a release by
grabbing a copy of the sources and running:</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr diff -r tag:v4.0.5..tag:v4.0.6
</pre>

<h2>Documentation</h2>

<p>We&#8217;ve always had HTML JavaDoc for the current stable release at
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/overview-summary.html"><code>doc/api/</code></a> on the java-gnome website.
We&#8217;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&#8217;ve decided to generate the JavaDoc from &#8216;<code>mainline</code>&#8217; periodically and
upload that instead. This means that there will, of course, be descriptions of
some methods which aren&#8217;t yet available in a released version of the library,
but they will clearly identifiable by virtue of having a <code>@since</code> tag showing
a version number greater than the most recent release. We&#8217;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.</p>

<p>The idea of having up-to-date illustrations of the various Widgets has proved
popular, and we&#8217;ve continued to update the suite of snapshots. Doing that 
is <em>also</em> tedious, but it does provide a good opportunity to test APIs we are
exposing especially where unit tests are less suitable.</p>

<p><img src="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Statusbar.png" alt="Statusbar" title=""/></p>

<h2>Looking ahead</h2>

<p>Almost as complex as the TreeView / TreeModel API are GTK&#8217;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.</p>

<p>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 &#8216;<code>cairo</code>&#8217; and &#8216;<code>gconf</code>&#8217;
branches need more QA and documentation work, but they&#8217;re looking good and will
definitely be featured in java-gnome 4.0.7.</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> &#8216;<code>mainline</code>&#8217; <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr clone bzr://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p><em>Well, now that I have this out of the way, I can finally stop worrying about having so much unreleased code and get back to the business of doing what I do for a living.</em></p>

<hr/>

<p><a href="http://www.operationaldynamics.com/">
<center>
<img src="http://www.operationaldynamics.com/images/logo/logo-60x76.jpg" border="0">
<img src="http://research.operationaldynamics.com/images/andrew_Hackergotchi.png" border="0">
</center>
</a></p>

<p>On a personal note, I mentioned that much of this coverage was driven by one of our legacy apps. About half way though this cycle, however, we decided we would be abandoning that program. Needless to say, it was more than slightly depressing to be putting so much work into writing new coverage for java-gnome in order to port such a large codebase in the certain knowledge that the application was not  going to be resurrected after all, <em>especially</em> as we have not yet managed to raise any revenue to offset our costs in taking on the Java bindings for GNOME.</p>

<p><strong>Cognitive Dissonance.</strong></p>

<p>Nevertheless, I kept at it largely because getting that app to run again represented a good test of the quality and comprehensiveness of the Java bindings. It needed doing, and that has ultimately been the motivation behind all our work re-engineering java-gnome. I gotta say it <em>was</em> wonderful seeing that program come back to life bit by bit as the errors slowly fell away as missing classes and methods were added to the library. That monster running again after almost two years represents the <code>4.0</code> version of java-gnome having surpassed the level of coverage that we used from the old <code>2.</code><em>x</em> version, and that&#8217;s something to be very positive about indeed.</p>

<p>Of course, now all I have to do is to continue to resist the temptation to go back to working on that beast. <code>:)</code> No, better things to be about.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Tue, 12 Feb 2008 12:54:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.6-release</guid>
    </item>

    <item>
      <title>java-gnome 4.0.5 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.5-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read
<a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.5 (26 Nov 2007)</h1>

<p><em>TreeView is here!</em></p>

<p>It&#8217;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&#8217;s powerful yet complex TreeView &amp;
TreeModel API.</p>

<h2>TreeView</h2>

<p>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.</p>

<p>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&#8217;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 <em>and</em> be sensible to use.</p>

<p>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.</p>

<p>along with numerous test cases in our unit test suite, and several
comprehensively worked <a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/doc/examples/treeview/ExampleTrailHeads.java">examples</a>.</p>

<p>This was a monster patch, and the culmination of not just three months direct
effort, but also where we&#8217;ve been heading since we first started the
re-engineering of Java bindings for GNOME. Although largely written by Andrew
Cowie, a <em>significant</em> 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&#8217;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.</p>

<h2>Continuing Improvement</h2>

<p>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.</p>

<p>We&#8217;ve begun to get the basics of image handling in place,</p>

<p>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 <code>int</code> response codes used by GTK into something suitably
strongly-typed, but all good.</p>

<p>Finally, minor improvements to all sorts of stuff,
notably from new contributor Mario Torre. Awesome!</p>

<p>For further details you can always grab a copy of the sources and run</p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr diff -r tag:v4.0.4..tag:v4.0.5
</pre>

<p>to see the complete code delta.</p>

<h2>Screenshots</h2>

<p><img src="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Window.png" alt="" style="float: right; text-align: right; padding-left: 15px;" /> For fun we built in a capability to
create demonstrations to be captured as screenshots to illustrate various
things. It doesn&#8217;t get more basic than the example on the
<a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/Window.html"><code>Window</code></a> documentation page, but it&#8217;s a nice touch. <code>:)</code> We&#8217;ve
screenshots for a number of Dialog classes and one for the TreeView page. I
imagine we&#8217;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&#8217;ll be
expecting along with well written documentation and unit tests when submitting
additions to the public API).</p>

<h2>Building and requirements</h2>

<p>The library now depends on GTK >= 2.12. Those packaging java-gnome for their
distributions please take note.</p>

<h2>Looking ahead</h2>

<p>Continuing to expand the coverage levels in the classes already exposed will
continue to dominate our attention; there&#8217;s still a long way to go but we&#8217;re
pleased with the progress we&#8217;ve made so far; you can definitely build real
applications with java-gnome now.</p>

<p>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.</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> <code>mainline</code> <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px;">
$ bzr clone bzr://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p><em>This release marks a particularly satisfying milestone for me. I have three+ years of work that&#8217;s been waiting to be ported to java-gnome 4.0, but I&#8217;ve needed a new TreeView binding in place before I could do so. So this is a big deal for me. At last I can start thinking about getting back to actually hacking on the applications I actually</em> <strong>want</strong> <em>to be working on, and not spending so much of time on the underlying bindings themselves. There&#8217;s still a lot that needs doing on java-gnome, but it&#8217;s getting closer.</em></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 26 Nov 2007 12:37:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.5-release</guid>
    </item>

    <item>
      <title>Automatically rendering and capturing screenshots</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/automatic-screenshots.html</link>
      <description><![CDATA[<p>One of the things I&#8217;ve often noted in the API documentation for the various GNOME libraries is that the examle screenshots always seem out of date. I think this is mostly because the look and feel we all interpret as &#8220;modern&#8221; is just that which happens to be shipping with the current version of the GNOME Desktop we&#8217;re using &#8212; and that default changes fairly frequently.</p>

<p>As I&#8217;ve been working on the GTK coverage in java-gnome, I&#8217;ve had in the back of my mind that it would be really cool if we had illustrations of the various Widgets and whatnot under discussion. More than cool, actually; a lot of the people developing with java-gnome are experienced programmers but new to Linux and the GNOME Desktop, so it&#8217;s probably pretty important that we help them along in learning which controls on their desktop correspond to which Widget classes. Capturing such screenshots manually is a bit of a pain, though, and even if we did that we&#8217;d still end up with them looking out of date within a year or so.</p>

<p>So I had a bit of fun last week and knocked something together that would <em>automatically</em> take screenshots of individual Windows or fragments thereof such that we could use them in the java-gnome API documentation.</p>

<h2>Snapshots</h2>

<p>First I cooked up a scheme to make it easy to write the little programlets that draw the Windows and Widgets (I used the term <code>Snapshot</code> to refer to these; nothing as elegant as the JUnit API, but hopefully it&#8217;ll improve over time). Then I wrote a harness to instantiate the sequence of Snapshot programs and to capture a screenshot of each one in turn.</p>

<p>GNOME ships with a tool in gnome-utils called <code>gnome-screenshot</code> which is handy, but a bit too focused on being a user driven program and is not available as a library in any event. So we pulled out the parts that actually capture the image (my Lord, talk about ninja voodoo X programming &#8212; I remember working directly with Xlib back in the late 80s;I am <em>so</em> glad we don&#8217;t have to do that anymore) and made it accessible programmatically. So all <code>Harness</code> has to do is something like:</p>

<pre><code>window = snapshot[i].getWindow();
window.showAll();
window.present();

pixbuf = Screenshot.capture();
</code></pre>

<p>and then save the Pixbuf to disk in the right place so that <code>&lt;img&gt;</code> tags in our JavaDoc can pick them up. I did up examples for Window, Button, a few MessageDialogs, and TreeView. They&#8217;ll be in java-gnome 4.0.5 which will be out within the next week or so.</p>

<h2>Off screen</h2>

<p>If you did this as a zillion Windows popping up in front of you, though, you&#8217;d probably end up capturing the wrong thing if you accidentally changed apps or something. 
So instead I tried to figure out how to do it <em>off</em> screen. The solution I came up with was using the virtual X server that ships with xorg, Xvfb. By doing:</p>

<pre><code>&#036; Xvfb :1 -ac -screen 0 640x480x24 -wr
</code></pre>

<p>we have a new X server running on <code>:1</code>, and then by passing <code>--display=:1</code> to the <code>Gtk.init()</code> call used to initialize GTK, the Windows rendered by the program will be sent to the virtual server, not the desktop running on <code>:0</code>, and then we can take our screenshots there.</p>

<p>I&#8217;ve had this in mind for a while as a way to do unit tests that absolutely need to have the Window mapped to the screen. Unlike the unit test scenario, though, there&#8217;s a catch: you want the Windows to look <strong>right</strong>, ie just as they would if they were on a user&#8217;s desktop. That doesn&#8217;t happen in a naked X server though; you need a window manager running and also the magic program that makes the GTK themes according to your current preferences:</p>

<pre><code>&#036; metacity --display=:1
&#036; gnome-settings-daemon --display=:1
</code></pre>

<p>otherwise you get that rather ugly default built-in GTK fallback theme and no window decorations, which would defeat the whole point of the exercise. So hook that all up to be <code>exec()</code>d when the <code>Harness</code> program starts and everything works great!</p>

<p><a href="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/InfoMessageDialog.html"><img alt="Screenshot of a MessageDialog" src="http://java-gnome.sourceforge.net/4.0/doc/api/org/gnome/gtk/InfoMessageDialog.png" border="0"></a></p>

<p><em>I&#8217;ll have to remember to switch themes back to Clearlooks before generating the screenshots for our next release&#8230;</em> :)</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Wed, 21 Nov 2007 06:15:00 GMT</pubDate>
      <guid isPermaLink="false">automatic-screenshots</guid>
    </item>

    <item>
      <title>java-gnome 4.0.4 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.4-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read
<a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.4 (26 Sep 2007)</h1>

<p><em>Coverage increasing!</em></p>

<p>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!</p>

<h2>Documentation improvements</h2>

<p>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&#8217;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).</p>

<p>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.</p>

<h2>New coverage</h2>

<p>Numerous people have been hard at work developing new coverage. The standards
for accepting patches which expose public API are high, so it&#8217;s awesome to see
bundles accepted for being merged to <code>mainline</code> from new contributors Thomas
Schmitz, Wouter Bolsterlee, and Nat Pryce.</p>

<p>The infrastructure for a number of areas important to supporting applications
including Menus, Toolbars, and Actions has been put in place.</p>

<p>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, miscellaneous constants and wrappers around
the stock item identifiers.</p>

<h2>Internals</h2>

<p>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&#8217;s hugely
appreciated!</p>

<p>The real gains are in internal quality. A number of serious bugs and
limitations have been overcome (<code>Glade</code> is working again, for example). The
generated code now guards against improper use (you can&#8217;t pass a <code>null</code> pointer
unless it&#8217;s allowed by the underlying library). Related to this is handling of
&#8220;<code>GError</code>&#8221; &#8212; Java side, bindings hackers will get <code>GlibException</code> which they
can then re-throw as an appropriate Java Exception, say <code>FileNotFoundException</code>
in the case of not being able to open a file.</p>

<p>This all goes along with numerous build system fixes by Srichand Pendyala to
make for an increasingly robust project. Thanks guys!</p>

<h2>Looking ahead</h2>

<p>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&#8217;s powerful but complex list Widget.</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> <code>mainline</code> <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px; font-size: small;">
$ bzr branch bzr://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p><em>Note switch to</em> <code>bzr://</code> <em>protocol.</em></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Wed, 26 Sep 2007 09:54:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.4-release</guid>
    </item>

    <item>
      <title>java-gnome 4.0.3 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.3-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>As promised at GUADEC, the landmark release of Java bindings for GTK and GNOME based on generated internals has indeed been made in July! (with like five and half minutes to spare) As is traditional now, this blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read
<a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the
<a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>,
of course!</em></p>

<hr/>

<h1>java-gnome 4.0.3 (31 Jul 2007)</h1>

<p><em>The code generator has landed!</em></p>

<p>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&#8217;re pleased to announce that the code generator
is a reality!</p>

<h2>Generated translation and JNI layers</h2>

<p>The primary goal of the java-gnome 4.0 re-engineering effort has been to switch
to an architecture whereby we could <em>generate</em> the bulk of the machinery
necessary to take make native calls into the GNOME libraries from Java.</p>

<p>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 &#8220;translation&#8221; layer (the Java code that
downshifts from our Proxy objects to primitives suitable to pass over the JNI
boundary, along with the <code>native</code> declarations necessary in order to call
methods actually written in C) and of the &#8220;JNI layer&#8221; (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).</p>

<p>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 <code>mockup/</code> 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 &#8216;codegen&#8217;
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 &#8212; 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.</p>

<p>We&#8217;ve been bug hunting and refining since then, pushing towards the point where
we could merge back to &#8216;mainline&#8217;, 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.</p>

<p><em>This post on the <a href="http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/code-generator-cometh.html">development of the java-gnome code generator</a>
contains further details should you be interested; the file
<a href="http://java-gnome.sourceforge.net/4.0/doc/design/5a-Architecture.html">5a-Architecture.txt</a> in the <code>doc/design/</code> directory of the
source code explains the rationale and origin of the engineering design.</em></p>

<h2>New coverage</h2>

<p>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 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 
along with some preliminary coverage of the lower level GDK event machinery.</p>

<p>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.</p>

<p><em>People upgrading from 4.0.2 will actually notice that there are stubs for
<strong>all</strong> of the public API classes; this was necessary to make the generated
code compile. Most of these are empty as yet.</em></p>

<h2>GList and friends</h2>

<p><code>GList</code> and <code>GSList</code> 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.</p>

<h2>Flags</h2>

<p>We&#8217;ve also worked out handling of native types that, while type defined as
enums, are actually bit fields.</p>

<p>Flags subclasses present an <code>or()</code> function allowing you to combine individual
Flags constants into a new composite Flags object. Yes it&#8217;s a lot of machinery
to do a logical <code>|</code>, but being strongly typed is a hallmark of java-gnome.</p>

<h2>Build improvements</h2>

<p>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.</p>

<p>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, <code>build/faster</code> (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.</p>

<p>The internal build script <em>should</em> be transparent; you still run <code>./configure</code>
and <code>make</code> as before. If you experience problems let us know.</p>

<h2>Thread safety</h2>

<p>In addition to the code generator, java-gnome 4.0.3 incorporates a
comprehensive thread safety strategy. </p>

<p>None of the major Java graphical toolkits out there let you make GUI calls from
threads other than the &#8220;main&#8221; one; they&#8217;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 &#8220;OK&#8221;, you have to jump through horrific
contortions to do so safely, resulting in cumbersome, clunky code.</p>

<p>By contrast, the new Java bindings of GTK presented in java-gnome are
<strong>transparently thread safe</strong>, 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.</p>

<p>Every call made to the native libraries is protected by entering the &#8220;GDK lock&#8221;
[that&#8217;s <code>gdk_threads_enter/leave()</code> for those familiar with the C side of
things]. The lock used is actually a Java side <code>synchronized</code> monitor and
therefore reentrant; nested calls all behave properly. When in a signal handler
callback the GDK lock is already held (you&#8217;re &#8220;in&#8221; the main loop when a
callback happens), but since it just works transparently you don&#8217;t need to
worry about it. If you do find a need to take the lock into account explicitly
in your own code, see <code>Gdk.lock</code> in <code>org.gnome.gdk</code>.</p>

<p><em>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 &#8212; 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 <a href="http://research.operationaldynamics.com/blogs/andrew/software/gnome-desktop/gtk-thread-awareness.html">GTK thread
&#8220;awareness&#8221;</a> and <a href="http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/thread-safety-for-java.html">java-gnome&#8217;s thread
strategy</a> if you wish further details on our approach to the
thread safety question.</em></p>

<p>Thanks in particular to Owen Taylor for having helped us navigate these waters!</p>

<h2>Looking ahead</h2>

<p>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.</p>

<p>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 &#8212; public API will only be
added when it is clearly documented and meets the <a href="http://java-gnome.sourceforge.net/4.0/objectives.php">approachability</a>
criterion.</p>

<p>There are still areas where the code generator needs to be improved; we need to
improve our handling for arrays, lists, and out-parameters &#8212; there are
numerous permutations with all sorts of ugly corner cases.</p>

<p>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.</p>

<p>Most importantly, the primary focus of the next few months will be developing a
quality binding for the backbone of many applications: the <code>TreeView</code> Widget
and the underlying <code>TreeModel</code> 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&#8217;ll be a good challenge.</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or easily checkout a branch from</em> <code>mainline</code> <em>using Bazaar:</em></p>

<pre style="background: black; color: white; margin: 10px; padding: 12px; font-size: small;">
$ bzr branch http://research.operationaldynamics.com/bzr/java-gnome/mainline java-gnome
</pre>

<p><em>Back to work!</em></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Tue, 31 Jul 2007 14:25:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.3-release</guid>
    </item>

    <item>
      <title>The code generator cometh</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/code-generator-cometh.html</link>
      <description><![CDATA[<p>Calling C libraries from Java is somewhat arcane. It&#8217;s not so much that it&#8217;s &#8220;hard&#8221; as it is laborious. Once you&#8217;ve got your mind around it, however, and put the build infrastructure in place into your project (admittedly nasty learning curves), it&#8217;s not such a big deal to add another call or three on the margin. But for a library like java-gnome, which aspires to present a vast native libraries like GTK, each incremental function means an <em>enormous</em> amount of mundane and repetitive work.</p>

<h2>Old way</h2>

<p>In the old java-gnome, this Java and C code was hand written for <em>every single method</em>. Needless to day half the bugs that were in there were the kinds of errors that arise from madly doing so much cutting and pasting that your brain shuts off. Adding new coverage was insanely painful. No kidding it was abandoned.</p>

<h2>New way</h2>

<p>The primary motivation to re-engineer the Java bindings for GTK and GNOME was to switch from having to hand write all this glue code to an architecture whereby we could generate these complicated middle layers.</p>

<p>I released original prototype in November after 6 months of design work, and have been solidifying it in the java-gnome 4.0 releases so far. Obviously we had to mock up the parts that will be generated to make sure that we had the architecture right, which was no fun, because that&#8217;s right back to hand writing all the hideous boring shit in the middle. I&#8217;ve been pretty happy with it, though. The overall design has done a good job of handling unexpected corner cases as they&#8217;ve come up, and that&#8217;s always a good sign. Best of all has been the positive feedback from people who have looked at the code and complimented the design (we even had one guy come into <code>#java-gnome</code> the other day and say <em>&#8220;java-gnome is really sexy&#8221;</em>. Nice!).</p>

<p>But hand writing the glue code necessary to expand coverage sucks, <em>especially</em> when the whole point was to be generating all the boring bits. As you can see from this overview slide of the java-gnome 4.0 architecture,</p>

<p><center>
<a href="http://www.operationaldynamics.com/reference/talks/PastPresentFuture/"><img alt="java-gnome 4.0 architecture slide" src="http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/call-stack.jpg" border="0" width="640" height="480"/></a>
</center></p>

<p>it&#8217;s up to the code generator to do the bulk of the work. We needed to figure out the detailed design first, obviously, but clearly the next job is to get the machinery to output the necessary Java (code to translate from our public API into types we can safely ship across the Java/C boundary, and the native method declarations) and the corresponding C (the JNI code necessary to cast parameters and then actual call to the underlying library) &#8230; and of course the reverse direction for return values and callbacks like signals.</p>

<p>About 3 months ago we got started on it.</p>

<h2>The codegen branch</h2>

<p>The code generator has been evolving slowly but steadily. It started life as a little spike I wrote last September in Perl. That wasn&#8217;t going to scale, so <a href="http://www.srichand.net.in/">Srichand Pendyala</a> ported it to Python. He and I worked out some design issues there, but then we realized that <em>that</em> wasn&#8217;t going to scale either, so I ported it to Java. It&#8217;s been going gang busters since then, and we&#8217;ve since had lots of help from <a href="null://">Vreixo Formoso</a> and new contributor <a href="null://">Sebastian Mancke</a>. It&#8217;s getting to be quite the beasty.</p>

<p>The full stream of <code>.defs</code> data is massive; obviously the goal we&#8217;re pushing towards is to reach the point where the code generator can parse all the <code>(define...)</code> blocks therein and then output the appropriate Java and C code to implement each block.</p>

<p>So many corner cases. First time I tried it on the full data set it was <em>not</em> pretty <code>:|</code>. But we&#8217;ve been working away at it, and making painful but steady progress. Eventually I adopted the expediency of just blacklisting types that we didn&#8217;t know what to do with (an out-parameter that returns an array of arrays of GObject pointers? Fuck off!) &#8212; and finally last week I got a run that completed generation over the set of .defs files that represent GTK. That was an outstanding moment.</p>

<p>As of this writing, the java-gnome code generator outputs a translation layer of <strong>475 classes</strong> containing <strong>5454 methods</strong> (with 405 blacklisted due to requiring types that we haven&#8217;t figured out what to do with yet) and <strong>733 callbacks</strong> (signal handler prototypes, mostly). There are still 162 odd compiler errors to go (some trivial, some <em>really</em> nasty), but we&#8217;re getting there!</p>

<h2>Public API</h2>

<p>This, of course, is just the glue in the middle. But this success means we are getting closer to the point where humans can get down to the serious work of writing the wrapper code and JavaDoc necessary to present those methods and signals we wish to expose in our public API.</p>

<p>One of the less appealing things about GTK in C is that numerous internals are unavoidably visible. In a language binding like java-gnome we don&#8217;t have to expose <em>any</em> of that &#8212; indeed, one of our primary design criteria has been zero such leakage. Thus there are a not insignificant number of entities in the .defs data that we don&#8217;t need to expose. GTK <em>is</em> huge, however, and it will take a long time to get our coverage up to a respectable level.</p>

<p>Where are we now? <strong>58 public methods</strong>, 0.01%. That&#8217;d be radically embarrassing to admit, except that we gotta start somewhere. But it&#8217;s onwards and upwards from here &#8212; and although there are still quite a number of engineering design issues that have yet to be tackled, I don&#8217;t have to hand write JNI code any more, and neither do you.</p>

<p>The code generator cometh.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Fri, 08 Jun 2007 09:36:00 GMT</pubDate>
      <guid isPermaLink="false">code-generator-cometh</guid>
    </item>

    <item>
      <title>Multi-threaded GTK applications - Part 2: java-gnome</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/thread-safety-for-java.html</link>
      <description><![CDATA[<p>I have long cherished a dream to make the Java bindings for GNOME thread safe. I didn&#8217;t know if it could be done, but I sure wanted to try.</p>

<p>The workaround you had to do to be able to make GTK calls from other threads in the old java-gnome was <em>terrible</em>. It&#8217;s terrible in all the other major Java widget toolkits too. This is rather surprising, actually: one of Java&#8217;s strengths is its support for using threads. Now don&#8217;t get me wrong: multiple threads are not a panacea and I know as well as anyone that you can shoot yourself in the foot quite easily when doing threaded programming. But it is easy to get on with writing concurrent programs in Java, and threads are a fundamental feature of the runtime environment. Thus it has always struck me as a big let down that the GUI toolkits aren&#8217;t thread-safe (worse in fact: with the &#8220;GUI use must be single threaded&#8221; requirement, they are thread-hostile).</p>

<p>So I&#8217;ve been studying this for a while now. Could we do better in java-gnome 4.0?</p>

<h2>Java&#8217;s synchronization primitives</h2>

<p>Anyone who has done Java programming will be aware of the <code>synchronized</code> keyword. You can use it as a qualifier to a method:</p>

<pre><code>public synchronized void doUsefulThings() {
    // code protected by object lock
}
</code></pre>

<p>but doing so is just shorthand for:</p>

<pre><code>public void doUsefulThings() {
    synchronized (this) {
        // code protected by object lock
    }
}
</code></pre>

<p>The key point is that the object being used as the lock doesn&#8217;t <em>have</em> to be <code>this</code>; it can be any object, ie</p>

<pre><code>public void doUsefulThings() {
    synchronized (obj) {
        // code protected by object lock
    }
}
</code></pre>

<p>Java synchronized blocks have a useful property: when you exit the block the lock is automatically released. This is good to know because if an Exception is thrown from some code called within the block, the lock won&#8217;t remain held. [By comparison, if you use lock functions explicitly (such as the J2SE 1.5 <code>Lock</code> interface) then you have to manually deal with the possibility of Exceptions being thrown by always using a <code>try {}</code>  block as follows:</p>

<pre><code>Lock obj;
...
    obj = new ReentrantLock();
...

public void doUsefulThings() {
    try {
        obj.lock();
        // code protected by object lock
    } finally {
        obj.unlock();
    }
}
</code></pre>

<p>which accomplishes the same thing, trading greater flexibility (you can have locks span methods or even classes) for slightly more cumbersome code]</p>

<p>Now, getting back to creating a Java binding around the GTK and GNOME libraries:</p>

<h2>What others wouldn&#8217;t dream of considering</h2>

<p>When you enable threading in GTK, you have to obey the injunction that all of your GDK and GTK calls must be done within the main GDK lock. As I discussed in my post about <a href="http://research.operationaldynamics.com/blogs/andrew/software/gnome-desktop/gtk-thread-awareness.html">GTK thread awareness</a> last week, this is fairly easy to ignore in C code largely because callbacks to signal handlers are done within the main loop running in a single (&#8220;main&#8221;) thread (since threads are only used infrequently in GNOME programs written in C), all within the GDK lock. But if you want to work from other threads, you have to surround that code which uses GTK with <code>gdk_threads_enter()</code> and <code>gdk_threads_leave()</code> and also do things like protect <code>GIdle</code> calls, etc.</p>

<p>As I said, I want to create java-gnome as a thread-safe API &#8212; no more of the ridiculous contortions imposed on the developer just to do GUI calls from a worker thread. A few ways to achieve this come to mind. Before I learned the above it seemed that the only way to do it would be to marshal every single call through some producer-consumer queue setup to convey the call across to the main thread. Yuk! [and more on this later]. Meanwhile, I learned about the actual thread awareness mechanism in GTK, and discovered that threaded use of GTK does <em>not</em> have to be done from the main thread only but from within the main <em>lock</em>. So why not just use that?</p>

<p>Instead of the default implementation (which is just is a simplistic <code>GMutex</code>), we:</p>

<ol>
<li>use <a href="http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html#gdk-threads-set-lock-functions"><code>gdk_threads_set_lock_functions()</code></a> to call custom functions to lock and unlock.</li>
<li>have these custom functions take and release a lock on a Java object.</li>
</ol>

<p>You could certainly do (2) by calling from C back to Java via a JNI invoke and having custom <code>lock()</code> and <code>unlock()</code> methods written in Java. But rather than having to make a cross boundary call, (which would be a pain to write, is much more complicated, requires you to write your own <code>Lock</code> implementation and probably all be rather slow), JNI enables you to directly take the lock on an object!</p>

<pre><code>    (*env)-&gt;MonitorEnter(env, obj);
    // code protected by object lock
    (*env)-&gt;MonitorExit(env, obj);
</code></pre>

<p>which is precisely the C equivalent of doing:</p>

<pre><code>    synchronized (obj) {
        // code protected by object lock
    }
</code></pre>

<p>in Java!</p>

<p><em>(Yes, yes, JNI is ugly to use. Why do you think we&#8217;re rewriting java-gnome? So we can generate that layer!)</em></p>

<p>Anyway, needless to say, the custom lock functions to pass to <code>gdk_threads_set_lock_functions()</code> are pretty straight forward. All we have to do is get a C side reference to the Java object, and then call <code>MonitorEnter()</code> and <code>MonitorLeave()</code> in our <code>lock()</code> and <code>unlock()</code> functions, respectively. Too easy.</p>

<p>But why all this trouble to change the GDK lock to a synchronization monitor on a Java object? Simple: now we can use the same lock from both the GDK side and from the Java side.</p>

<p>This is brilliant, because it means we can transparently co-operate with the Java VMs thread co-ordination mechanisms, rather than fighting against them or worse ignoring them. And that suddenly means just get on with making the library thread-safe. Here&#8217;s why: <strong>Java monitors are reentrant</strong>. If the thread already holds the lock on an object and it encounters another <code>synchronized</code> block requesting the same lock, it just carries on [nesting the monitors, as you might imagine].</p>

<p>So the combination of:</p>

<ol>
<li>Replacing the default GDK lock implementation with something that enters and exits a Java object monitor (thus protecting all internal GTK usage with that lock), plus</li>
<li>A <code>synchronized</code> wrapper around each GTK call (thus protecting all Java side usage of GTK with the same lock), especially <code>Gtk.main()</code> (thus creating the condition that the main loop is running within the lock), plus</li>
<li>The (largely unwritten) fact that the GTK main loop <em>releases</em> the lock by calling <code>gdk_threads_leave()</code> when it isn&#8217;t doing anything</li>
</ol>

<p>means that other Java threads can safely make calls into GTK. Any thread that comes along while the main loop is busy will simply find the lock held by another thread (the &#8220;main&#8221; thread, as it happens) and will wait.</p>

<p>Point 3 bears closer examination. One of the other interesting details about Java <code>synchronized</code> blocks is that if a call is made to <code>Object.wait()</code> within it, the lock is silently released until the condition arises and then the thread tries to reacquire the lock so that the next instruction takes place inside the monitor as expected. Given that our wrapper code around the native call to start the main loop is this:</p>

<pre><code>static void main() {
    synchronized (Gdk.lock) {
        gtk_main();
    }
}
</code></pre>

<p>we need that <code>gtk_main()</code> behaved as if a Java <code>wait()</code> call was made and thus releases the lock so that other threads can run. Interestingly, this is exactly the effect we end up with because although this code is marked as being within the section locking the <code>Gdk.lock</code> object, as the GTK main loop cycles it releases the lock via <code>gdk_threads_leave()</code> and then reestablishes it with <code>gdk_threads_enter()</code>. The effect is that the monitor on Gdk.lock is frequently relinquished, which is the behaviour that is expected if a piece of Java code object executes <code>wait()</code> within a monitor block. Which is exactly what we need!</p>

<p>As for point 2, while no C developer working with GTK would ever have contemplated protecting every single function call, for us wrapping a <code>synchronize (lock) { ... }</code> block around each call is easy <em>(especially given that we&#8217;re generating that layer &#8212; two extra lines in the code generator, and BAMN! Done!)</em> And because the lock is reentrant (recursive if you will), the normal C reflex to avoiding nesting the GDK lock discussed in my last post is no longer applicable. The thread making the calls already holds the lock, and just proceeds merrily.</p>

<h2>But isn&#8217;t that going to be really slow?</h2>

<p>No, actually. Sun&#8217;s &#8220;Hotspot&#8221; Java VM is <em>highly</em> optimized for two particular cases:</p>

<ul>
<li>acquiring an uncontested lock, and </li>
<li>entering a block if the current thread already holds the lock in question.</li>
</ul>

<p>You see, threads needing to take locks is very common, and early on in Java it <em>was</em> a bottleneck. So they tuned the hell out of it and both are <strong>really</strong> fast. More to the point we&#8217;ve tried it, and there is no user visible performance impact. Things run really, <em>really</em> nicely.</p>

<p>Remember I dismissed arbitrary function marshaling? There are thousands of functions in GTK alone; to arbitrary wrap and pass a representation of each native function would mean creating a message object to convey every single call, with another object to wrap <em>each parameter</em>. Ouch. One of the great achievements of java-gnome 4.0 was to <em>reduce</em> the object pressure. And while we might have been able to do it this way and so have only one GUI thread, we would have completely wrecked the type-safe and simple design we have now which takes advantage of the fact that passing primitive types across JNI boundary is cheap (The very reason that primitives in Java are not objects is because sooner or later the bytes they represent will have to be passed across to native code, and so by design they optimized things to that this would be cheap. In our case, we take advantage of this by simply using JNI to make a function call with arguments on the stack. Too easy. Otherwise you have to do complex bi-directional type lookups (reflection on the Java side and the JNI equivalents in C), and doing this on <em>every</em> method and parameter really <em>would</em> be slow.</p>

<p>Against all that, the cost of grabbing a lock is trivial, and the elegance of just simply using Java&#8217;s <code>synchronized</code> mechanism is really encouraging. That&#8217;s ultimately why I&#8217;m excited about this design for giving java-gnome thread safety.</p>

<h2>java-gnome thread safety in action</h2>

<p>Below is a tread dump from a small sample demo program that I wrote. All it does is fire off a worker thread when a Button is clicked. The worker is just a tight loop to make repeated calls to update a Label with an (incrementing) number. If you&#8217;re not a Java developer you won&#8217;t be used to reading these, but even if you aren&#8217;t you will probably get the idea pretty quickly: all the worker threads are waiting on the GTK lock except <code>B</code> which has the lock and is the thread currently able to update the Label!</p>

<p><em>(For clarity, I&#8217;ve cut out the VM&#8217;s system threads)</em></p>

<pre>
Button pressed. Launching A.
Button pressed. Launching B.
Button pressed. Launching C.
Button pressed. Launching D.

Full thread dump Java HotSpot(TM) Client VM (1.5.0_08-b03 mixed mode):

"D" prio=1 tid=0x0823a3c8 nid=0x2dba waiting for monitor entry [0xa969a000..0xa969aeb0]
        at org.gnome.gtk.GtkLabel.setLabel(GtkLabel.java:52)
        - waiting to lock <0xaaaf1440> (a org.gnome.gdk.Gdk$Lock)
        at org.gnome.gtk.Label.setLabel(Label.java:67)
        at WorkerTiming.run(WorkerTiming.java:112)
        at java.lang.Thread.run(Thread.java:595)

"B" prio=1 tid=0x0822e800 nid=0x2db8 runnable [0xa9598000..0xa9599030]
        at org.gnome.gtk.GtkLabel.gtk_label_set_label(Native Method)
        at org.gnome.gtk.GtkLabel.setLabel(GtkLabel.java:53)
        - locked <0xaaaf1440> (a org.gnome.gdk.Gdk$Lock)
        at org.gnome.gtk.Label.setLabel(Label.java:67)
        at WorkerTiming.run(WorkerTiming.java:112)
        at java.lang.Thread.run(Thread.java:595)

"C" prio=1 tid=0x0823f0b8 nid=0x2db9 waiting for monitor entry [0xa9517000..0xa9517fb0]
        at org.gnome.gtk.GtkLabel.setLabel(GtkLabel.java:52)
        - waiting to lock <0xaaaf1440> (a org.gnome.gdk.Gdk$Lock)
        at org.gnome.gtk.Label.setLabel(Label.java:67)
        at WorkerTiming.run(WorkerTiming.java:112)
        at java.lang.Thread.run(Thread.java:595)

"A" prio=1 tid=0x08085fc0 nid=0x2db7 waiting for monitor entry [0xa9496000..0xa9497130]
        at org.gnome.gtk.GtkLabel.setLabel(GtkLabel.java:52)
        - waiting to lock <0xaaaf1440> (a org.gnome.gdk.Gdk$Lock)
        at org.gnome.gtk.Label.setLabel(Label.java:67)
        at WorkerTiming.run(WorkerTiming.java:112)
        at java.lang.Thread.run(Thread.java:595)

"main" prio=1 tid=0x0805c880 nid=0x2d95 waiting for monitor entry [0xbfdab000..0xbfdac138]
        at org.gnome.gtk.Gtk.gtk_main(Native Method)
        at org.gnome.gtk.Gtk.main(Gtk.java:124)
        - locked <0xaaaf1440> (a org.gnome.gdk.Gdk$Lock)
        at WorkerTiming.main(WorkerTiming.java:92)

A done.
C done.
D done.
B done.
</pre>

<p>Note the cunningly selected class name of the lock instance <code>:)</code>. Normally people just do <code>Object lock = new Object();</code> and synchronize on that. But &#8220;<code>waiting to lock a java.lang.Object</code>&#8221; isn&#8217;t as helpful as it might be, and &#8220;<code>waiting on the Gdk lock</code>&#8221;, while cosmetic, seems a nice touch.</p>

<p>One slightly weird thing is that the VM thread dump for &#8220;main&#8221; notes a marker on the stack saying where a <code>synchronized</code> block was entered which does make it look an awful lot like it&#8217;s also holding the lock. That doesn&#8217;t make any sense because JNI side <code>MonitorExit()</code> must have been called and the main loop not running else another thread couldn&#8217;t <em>be</em> running. I worried about this until I read it a bit more closely and realized it is correct: the thread itself says it is waiting to be able to enter a monitor, and the only runnable thread is indeed <code>B</code>. It&#8217;s still a bit confusing, though; I think we should see about contributing a fixing for that in the VM &#8212; something that is now possible thanks to Sun having freed Java.</p>

<h2>Conclusion</h2>

<p>Thread safety is ultimately about protecting data from being left in an inconsistent state because of a context switch. That GTK imposes the restriction that calls must all be made from within a defined lock is not unreasonable at all and a standard approach thread safety. That we have the ability to supplant that mutex with a one that takes care of additional application requirements is a really wonderful feature of GDK.</p>

<p>Code to implement this strategy in java-gnome has been implemented on a quick temporary branch (go <code>bzr</code>!) so we can kill off this idea if we have to, but so far it has handled every tricky situation we can come with to throw at it: firing new Windows, cascading signal callbacks, nested main loops, and lock starvation. While throwing a <code>synchronized</code> block around every call at first seems extreme, it doesn&#8217;t cost us much, and actually follows good practice of keeping the locked sections as small as possible.</p>

<p>It still needs more testing, but thanks very much to <a href="http://srichand.net.in/">Srichand Pendyala</a> (who worked with me to figure out that a message queue architecture for passing arbitrary calls to a single GUI thread across the JNI boundary would be a nightmare), <a href="null://">Vreixo Formoso</a> and <a href="http://blogs.gnome.org/portal/kbrae">Karsten Br&#228;ckelmann</a> (who have traced the code paths of this implementation of thread safety, listened to my arguments, and have reached the point of telling <em>me</em> why it will work and to stop worrying), <a href="http://kennke.org/blog">Roman Kennke</a> (who discussed with me his hypothesis that a recursive mutex would be a <a href="http://bugzilla.gnome.org/show_bug.cgi?id=425995">sound default</a> for the GDK lock), and as ever to our guardian angel, <a href="http://fishsoup.net/blog/">Owen Taylor</a> (who never ceases to amaze me with the quality of his contributions).</p>

<p>I have little doubt that if we follow this course of action, we will end up finding races in the underlying GTK libraries where the required <code>GDK_THREADS_ENTER()</code>/<code>GDK_THREADS_LEAVE()</code> macros were not used to protect code in idle callbacks and what not. It&#8217;s inevitable; the code paths that we are exercising are not as widely used as the more usual &#8220;all in the lock all in a single-thread&#8221; pattern that most GNOME applications written in C follow. Given the requirements of the <a href="http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html#id2755107">GDK threads</a> page, however, this would amount to a bug, and if tripping over such things occasionally (and contributing to rooting them out) is the price of a thread safe java-gnome, then it seems well worth it. Ultimately it will make the code better for everyone, and that&#8217;s what open source is about, after all.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Tue, 29 May 2007 06:56:00 GMT</pubDate>
      <guid isPermaLink="false">thread-safety-for-java</guid>
    </item>

    <item>
      <title>java-gnome 4.0.2 released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.2-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><em>This blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read <a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> &#8230; or in the <a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>, of course!</em></p>

<hr/>

<h1>java-gnome 4.0.2 (12 Feb 2007)</h1>

<p><em>The End of the Beginning!</em></p>

<h2>Major bugfixes and refactorings</h2>

<p>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 <code>g_type_name()</code> on a
GValue <em>containing</em> 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
<em>also</em> reasonably expect).</p>

<p>This led to all kinds of nastiness since the type name was what we were using
in our <code>instanceFor()</code> 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 <code>g_type_name()</code> told us
was &#8220;GtkContainer&#8221;, not &#8220;GtkVBox&#8221;! And that was a big problem, because
Container is abstract, and besides, we want to instantiate a concrete VBox
Proxy, not a Container one!</p>

<p>The solution basically boiled down to having two separate code paths: one
named <code>objectFor()</code> [a greatly simplified version of the previous
<code>instanceFor()</code>] which returns normal Proxy objects for GObject subclasses
(Buttons and Labels and whatnot), and a new code path available via
<code>valueFor()</code> to specifically return our GValue Proxy for the cases where we
know we&#8217;re getting a GValue back. Since that occurs in limited and known
circumstances only (ie, when we&#8217;re getting properties) it&#8217;s no problem to know
which to use when.</p>

<p>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.</p>

<p>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.</p>

<p>This allowed a further simplification of the <code>valueFor()</code> mechanism and even
more smashing about in Plumbing with a chainsaw. Net result was a <em>reduction</em>
by several hundred lines of code. Yeay!</p>

<p>All of these changes were confined to the internals of the binding machinery
and are not user visible.</p>

<h2>Loading <code>.glade</code> files</h2>

<p>User interface designers are nothing new, but one of the really cool things
about GTK has long been the existence of <code>libglade</code>. It&#8217;s a library which
takes the output of a one of the GNOME user interface designers (such as such
as <strong>Glade 3</strong> or <strong>Gazpacho</strong>) and dynamically, at runtime, generates live
Windows full of Widgets!</p>

<p>With the arbitrary Proxy retrieval sorted out, the beginnings of a binding of
<code>libglade</code> was possible. None of the fancy stuff is there yet, but a <code>.glade</code>
file can be loaded, and Widgets retrieved from the instantiated tree.</p>

<p>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&#8217;ll
see.</p>

<h2>Testing framework</h2>

<p>We&#8217;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.</p>

<p>You can run the suite from Eclipse, by specifying a JUnit 3 launcher on class
UnitTests in the default package in <code>tests/java</code>, or by running </p>

<pre><code>&#036; make test
</code></pre>

<p>the command line.</p>

<h2>Further coverage</h2>

<p>This release also sees the addition of <code>FileChooser</code>, <code>FileChooserButton</code>, 
<code>FileChooserDialog</code> etc.
This is significant because GtkFileChooser is an <em>interface</em> in GTK, and
GtkFileChooserButton implements it. We&#8217;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.</p>

<p>Finally, a number of new signals were exposed on <code>Widget</code>
though these were mostly the result of doing live demonstrations at
conferences of how easy extending the coverage of the new bindings is.</p>

<h2>Memory management</h2>

<p>We have successfully implemented full GObject memory management in java-gnome
4.0 using GLib&#8217;s ToggleRef mechanism.</p>

<p>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 <em>does</em> 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()&#8217;d and destroyed.</p>

<p>You can watch the reference system in action if you set
<code>Debug.MEMORY_MANAGEMENT</code> to <code>true</code>.</p>

<p>Huge thanks go to Vreixo Formoso Lopes who collaborated on the design,
reviewed the implementation, and contributed test case code.</p>

<h2>Build system improvements</h2>

<p>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.</p>

<p>On the eve of release, Srichand Pendyala noticed that if you are running such
a system, a package named <code>libglade-dev</code> 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&#8217;ll add a check for this Debian
specific behaviour in 4.0.3.</p>

<p>The <code>VERSION</code> and <code>APIVERSION</code> constants were moved to <code>org.gnome.gtk.Version</code>
so that anyone working on the Gtk main class isn&#8217;t forced to do a
re-configuration every time they save.</p>

<h2>Installation and Packaging</h2>

<p>java-gnome 4.0 now has the standard <code>make install</code> command, and the equally
standard <code>--prefix</code> option to <code>./configure</code>.</p>

<pre><code>&#036; ./configure --prefix=/usr
&#036; make
&#036; sudo make install
</code></pre>

<p>The <code>install</code> target understands the <code>DESTDIR</code> variable used by packagers to
install to a specified prefix <em>within</em> a temporary directory.</p>

<p>See the <a href="README.html"><code>README</code></a> file for details.</p>

<hr/>

<p><em>The feature additions described above were done to bring java-gnome up to
speed for the GTK &amp; GNOME tutorial given at <a href="http://lca2007.linux.org.au/talk/258">linux.conf.au</a>. With that
past, we&#8217;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 <code>.defs</code> files and output the translation code.</em></p>

<p><em>And so my firm returns to focusing on securing the funding needed to develop the project. Once more into the breach! When we succeed, the code generator will be our top priority and shouldn&#8217;t take more than a couple months to complete.</em></p>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>or clone a branch from</em> <code>mainline</code> <em>in our DVCS.</em></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 12 Feb 2007 13:03:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.2-release</guid>
    </item>

    <item>
      <title>First tarball in the java-gnome 4.0 series released!</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-4.0.1-release.html</link>
      <description><![CDATA[<p><a href="http://java-gnome.sourceforge.net/">
<center>
<img src="http://java-gnome.sourceforge.net/images/java-gnome_LargeLogo.png" border="0">
</center>
</a></p>

<p><strong>After 9 months of design, engineering, and mad coding, I am pleased at long last to make the first public release of the new java-gnome bindings.</strong></p>

<p><em>We are now at the state where we have not just a theory but a working architecture that has been validated through interaction online and at conferences with the community around the world. My firm, Operational Dynamics, has sponsored the work to this point, and we are now seeking revenue to carry out the engineering necessary to take the bindings from a prototype with coverage of 0.1% to the level where it will be a fully usable binding. If you think your firm would be interested in engaging us to this end, or to ensure a piece of GNOME that you need is present, then please contact Andrew Cowie, <a href="mailto:andrew&#64;operationaldynamics.com">andrew&#64;operationaldynamics.com</a>.</em></p>

<p><em>If it isn&#8217;t obvious, there&#8217;s still quite a bit of fluidity, and so I recommend to our downstream that it&#8217;s not quite yet time to package up java-gnome 4.0 for your distro. I&#8217;ll be in touch with the individual package maintainers in the coming months. Likewise for developers, yes, it&#8217;s exciting, but no, it&#8217;s not really ready for writing full apps with (though one guy did write something to show the cricket scores!). So while it is not really prime time (indeed, me even blogging about it smacks a bit of preemption), the open source vibe has ever been to release early and often so that others can participate. If you want to have a voice in the shape of the Java bindings for GTK and GNOME, you&#8217;re welcome to get involved.</em></p>

<p><em>The rest of this blog post is the release note from the</em> <code>NEWS</code> <em>file which you can read <a href="http://java-gnome.sourceforge.net/4.0/NEWS.html">online</a> or in the <a href="http://research.operationaldynamics.com/bzr/java-gnome/mainline/NEWS">sources</a>, of course!</em></p>

<hr/>

<h1>java-gnome 4.0.1 (05 Jan 2007)</h1>

<p><em>It&#8217;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.</em></p>

<p>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&#8217;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:</p>

<h2>Project documentation</h2>

<p>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 <a href="http://java-gnome.sourceforge.net/4.0/README.html"><code>README</code></a> and
<a href="http://java-gnome.sourceforge.net/4.0/HACKING.html"><code>HACKING</code></a> 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 <a href="http://java-gnome.sourceforge.net/4.0/doc/design/README.html"><code>doc/design/</code></a> and
<a href="http://java-gnome.sourceforge.net/4.0/doc/style/MARKUP.html"><code>doc/style/</code></a>.</p>

<h2>Project website</h2>

<p>Create an entirely new website for <a href="http://java-gnome.sourceforge.net/">http://java-gnome.sourceforge.net/</a>,
introducing sections &#8220;<a href="http://java-gnome.sourceforge.net/4.0/">About</a>&#8221;, &#8220;<a href="http://java-gnome.sourceforge.net/4.0/doc/">Documentation</a>&#8221;,
&#8220;<a href="http://java-gnome.sourceforge.net/4.0/get/">Download</a>&#8221; and &#8220;<a href="http://java-gnome.sourceforge.net/4.0/lists/">Interact</a>&#8221; 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
<a href="http://java-gnome.sourceforge.net/2.x/">2.x</a> bindings have been unmaintained for some time now and are
formally deprecated.</p>

<p>The website is no longer a wiki but is entirely within the source code of
java-gnome itself. See the <code>web/public/</code> directory; improvements welcome.</p>

<h2>Major engineering</h2>

<p>Quite significantly, the infrastructure to get a Proxy or Constant instance
for any arbitrary C side pointer or enum is complete, involving <em>significant</em>
work to the <code>Plumbing</code> classes,
along with the corresponding C side code, especially in <code>GValue.c</code></p>

<p>This was a necessary building block in order to complete the generalized
<code>getProperty()</code> 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.</p>

<h2>New coverage</h2>

<p><code>Label</code>, <code>Fixed</code>, <code>Box</code>, <code>VBox</code>, <code>HBox</code>
and corresponding [working] mockup translation and native code.</p>

<p>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 <code>bzr bundle</code> submission process. Awesome.</p>

<h2>Build improvements</h2>

<p>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.</p>

<p>The tiny example program that we have been using to validate the code,
<code>Experiment</code> is now compiled by the build system if you so request. Try <code>make
demo</code>.</p>

<h2>API documentation</h2>

<p>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.</p>

<p>All source code [comments, ie JavaDoc] have been spell checked! Initial top
level <code>overview.html</code> and <code>package.html</code> files have also been written to help
round out the JavaDoc.</p>

<h1>java-gnome 4.0.0 (26 Nov 2006)</h1>

<p><em>Initial release of the java-gnome 4.0 prototype, corresponding to the first
public demonstration of the new bindings done at
<a href="http://foss.in/2006/">foss.in/2006</a> at Bangalore, India.</em></p>

<p>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.</p>

<h2>Initial coverage</h2>

<p>Wrapper layer presenting the public API to developers: <code>Widget</code>, <code>Container</code>, <code>Bin</code>,
<code>Button</code>, <code>Window</code>, along with complete translation layer implementations.</p>

<p>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&#8217;t want to be
writing much more translation layer Java and C code by hand. Yuk.</p>

<h2>Signal API</h2>

<p>The defining aspect of GUI programming is, of course, that it is event driven.
In addition to the &#8220;forward&#8221; direction of making calls to the native library
and having return values bubble back up, there is the &#8220;reverse&#8221; direction of
connecting callback handlers to the various signals that different Widgets
offer, and having those signal events result in those handlers being invoked.</p>

<p>java-gnome 4.0 has an entirely new and redesigned signal connection and
callback API. This functionality was demonstrated, and coverage of
<strong><code>Button.CLICKED</code></strong> and <strong><code>Window.DELETE</code></strong> 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&#8217;s hooked up, and it works. It&#8217;s like black
magic :)</p>

<h2>Build</h2>

<p>java-gnome is configured and built using Andrew Cowie&#8217;s Equivalence build
scripts. It builds on Gentoo and should build on a Debian or Fedora derived
system as well. See <a href="http://java-gnome.sourceforge.net/4.0/README.html"><code>README</code></a> for further details.</p>

<p>At the moment, java-gnome is a single source package. That <a href="http://java-gnome.sourceforge.net/4.0/doc/design/3a-PackageNames.html">may or may not</a> change.</p>

<p>The source code is available via <strong><code>bzr</code></strong>. Again, see <code>README</code>.</p>

<hr/>

<p><em>You can download java-gnome from</em> <a href="http://ftp.gnome.org/pub/GNOME/sources/java-gnome/4.0/"><code>ftp.gnome.org</code></a> <em>but at this stage you&#8217;re just as well off to get the code from</em> <code>mainline</code> <em>in our DVCS. I&#8217;m pleased to say it&#8217;s moving quickly.</em> :)</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Fri, 05 Jan 2007 14:48:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-4.0.1-release</guid>
    </item>

    <item>
      <title>Spell checking Java source code</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/spell-checking-source-code.html</link>
      <description><![CDATA[<p><em>Dammit, Jim, I&#8217;m an Engineer, not an English major!</em></p>

<p>API documentation is incredibly important, but unlike tutorials or other reference documents that can be written in conventional text editors or word processors with nice built in spell checkers, the public API of a Java project is conveyed through JavaDoc comments that are contained in source code right next to each class and method as they are declared. We necessarily find ourselves with tons of generated web pages covered in prose&#8230; and full of spelling mistakes.</p>

<p>So I&#8217;ve had it in mind for a while to run <strong><code>aspell</code></strong> over the java-gnome sources. Raving insanity, that&#8217;s for sure. Spell check <em>source code</em>? Are you mad?</p>

<p>Well, being suitable euphoric on New Year&#8217;s Day, I decided &#8220;what the hell, why not&#8221; and gave it a try. One thing that was obvious was that I was going to end up with a ridiculous number of unknown words that were going to need adding. Rather than 
filling my personal dictionary (the one in <code>&#036;HOME</code>) with tons of project specific crud, I used <code>aspell</code>&#8217;s -p option to specify a new word list in the project&#8217;s top level directory. Easy enough with <strong><code>bzr</code></strong> &#8212; they&#8217;ve got a <code>bzr root</code> command that tells you the path of the project root. Nice.</p>

<p>Here&#8217;s the command line I used:</p>

<pre><code>aspell -x -c -p `bzr root`/.aspell.en.pws -H Button.java
</code></pre>

<p>It worked pretty well. The tokens sure did add up in a hurry, though. Java language keywords? Ok, no problem. Class names? Sure, makes sense to add them &#8212; many had already turned up when spell-checking other documentation in the project. But uh oh: it wants to know about <code>getLabel(</code> and <code>num</code> and <code>x</code> and every other bit of source code. Yikes. Quite the pain to add all that stuff while working through the files just to get to the JavaDoc and normal comments in order to fix the spelling in the text there.</p>

<p>But worth it&#8230; we now have spell checked API documentation!</p>

<p>What would really be neat is to write a little module for <strong><code>aspell</code></strong> that adds a mode that understands to only spell check stuff between <code>/*</code> and <code>*/</code> characters. The <code>-H</code> flag above tells <strong><code>aspell</code></strong> to ignore HTML markup, and there are modes for LaTeX and others. So hopefully a &#8220;source code&#8221; mode would be feasible, and I could start again and have a slightly better signal-to-noise ratio :)</p>

<p>Happy New Year!</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Thu, 04 Jan 2007 23:01:00 GMT</pubDate>
      <guid isPermaLink="false">spell-checking-source-code</guid>
    </item>

    <item>
      <title>java-gnome 2.14.3 released</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-2.14.3-release.html</link>
      <description><![CDATA[<p>Last week the java-gnome project did a point release of the stable branch of the Java bindings allowing you to write GTK and GNOME programs from Java. The 2.14.3 set of tarballs consist of:</p>

<pre><code>glib-java      0.2.6
cairo-java     1.0.5
libgtk-java    2.8.7
libgnome-java  2.12.5
libglade-java  2.12.6
libgconf-java  2.12.4
libvte-java    0.12.1
libeds-java    0.5.1
</code></pre>

<p>As one would expect of a version number like 2.14.3, this release consists mostly of bugfixes and minor changes improving stability.</p>

<p>Of particular note are <a href="http://bugzilla.gnome.org/show_bug.cgi?id=354283">large contributions</a> of patches and cleanups to the example code which ships with the sources of each library in <code>doc/examples</code> from the Sun team in Ireland. You guys are terrific. This effort was led by Michal Pryc.</p>

<p>You can download the tarballs making up this release from <a href="http://ftp.gnome.org/pub/GNOME/sources/"><code>ftp.gnome.org</code></a>. Anyone interested in learning more about writing GTK and GNOME applications using Java can either go to our website, <a href="http://java-gnome.sourceforge.net/"><code>java-gnome.sourceforge.net</code></a> , or join us in <code>#java-gnome</code> on GIMPnet.</p>

<p>Meanwhile, work continues on what will become the java-gnome 2.16.0 set, which should hopefully be released soon.</p>

<p><em>As has been noted in several emails to both the java-gnome-developer and java-gnome-hackers mailing lists, we are engaged in a re-engineering of the Java bindings around the GNOME libraries, and so a major API break is expected after the java-gnome 2.16 series.</em></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 25 Sep 2006 13:35:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-2.14.3-release</guid>
    </item>

    <item>
      <title>java-gnome team IRC meeting</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/team-meeting.html</link>
      <description><![CDATA[<p>The various people interested in the <a href="http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/"><code>java-gnome</code></a> project
are having a team meeting tomorrow, 272100Z Apr 06.
Anyone contributing to or using java-gnome, or interested
in writing GTK and GNOME from Java is welcome to attend.</p>

<p>Times are as follows;</p>

<pre>
        Hawaii       11:00 Thu, 27 Apr 06  (HST) -10
        Los Angeles  14:00 Thu, 27 Apr 06  (PDT)  -7
        <font color="blue">Toronto      17:00 Thu, 27 Apr 06  (EDT)  -4</font>
        New York     17:00 Thu, 27 Apr 06  (EDT)  -4
        Fredericton  18:00 Thu, 27 Apr 06  (ADT)  -3
        Brazil       18:00 Thu, 27 Apr 06  (BRT)  -3
        <font color="green">Zulu         21:00 Thu, 27 Apr 06  (UTC)  +0</font>
        <font color="blue">London       22:00 Thu, 27 Apr 06  (BST)  +1</font>
        Paris        23:00 Thu, 27 Apr 06 (CEST)  +2
        Dubai        01:00 Fri, 28 Apr 06  (GST)  +4
        Bangalore    02:30 Fri, 28 Apr 06  (IST)  +5.5
        Perth        05:00 Fri, 28 Apr 06  (WST)  +8
        Singapore    05:00 Fri, 28 Apr 06  (SGT)  +8
        Adelaide     06:30 Fri, 28 Apr 06  (CST)  +9.5
        Brisbane     07:00 Fri, 28 Apr 06  (EST) +10
        <font color="blue">Sydney       07:00 Fri, 28 Apr 06  (EST) +10</font>
        Auckland     09:00 Fri, 28 Apr 06 (NZST) +12
</pre>

<p>We&#8217;re going to chat about architecture directions, release schedules, goals and
figure out what might be feasible. Topics up for discussion include:</p>

<ul>
<li>ways we could refactor things that need improving, such as
the signal API.</li>
<li>perhaps cutting out the ridiculous amount of code that&#8217;s cut and pasted as we
extend the coverage of the bindings. That leads to considering whether or not
things are generated, and if so, how much, what and how?</li>
<li>questions like &#8220;how do we unit test the bindings&#8221;?</li>
<li>release schedules.</li>
<li>reducing the barrier to entry for new developers wanting to use our code and
even more importantly making it easier for new people to contribute to the
maintenance and evolution of the bindings themselves.</li>
</ul>

<p>Some of these are <strong>huge</strong> tasks (at least in terms of their
invasiveness) so if we are to embark upon them it means severe API break
(<em>fine</em>), fairly prolonged effort (<em>tougher</em>) from a fairly large number of people
(<em>who grow on trees like money, right?</em>)</p>

<p>Nevertheless, these are all lovely ideas. They just need some design and focus. So
we&#8217;ll chat about all these things, and see where we&#8217;re going. <code>java-gnome</code> has
been going as a project since 1998 and is on it&#8217;s 5th team of maintainers!
That&#8217;s an excellent legacy, and now it&#8217;s up to the current generation to take
it to the next level.</p>

<p><code>java-gnome</code> is a rather unique project in the open source space in that it
opens up GTK and GNOME to a whole legion of people who have long been
interested in contributing but who, being Java developers,
have been somewhat ignored and even snubbed by the core desktop hackers. Times
they are a changin&#8217;, and it&#8217;s awesome to be a part of bringing new communities
to the free software world.</p>

<p>Meeting in <code>#java-gnome</code> on <code>irc.gimp.net</code>, of course. See <a href="http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/AgendaTeamMeeting">AgendaTeamMeeting</a>
for some idea of what we might talk about.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Thu, 27 Apr 2006 13:33:00 GMT</pubDate>
      <guid isPermaLink="false">team-meeting</guid>
    </item>

    <item>
      <title>java-gnome 2.14.0 released</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-2.14.0-release.html</link>
      <description><![CDATA[<p>After months of sterling effort, the java-gnome team has released the 2.14.0 set of tarballs, consisting of:</p>

<pre><code>glib-java 0.2.4
cairo-java 1.0.3
libgtk-java 2.8.4
libglade-java 2.12.3
libgnome-java 2.12.2
libgconf-java 2.12.2
</code></pre>

<p>The release is the culmination of an incredible amount of work from the diverse community of people who contribute to the java-gnome project. The effort for the past six months and more has been focused on stability, but this has come from a very practical direction: increasing numbers of people using java-gnome libraries, especially the flagship GTK bindings in libgtk-java, have uncovered bugs, spruced up documentation, improved memory management, and increased the number of platforms we build on.</p>

<p>In particular, huge kudos goes to the <a href="http://sourceware.org/frysk/"><code>frysk</code></a> team, largely centred out of Red Hat&#8217;s Toronto office, for having made a huge contribution: java-gnome now builds and runs crash free on 64 bit systems! The effort to do so was not merely the fringe effort of another marginal architecture, but involved dramatically improving the code throughout the JNI layer of the various libraries (where the Java code can talk to C code and thus interface with the underlying Glib, GTK, and GNOME libraries). While running on 64 bit machines is the obvious outcome, this work has benefited every user of java-gnome in terms of increased performance, reduced memory footprint and dramatically improved stability. This effort was led by Andrew Cagney.</p>

<p><em>This work did involve an ABI compatibility break, so the bump from 2.12.x to 2.14.x of the &#8220;version&#8221; of the overall family signifies this ABI change. People using the libraries built with GCJ to create native executables will have to relink their applications. For this reason and others, we are <a href="http://sourceforge.net/mailarchive/forum.php?thread_id=9945944&amp;forum_id=11301">contemplating</a> an epoch shift in our major version number so that we use version number changes appropriately as ABI and API changes happen in our libraries rather than whatever may or may not be happening on the libraries below. For the moment, however, we have kept the our individual library versions tracking the minimum required version of the underlying library they bind.</em></p>

<p>The last several months have seen bug reports and code contributions from a number of developers new to the project. This release could not have happened without the hard work of these people in tracking down issues and taking the time to report - and in many cases, fix - the problem. Of course, acknowledgements have to be made to the current java-gnome hackers: Ismael Juma, Andrew Cagney, Adam Jocksch, Sami Wagiaal, Igor Foox, Joao Victor, and Remy Suen. Developers out in the real world have been reporting bugs and making code contributions as well: Sandor Bodo-Merle, Lars Weber, Emmanuel Rodriguez, Damian Minkov, Nicholas Lativy and Sean Coughlan. And out of nowhere, Dan Williams, a very experienced hacker indeed, has been single handedly rescuing our Cairo bindings. Fantastic. It&#8217;s awesome to have all of you using this code and contributing to its improvement - truly this is software libr&eacute; in action. </p>

<p>There are two people who need to be singled out. Firstly I would highlight the work of Remy Suen, who has tirelessly been going through bugzilla, reproducing what are often old or neglected bugs and in many cases implementing fixes! This is the sort of work that is usually thankless but it makes all the difference to the people affected by issues, and ultimately, to everyone using the code. Thanks Remy!</p>

<p>The other person is Ismael Juma. Alone of the previous generation of developers, Ismael has stuck with the project. He has a phenomenal knowledge of the architecture of java-gnome, especially on the memory management side, and has patiently guided numerous developers, old and new, to understand how they can best approach coding a solution to a problem. Ismael&#8217;s willingness to review code and offer insightful critique is the backbone of the project. Ismael, we don&#8217;t always agree, but you&#8217;re a pleasure to work with. Awesome job, mate.</p>

<p>You can download the java-gnome tarballs making up this release <a href="http://research.operationaldynamics.com/linux/java-gnome/">here</a>. Anyone interested in learning more about writing GTK and GNOME applications using Java can either go to our website, <a href="http://java-gnome.sourceforge.net/">java-gnome.sourceforge.net</a> , or join us in <code>#java-gnome</code> on GIMPnet.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Sun, 26 Mar 2006 10:49:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-2.14.0-release</guid>
    </item>

    <item>
      <title>An ebuild for GCJ-4</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/gcj-jdk-4.1.0-preliminary-ebuild.html</link>
      <description><![CDATA[<p>For some time now I&#8217;ve been working on trying to get GCJ 4.x.y going on my machine. I run Gentoo which usually implies that I have rapid access to the latest of anything I need. The exception is GCC; being a system upon which one compiles just about everything from source, the system compiler is the one thing that really, <em>really</em> needs to work. So I am happily running <code>gcc-3.4.3</code> which is fine, except that I really want <code>gcj-4</code> for my Java development work.</p>

<p>A while back I posted about some <a href="http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/gcj-4.0.0-linking-problem.html">linking issues</a> I was running in to. An update on that: Over the past few months, the guys at Red Hat in Toronto finally figured out that in addition to all the the <code>LD_LIBRARY_PATH</code> nonsense and <code>-Wl,-rpath=</code> stuff I was hacking away with, the traditional Java <code>-Djava.library.path=</code> would work with GCJ. [In fact, it appears that it is necessary to do so to talk to the <code>System.loadLibrary()</code> calls].</p>

<p>But I still needed a modern GCJ to compile with. I&#8217;ve been working with <a href="http://journal.boblycat.org/karltk/">Karl Trygve Kalleberg</a> and others about figuring out an ebuild that would install GCJ without getting in the way of the system&#8217;s primary GCC install. I&#8217;ve long since figured out building GCC manually, but I wanted an ebuild to use the large collection of libraries that the Gentoo compiler team had already worked out for figuring out tarball names, fetching, patching and what not. So over the last couple days I gave it another go. Success!</p>

<p>This time I wrote an ebuild that uses the <code>toolchain</code> eclass for <code>src_unpack()</code> which has lots of magic. I didn&#8217;t use it for <code>src_compile()</code> as it was a little to hard to constrain its configure to behave with the <code>&#036;PREFIX</code> I  wanted, but I was able to pull a few useful tidbits.</p>

<p>I have called my ebuild <code>gcj-jdk</code>. It installs to <code>/opt/gcj-jdk</code> which goes nicely alongside <code>/opt/sun-jdk-1.4.2.04</code> (also vaguely following the naming conventions that Red Hat is using) I wonder if version number or at least <code>-4</code> or <code>-4.1</code>  would be a good idea&#8230; and <code>SLOT</code>ing? One thing I have <strong>not</strong> done is try to do the <code>java-gcj-compat</code> thing the Fedora guys did (scripts that are  wrappers that emulate <code>java</code> and <code>javac</code>) &#8212; as I told <code>#gentoo-java</code> last night, someone else is welcome to grab that and add it &#8212; but from where I sit <code>gcj -C</code> is a tricky beast (and <code>gcj -c &amp;&amp; gcj --main</code> are even more complex);  just assuming it and <code>gij</code> are a drop in replacement for a Real Java VM is asking for trouble.</p>

<p>I used <code>4.1.0_beta20051105</code> which is the most recent snapshot as of last week, but I had to use <code>--disable-java-awt</code> (and for good measure disabled the other GTK/glib/cairo stuff) &#8230; being a java-gnome hacker I surely don&#8217;t need AWT but for whatever reason <code>--enable-java-awt=gtk</code> was causing the build to break.</p>

<p>Release early, release often&#8230; so here you go: <a href="http://research.operationaldynamics.com/linux/gentoo/dev-java/gcj-jdk/"><code>gcj-jdk-4.1.0_beta20051105</code></a>. It&#8217;ll want a recent <code>binutils</code> (I needed <code>~x86</code>) and a recent <code>glibc</code> as well. Use at own risk!</p>

<p>Things that still need doing:</p>

<ul>
<li>figure out which patches in <code>files/</code> are actually needed</li>
<li>make sure that it <strong>really</strong> is not interfering or interacting with <code>gcc-config</code></li>
<li>decide on a destination naming convention (<code>/opt/gcj-jdk-4.1</code>? <code>/opt/gcj-4</code>?)</li>
<li>try and trim the install down [2 seconds after <code>./configure</code> fires off it mentions that it&#8217;s decided to build <code>fortran</code> and <code>objc</code> as well as <code>c</code> and <code>c++</code> and java. C and C++ are probably unavoidable, but the first two? Dependencies probably need trimming as well.</li>
<li><code>java-config</code> integration if <code>java</code> and <code>javac</code> wrappers get put in?</li>
</ul>

<p>Comments welcome to <a href="mailto:gentoo-java@lists.gentoo.org"><code>gentoo-java</code></a></p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Mon, 14 Nov 2005 06:22:00 GMT</pubDate>
      <guid isPermaLink="false">gcj-jdk-4.1.0-preliminary-ebuild</guid>
    </item>

    <item>
      <title>java-gnome 2.12.1 released</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/java-gnome-2.12.1-release.html</link>
      <description><![CDATA[<p>The <a href="http://java-gnome.sourceforge.net/"><code>java-gnome</code></a> team is pleased to announce the release of java-gnome 2.12.1, comprising:</p>

<pre><code>glib-java     0.2.1
cairo-java    1.0.1
libgtk-java   2.8.1
libgnome-java 2.12.1
libglade-java 2.12.1
libgconf-java 2.12.1
</code></pre>

<p>You can read the <a href="http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/NewsTwoTwelveOne">release notes</a> for this iteration on our wiki. This set is, of course, mostly bug fixes; for more detailed information, see the release news item we wrote when we <a href="http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/NewsTwoTwelveZero">released libgtk-java 2.8.0</a> a few weeks ago.</p>

<p>You can download the sources from our <a href="http://research.operationaldynamics.com/linux/java-gnome/">download page</a>. [We don&#8217;t have access to <code>ftp.gnome.org</code>, so my firm has been hosting the release tarballs for this cycle].</p>

<p>Gentoo users: I&#8217;ve updated the ebuilds I maintain; you can grab the <a href="http://research.operationaldynamics.com/linux/gentoo/#java-gnome">ebuilds</a> from our site as well (submitted Gentoo bugzilla as <a href="http://bugs.gentoo.org/show_bug.cgi?id=108142">#108142</a>)</p>

<p>As ever, discussion about the direction and development of these language bindings takes place on the <code>java-gnome-hackers</code> <a href="http://sourceforge.net/mailarchive/forum.php?forum=java-gnome-hackers">mailing list</a>; if you&#8217;re interested in <em>using</em> java-gnome for your own projects and looking for a helping hand, don&#8217;t hesitate to ask on <code>java-gnome-developer</code>, also at SourceForge. Or join us in <code>#java-gnome</code>, on GIMP-net.</p>

<p>AfC</p>
]]></description>
      <author>andrew@operationaldynamics.com (Andrew Cowie)</author>
      <category>/andrew/software/java-gnome</category>
      <pubDate>Tue, 25 Oct 2005 22:22:00 GMT</pubDate>
      <guid isPermaLink="false">java-gnome-2.12.1-release</guid>
    </item>

    <item>
      <title>Testing the GTK 2.6 to 2.8 upgrade path - Part 2</title>
      <link>http://research.operationaldynamics.com/blogs/andrew/software/java-gnome/gtk26-to-gtk28-part2.html</link>
      <description><![CDATA[<p>I&#8217;ve been testing the upgrade path for <a href="http://java-gnome.sourceforge.net/"><code>java-gnome</code></a>. Last week I <a href="http://research.