[Java-gnome-developer] Doing the right thing
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2004-10-13 16:58:16
|
Hey, So I've been rewriting my little geode [1] archive-to-usbkey script in java-gnome, largely as an exercise in doing something actually useful before I proceed with [risking] using java-gnome in a bigger project. Mostly, this isn't a GUI event driven thing - it's just a bog standard program that happens to want to display its progress in a nice GUI window. That, however, means a worker thread, and then trying to cause things to happen in the GUI instance. My question is this: have I done this code right? I'm asking now, before I get too much further down the track. I've done all the bits of this individually in the past (duh), but I'm worried that in combining them I've made some fatal assumption to do with GTK, or how java-gnome wraps it, or.... It does seem to work fine, although I had to play around quite a bit before I got the the worker thread and the [implicit] main thread to co-operate nicely together. Mark pointed out to me that I needed to use "CustomEvents" to fire any the Gtk.main loop. I'm *not* doing that and everything seems to work (although I did fire a CustomEvent to ensure that the main loop had a chance to run). So is this horrible code, or will it do as a skeleton to proceed from? I'm not talking about things like "oh there's a package class in your file that should be in a separate file" but rather whether or not I've gone about things the right way. [It's my hope that this is good enough that it can eventually become a good quality, "easy to understand" reference example for people new to java-gnome to look at after the examples] I've attached the main .java file if you want to have a peek. If you're actually inclined to want to build it (cool!), you can get it by: tla register-archive http://research.operationaldynamics.com/arch/hacks/ tla get an...@op...--hacks/geode--trunk--0.3 geode cd geode And then either make java to compile the classes and run it in a standard JVM, or make native to build it with GCJ and run the resultant executable. You'll have to change the Makefile as it assumes your bleeding edge gnome libraries are in /opt/gnome2 . [No, there's no configure or any of that nonsense yet]. [For those struggling with getting gcj to work right, the native section of the Makefile may be of interest to you - I've been using GCJ quite successfully with java-gnome for some time now] As I said, it's just a skeleton at this point. It works (!), but I really would welcome any suggestions, help, abuse, or advice before I slog on further. Thanks! AfC Sydney [1] Presently, geode is a bash scrip from hell, but if nothing else it's a good practical application of zenity. I use it every day. See http://www.operationaldynamics.com/reference/software/scripts/#geode -- Andrew Frederick Cowie OPERATIONAL DYNAMICS Operations Consultants and Infrastructure Engineers http://www.operationaldynamics.com/ |