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|
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Nice article, thanks for the
4 hours 19 min ago
- I once had a better way I
10 hours 5 min ago
- Not only you I too assumed
10 hours 22 min ago
- another very interesting
12 hours 15 min ago
- Reply to comment | Linux Journal
14 hours 9 min ago
- Reply to comment | Linux Journal
21 hours 3 min ago
- Reply to comment | Linux Journal
21 hours 19 min ago
- Favorite (and easily brute-forced) pw's
23 hours 10 min ago
- Have you tried Boxen? It's a
1 day 5 hours ago
- seo services in india
1 day 9 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a 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
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
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?