Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.common.gui
Class DndSupport

java.lang.Object
  extended by com.sciapp.common.gui.DndSupport
All Implemented Interfaces:
DragGestureListener, DragSourceListener, DropTargetListener, EventListener

public abstract class DndSupport
extends Object
implements DragGestureListener, DragSourceListener, DropTargetListener

The DndSupport support class enables drag and drop for a component. It implements all three interfaces for registering itself as a listener for drag starting (DragGestureListener), drag (DragSourceListener) and drop events (DropTargetListener).

Subclasses should implement the dragStarted and dragStopped methods, as well as override any needed empty interface methods, such as dragGestureRecognized or drop.


Field Summary
protected  Component component
          the component for which drag and drop is enabled
 
Constructor Summary
DndSupport(Component component)
          Constructs a DndSupport.
 
Method Summary
 void dragDropEnd(DragSourceDropEvent dsde)
          This method is invoked to signify that the Drag and Drop operation is complete.
 void dragEnter(DragSourceDragEvent dsde)
          Called as the cursor's hotspot enters a platform-dependent drop site.
 void dragEnter(DropTargetDragEvent e)
          Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for the DropTarget registered with this listener.
 void dragExit(DragSourceEvent dse)
          Called as the cursor's hotspot exits a platform-dependent drop site.
 void dragExit(DropTargetEvent e)
          Called while a drag operation is ongoing, when the mouse pointer has exited the operable part of the drop site for the DropTarget registered with this listener.
 void dragGestureRecognized(DragGestureEvent dge)
          A DragGestureRecognizer has detected a platform-dependent drag initiating gesture and is notifying this listener in order for it to initiate the action for the user.
 void dragOver(DragSourceDragEvent dsde)
          Called as the cursor's hotspot moves over a platform-dependent drop site.
 void dragOver(DropTargetDragEvent e)
          Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site for the DropTarget registered with this listener.
protected abstract  void dragStarted(MouseEvent e)
          Called when a mouse button has been pressed on the component.
protected abstract  void dragStopped(MouseEvent e)
          Called when a mouse button has been released on the component.
 void drop(DropTargetDropEvent e)
          Called when the drag operation has terminated with a drop on the operable part of the drop site for the DropTarget registered with this listener.
 void dropActionChanged(DragSourceDragEvent dsde)
          Called when the user has modified the drop gesture.
 void dropActionChanged(DropTargetDragEvent e)
          Called if the user has modified the current drop gesture.
 Component getComponent()
          Returns the component for which drag and drop is enabled.
 void setComponent(Component component)
          Assigns the component for which drag and drop is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

component

protected Component component
the component for which drag and drop is enabled

Constructor Detail

DndSupport

public DndSupport(Component component)
Constructs a DndSupport.

Method Detail

dragDropEnd

public void dragDropEnd(DragSourceDropEvent dsde)
This method is invoked to signify that the Drag and Drop operation is complete. The getDropSuccess() method of the DragSourceDropEvent can be used to determine the termination state. The getDropAction() method returns the operation that the drop site selected to apply to the Drop operation. Once this method is complete, the current DragSourceContext and associated resources become invalid.

Specified by:
dragDropEnd in interface DragSourceListener
Parameters:
dsde - the DragSourceDropEvent

dragEnter

public void dragEnter(DragSourceDragEvent dsde)
Called as the cursor's hotspot enters a platform-dependent drop site. This method is invoked when all the following conditions are true:

Specified by:
dragEnter in interface DragSourceListener
Parameters:
dsde - the DragSourceDragEvent

dragEnter

public void dragEnter(DropTargetDragEvent e)
Called while a drag operation is ongoing, when the mouse pointer enters the operable part of the drop site for the DropTarget registered with this listener.

Specified by:
dragEnter in interface DropTargetListener
Parameters:
e - the DropTargetDragEvent

dragExit

public void dragExit(DragSourceEvent dse)
Called as the cursor's hotspot exits a platform-dependent drop site. This method is invoked when any of the following conditions are true: OR OR

