Chapter 17: OO for Graphical User Interfaces, A Tour of Three Toolkits


OVERVIEW

Graphical user interface (GUI) programming is probably the most fertile application of object-oriented ideas. The requirements of GUI programming are complex, to say the least. First of all, there is the issue of layout. How to write a program so that the layout displayed on a computer terminal maintains its visual aesthetic and functionality as the user resizes a GUI to suit his/her particular needs? Then there is the issue of rendering graphics, displaying images, playing video clips and sounds files-all compute-intensive operations. Additionally, a GUI must be programmed in such a way that it remains responsive to user interaction even as it is engaged in compute-intensive operations. Over the years, OO has emerged as the best way to meet these diverse requirements of GUI programming.

With regard to what the various OO toolkits can do for GUI design, it is instructive to ponder the similarities between programming up a functional and aesthetically pleasing GUI, on the one hand, and designing and constructing a beautiful building, on the other. There is no science of GUI design, just as there is no science of architecture. Yet, over the years we have learned that humans have distinct preferences with regard to how a GUI is laid out and how its functionality is engineered, just as we know about our distinct preferences concerning the various dimensions of living spaces and how the spaces are put to use. We could refer to these human preferences as invariances.[1]

This analogy with architecture is important to us for two reasons: First, the programming tools for GUI must not allow easy violation of the universal human preferences I referred to as invariances, in the same sense that the written and the unwritten rules of architecture do not allow for living spaces that are aesthetically and functionally offensive to humans. As we will see in this chapter, the GUI toolkits of various kinds provide layout managers that in some cases come with built-in smarts to keep a spatial layout from looking grotesque as a programmer packs more and more graphical components into a GUI or as a user tries to change the horizontal and the vertical dimensions of a GUI. With regard to the human preferences concerning the responsiveness of a GUI, modern GUI programming languages permit a programmer to deploy separate threads of computation if an interaction between a human and the GUI calls for intensive computing.

The second reason for the importance of the architecture analogy is that just as a study of the history of building construction and design is important to inculcate in a student a sense of what has worked in the past and what serves as a foundation for the future, a study of the history of the GUI toolkits is likely to serve the same purpose. In what follows, therefore, we will start with a brief history of the GUI toolkits. An interesting detail that emerges from this history is the important role that was played by object-orientation in GUI programming even before OO became mainstream.

The section on history will be followed by a presentation of the main features of three high-level toolkits for GUI design: one from Java (AWT/Swing), one from C++ (Qt), and one using simulated object-orientation in C (GNOME/GTK+),[2] the last because GTK+ has emerged as an important GUI toolkit and because it is educational to see the power of simulated object-orientation directly in C.

The reader will not find this chapter exhaustive- since, after all, one could write an entire book on GUI programming in Java alone, or in C++ alone, or in C alone. Our focus will be more on capturing the essential ideas of each toolkit, providing a reader with sufficient information to get started with his or her own efforts at GUI design, leaving the rest to extensive information available on the web and to other excellent books devoted solely to GUI issues. This chapter leaves unaddressed important topics such as the playing of sounds files and video clips.

[1]The notion that the author is trying to convey through invariances is different from the notion of patterns as in [1]. Invariances are meant to refer to human preferences at a more basic level than what is addressed by patterns. The "golden proportion" could be an example of an invariance.

[2]In the GNOME/GTK+ pairing, GNOME is a desktop environment that is based on the GTK+ GUI toolkit. But since it is convenient to use some of the functions of GNOME for constructing GTK+ based GUIs, we consider them paired in this chapter.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net