Unfurling Java's data transfer API
Learn to share data among applications with Java's data transfer classes
By Todd Sundsted, JavaWorld.com, 05/01/98
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
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.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
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
- "MVC meets Swing" Explore the underpinnings of the JFC's Swing components.
- "Put your user interface on a diet" Replace those heavyweight components with leaner, meaner lightweight components.
- "Internationalize dynamic messages" Build flexible formatters for international applications with Java 1.1.
- "Localize this!" Use resource bundles to make your applications multicultural.
- "Write world-class applications" From Chicago to Copenhagen, Colombia to Cameroon -- Java provides the tools for writing truly international applications.
- "Use the two "R"s of Java 1.1 -- Readers and Writers" Learn how to use the two new additions to the
java.io package -- class Reader and class Writer -- to filter out unwanted e-mail.
- "Waging war on electronic junk mail" Put Java on the front line in the war against electronic junk mail.
- "Build dynamically extensible applications" Find out how to build programs that you can extend dynamically -- even while they execute.
- "3D computer graphicsGetting the hang of VRML" Learn about VRML and how you can use it to define your own virtual world.
- "3D computer graphicsMoving from wire-frame drawings to solid, shaded models" Find out how to create surfaces and add illumination to make your models more realistic.
- "3D computer graphicsSlide it, spin it, make it move -- transforming your virtual world" Learn how to make your virtual world satisfy even the toughest customer.
- "3D computer graphicsModel your world" From its start as an exotic research topic in government and university labs, virtual reality is making its move into the
mainstream of corporate America -- find out how you can gain entry into this elite club.
- "When static images just don't make the cut" Learn how to spice up your applets and applications with animated images.
- "How Java uses the the producer/consumer model to handle images -- An insider's look" Learn more about Java's powerful image-handling technique, then follow my simple procedures for building your own producer
and consumer components.
- "Learn how applets load network-based images asynchronously" Here's a close look at the way Java applets handle images in a network-based environment.
- "Drawing text is easy with three Java classes" Find out how to create text that's visually appealing through this explanation of what classes to use and how they work
together.
- "Examining HotSpot, an object-oriented drawing program" Learn how the pieces of the Java language and class library fit together through a study of this Java program
- "Using the Graphics class" A close look at the Graphics class and the drawing primitives it provides, and a demonstration of its use.
- "Observer and Observable" An introduction to the Observer interface and Observable class using the Model/View/Controller architecture as a guide.
- "The effective user interface" Five ways to enhance the appearance and effectiveness of your user interface
- "Java and event handling" How events are passed to user interface components, how to create event handlers, and more.
- "Introduction to the AWT" A description of Java's user interface toolkit.