edu.northwestern.at.utils.swing
Class ListDropTargetOnItem

java.lang.Object
  extended by edu.northwestern.at.utils.swing.XDropTarget
      extended by edu.northwestern.at.utils.swing.ListDropTargetOnItem
All Implemented Interfaces:
java.awt.dnd.DropTargetListener, java.util.EventListener

public abstract class ListDropTargetOnItem
extends XDropTarget

An abstract base class for JList drop targets where the targets are the list elements.

This base class is appropriate for use in situations where drops are on elements rather than between them.

As the user moves the mouse over the list, the cell under the mouse is hilighted by outlining it and painting over it with translucent green. Only "valid" target cells are hilighted. The concrete subclass must implement the targetIsValid method to make the decision about which cells are valid targets.

Thanks to the superclass XDropTarget lists autoscroll during drags.


Constructor Summary
ListDropTargetOnItem(javax.swing.JList list, javax.swing.JScrollPane scrollPane)
          Constructs a new list drop target.
 
Method Summary
abstract  void acceptDrop(int targetIndex, java.awt.dnd.DropTargetDropEvent dtde)
          Accepts a drop on a target.
 void dragExit(java.awt.dnd.DropTargetEvent dte)
          Handles drag exit events.
 void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
          Handles drag over events.
 void drop(java.awt.dnd.DropTargetDropEvent dtde)
          Handles drop events.
 int getScrollIncrement(boolean up)
          Gets the scroll increment for autoscrolling.
 void stopDrag()
          Stops a drag.
abstract  boolean targetIsValid(int targetIndex, java.util.List flavors)
          Returns true if a target cell is valid.
 
Methods inherited from class edu.northwestern.at.utils.swing.XDropTarget
dragEnter, dropActionChanged, setGhost, stopCurrentTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListDropTargetOnItem

public ListDropTargetOnItem(javax.swing.JList list,
                            javax.swing.JScrollPane scrollPane)
Constructs a new list drop target.

Parameters:
list - The list.
scrollPane - The scroll pane if the list is scrollable, else null.
Method Detail

getScrollIncrement

public int getScrollIncrement(boolean up)
Gets the scroll increment for autoscrolling.

Specified by:
getScrollIncrement in class XDropTarget
Parameters:
up - True if scrolling up, false if scrolling down.

stopDrag

public void stopDrag()
Stops a drag.

Overrides:
stopDrag in class XDropTarget

dragExit

public void dragExit(java.awt.dnd.DropTargetEvent dte)
Handles drag exit events.

Specified by:
dragExit in interface java.awt.dnd.DropTargetListener
Overrides:
dragExit in class XDropTarget
Parameters:
dte - The event.

dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
Handles drag over events.

Specified by:
dragOver in interface java.awt.dnd.DropTargetListener
Overrides:
dragOver in class XDropTarget
Parameters:
dtde - The event.

drop

public void drop(java.awt.dnd.DropTargetDropEvent dtde)
Handles drop events.

Specified by:
drop in interface java.awt.dnd.DropTargetListener
Specified by:
drop in class XDropTarget
Parameters:
dtde - The event.

targetIsValid

public abstract boolean targetIsValid(int targetIndex,
                                      java.util.List flavors)
Returns true if a target cell is valid.

Parameters:
targetIndex - The target cell index.
flavors - A list of the data flavors in the drag source.
Returns:
True if target cell is valid, false otherwise.

acceptDrop

public abstract void acceptDrop(int targetIndex,
                                java.awt.dnd.DropTargetDropEvent dtde)
Accepts a drop on a target.

Parameters:
targetIndex - The target cell index on which the drop occurred.
dtde - The drop target drop event.