com.jmex.awt.swingui.dnd
Class JMEDragAndDrop

java.lang.Object
  extended by com.jmex.awt.swingui.dnd.JMEDragAndDrop

public class JMEDragAndDrop
extends java.lang.Object

Drag and Drop support for JMEDesktop see jmetest.awt.swingui.dnd.TestJMEDragAndDrop for an example.

Author:
Galun

Constructor Summary
JMEDragAndDrop(JMEDesktop desktop)
          create a drag and drop support for this desktop
 
Method Summary
static javax.swing.ImageIcon createTextIcon(javax.swing.JComponent c, java.lang.String text)
          creates an ImageIcon using the supplied text.
 void doDrag(java.awt.event.MouseEvent event)
          drag the icon around.
 void doDrop(java.awt.event.MouseEvent e)
          the drag is about to end.
 JMEDropTargetListener getDropTargetListener()
          return the current drop target listener
 java.awt.datatransfer.Transferable getTransferable()
          get the transferable (the wrapped object to transport via drag and drop)
 boolean isDragging()
          check whether there is currently a drag in progress
 boolean isDragPanel(java.awt.Component c)
          check if the component is the drag component
 void mouseEntered(java.awt.event.MouseEvent e)
          called by the DragGestureRecognizer on mouse enter events
 void mouseExited(java.awt.event.MouseEvent e)
          called by the DragGestureRecognizer on mouse exit events
 void startDrag(JMEDragGestureEvent dge, javax.swing.ImageIcon icon, java.awt.datatransfer.Transferable transferable, JMEDragSourceListener listener)
          start to drag an object this is the same as calling startDrag( JMEDragGestureEvent dge, ImageIcon icon, Transferable transferable, JMEDragSourceListener listener, false )
 void startDrag(JMEDragGestureEvent dge, javax.swing.ImageIcon icon, java.awt.datatransfer.Transferable transferable, JMEDragSourceListener listener, boolean allowFreeDrop)
          start to drag an object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JMEDragAndDrop

public JMEDragAndDrop(JMEDesktop desktop)
create a drag and drop support for this desktop

Parameters:
desktop - the JMEDesktop to add drag and drop support
Method Detail

getTransferable

public java.awt.datatransfer.Transferable getTransferable()
get the transferable (the wrapped object to transport via drag and drop)

Returns:
the Transferable or null if there is no drag and drop in progress

isDragPanel

public boolean isDragPanel(java.awt.Component c)
check if the component is the drag component

Parameters:
c - the component to check
Returns:
true if this is the drag component

startDrag

public void startDrag(JMEDragGestureEvent dge,
                      javax.swing.ImageIcon icon,
                      java.awt.datatransfer.Transferable transferable,
                      JMEDragSourceListener listener)
               throws JMEDndException
start to drag an object this is the same as calling startDrag( JMEDragGestureEvent dge, ImageIcon icon, Transferable transferable, JMEDragSourceListener listener, false )

Parameters:
dge - the drag gesture event that initiated the dragging
icon - the icon to represent the dragged object
transferable - the wrapped object to drag
listener - the drag source listener
Throws:
JMEDndException
See Also:
startDrag(JMEDragGestureEvent, javax.swing.ImageIcon, java.awt.datatransfer.Transferable, JMEDragSourceListener, boolean)

startDrag

public void startDrag(JMEDragGestureEvent dge,
                      javax.swing.ImageIcon icon,
                      java.awt.datatransfer.Transferable transferable,
                      JMEDragSourceListener listener,
                      boolean allowFreeDrop)
               throws JMEDndException
start to drag an object

Parameters:
dge - the drag gesture event that initiated the dragging
icon - the icon to represent the dragged object
transferable - the wrapped object to drag
listener - the drag source listener
allowFreeDrop - whether to allow drops on the desktop without a drop target (drops in free space)
Throws:
JMEDndException

isDragging

public boolean isDragging()
check whether there is currently a drag in progress

Returns:
true if there is a drag started

doDrag

public void doDrag(java.awt.event.MouseEvent event)
drag the icon around. This is called by the DragGestureRecognizer on Mouse Drag events

Parameters:
event - the mouse event

doDrop

public void doDrop(java.awt.event.MouseEvent e)
the drag is about to end. This is called by DragGestureRecongnizer after dragging when the mouse button is released

Parameters:
e - the mouse event that ends the dragging

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
called by the DragGestureRecognizer on mouse enter events

Parameters:
e - the mouse event that triggered

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
called by the DragGestureRecognizer on mouse exit events

Parameters:
e - the mouse event that triggered

createTextIcon

public static javax.swing.ImageIcon createTextIcon(javax.swing.JComponent c,
                                                   java.lang.String text)
creates an ImageIcon using the supplied text. This can be used to drag text around.

Parameters:
c - the component to take the font from (typically the drag source)
text - the text to put into the image
Returns:
a new ImageIcon

getDropTargetListener

public JMEDropTargetListener getDropTargetListener()
return the current drop target listener

Returns:
the current drop target listener or null if there is none