jruby/docs BETA
org.eclipse.swt.dnd 25
C ByteArrayTransfer
C Clipboard
C DND
C DragSource
C DragSourceAdapter
C DragSourceEffect
C DragSourceEvent
I DragSourceListener
C DropTarget
C DropTargetAdapter
C DropTargetEffect
C DropTargetEvent
I DropTargetListener
C FileTransfer
C HTMLTransfer
C ImageTransfer
C RTFTransfer
C TableDragSourceEffect
C TableDropTargetEffect
C TextTransfer
C Transfer
C TransferData
C TreeDragSourceEffect
C TreeDropTargetEffect
C URLTransfer
DropTarget — members 9+
C new(control, style)
C add_drop_listener(listener)
M control() Control
M drop_listeners() DropTargetListener[]
M drop_target_effect() DropTargetEffect
C drop_target_effect=(effect)
C remove_drop_listener(listener)
M transfer() Transfer[]
C transfer=(transfer_agents)
from Widget
C add_dispose_listener(listener)
C add_listener(event_type, listener)
M auto_direction?() boolean
M data() Object
C data=(data)
M display() Display
C dispose()
M disposed?() boolean
M get_data(key) Object
M get_listeners(event_type) Listener[]
M get_typed_listeners(event_type, listener_type) Stream<L>
M is_listening(event_type) boolean
C notify_listeners(event_type, event)
C remove_dispose_listener(listener)
C remove_listener(event_type, listener)
C reskin(flags)
C set_data(key, value)
M style() int
M to_string() String

org.eclipse.swt.dnd.DropTarget

class extends Widget 9 members

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

Constructors

new

new ( Control control, int style )
Java: <init>(org.eclipse.swt.widgets.Control control, int style)

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.

nametypedescription
controlorg.eclipse.swt.widgets.Controlthe Control over which the user positions the cursor to drop the data
styleintthe 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.

Instance Methods

add_drop_listener

add_drop_listener ( DropTargetListener listener )
Java: 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

nametypedescription
listenerorg.eclipse.swt.dnd.DropTargetListenerthe 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

control

Control control ( )
Java: getControl() · also: get_control

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

drop_listeners

DropTargetListener[] drop_listeners ( )
Java: getDropListeners() · also: get_drop_listeners

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

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

drop_target_effect

DropTargetEffect drop_target_effect ( )
Java: getDropTargetEffect() · also: get_drop_target_effect

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

drop_target_effect=

drop_target_effect= ( DropTargetEffect effect )
Java: setDropTargetEffect(org.eclipse.swt.dnd.DropTargetEffect effect) · also: set_drop_target_effect

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.

nametypedescription
effectorg.eclipse.swt.dnd.DropTargetEffectthe drop effect that is registered for this DropTarget

remove_drop_listener

remove_drop_listener ( DropTargetListener listener )
Java: 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.

nametypedescription
listenerorg.eclipse.swt.dnd.DropTargetListenerthe 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

transfer

Transfer[] transfer ( )
Java: getTransfer() · also: get_transfer

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

transfer=

transfer= ( Transfer[] transfer_agents )
Java: setTransfer(org.eclipse.swt.dnd.Transfer[] transferAgents) · also: set_transfer

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.

nametypedescription
transfer_agentsorg.eclipse.swt.dnd.Transfer[]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

Inherited

from Widget

add_dispose_listener

add_dispose_listener ( DisposeListener listener )
Java: 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.

nametypedescription
listenerorg.eclipse.swt.events.DisposeListenerthe listener which should be notified when the receiver is disposed

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

add_listener

add_listener ( int event_type, Listener listener )
Java: 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.

nametypedescription
event_typeintthe type of event to listen for
listenerorg.eclipse.swt.widgets.Listenerthe listener which should be notified when the event occurs

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

auto_direction?

boolean auto_direction? ( )
Java: isAutoDirection() · also: is_auto_direction

Returns true if the widget has auto text direction, and false otherwise.

Returns: true when the widget has auto direction and false otherwise

data

Object data ( )
Java: getData() · also: get_data

Returns 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

Throws

SWTException
  • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread

data=

data= ( Object data )
Java: setData(Object data) · also: set_data

Sets 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.

nametypedescription
dataObjectthe widget data

Throws

SWTException
  • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread

display

Display display ( )
Java: getDisplay() · also: get_display

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

Throws

SWTException
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed

dispose

dispose ( )
Java: 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.

Throws

SWTException
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver

disposed?

boolean disposed? ( )
Java: isDisposed() · also: is_disposed

Returns 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

get_data

Object get_data ( String key )
Java: 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.

nametypedescription
keyStringthe name of the property

Returns: the value of the property or null if it has not been set

Throws

IllegalArgumentException
  • ERROR_NULL_ARGUMENT - if the key 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

get_listeners

Listener[] get_listeners ( int event_type )
Java: getListeners(int eventType)

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.

nametypedescription
event_typeintthe type of event to listen for

Returns: an array of listeners that will be notified when the event occurs

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

get_typed_listeners

Stream<L> get_typed_listeners ( int event_type, Class<L> listener_type )
Java: 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.

nametypedescription
event_typeintthe type of event to listen for

Returns: a stream of typed listeners that will be notified when the event occurs

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

is_listening

boolean is_listening ( int event_type )
Java: 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.

nametypedescription
event_typeintthe type of event

Returns: true if the event is hooked

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

notify_listeners

notify_listeners ( int event_type, Event event )
Java: 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.

nametypedescription
event_typeintthe type of event which has occurred
eventorg.eclipse.swt.widgets.Eventthe event data

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

remove_dispose_listener

remove_dispose_listener ( DisposeListener listener )
Java: removeDisposeListener(org.eclipse.swt.events.DisposeListener listener)

Removes the listener from the collection of listeners who will be notified when the widget is disposed.

nametypedescription
listenerorg.eclipse.swt.events.DisposeListenerthe 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

remove_listener

remove_listener ( int event_type, Listener listener )
Java: 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.

nametypedescription
event_typeintthe type of event to listen for
listenerorg.eclipse.swt.widgets.Listenerthe 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

reskin

reskin ( int flags )
Java: 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#ALL
all children in the receiver's widget tree should be skinned
SWT#NONE
only the receiver should be skinned

nametypedescription
flagsintthe flags specifying how to reskin

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

set_data

set_data ( String key, Object value )
Java: 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.

nametypedescription
keyStringthe name of the property
valueObjectthe new value for the property

Throws

IllegalArgumentException
  • ERROR_NULL_ARGUMENT - if the key 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

style

int style ( )
Java: getStyle() · also: get_style

Returns 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

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

to_string

String to_string ( )
Java: toString()

Returns a string containing a concise, human-readable description of the receiver.

Returns: a string representation of the receiver