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
}
});
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.
| name | type | description |
|---|---|---|
| control | org.eclipse.swt.widgets.Control | the Control over which the user positions the cursor to drop the data |
| style | int | 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 |
| SWTException |
|
|
| SWTError |
NOTE: ERROR_CANNOT_INIT_DROP should be an SWTException, since it is a recoverable error, but can not be changed due to backward compatibility. |
|
addDropListener(org.eclipse.swt.dnd.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 the DropTargetListener
interface.
dragEnter is called when the cursor has entered the drop target boundaries
dragLeave is called when the cursor has left the drop target boundaries and just before
the drop occurs or is cancelled.
dragOperationChanged is called when the operation being performed has changed
(usually due to the user changing the selected modifier key(s) while dragging)
dragOver is called when the cursor is moving over the drop target
dropAccept is 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 the event.detail field
drop is called when the data is being dropped
| name | type | description |
|---|---|---|
| listener | org.eclipse.swt.dnd.DropTargetListener | the listener which should be notified |
| IllegalArgumentException |
|
|
| SWTException |
|
|
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
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
the DropTargetListener interface.
Returns: the listeners who will be notified when a drag and drop operation is in progress
| SWTException |
|
|
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
setDropTargetEffect(org.eclipse.swt.dnd.DropTargetEffect effect) · also: set_drop_target_effectSpecifies 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.
| name | type | description |
|---|---|---|
| effect | org.eclipse.swt.dnd.DropTargetEffect | the drop effect that is registered for this DropTarget |
removeDropListener(org.eclipse.swt.dnd.DropTargetListener listener)Removes the listener from the collection of listeners who will be notified when a drag and drop operation is in progress.
| name | type | description |
|---|---|---|
| listener | org.eclipse.swt.dnd.DropTargetListener | the listener which should no longer be notified |
| IllegalArgumentException |
|
|
| SWTException |
|
|
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
setTransfer(org.eclipse.swt.dnd.Transfer[] transferAgents) · also: set_transferSpecifies 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.
| name | type | description |
|---|---|---|
| transfer_agents | org.eclipse.swt.dnd.Transfer[] | a list of Transfer objects which define the types of data that can be dropped on this target |
| IllegalArgumentException |
|
|
addDisposeListener(org.eclipse.swt.events.DisposeListener listener)Adds the listener to the collection of listeners who will
be notified when the widget is disposed. When the widget is
disposed, the listener is notified by sending it the
widgetDisposed() message.
| name | type | description |
|---|---|---|
| listener | org.eclipse.swt.events.DisposeListener | the listener which should be notified when the receiver is disposed |
| IllegalArgumentException |
|
|
| SWTException |
|
|
addListener(int eventType, org.eclipse.swt.widgets.Listener listener)Adds the listener to the collection of listeners who will
be notified when an event of the given type occurs. When the
event does occur in the widget, the listener is notified by
sending it the handleEvent() message. The event
type is one of the event constants defined in class SWT.
| name | type | description |
|---|---|---|
| event_type | int | the type of event to listen for |
| listener | org.eclipse.swt.widgets.Listener | the listener which should be notified when the event occurs |
| IllegalArgumentException |
|
|
| SWTException |
|
|
isAutoDirection() · also: is_auto_directionReturns true if the widget has auto text direction,
and false otherwise.
Returns: true when the widget has auto direction and false otherwise
getData() · also: get_dataReturns the application defined widget data associated with the receiver, or null if it has not been set. The widget data is a single, unnamed field that is stored with every widget.
Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
Returns: the widget data
| SWTException |
|
|
setData(Object data) · also: set_dataSets the application defined widget data associated with the receiver to be the argument. The widget data is a single, unnamed field that is stored with every widget.
Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
| name | type | description |
|---|---|---|
| data | Object | the widget data |
| SWTException |
|
|
Returns the Display that is associated with
the receiver.
A widget's display is either provided when it is created
(for example, top level Shells) or is the
same as its parent's display.
Returns: the receiver's display
| SWTException |
|
|
dispose()Disposes of the operating system resources associated with
the receiver and all its descendants. After this method has
been invoked, the receiver and all descendants will answer
true when sent the message isDisposed().
Any internal connections between the widgets in the tree will
have been removed to facilitate garbage collection.
This method does nothing if the widget is already disposed.
NOTE: This method is not called recursively on the descendants
of the receiver. This means that, widget implementers can not
detect when a widget is being disposed of by re-implementing
this method, but should instead listen for the Dispose
event.
| SWTException |
|
|
isDisposed() · also: is_disposedReturns true if the widget has been disposed,
and false otherwise.
This method gets the dispose state for the widget.
When a widget has been disposed, it is an error to
invoke any other method (except #dispose()) using the widget.
Returns: true when the widget is disposed and false otherwise
getData(String key)Returns the application defined property of the receiver with the specified name, or null if it has not been set.
Applications may have associated arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
| name | type | description |
|---|---|---|
| key | String | the name of the property |
Returns: the value of the property or null if it has not been set
| IllegalArgumentException |
|
|
| SWTException |
|
|
Returns an array of listeners who will be notified when an event
of the given type occurs. The event type is one of the event constants
defined in class SWT.
| name | type | description |
|---|---|---|
| event_type | int | the type of event to listen for |
Returns: an array of listeners that will be notified when the event occurs
| SWTException |
|
|
getTypedListeners(int eventType, Class<L> listenerType)Returns the typed listeners who will be notified when an event of the given type occurs.
The event type is one of the event constants defined in class SWT
and the specified listener-type must correspond to that event.
If for example the eventType is SWT#Selection,
the listeners type should be SelectionListener.
| name | type | description |
|---|---|---|
| event_type | int | the type of event to listen for |
Returns: a stream of typed listeners that will be notified when the event occurs
| SWTException |
|
|
isListening(int eventType)Returns true if there are any listeners
for the specified event type associated with the receiver,
and false otherwise. The event type is one of
the event constants defined in class SWT.
| name | type | description |
|---|---|---|
| event_type | int | the type of event |
Returns: true if the event is hooked
| SWTException |
|
|
notifyListeners(int eventType, org.eclipse.swt.widgets.Event event)Notifies all of the receiver's listeners for events
of the given type that one such event has occurred by
invoking their handleEvent() method. The
event type is one of the event constants defined in class
SWT.
| name | type | description |
|---|---|---|
| event_type | int | the type of event which has occurred |
| event | org.eclipse.swt.widgets.Event | the event data |
| SWTException |
|
|
removeDisposeListener(org.eclipse.swt.events.DisposeListener listener)Removes the listener from the collection of listeners who will be notified when the widget is disposed.
| name | type | description |
|---|---|---|
| listener | org.eclipse.swt.events.DisposeListener | the listener which should no longer be notified |
| IllegalArgumentException |
|
|
| SWTException |
|
|
removeListener(int eventType, org.eclipse.swt.widgets.Listener listener)Removes the listener from the collection of listeners who will
be notified when an event of the given type occurs. The event
type is one of the event constants defined in class SWT.
| name | type | description |
|---|---|---|
| event_type | int | the type of event to listen for |
| listener | org.eclipse.swt.widgets.Listener | the listener which should no longer be notified |
| IllegalArgumentException |
|
|
| SWTException |
|
|
reskin(int flags)Marks the widget to be skinned.
The skin event is sent to the receiver's display when appropriate (usually before the next event
is handled). Widgets are automatically marked for skinning upon creation as well as when its skin
id or class changes. The skin id and/or class can be changed by calling Display#setData(String, Object)
with the keys SWT#SKIN_ID and/or SWT#SKIN_CLASS. Once the skin event is sent to a widget, it
will not be sent again unless reskin(int) is called on the widget or on an ancestor
while specifying the SWT.ALL flag.
The parameter flags may be either:
SWT#ALLSWT#NONE| name | type | description |
|---|---|---|
| flags | int | the flags specifying how to reskin |
| SWTException |
|
|
setData(String key, Object value)Sets the application defined property of the receiver with the specified name to the given value.
Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
| name | type | description |
|---|---|---|
| key | String | the name of the property |
| value | Object | the new value for the property |
| IllegalArgumentException |
|
|
| SWTException |
|
|
getStyle() · also: get_styleReturns the receiver's style information.
Note that the value which is returned by this method may
not match the value which was provided to the constructor
when the receiver was created. This can occur when the underlying
operating system does not support a particular combination of
requested styles. For example, if the platform widget used to
implement a particular SWT widget always has scroll bars, the
result of calling this method would always have the
SWT.H_SCROLL and SWT.V_SCROLL bits set.
Returns: the style bits
| SWTException |
|
|
toString()Returns a string containing a concise, human-readable description of the receiver.
Returns: a string representation of the receiver