HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

The Microline Component Toolkit (MCT) is a powerful new product with years of experience behind it. Designed for professional developers, but usable by even a novice, the MCT brings new levels of GUI sophistication to Java, and for the first time brings professional UNIX-style components to those who still believe that "Motif" refers only to interior decorating. The MCT carries all the advantages of slick, powerful, UNIX widgets without the complexity and single-platform constraints traditionally associated with them. Using Java, Microline has helped to usher in a new era in GUI programming.

Wait a second. What the heck is a widget? No, it's not a troll from fantasy land or an aquatic midget. A widget is a name for a GUI component that performs some function. In Java, member Components of the AWT (like Lists, Choices, and Buttons) are all widgets; albeit simple ones. The Microline Component Tookit provides powerful new widgets based on those used in Motif X-windows operating systems. Many Microsoft Windows users are often surprised to learn that many of the new, snazzy features in Windows 95 and NT 4.0 have been on UNIX machines for a long time. Fancy widgets like expandable trees, right-click pop-up menus, and tabbed panels have been part of some Xwindows systems since their inception.

Microline has made a name for itself providing widgets like these on UNIX platforms for several years. Their tree, tab, and table widgets are so good, in fact, that Netscape uses them for the UNIX platform versions of its award-winning Navigator software. Now they have brought these goodies to an eager Java developer community, and the results promise to be nothing but positive for the end consumer. The current Java AWT is very powerful, but somewhat limited. Many developers have been seeking extensions to the AWT that provide for powerful, yet easy to use components. The MCT does just that.

MCT Components
The MCT is made up of three core components: the Grid, Tree, and TabPanel. Let's take a look at each of these classes in a bit more detail.

The Grid component provides for an array of cells laid out in a spreadsheet-style grid. It allows user selection of individual cells, or of entire rows/columns. It can handle text, graphics, and even Components in the cells, can intelligently size or resize rows/columns, and allows a variety of interactions with the user. The Grid also has optional, intelligent, and automatic scrollbars that help display large amounts of data. The default MCT Grid is not terribly exciting; not much more than a GridLayout and some Labels. But Grids can get more interesting, especially when you start interacting them with the user. Figure 1 is an example of a Grid that contains a TextField, selectable text, and a series of Buttons. The headings at the top allow the user to resize its columns easily.

Figure 1
Figure 1

Resizing columns is not the only interaction provided by Grid. In the previous example, each of the Buttons triggered a standard Java Event. Events can also be trapped when the user selects an individual cell, or an entire row/column. Double-click and other mouse/keyboard events unique to Grid can also be used to provide complex user interaction. Figure 2 shows a simple scenario that prints to System.out every time a row is selected.

Figure 2
Figure 2

The MCT Tree Component is actually a sub-class of Grid that displays a hierarchical tree in its first column. This type of widget is used in several GUI operating systems to provide an easy way to navigate disk files and directories. However, this is not the only use for Trees - as all good Computer Science majors know, the Tree data structure can be used to represent myriad forms of data in all fields, especially science. Having a graphical way to represent this data is an extremely useful programming tool.

Trees are represented with both graphics and text, the default being the common folder/file combination. However, other icons can easily be used. The tree in Figure 3 uses custom icons and contains both vertical and horizontal scrollbars, when necessary. Vertical scrolling is done one row at a time, while horizontal scrolling is done one pixel at a time, making tree traversal very easy. Double-clicking an expandable node will collapse or expand it, as will clicking on the "+" or "-" that is next to the node. Both kinds of nodes can be selected easily, and a program can take action based on that selection.

Figure 3
Figure 3

Most Trees are created all at once and then displayed. However, this can often be impractical for very large structures, especially when only part of the Tree needs to be displayed at any one given time. To account for this, the Tree class allows your programs to override the default expand/collapse behavior, and change the contents of the Tree dynamically. In a dynamic Tree, each folder expands to reveal another set of folders, added dynamically when the selection is made. In addition, when a folder is selected (single-clicked), a list of "files" contained in it is displayed in a column on the right. Remember, the Tree is really just a souped-up Grid.

A GUI element that has become very popular these days for setting preferences and displaying pages of related information is the TabPanel. Tabs can be laid out in rows or columns, on the top, bottom, left, or right of a Panel. Each tab can have its own Panel associated with it, or it can cause the program to change the contents of a single Panel. Either way, it is a very handy user interface tool that hundreds of commercial applications already take advantage of.

TabPanels can get very complex and exciting. TabPanel even comes with several different border choices and other options useful for customization. Like all MCT Components, TabPanels can contain text, graphics, or other Components. The tab labels themselves can handle text and graphics, too.

