Monday, July 24, 2006

This is an excerpt from my talk at CodeCamp 2.0 on 7/22.

Adding the Visual Editor

The Visual Editor is in fact a plug-in. And one you’re going to want if you plan to develop a win form.

I understand with Eclipse 3.2, Callisto makes installation simpler. But with 3.1.2, this is what I did. I chose Help à Software Updates à Find and Install.

1.    Select the Search for New features to install. Click Next

2.    Click on the New Remote Site … button and add http://update.eclipse..org/tools/ve/updates/1.0. Name it VE.

3.    Click on the New Remote Site … button and add http://update.eclipse.org/tools/emf/updates. Name it EMF.

4.    Click on the New Remote Site … button and add http://update.eclipse.org/updates/3.0 . Name it Old Eclipse.

5.    Select VE, EMF, and Old Eclipse. Click Finish.

 

 

 

 

How do you know the Visual Editor is installed? Open Eclipse, type Ctrl+N and look under the Java node to see Visual Class.

 

SWT, Swing, AWT

I’m going to show a little example using the Visual editor with SWT.  I don’t have much experience with these GUI libraries. From what I’ve read, I like SWT best, but I understand that Swing has strong adherents. I’d rather respect the differences than argue them.

SWT is the Standard Widget Toolkit. It’s the foundation for the Eclipse user interface from IBM. Originally IBM used Smalltalk internally, but it had deployment and configuration problems.

Sun wanted a portable widget API and wrote AWT, the Abstract Windowing Toolkit. Many considered it overly complex. Sun abandoned AWT in favor of JFC, the Java Foundation Classes, also known as Swing.

AWT suffered from a “lowest common denominator (LCD)” approach. To remain faithful to “write once, run anywhere” AWT offered only features supported by all the native windowing operating systems.

Swing solved the LCD problem by using no native code and no native widgets. Swing has “pluggable look and feels.” By default Swing adopts the native platform’s look and feel.

Some people maintain that Swing has not lived up to its promise. Reasons are speed (actually lack thereof) and look and feel. Swing devotees bristle at these statements. Swing performance has greatly improved (especially with JDK 1.4), but I read that it continues to be somewhat more sluggish than native applications. (I don’t really know; I haven’t done any performance studies.) About the look and feel … well, you can plug in whatever you want, but Swing may always be a step behind the latest GUIs because support for the GUI must be written explicitly into the Java library.

OTI (Object Technology International, who created widget interfaces for OTI Smalltalk and is now part of IBM) set out to create another GUI library and correct the faults of AWT and Swing. This was SWT. It uses native functionality when available, Java implementation when not.

Installing SWT

SWT is distributed as an archive file; I downloaded swt-3.1.2-gtk-linux-x86.zip. Then, open Eclipse and select File à Import … à Existing Projects Into Workspace.

 

 

 

The result is that org.eclipse.swt appears in the Package Explorer.

Writing a Simple Win Form with VE and SWT

Open Eclipse. Select File à New à Project … à Java Project. Click Next. Type in a Project Name and click Next, then Finish.

 

 

In the Package Explorer, under the Project Name, select src, right-click. Select New à Other à Visual Class. Type in a package name and a class name.

 

The class appears in the Visual Editor.

 

Drop down the Bean toolbar. Choose SWT Controls à Button. Release the mouse, then click on the win form. A button appears. Resize it. Then, select the button and right-click. Choose Set Text and type in the text you want to be displayed on the button. Using this same technique, make a textbox.

Then select the button and right-click. Select Events à Add Events … Choose “implements: …” and select Finish.

 

Then, add code in the button handler to write the textbox.

 

Now select the containing package in the Package Explorer and right-click. Choose Run As … à SWT application.

 

 

7/24/2006 9:31:52 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):