XPToolkit drag and drop

Written by Eric Vaughan
Modified by Chris McAfee
Mon Feb 8 16:08:03 PST 1999

Simple Use cases

NGLayout requirements

High Level Design

This is a very preliminary design for drag and drop within NGLayout.

Design goals:

  1. Simple. Simple. Simple. It must be simple enough so it can be implemented in a reasonable amount of time. Yet powerful enough not to paint us in a corner.
  2. Compatible. It can't be completely on another planet. It should have a familiar API that is easy to use and learn. And should mesh well with other systems we may want to talk to. One obvious one is JAVA. In all likelyhood there is a good chance we will be interfacing with java applets.
  3. Take advantage of other people's work. Sun has already written a lot of platform specific code to deal with Transferables and DataFlavors. While we may not be able to use this code directly we do have access to and can see how it was implemented.

With this in mind here is my first cut. For simplicity it is shown in a java like syntax.

DragSource - Interface

The drag source is an interface representing the source of a drag operation. Its responsible for supplying a object that can get the data in differing formats called DataFlavors. During the drag it receives events when the dragged object enters or leaves a drop location (DragDestination). It is also responsible for telling the drag session what kind of actions it can do such as move, copy, link.

DragDestination - Interface

The destination represents a target of drop events. It is notified when a dragged object enters, leaves, or is dropped on it.

DraggedObject - Interface

This represent the dragged object during a drag session. It knows the source and destination as well as managing when the user changes the current action by pressing ctrl, shift, alt, ect.

DragService - Global

This is a global object that is called whenever a drag session needs to be started.

Transferable - Interface

An object that can get the data from the source in different types (Flavors)

DataFlavor

A particular type of Data.

Actions

Types of actions that can be done on the drag.

1. none 0
2. copy 1
2. move 2
3. link 4
4. custom 8

Use Case

User drags a file from a source to a destination

  1. User clicks on the drag source and begins dragging
  2. Drag enters the drag destination
  3. User drops

Event trace

eventTrace.gif (2990 bytes)

  1. When the user begins dragging startDrag is called on the global drag service. StartDrag is called with several arguments.
  2. When the drag target is entered dragEnter is called on the dragDestination by the dragService with the dragged object. dragEntered must return an integer representing the possible actions this destination can accept. Such as copy, move, or link. This is done by OR values together. In this example it returns copy|move.
  3. dragEnteredDestination is called on the dragSource. Who returns what operations it supports in this case it only return copy. At this point we can determine what actions are possible by ANDING the result of dragEnter on the DragDestination and the DragSource. The result is only copy is possible.
  4. dragOver is called on the dragDestination. It returns copy|move. Notice we are again returning what what is possible again. This it very usefull if our DragDestination implements its own hotspots and manages them itself.
  5. The user releases the mouse. The only possible action is copy (Result of ANDING the source and destintation actions).
  6. The dragDestination gets the Transferable from the draggedObject and calls getTransferData to get the dragged data.
  7. dragStopped is called on the dragSource with the ANDED actions.

Some ideas on how to use this in NGLayout

Here are 2 different ways this architecture can be implemented in NGLayout. I'm not an expert on NGLayout so if I'm completely off base let me know.

  1. Any frame that wanted to implement drag and drop could implement the DragSource or DragDestination appropriately. The advanage to this is Frame would not have to be changed. The disadvantage is subclassing would be required for drag and drop.
  2. All frames would have a method setDragSource() and setDragDestination(). The advantage of this is if a user wanted to make a text field on a web page receive drop events all they would have to do is call setDragSource() on the button in javaScript rather that subclassing.

Owners

NGLayout only work - Eric Vaughan
PC - ????
MAC - Steve Dagley
Unix   - Chris McAfee

Schedule

Tasks Duration in days
TBD  

Dependencies

TBD