The TabPanel in Figure 4 shows many tabs laid out in rows across the top. The TabPanel has many options for the sizing of tabs, and is usually quite intelligent. The Button used in this example allows tabs to be dynamically added to the TabPanel.

Figure 4
Figure 4

Progress Meters and Other Tools
Although the MCT consists mainly of these three major Components, it has other features that aid program development. One of the minor Components that is very useful, although not quite as glitzy as some others, is the Progress Component. This is used to create a variety of status and progress indicators, including percentage, time estimates, and other information displays.

In addition to its AWT Components, the MCT comes with several utility objects that provide useful functions. One of the best is something called the IconMaker-a utility so useful you'll wonder why it's not included with one of the standard Java packages! The IconMaker allows you to create Image objects based on Strings, instead of having to store them on-disk as tiny GIFs or JPEGs. If used excessively, this can swell the size of your source code, but in moderation can make your life very easy. Observe the following example:

This Image was created by the IconMaker using the following lines of code:


Although this is hardly a great Object-Oriented Programming practice, it is far easier and faster than trying to design a silly little icon in an external graphics program.

The MCT also comes with other utility objects, although none as eye-catching as the IconMaker. However, some of them do rival its utility: tools for word-wrapping, drawing, and shadowing are all included in the MCT's utility classes.

Even though the MCT is a very useful and powerful set of tools, it is not perfect.

Although bugs in the MCT are rare, it does suffer from some of the AWT troubles that have plagued the Java language on PC platforms. The MCT also inherits some GUI bugs from the AWT that, through no fault of their own, make some of its classes hard to use. Microline has been working very hard with Netscape to eliminate bugs in that implementation of the AWT, and their efforts have paid off in the most recent Beta of Netscape Navigator, which handles MCT Components very nicely.

Probably due to their many years of UNIX programming, MCT's designers have employed some non-standard Java techniques. The most obvious one that veteran Java developers may have some trouble adapting to is the notion of resources. Attributes of the MCT Components are not set via methods like setBackground() and setText(). Rather, they all use the same method, setValue(), to add and change resources. A resource is a string that represents a certain Component attribute. For instance, the TabPanel has a resource named "tabsPerRow" which defines the maximum number of tabs in each row. If this value is set to zero (or not set at all), all tabs will be put into one row.

Now, this may seem like a flexible system; more flexible, in fact, than the one built in to the AWT. This is very true, and adapting to the resource system is easy and painless. However, it has its dangers. The Java design team had certain principles and goals that they imposed on the language, to ensure its security. One of these was the tenet that errors and unexpected behaviors ought to be caught at compile-time rather than at run-time. This prevents nasty bugs from plaguing helpless users. This is the reason for Java's strict type-checking and syntax rules. However, the resource system defeats this compile-time scrutiny. For instance, in one sample applet I tried to write, I accidentally typed "tabsPerSnow" instead of "tabsPerRow". The applet compiled fine, but the TabPanel did not place its rows as intended.

Luckily, the MCT does handle errors like this at run-time. The program displayed the following error message in the standard out window:

Ml: WARNING: convert(): Unknown resource tabsPerSnow
Ml: WARNING: setValues(): conversion failed for tabsPerSnow

This allowed me to track down the error with relative ease, and the incident did not cause any damage whatsoever. However, it is conceivable, albeit unlikely, that this could be exploited to harass the user in some way, and it does add another step to the debugging/testing cycle of development. So long as developers are all honorable, just, and compassionate, this should not prove to be a serious problem.

The Microline Component Toolkit is the perfect addition to any professional developer's utility collection. It is distributed in its "lite" version for free, which can be downloaded from Microline's web page. The lite version is crippled in that it does not support Grids or Trees with more than 105 rows or columns. Developers are encouraged to check out the lite version and develop applications with it, under Microline's very generous licensing policy. For those professionals who can afford it, the full version can be purchased for $399. The MCT can then be "unlocked" with a special Key class distributed only to registered users. The Key approach to selling Java software is very cleverĐit allows programs developed under the lite version of the MCT to be fully compatible with the full version, yet makes pirating the software difficult and traceable.

Many big, important companies have purchased the full MCT, and many more have tried out the lite version. The MCT has also been rewritten to support Netscape's new Internet Foundation Classes. The new product is called the Microline View Toolkit. Microline has also promised "additional", unspecified Components "soon". If you're a professional developer, the MCT is your top choice for powerful, professional Java widgets.

About the Author
Eric Ries is the Games and Graphics editor for JDJ. In his spare time, he develops Java applications and writes for books and magazines. He is a founding member of TeamJava, and is doing Intranet development with Pacific Communications Sciences Inc.


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.