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

Once upon a time, it looked as though I was set for a while on software. I had L-View, the new picture editing shareware everyone was talking about. I had Microsoft Paint, a pretty good graphics creation program (if you didn't mind your graphics looking like a child in first grade had drawn them). I had HTML Notepad and a full head of hair. What more could a budding young Web developer ask for to guarantee success in this brand new industry?

As we all know, a lot has changed since then. The passing of time, as well as the dawning of new technologies, has led to the obsolescence of all of the aforementioned. (It's my hair I miss the most!) By the time the Java revolution exploded, the deck had been re-shuffled and graphics development was no exception to this rule. I've always tried to keep up with the latest developments in graphics, so I was anxious to try JViews, a new Java graphics development class library from ILOG.

I've seen Java graphics packages before, many of which were not very impressive. They offered nothing more than a sparse menu of simple shapes, forms and limited choices of ways the graphics can interact with objects. JViews is different, however.

Your system must be enabled with JDK 1.1 or better. A classpath variable has to be set to the directory the install program resides in. Open a command prompt and type: java JViews. Installation is automatic from there.

It Inherits its Power from C++ ILOG took what they had learned from developing their C++ graphics library and applied it to Java. The result is a library of Java classes that can be used in the development of high performance graphics displays. It is especially useful for network layout displays, map displays (even if the end user wants to overlay these maps with their own customized objects) and customized editors. The displays that can be built with JViews can contain a very large number of graphics, upwards of tens of thousands of objects. This allows JViews to shine for those industrial-strength apps. Another benefit is the separation of presentation from behavior. While one set of pre-defined objects are graphics that know how to draw themselves, another set represents behaviors, such as selection, drag/drop and resizing. This separation has a few big advantages. Developers can assign any behavior to a graphic object to change its function. Pre-defined behavior objects can be subclassed so end users can fine-tune it to their exact needs.

Although JViews is based on C++, it has the completely open architecture that is the cornerstone of Java development. Any Java lightweight component can be taken and used as a node on a network. Some of the JViews classes can even be wrapped as beans and placed on a GUI builder palette alongside other beans. JViews is built in two levels: The 2D graphics level, and the manager level.

Create Basic or Complex Graphics with JViews' Huge Library
The 2D graphics level provides graphic objects to control appearance, and interaction objects to control behavior. Provided also are the basic tools needed to combine graphic and interaction objects to form a complete application.

The manager level of JViews organizes sets of graphic objects into multiple views and layers with higher order interactions. All of these aspects are grouped together by an object called a manager. The grapher, a class that organizes certain objects into nodes and links, is included among the manager class hierarchy.

JViews comes equipped with IlvEdit, a handy editor that is provided with source code. It allows you to easily create and edit graphic objects. The starting point for these objects is the class IlvGraphic. This class allows the graphic object to draw itself at any given destination port. If necessary, an associated object of the IlvTransformer class may be used to change the coordinates of the graphic object. IlvGraphic also has member functions that allow you to set and change geometric dimensions. Various member functions are provided to implement user properties that can be associated with an object for application-specific purposes.

It Doesn't Just Create Graphics - It Interfaces them as Well
I remember when I knew of only one way to interface graphics with some sort of function or application, and that was through HTML. The HREF tag was used to create a simple link to another Web page or an application from the server that could run through the browser. Today's fast-paced, competitive environment does not allow us to get off so easily, however. There is a very real and immediate need to create GUI interfaced applications that function both on and off the Web. JViews provides us with just the tool we need to create these applications.

An application-programming interface (API)--a library of Java classes which contains pre-defined graphic objects and various behaviors which can be applied to these objects--is also included. The result is an easy, no-nonsense approach to interfacing graphic objects to applications. A friend of mine who is in the process of interfacing all of his household lighting through his computer was so impressed with this software that he wants to try to use it to make a GUI interface for his system. Turning on a light or the stereo was never this exciting!

A Basic Example
Letıs take a quick look at a simple example of how JViews is used. First, weıll make a simple map. The first example shows the creation of a manager and how to load a graphic objects file into this manager. The example given shows a scrolling window of a map of the USA.

Figure 1
Figure 1:  The first example creates a scrolling
map of the USA with two custom objects atop it

Hereıs some of the code used to create this applet:

First, the library must be imported:

import ilog.views.*;

The applet and AWT packages must also be imported:

import java.applet.*;
import java.awt.*;

If the file is going to be loaded through a URL, the java.net package must be used:

import java.net.*;

The applet class named sample1 is now created. This applet has two fields: The manager (class IlvManager) that stores the objects and the viewer (class IlvManagerView), which displays the content of the manager.

public class Sample1 extends Applet {
IlvManager manager;
IlvManagerView mgrview;

For the initialization of the applet, the manager is created:

public void init() {
manager = new IlvManager();
IlvReliefLabel obj = new
IlvReliefLabel(newIlvRect(580, 160,50, 30),
"One";manager.addObject(obj, 1, false);
obj = new IlvReliefLabel(new IlvRect(530,
330, 50, 30) ³Two²
manager.addObject(obj, 1, false);

The second example provided, sample2.java, shows the use of selection interactor. In this example, a button has been added to the applet. Once the button has been clicked on, graphic objects can be selected, moved and it is even possible to modify their shape.

Figure 2
Figure 2:  Here, variuos states can be moved and
morphed by clicking and dragging

A field named selectInteractor has been added in the class:

void createInteractorButtons()
Button button;
button = new Button("Select");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (selectInteractor == null)
selectInteractor = new IlvSelectInteractor();
if (mgrview.getInteractor() != selectInteractor)
add("South", button);

It might be worth noting that the SelectInteractor is a pre-defined behavior that controls the selection of an object, the ³resize handles² that indicate that an object is selected, moved and resized, etc. Developers can choose to use this behavior ³as is², or subclass to modify just those parts of it that they want to tailor.

Other Features

  • Compatibility: JViews works with all AWT (abstract window toolkit), JFC (Java foundation classes) and JavaBean components. Other Java GUI builders such as Symantecıs Visual Café and Sunıs Java Workshop can encapsulate JViews classes as JavaBeans to place on the palette and use like other components.
  • Browser support: JViews can be used on any browser that supports the latest JDK. This includes Netscape Communicator, Sunıs HotJava and, of course, Microsoft Internet Explorer.
  • Importation of external formats: JViews is equipped with file reformatters to import existing 2D graphics data files. The DXF file reader imports AutoCAD files.
All in all, JViews is an excellent library from which really cool apps can be built. It enables developers to quickly and easily produce clean, crisp graphics that can be used for demonstration purposes or to be interfaced with more complex applications. It offers compatibility with other applications and, best of all, itıs Pure Java, which means total platform independence. If you are in a position where you need a no-nonsense, hard hitting application to develop GUI interfaced graphics, give it a try. I did, and I loved it. Now if I could just find a way to get it to grow hair!

About the Author
Edward Zebrowski is a technical writer based in the Orlando, FL area. Ed runs his own Web development company, ZebraWeb, and can be reached on the net at [email protected]


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.