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.
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.*.
Component that will be the potential source of a drag:
DragSource,
or use DragSource.getDefaultDragSource()
to obtain the default DragSource for the VM.
DragGestureRecognizer.
In this simplified implementation, you can only create a standard DragGestureRecognizers
using DragSource.createDefaultDragGestureRecognizer().DragGestureRecognizer is created, it is attached
to a Component (to watch) and a DragGestureListener
(to receive DragGestureEvents).Component, the DragGestureListener
will receive a DragGestureEvent.
It must then determine if it wants to start a drag operation. If it does,
it calls DragSource.startDrag().
It must provide the startDrag() method with the data to drag
(in the form of a java.awt.datatransfer.Transferable) and
a DragSourceListener.DragSourceListener
will receive events as the drag progresses, ultimately receiving a DragSourceDropEvent
that indicates if the data was successfully transferred to a drop target
(or not).Component that will be the potential target (destination)
of a drop:
DropTarget
and attach it to a Component and a DropTargetListener.DropTargetListener
will receive DropTargetEvents
as the user drags the cursor over the Component. The listener
must determine if it can/wants to accept the drag by calling either acceptDrop()
or rejectDrop().DropTargetDropEvent.
At this time the target is responsible for getting the data contained
in the drop. At the end of the data transfer, the target signals the drop's
success (or lack thereof) by calling DropTargetDropEvent.dropComplete(boolean).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.
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.