Developing GNOME Applications with Java
Listing 8. GnomeSesameFormat.glade Fragment
... <widget class="GtkButton" id="buttonFormat"> ... <signal name="clicked" handler="onFormatButtonClicked" last_modification_time= "Wed, 02 Feb 2005 19:16:35 GMT"/> ... <widget class="GtkDialog" id="errUI"> <child internal-child="vbox"> <widget class="GtkVBox" id="vboxErr"> ... <child internal-child="action_area"> <widget class="GtkHButtonBox" id="hboxErrOk"> ... <child> <widget class="GtkButton" id="buttonErrOk"> ... <signal name="clicked" handler="onErrOkButtonClicked" last_modification_time= "Wed, 02 Feb 2005 19:22:48 GMT"/> ... </widget> </child> </widget> </child> <child> <widget class="GtkHBox" id="hboxStop"> ... <child> <widget class="GtkImage" id="imageStop"> ... </widget> </child> <child> <widget class="GtkLabel" id="labelErr"> ... </widget> </child> </widget> </child> </widget> </child> </widget>
Listing 7 displays some of the corresponding Java source code for GnomeSesameFormat. Listing 8 contains a portion of GnomeSesameFormat's interface definition.
GnomeSesameFormat is a simple application I developed, and most of its work is done by executing an external program called sesame-format. sesame-format formats a disk to contain an encrypted filesystem. GnomeSesameFormat simply provides a GUI wrapper for this command-line tool. GnomeSesameFormat can be executed with its --dry-run option to facilitate testing and experimenting. As of this writing, it's probably a bad idea to format a disk using this tool. A screenshot of GnomeSesameFormat is shown in Figure 5.
The GnomeSesameFormat application is implemented in a single class, GnomeSesameFormat. The GnomeSesameFormat class' main function initializes the GTK libraries using the Gtk.init method, creates a new GnomeSesameFormat instance and releases control to the GTK event loop by calling Gtk.main.
The interesting work begins in the GnomeSesameFormat class' constructor. In the constructor, a LibGlade object is instantiated. It reads a GLADE user interface description and instantiates its corresponding objects. A reference to these objects can be retrieved by name using the LibGlade object's getWidget method. Once we have a reference to an interface component, we can use them as if we created them ourselves. The GnomeSesameFormat class also contains the signal handling methods referenced in GnomeSesameFormat.glade.
In developing GnomeSesameFormat, I used the four steps presented above. For example, a button was defined using GLADE as part of the application's GUI (step 1). The button was named buttonFormat (step 2). Again using GLADE, a method name of onButtonFormatClicked was designated to handle the button's clicked symbol (step 3). Finally, the onButtonFormatClicked method was implemented in GnomeSesameFormat's Java source code (step 4).
In order to manipulate components further, libglade can provide a reference to an individual component. A LibGlade object's getWidget method provides this capability. To illustrate this, we can investigate GnomeSesameFormat's errUI component. The errUI component is a Window that displays error messages for the user. The errUI window was defined in GLADE (step 1) and named (step 2). Because we know the name of errUI, we can get a reference to it by calling getWidget(errUI). Once we receive a reference to the component, any GTK method may be invoked. GnomeSesameFormat uses errUI's show and hide methods.
The GNOME Project provides the ability to develop applications in C, C++, Java, Python and Perl. In addition, external projects such as Mono provide even more diversity. When used with several of these alternatives, the GLADE User Interface Builder makes it possible to write applications quickly with a graphical user interface for the GNOME platform. Once the graphical components are defined, an application shell and signal handlers all are that remain to be implemented. This implementation can be done using any programming language.
Resources for this article: /article/8274.
Mike Petullo currently is working at WMS Gaming and pursuing a Master's degree at DePaul University. He has been tinkering with Linux since 1997 and welcomes your comments sent to firstname.lastname@example.org. Thank you to Noah Alcantara for helping to review this article.
- Two Pi R
- Readers' Choice Awards 2013
- AIDE—Developing for Android on Android
- Best. Cake. Ever.
- The Geek's Guide to the Coolest 2013 Holiday Gifts
- A Handy U-Boot Trick
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- Raspberry Pi: the Perfect Home Server
- Tech Tip: Really Simple HTTP Server with Python
- Nice coding on the cake. I
13 min 42 sec ago
- Baker's identity
5 hours 3 min ago
- Uber jealous
10 hours 31 sec ago
- Reality is disapointing
20 hours 32 min ago
- Máy sấy quần áo
23 hours 19 min ago
- Services on GlusterFS
23 hours 28 min ago
- Reply to comment | Linux Journal
1 day 1 hour ago
- Definitely cool stuff here
1 day 2 hours ago
- thanks for the information
1 day 3 hours ago
- nice information thanks
1 day 4 hours ago