Specified by:
dragExit in interface DragSourceListener
Parameters:
dse - the DragSourceEvent

dragExit

public void dragExit(DropTargetEvent e)
Called while a drag operation is ongoing, when the mouse pointer has exited the operable part of the drop site for the DropTarget registered with this listener.

Specified by:
dragExit in interface DropTargetListener
Parameters:
e - the DropTargetEvent

dragGestureRecognized

public void dragGestureRecognized(DragGestureEvent dge)
A DragGestureRecognizer has detected a platform-dependent drag initiating gesture and is notifying this listener in order for it to initiate the action for the user.

Specified by:
dragGestureRecognized in interface DragGestureListener
Parameters:
dge - the DragGestureEvent describing the gesture that has just occurred

dragOver

public void dragOver(DragSourceDragEvent dsde)
Called as the cursor's hotspot moves over a platform-dependent drop site. This method is invoked when all the following conditions are true:

Specified by:
dragOver in interface DragSourceListener
Parameters:
dsde - the DragSourceDragEvent

dragOver

public void dragOver(DropTargetDragEvent e)
Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site for the DropTarget registered with this listener.

Specified by:
dragOver in interface DropTargetListener
Parameters:
e - the DropTargetDragEvent

dragStarted

protected abstract void dragStarted(MouseEvent e)
Called when a mouse button has been pressed on the component. This method should perform some initialization before the dragGestureRecognized method is called.

Parameters:
e - the mouse pressed event triggering the start of a drag event

dragStopped

protected abstract void dragStopped(MouseEvent e)
Called when a mouse button has been released on the component. This method is invoked only if a button has been previously pressed which did not trigger a drag event.

Parameters:
e - the mouse released event triggering the stop of a drag event

drop

public void drop(DropTargetDropEvent e)
Called when the drag operation has terminated with a drop on the operable part of the drop site for the DropTarget registered with this listener.

This method is responsible for undertaking the transfer of the data associated with the gesture. The DropTargetDropEvent provides a means to obtain a Transferable object that represents the data object(s) to be transfered.

From this method, the DropTargetListener shall accept or reject the drop via the acceptDrop(int dropAction) or rejectDrop() methods of the DropTargetDropEvent parameter.

Subsequent to acceptDrop(), but not before, DropTargetDropEvent's getTransferable() method may be invoked, and data transfer may be performed via the returned Transferable's getTransferData() method.

At the completion of a drop, an implementation of this method is required to signal the success/failure of the drop by passing an appropriate boolean to the DropTargetDropEvent's dropComplete(boolean success) method.

Note: The data transfer should be completed before the call to the DropTargetDropEvent's dropComplete(boolean success) method. After that, a call to the getTransferData() method of the Transferable returned by DropTargetDropEvent.getTransferable() is guaranteed to succeed only if the data transfer is local; that is, only if DropTargetDropEvent.isLocalTransfer() returns true. Otherwise, the behavior of the call is implementation-dependent.

Specified by:
drop in interface DropTargetListener
Parameters:
e - the DropTargetDropEvent

dropActionChanged

public void dropActionChanged(DragSourceDragEvent dsde)
Called when the user has modified the drop gesture. This method is invoked when the state of the input device(s) that the user is interacting with changes. Such devices are typically the mouse buttons or keyboard modifiers that the user is interacting with.

Specified by:
dropActionChanged in interface DragSourceListener
Parameters:
dsde - the DragSourceDragEvent

dropActionChanged

public void dropActionChanged(DropTargetDragEvent e)
Called if the user has modified the current drop gesture.

Specified by:
dropActionChanged in interface DropTargetListener
Parameters:
e - the DropTargetDragEvent

getComponent

public Component getComponent()
Returns the component for which drag and drop is enabled.

Returns:
the drag n' drop enabled component

setComponent

public void setComponent(Component component)
Assigns the component for which drag and drop is enabled.

Parameters:
component - the drag n' drop enabled component to assign

Copyright © 2005 Scientific Applications. All Rights Reserved.