This class is a hyper-thin wrapping of
libglade
, a library
that allows you to transform the XML interface definition files generated
by the GNOME User Interface Designers (of which
Glade
is the
original and best known) into live Widgets in your application.
Using
libglade
is pretty easy. You prepare your user
interface in
Glade
, write some code to load it in, and then
extract the particular Widgets that you care about further manipulating.
Since we're stuck with the somewhat stupid name that the underlying library
used for the tree of instantiated widgets, we recommend you use a variable
name like
glade
or
processedTree
for the
Xml
object you get back, perhaps as follows:
final Xml glade;
final Window top;
final Button confirm;
glade = Glade.parse("HelpWindow.glade", "window1");
top = (Window) glade.getWidget("window1");
confirm = (Button) glade.getWidget("button4");
If you're wonder where
"window1"
and
"button4"
came from, they are the style of names that the
Glade
designer generates for its Widgets by default.
To improve
maintainability, you are highly encouraged to change these automatically
generated names to ones which corresponds to the variable names being used
in your Java code! In other words, something like:
confirm = (Button) glade.getWidget("confirmButton");
These examples do, however, expose the two major structural weaknesses of
using Glade:
- it is not type safe. We do our best to check you aren't asking for
something that you shouldn't, but you are still at the mercy of
ClassCastException
(or worse a segmentation fault) if you
get it wrong.
- the names embedded in your
parse()
and
getWidget()
calls are tightly coupled to the textual names
created in the Glade
program. If you refactor your Java
code, sooner or later you will forget to change the corresponding names in
the .glade
files, which will inevitably lead to confusion
down the road.
All that said,
libglade
provides a rapid application
development capability par excellence, and is a significant part of almost
every GNOME application.
Warning: There has been considerable discussion within GNOME
about the state of libglade
and it is widely expected that
it will be replaced by GtkBuilder
within GTK in the very
near future. If that occurs before java-gnome 4.2 we will not release Glade
to stable. Indeed, that event may well be the trigger to bump to 4.1