Drag and Drop Adaptor for MRJ and Java2

The com.gloaming.awt.dnd package provides a functional subset of the Java2 Drag and Drop API which will execute predictably in both a 1.1 and 1.2 runtime environment.

Overview

The API provided by this package emulates a subset of the Java2 Drag and Drop API provided in the Java 1.2 foundation classes. At run-time, this package looks for the presence of the Java 1.2 Drag and Drop classes, and uses them if possible. If the Java2 classes are not present, it tries to emulate the Java2 interfaces using the MRJ (Macintosh Runtime for Java) Drag and Drop library. If neither are present, the public interfaces perform no function. Often returning afunctional place-holder objects so that applications need not be burdened with conditional code when drag and drop services are not available.

The motivation behind the design of this package is simple. We want to support drag and drop as a user interface feature wherever possible. Currently, the Java 1.2 and Java 1.1.8 with MRJ (Macintosh) extensions have built-in support for drag and drop. In those environments we want drag and drop to work. In other environments, we want the application to be functional, even if drag and drop features are not supported.

Ultimately, you can abandon support for pre-1.2 systems, at which time this package can be disposed of and applications can be recompiled simply by changing their import statements from com.gloaming.awt.dnd.* to java.awt.dnd.*.

Using Drag and Drop

Drag and drop is an expansive subject and the Java2 drag and drop APIs are not trivial. However, implementing drag and drop in an AWT or Swing application can be broken down into these basic steps:

Build Notes

Building the Library

The DNDAdaptor code is tolerant of the fact that the Java2 and/or MRJ drag and drop classes may be missing at runtime. However, the compiler is not so forgiving. To compile the library, both the MRJ and Java2 drag and drop classes must be present.

To build the DNDAdaptor.jar library will require a copy of the MRJClasses.zip and the Java2 java.awt.dnd package. These must be available to the compiler to define the interfaces and classes referenced by the DNDAdaptor. However, they should not be included in the output library.

To build the DNDAdaptor.jar library in a Java2 environement, include a copy of the MRJClasses.zip file and compile all of the com.gloaming.awt.dnd source files and combine them into a single library.

To build the library in a Java 1.1 environment, first obtain a Java2 rt.jar file from an installed Java 1.2 system. Extract all of the classes in the java.awt.dnd and java.util packages from the library. Create two new jars: Java2DND.jar and Java2Autoscroll.jar. The Java2Autoscroll.jar contains only one class file: java.awt.dnd.Autoscroll.class. The Java2DND.jar library should contain all of the reamining classes in the java.awt.dnd and java.util packages. A list of the classes included in each of these jars is in the Java2DND folder. I would have gladely included the finished jar files except that Sun prohibits partial redistribution of their systems.

Building Your Application

Compile your application using the DNDAdaptor.jar library. If your application does not implement autoscrolling, you need only to compile and link your Java source code against this library. Whether you include the DNDAdaptor.jar file in the CLASSPATH or include the classes in your ourput file is up to you.

Using the Autoscroll interface requires that the java.awt.dnd.Autoscroll interface be present at compile time. To satisfy this requirement, add the Java2Autoscroll.jar library to your project. Do not include the contents of the Java2Autoscroll.jar library in your output. It needs to be present only to resolve the Autoscroll interface definition at compile time.

Related Documentation

For overviews, tutorials, examples, guides, and tool documentation, please see: