|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.swing.XDropTarget
public abstract class XDropTarget
An abstract base class for drop targets.
This class implements a drop target listener for any AWT component. It handles the details of image dragging if the underlying OS does not support it and the details of autoscrolling scrollable targets.
Concrete subclasses must implement the getScrollIncrement and drop methods.
Autoscrolling is enabled only if the component is scrollable, and
only if the drag and drop operation was started by the partner
XDragSource
class within the same JVM. We have implemented our
own autoscrolling and do not use Swing's built-in facilities. Our
autoscrolling starts when the user drags the mouse above or below the
scrolling component, not when he moves the mouse near the top or bottom
and pauses.
This class has an incestuous relationship with its partner
XDragSource
class. See that class overview for more details.
Constructor Summary | |
---|---|
XDropTarget(javax.swing.JComponent component,
javax.swing.JScrollPane scrollPane)
Constructs a new drop target. |
Method Summary | |
---|---|
void |
dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
Handles drag enter events. |
void |
dragExit(java.awt.dnd.DropTargetEvent dte)
Handles drag exit events. |
void |
dragOver(java.awt.dnd.DropTargetDragEvent dtde)
Handles drag over events. |
abstract void |
drop(java.awt.dnd.DropTargetDropEvent dtde)
Handles drop events. |
void |
dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
Handles drop action changed events. |
abstract int |
getScrollIncrement(boolean up)
Gets the scroll increment. |
static void |
setGhost(java.awt.image.BufferedImage ghostImage,
java.awt.Point ghostOffset)
Sets the ghost image for manual image dragging. |
static void |
stopCurrentTarget()
Stops the current target at the end of a drag and drop operation. |
void |
stopDrag()
Stops the current drag and drop operation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XDropTarget(javax.swing.JComponent component, javax.swing.JScrollPane scrollPane)
component
- The component.scrollPane
- The scroll pane if the component is
scrollable, else null. Method Detail |
---|
public static void stopCurrentTarget()
This method is invoked by XDragSouce.dragDropEnd
when a drag and drop operation ends
(when the user releases the mouse button).
Autoscrolling and ghost image dragging are both terminated for the currently active drop target, if any.
public static void setGhost(java.awt.image.BufferedImage ghostImage, java.awt.Point ghostOffset)
This method is invoked by XDragSource.startDrag
if the underlying OS does not support
image dragging. In this case this class takes care of manually
dragging the ghost image as the mouse enters and moves over
drop targets.
ghostImage
- The ghost image.ghostOffset
- The image offset. public void stopDrag()
Subclasses may override this method, but they must remember to invoke super.stopDrag.
public void dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
Any previously active drop target is stopped, the autoscroll timer is stopped, and the y coordinate of the mouse location is recorded.
Subclasses often override this method, but must remember to invoke super.dragEnter.
dragEnter
in interface java.awt.dnd.DropTargetListener
dtde
- The event. public void dragExit(java.awt.dnd.DropTargetEvent dte)
The ghost image is cleared. If the last known y coordinate of the mouse is within 20 pixels of the top or bottom of the component's viewport the autoscrolling timer is started.
Subclasses may override this method, but must remember to invoke super.dragExit.
dragExit
in interface java.awt.dnd.DropTargetListener
dte
- The event. public void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
Any previously active different drop target is stopped, the autoscroll timer is stopped, the y coordinate of the mouse location is recorded, and the ghost image is cleared and redrawn.
Subclasses may override this method, but must remember to invoke super.dragOver.
dragOver
in interface java.awt.dnd.DropTargetListener
dtde
- The event. public void dropActionChanged(java.awt.dnd.DropTargetDragEvent dtde)
The implementation does nothing. Subclasses may override this method if they wish.
dropActionChanged
in interface java.awt.dnd.DropTargetListener
dtde
- The event. public abstract int getScrollIncrement(boolean up)
up
- True if scrolling up, false if down. public abstract void drop(java.awt.dnd.DropTargetDropEvent dtde)
drop
in interface java.awt.dnd.DropTargetListener
dtde
- The event.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |