Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Unfurling Java's data transfer API

Learn to share data among applications with Java's data transfer classes

Return with me, if you will, to the early 1980s. Applications running on relatively inexpensive desktop hardware were just beginning to make a real difference in how work was done. The transformation began with VisiCalc in 1979. A few years later Ashton-Tate released dBASE II. Then, in 1982, Satellite Software released WordPerfect. By the time Lotus 1-2-3 appeared in 1983, the changes were nearly irreversible.

By 1984 users had numerous productivity packages to choose from. They could crunch numbers, write proposals, and query databases with near complete abandon. There was only one small problem. Most of the available applications sported only primitive data sharing capabilities (if they offered support for data sharing at all).

The consequence? In order to create a compound document composed of text, graphs, tables, and charts, a user had to cut and paste -- and I mean literally cut and paste.

Then along came Mac

In January 1984, Apple launched the Macintosh. Compared with its competitors, the Mac had several obvious advantages:

  • It had an easy-to-use desktop
  • Applications had a consistent graphical user interface
  • Applications and the system worked together and shared resources to a degree never seen before


One such shared resource was the clipboard. The clipboard allowed users to move data between applications by cutting or copying the data from one document (into the clipboard) and pasting it into another (from the clipboard).

The clipboard turned out to be a very powerful data transfer model. It worked so well, in fact, that to this day every GUI platform supports some form of clipboard functionality.

In order to be successful, Java can provide no less.

Java's requirements for data transfer

The architects of the Java class library had several requirements in mind when they designed the classes that implement data transfer.

First, the mechanism should be general enough to handle all current and any future data-transfer models. In particular, it should support both the clipboard model and the drag-and-drop model, using the same underlying machinery. Second, it should allow the programmer to create and transfer data types beyond those known or envisioned by the architects themselves. Finally, it should allow data transfer between Java applications and non-Java applications.

Let's take a look at what they came up with.

Data and data flavors

The data that applications transfer comes in many types -- text data and image data being two of the most obvious types. Each of these data types can appear in a number of different formats (or flavors, to use the term the Java architects selected).

Let's consider why a data type may exist in many flavors.

A application typically stores and transfers data in a data format designed to support the features the application provides. For example, a word processing application must store text as well as embedded formatting instructions, while a text editor stores only text. Each application's preferred storage format reflects this fact.

Now imagine what would happen if I tried to transfer data between the two applications. The word processor might understand plain text, but the text editor would surely be confused by the embedded formatting instructions. Considering that there are as many proprietary text formats as there are software vendors, the situation quickly degenerates into a hopeless mess.

1 | 2 | 3 | 4 |  Next >
Resources
  • The data transfer design specification http://www.javasoft.com/products/jdk/1.1/docs/guide/awt/designspec/datatransfer.html
  • The Transferable interface http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.datatransfer.Transferable.html
  • The DataFlavor class http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.datatransfer.DataFlavor.html
  • The Clipboard class http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.datatransfer.ClipboardOwner.html
  • The ClipboardOwner class http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.datatransfer.Clipboardowner.html
  • "AgentsNot just for Bond anymore" (JavaWorld, April 1997) defines agents and provides a tutorial on how to create them in Java using IBM's Aglet Workbench
    http://www.javaworld.com/javaworld/jw-04-1997/jw-04-agents.html
  • "The architecture of aglets, Part 1" (JavaWorld, April 1997) describes the inner workings of aglets, IBM Japan's Java-based autonomous software agent technology
    http://www.javaworld.com/javaworld/jw-04-1997/jw-04-hood.html
  • "The architecture of aglets, Part 2Solve real problems with aglets, a type of mobile agent" (JavaWorld, May 1997) explains the significance of mobile agents
    http://www.javaworld.com/javaworld/jw-05-1997/jw-05-hood.html
  • Download this article and the complete source as a gzipped tar file; http://www.javaworld.com/javaworld/jw-05-1998/howto/jw-05-howto.tar.gz
  • Download this article and the complete source as a zip file
    http://www.javaworld.com/javaworld/jw-05-1998/howto/jw-05-howto.zip
  • Previous How-To Java articles