Vertical text align of radio buttons in java

I have been doing some GUI java code in both swing and SWT recently and find text alignment a niggling annoyance of mine. Often you want to align components with the text line vertically of combo or check boxes.

Here is the code for determining the width in pixels for the two most popular GUI libraries in java. Both are cross platform/look-and-feel solutions.


JRadioButton radio = new JRadioButton();
int raddioButtonOffset =
    + radio.getIconTextGap()
    + radio.getInsets().left;


// get the width of a space
GC gc = new GC(parent);
int spaceWidth = gc.getAdvanceWidth(' ');

// create radio widget to get widths
Button radioButton = new Button(parent, SWT.RADIO);
Point baseSize =
    radioButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
radioButton.setText(" ");
Point withSpaceSize =
    radioButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);

int radioButtonOffset =
    - ((withSpaceSize.x - baseSize.x) / 2)
    - spaceWidth;

Down again?

This week the blog went down again with “500 Internal Server Error” again. This time however I believe that the problem has been resolved for good this time however.

Back when I started this blog in 2003 with WordPress 1.0 there was no WYSIWYG editor so I wrote the first 18 months of posts in Textile before WordPress 2.0 was released with the TinyMCE editor for writing posts. And after that I couldn’t be bothered re-formatting them so I left the Textile plugin turned on and as it turns out it created the problems so hopefully it’s all finished with now. Thanks again to the support staff of Profusehost.


I have become a bit obsessed with the java community lately more in a consuming fashion than a participatory fashion, reading Java Desktop and listening to the Java Posse and it just keeps coming up how much everyone loves Netbeans and that everyone should be using it for Java development.

Features such as Mattise look to be very good and a great reason to use the IDE. However as an Eclipse user there are just too many features that I miss to change IDE for now.

  1. Per project settings including templates and code style
  2. Macro for YEAR for code templates
  3. Incremental compiler.
    On a small project of only one file takes a good 3 seconds just to launch even if it is built. Like really do you need to build a jar always when executing projects? As good as running everything through ant sounds it is just too slow when compared to what you get for free with eclipse.
  4. Editor support.
    Supposibly the java editor is greatly improved for version 6, however in the test build I used M9 it is still slow, non intuitive and just painful give me eclipses Ctrl-1 quick fix any day.

Completion in the IDE space is good but for my everyday java development it is still impossible for me to switch.

gstreamer port to Java

It has long been discussed in the java community about the lack of a good multimedia framework for the platform. After reading Chris Adamson’s wrap up of his JavaONE BoF I felt here is a cause I could really get behind.

I starting thinking yes wouldn’t it be great if gstreamer was ported to java. I started doing some research and grabbed a copy of the gstreamer cvs. But just as I was getting my hopes up I read that sun was going to do something about multimedia. But by the time I got to the end of the blog entry I realized that it is a smaller project of giving a common java wrapper for the platform services ie Qucktime on OSX, DirectShow on Windows and I guess gstreamer on Linux.

As the days went on and the comments on Chris Adamson’s blog kept commoning many people believe that a full stack is needed but no one is willing as far as I can tell willing to have a go at it. One even goes as far as to say that it is too hard because gstreamer usually just wraps other binaries such as ffmpeg and would just be too hard.

There is also the Cortado sub project of flumotion which is a very simple applet for viewing ogg theora videos. At it’s core there is a partial port of gstreamer that is undocumented and is very C-style coding.

So for fun I want to start trying a full port, so I have read the gstreamer application development manual and the plugin writers guide and now feel I have a fairly good understanding of what is under the hood and how much work this is going to be. I think alot more than I even realize right now.

A few design features I am thinking of going with now are:

  • Full java stack as far as possible only pure hardware plugins such as video4linux etc would call native code.
  • Rewrite all previous java implementations ie, jorbis.
  • Elements as POJO’s and use introspection for properties rather than a map.
  • Java SE 6 only.
  • Heavy use of java.util.concurrent.
  • Core released as GPL plus classpath exception and plugins most likely GPL.

Now I know it will be a lot of work and knowing me it will probably never be released but if you think this is a good idea and want to put you 2c’s in then please leave a comment.

Update: 16 Jan 2009

Well with the release of JavaFX and the fact that I never have any time to code outside of work I guess this idea will never actually come to fruition.

Asserting SwingWorker

I have had a chance to play around with some java code recently for a change of pace and I was excited to use the new SwingWorker class in JSE6. However I also am in the habit of programming with asserts which I found out to be a problem if one triggers while running in a SwingWorker thread.

If you look at the base class of SwingWorker, FurtureTask, in the inner class Sync, which is where the actual task is run there is this method:

