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 email@example.com. Thank you to Noah Alcantara for helping to review this article.
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Kernel Problem
3 hours 47 min ago
- BASH script to log IPs on public web server
8 hours 14 min ago
11 hours 49 min ago
- Reply to comment | Linux Journal
12 hours 22 min ago
- All the articles you talked
14 hours 45 min ago
- All the articles you talked
14 hours 49 min ago
- All the articles you talked
14 hours 50 min ago
19 hours 15 min ago
- Keeping track of IP address
21 hours 6 min ago
- Roll your own dynamic dns
1 day 2 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?