org.eclipse.swt.dnd
Class DropTarget

java.lang.Object
  |
  +--org.eclipse.swt.widgets.Widget
        |
        +--org.eclipse.swt.dnd.DropTarget

public class DropTarget
extends Widget

Untamed: Class DropTarget defines the target object for a drag and drop transfer. IMPORTANT: This class is not intended to be subclassed.

This class identifies the Control over which the user must position the cursor in order to drop the data being transferred. It also specifies what data types can be dropped on this control and what operations can be performed. You may have several DropTragets in an application but there can only be a one to one mapping between a Control and a DropTarget. The DropTarget can receive data from within the same application or from other applications (such as text dragged from a text editor like Word).

	int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
	Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
	DropTarget target = new DropTarget(label, operations);
	target.setTransfer(types);
 

The application is notified of data being dragged over this control and of when a drop occurs by implementing the interface DropTargetListener which uses the class DropTargetEvent. The application can modify the type of drag being performed on this Control at any stage of the drag by modifying the event.detail field or the event.currentDataType field. When the data is dropped, it is the responsibility of the application to copy this data for its own purposes.

	target.addDropListener (new DropTargetListener() {
		public void dragEnter(DropTargetEvent event) {};
		public void dragOver(DropTargetEvent event) {};
		public void dragLeave(DropTargetEvent event) {};
		public void dragOperationChanged(DropTargetEvent event) {};
		public void dropAccept(DropTargetEvent event) {}
		public void drop(DropTargetEvent event) {
			// A drop has occurred, copy over the data
			if (event.data == null) { // no data to copy, indicate failure in event.detail
				event.detail = DND.DROP_NONE;
				return;
			}
			label.setText ((String) event.data); // data copied to label text
		}
 	});
 
Styles
DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
Events
DND.DragEnter, DND.DragLeave, DND.DragOver, DND.DragOperationChanged, DND.DropAccept, DND.Drop


Field Summary
private  Control control
           
private  Listener controlListener
           
private  TransferData[] dataTypes
           
private static String DROPTARGETID
           
private  DragUnderEffect effect
           
private  int iDataObject
           
private  org.eclipse.swt.internal.ole.win32.COMObject iDropTarget
           
private  int keyState
           
private  int lastOperation
           
private  int refCount
           
private  TransferData selectedDataType
           
private  Transfer[] transferAgents
           
 
Fields inherited from class org.eclipse.swt.widgets.Widget
 
Constructor Summary
DropTarget(Control control, int style)
          Enabled: Creates a new DropTarget to allow data to be dropped on the specified Control.
 
Method Summary
 void addDropListener(DropTargetListener listener)
          Enabled: Adds the listener to the collection of listeners who will be notified when a drag and drop operation is in progress, by sending it one of the messages defined in the DropTargetListener interface.
private  int AddRef()
           
(package private) static int checkStyle(int style)
           
protected  void checkSubclass()
          Checks that this class can be subclassed.
private  void createCOMInterfaces()
           
private  void disposeCOMInterfaces()
           
private  int DragEnter(int pDataObject, int grfKeyState, int pt_x, int pt_y, int pdwEffect)
           
private  int DragLeave()
           
private  int DragOver(int grfKeyState, int pt_x, int pt_y, int pdwEffect)
           
private  int Drop(int pDataObject, int grfKeyState, int pt_x, int pt_y, int pdwEffect)
           
 Control getControl()
          Enabled: Returns the Control which is registered for this DropTarget.
 Display getDisplay()
          Enabled:
private  int getOperationFromKeyState(int grfKeyState)
           
 Transfer[] getTransfer()
          Enabled: Returns a list of the data types that can be transferred to this DropTarget.
 void notifyListeners(int eventType, Event event)
          Enabled:
private  void onDispose()
           
private  int opToOs(int operation)
           
private  int osToOp(int osOperation)
           
private  int QueryInterface(int riid, int ppvObject)
           
private  int Release()
           
 void removeDropListener(DropTargetListener listener)
          Enabled: Removes the listener from the collection of listeners who will be notified when a drag and drop operation is in progress.
 void setTransfer(Transfer[] transferAgents)
          Enabled: Specifies the data types that can be transferred to this DropTarget.
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getStyle, isDisposed, isListening, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

