Class DropTarget
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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Control(package private) Listener(package private) static final String(package private) static Callback(package private) int(package private) static Callback(package private) int(package private) static Callback(package private) int(package private) static Callback(package private) int(package private) static final int(package private) DNDEvent(package private) Runnable(package private) long(package private) long(package private) DropTargetEffect(package private) static final String(package private) int(package private) TransferData(package private) int(package private) Transfer[] -
Constructor Summary
ConstructorsConstructorDescriptionDropTarget(Control control, int style) Creates a newDropTargetto allow data to be dropped on the specifiedControl. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDropListener(DropTargetListener listener) 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 theDropTargetListenerinterface.(package private) static intcheckStyle(int style) protected voidChecks that this class can be subclassed.(package private) voiddrag_data_received(long widget, long context, int x, int y, long selection_data, int info, int time) (package private) static longDrag_Data_Received(long widget, long context, long x, long y, long data, long info, long time) (package private) booleandrag_drop(long widget, long context, int x, int y, int time) (package private) static longDrag_Drop(long widget, long context, long x, long y, long time) (package private) voiddrag_leave(long widget, long context, int time) (package private) static longDrag_Leave(long widget, long context, long time) (package private) booleandrag_motion(long widget, long context, int x, int y, int time) (package private) static longDrag_Motion(long widget, long context, long x, long y, long time) (package private) static DropTargetFindDropTarget(long handle) Returns the Control which is registered for this DropTarget.Returns an array of listeners who will be notified when a drag and drop operation is in progress, by sending it one of the messages defined in theDropTargetListenerinterface.Returns the drop effect for this DropTarget.(package private) intTransfer[]Returns a list of the data types that can be transferred to this DropTarget.(package private) void(package private) intopToOsOp(int operation) (package private) intosOpToOp(int osOperation) voidremoveDropListener(DropTargetListener listener) Removes the listener from the collection of listeners who will be notified when a drag and drop operation is in progress.voidsetDropTargetEffect(DropTargetEffect effect) Specifies the drop effect for this DropTarget.(package private) booleansetEventData(long context, int x, int y, int time, DNDEvent event) voidsetTransfer(Transfer... transferAgents) Specifies the data types that can be transferred to this DropTarget.(package private) voidupdateDragOverHover(long delay, DNDEvent event) Methods inherited from class Widget
addDisposeListener, addListener, addTypedListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setData, toString
-
Field Details
-
control
Control control -
controlListener
Listener controlListener -
transferAgents
Transfer[] transferAgents -
dropEffect
DropTargetEffect dropEffect -
selectedDataType
TransferData selectedDataType -
selectedOperation
int selectedOperation -
keyOperation
int keyOperation -
dragOverStart
long dragOverStart -
dragOverHeartbeat
Runnable dragOverHeartbeat -
dragOverEvent
DNDEvent dragOverEvent -
drag_motion_handler
int drag_motion_handler -
drag_leave_handler
int drag_leave_handler -
drag_data_received_handler
int drag_data_received_handler -
drag_drop_handler
int drag_drop_handler -
DEFAULT_DROP_TARGET_EFFECT
- See Also:
-
IS_ACTIVE
- See Also:
-
DRAGOVER_HYSTERESIS
static final int DRAGOVER_HYSTERESIS- See Also:
-
Drag_Motion
-
Drag_Leave
-
Drag_Data_Received
-
Drag_Drop
-
dropController
long dropController
-
-
Constructor Details
-
DropTarget
Creates a newDropTargetto allow data to be dropped on the specifiedControl. 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- theControlover which the user positions the cursor to drop the datastyle- 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- Throws:
SWTException-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
SWTError-- ERROR_CANNOT_INIT_DROP - unable to initiate drop target; this will occur if more than one drop target is created for a control or if the operating system will not allow the creation of the drop target
NOTE: ERROR_CANNOT_INIT_DROP should be an SWTException, since it is a recoverable error, but can not be changed due to backward compatibility.
- See Also:
-
-
Method Details
-
checkStyle
static int checkStyle(int style) -
Drag_Data_Received
static long Drag_Data_Received(long widget, long context, long x, long y, long data, long info, long time) -
Drag_Drop
static long Drag_Drop(long widget, long context, long x, long y, long time) -
Drag_Leave
static long Drag_Leave(long widget, long context, long time) -
Drag_Motion
static long Drag_Motion(long widget, long context, long x, long y, long time) -
FindDropTarget
-
addDropListener
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 theDropTargetListenerinterface.dragEnteris called when the cursor has entered the drop target boundariesdragLeaveis called when the cursor has left the drop target boundaries and just before the drop occurs or is cancelled.dragOperationChangedis called when the operation being performed has changed (usually due to the user changing the selected modifier key(s) while dragging)dragOveris called when the cursor is moving over the drop targetdropAcceptis called just before the drop is performed. The drop target is given the chance to change the nature of the drop or veto the drop by setting theevent.detailfielddropis called when the data is being dropped
- Parameters:
listener- the listener which should be notified- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
checkSubclass
protected void checkSubclass()Description copied from class:WidgetChecks that this class can be subclassed.The SWT class library is intended to be subclassed only at specific, controlled points (most notably,
CompositeandCanvaswhen 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:
checkSubclassin classWidget
-
drag_data_received
void drag_data_received(long widget, long context, int x, int y, long selection_data, int info, int time) -
drag_drop
boolean drag_drop(long widget, long context, int x, int y, int time) -
drag_leave
void drag_leave(long widget, long context, int time) -
drag_motion
boolean drag_motion(long widget, long context, int x, int y, int time) -
getControl
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
-
getDropListeners
Returns an array of listeners who will be notified when a drag and drop operation is in progress, by sending it one of the messages defined in theDropTargetListenerinterface.- Returns:
- the listeners who will be notified when a drag and drop operation is in progress
- Throws:
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.4
- See Also:
-
getDropTargetEffect
Returns the drop effect for this DropTarget. This drop effect will be used during a drag and drop to display the drag under effect on the target widget.- Returns:
- the drop effect that is registered for this DropTarget
- Since:
- 3.3
-
getOperationFromKeyState
int getOperationFromKeyState() -
getTransfer
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
-
onDispose
void onDispose() -
opToOsOp
int opToOsOp(int operation) -
osOpToOp
int osOpToOp(int osOperation) -
removeDropListener
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 no longer be notified- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setTransfer
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- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if transferAgents is null
-
setDropTargetEffect
Specifies the drop effect for this DropTarget. This drop effect will be used during a drag and drop to display the drag under effect on the target widget.- Parameters:
effect- the drop effect that is registered for this DropTarget- Since:
- 3.3
-
setEventData
-
updateDragOverHover
-