| Starting from JDK 1.2 drag and drop was possible for Java applications. Unfortunately
the framework to be used is rather complex. As of JDK 1.4 a new, more simple Dnd framework
was added, but unfortunately if you want to be backwards compatible, you still have to
stick with the old framework.
This helper class should make it easier to implement DnD for JDK 1.2 and 1.3. To add drop
support for a Component, you only have to write your Implementation of DropPasteWorkerInterface.
This interface is responsible to read data from a Transferable and add it to the model of the
target component.
DropTargetHelper helper = new DropTargetHelper();
helper.registerDropPasteWorker (new ReverseDbNodesDropWorker());
aComponent.setDropTarget(helper.getDropTarget ());
If you want to supply your own implementation of a DropTargetListener or an extension
of the implementation in this class, you have to use the following code:
helper.setDefaultDropTargetListener(aDTListener);
helper.removeDefaultDropTargetListener();
helper.registerDefaultDropTargetListener();
Because the DropTarget is a unicast source, you first have to remove the
old listener and the register the new. If you do not remove the listener
before adding a new one, a TooManyListenersException is thrown.
author: Florian Bruckner version: $Id: DropTargetHelper.java,v 1.1.2.1 2005/12/21 22:32:42 tomdz Exp $ |