control

private Control control

controlListener

private Listener controlListener

transferAgents

private Transfer[] transferAgents

effect

private DragUnderEffect effect

DROPTARGETID

private static final String DROPTARGETID

iDropTarget

private org.eclipse.swt.internal.ole.win32.COMObject iDropTarget

refCount

private int refCount

selectedDataType

private TransferData selectedDataType

dataTypes

private TransferData[] dataTypes

lastOperation

private int lastOperation

keyState

private int keyState

iDataObject

private int iDataObject
Constructor Detail

DropTarget

public DropTarget(Control control,
                  int style)
Enabled: Creates a new DropTarget to allow data to be dropped on the specified Control. Creating an instance of a DropTarget may cause system resources to be allocated depending on the platform. It is therefore mandatory that the DropTarget instance be disposed when no longer required.

Parameters:
control - the Control over which the user positions the cursor to drop the data
style - the bitwise OR'ing of allowed operations; this may be a combination of any of DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
See Also:
Widget.dispose(), checkSubclass(), DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
Method Detail

addDropListener

public void addDropListener(DropTargetListener listener)
Enabled: Adds the listener to the collection of listeners who will be notified when a drag and drop operation is in progress, by sending it one of the messages defined in the DropTargetListener interface.

Parameters:
listener - the listener which should be notified
See Also:
DropTargetListener, removeDropListener(org.eclipse.swt.dnd.DropTargetListener), DropTargetEvent

AddRef

private int AddRef()

checkStyle

static int checkStyle(int style)

checkSubclass

protected void checkSubclass()
Description copied from class: Widget
Checks that this class can be subclassed.

The SWT class library is intended to be subclassed only at specific, controlled points (most notably, Composite and Canvas when implementing new widgets). This method enforces this rule unless it is overridden.

IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.

The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.

Overrides:
checkSubclass in class Widget

createCOMInterfaces

private void createCOMInterfaces()

disposeCOMInterfaces

private void disposeCOMInterfaces()

DragEnter

private int DragEnter(int pDataObject,
                      int grfKeyState,
                      int pt_x,
                      int pt_y,
                      int pdwEffect)

DragLeave

private int DragLeave()

DragOver

private int DragOver(int grfKeyState,
                     int pt_x,
                     int pt_y,
                     int pdwEffect)

Drop

private int Drop(int pDataObject,
                 int grfKeyState,
                 int pt_x,
                 int pt_y,
                 int pdwEffect)

getControl

public Control getControl()
Enabled: Returns the Control which is registered for this DropTarget. This is the control over which the user positions the cursor to drop the data.

Returns:
the Control which is registered for this DropTarget

getDisplay

public Display getDisplay()
Enabled:

Specified by:
getDisplay in class Widget
Returns:
the receiver's display

getOperationFromKeyState

private int getOperationFromKeyState(int grfKeyState)

getTransfer

public Transfer[] getTransfer()
Enabled: Returns a list of the data types that can be transferred to this DropTarget.

Returns:
a list of the data types that can be transferred to this DropTarget

notifyListeners

public void notifyListeners(int eventType,
                            Event event)
Enabled:

Overrides:
notifyListeners in class Widget
Parameters:
eventType - the type of event which has occurred
event - the event data

onDispose

private void onDispose()

opToOs

private int opToOs(int operation)

osToOp

private int osToOp(int osOperation)

QueryInterface

private int QueryInterface(int riid,
                           int ppvObject)

Release

private int Release()

removeDropListener

public void removeDropListener(DropTargetListener listener)
Enabled: Removes the listener from the collection of listeners who will be notified when a drag and drop operation is in progress.

Parameters:
listener - the listener which should be notified
See Also:
DropTargetListener, addDropListener(org.eclipse.swt.dnd.DropTargetListener)

setTransfer

public void setTransfer(Transfer[] transferAgents)
Enabled: Specifies the data types that can be transferred to this DropTarget. If data is being dragged that does not match one of these types, the drop target will be notified of the drag and drop operation but the currentDataType will be null and the operation will be DND.NONE.

Parameters:
transferAgents - a list of Transfer objects which define the types of data that can be dropped on this target


comments?