boolean innerRunAndReset() {
    if (!compareAndSetState(0, RUNNING))
        return false;
    try {
        runner = Thread.currentThread();
        if (getState() == RUNNING)
  ; // don't set result
        runner = null;
        return compareAndSetState(RUNNING, 0);
    } catch (Throwable ex) {
        return false;

The observant reader will notice that this code will catch all Throwables, which is the base class of Exception and Error, and an assert in java will throw a AssertError so your code will bomb out silently without notification if any Throwable is thrown.

try {
    // do threadded work here
} catch (AssertionError e) {
        "Assertion while processing: {0}\n{1}",
        new Object[] { e.getMessage(),
        e.getStackTrace()[0] });
} catch (Exception e) {
        "Exception throw during processing {0}\n{1}",
        new Object[] { e.getClass().getName(),
        e.getMessage() });
    throw e;
} catch (Error e) {
        "Error throw during processing {0}\n{1}",
        new Object[] { e.getClass().getName(),
        e.getMessage() });
    throw e;

I use the a statically defined Logger, logger, to print output from the Exceptions and Errors.

This allows the thread to throw asserts but keep going and if it does bomb out on any other Error or Exception you get notified in your log making debugging a SwingWorker a bit easier.

Card Reader on BenQ S52

In my continued coverage of getting my BenQ S52 laptop running correctly under Ubuntu Linux, I recently had the need to use the integrated memory card reader with an SD card.

And Lucky me it didn’t just work so I hunted around the internet which lead me to an article on the Ubuntu forums. However I found that this does not work with this particular laptop and should not be done.

The solution however is simple you just have to make sure the tifm_sd module is loaded. The it does just work which is great. Though if you are wanting to use another type of card with this reader you are out of luck for now as SD is the only format that is supported by the driver at the moment.

So to load this module once

> sudo modprobe tifm_sd

But to load it at every boot add tifm_sd to /etc/modules

A Podcast for the Few

I have been listening to the software engineering radio podcast for a few months now it covers a number of topics on current software engineering trends and has interviews with different developers.

I enjoyed the recent episode on dynamic languages for static minds, which applies so well to me, although I still haven’t been converted to a dynamic language developer it has got me to re think my ideas on them.

Since I finished University over a year ago now I was missing the new ideas and methodologies that gets taught there but programs like this enable me to learn new ideas while working, ahh listening to music/podcasts while you work.

I recommend subscribing to this program which releases a new episode about every 10 days for all you SE’s out there.

Internal Server Error

I have been experiencing troubles with wordpress recently causing “500 Internal Service” errors from apache, causing the php scripts to crash apache with a o so useful “segmentation fault” but all is well now. Thanks to John from profusehost for working so tirelessly on fixing this issue. You are still the greatest free webspace there is.

The coolness of a 3D desktop

Well it’s happened I have been working full time for over a year now and I am just getting more and more slack at writing valuable stuff on my blog, he he he.

But something most wonderful has happened over the Christmas break the alsa bug report tracking the problem with my soundcard has heated up, and someone found that by poking a register my soundcard will work under Linux.

So I have been spending the last few weeks getting back into my OS of choice.

I have Compiz working which is the coolest innovation on the desktop in a long time. I actually started with the fork Beryl but that version has a problem with java swing that is only fixed for Compiz in a Beta update for Java6 but not Beryl. So I am now enjoying the spinning cube virtual desktop, wobbly windows and the like in all their glory.

I also received an old Dell Latitude 600m which I mentioned I could use as a server box at home. The idea was to use it to host a webserver for AME, if I ever get it finished, so that I could host my own ads and receive full donations as per the sourceforge terms of service. But since I have not managed to finish it yet, I have been finding uses for it as a home server.

Such as using it to host torrentflux, as well as a SAMBA server for home multimedia sharing and I think I will get rid of my embedded print server and use it as a print server for the house aswell no need to pay for multiple devices to be running all the time.

And our land development has been pushed back to a release some time in April so house is on hold for now. Should get this post out it has been way to long coming till next time.

Ready Set Rant

Well are you all ready for yet another rant about people and their cars? Well I certainly am.

Last Friday I was pulling out of a car park and I noticed as I was pulling back that the person directly behind me had their reversing lights on also but as a I was already going and they were just starting I thought, “Hey I’m right here just keep going and they will wait”. Well how wrong I was! grrr.

So I got halfway out just about to put my car into 1st gear and I see this person pulling out I thought “Oh no!” so I hit the horn…. But to no avail this looser just kept coming all I could do was sit there hand on horn and wait for the inevitable… Once they realized what happened they quickly pulled back in and I get out to assess the damage.

Thankfully they didn’t cause any damage. But they didn’t even get out of their car; this stupid looking Kia Carnaval thing. I couldn’t believe it they just sat their. But as there was no damage it was Friday evening and I had my dinner in the car going cold I just couldn’t be bothered with it all. So I left….

Now I guess they couldn’t see my little Excel in their giant blind spot maybe but to not stop while there is a horn going for like 3 seconds behind you is just plain stupid… Grrr.

Enough of that now I’m getting red blooded just thinking about it. I checked broken code into source control last week, a first for me. We are in the middle of a giant refactor of our codebase so it’s only natural that I can’t do it alone but checking in code that leaves the copy under source control unable to compile just feels dirty…

Oh well until next time rant on brother/sister.