/** {@inheritDoc} */
 public void dragEnter(DropTargetDragEvent evt) {
   target = (JComponent) evt.getDropTargetContext().getComponent();
   TransferHandler th = target.getTransferHandler();
   canImport = th.canImport(target, evt.getCurrentDataFlavors());
   if (canImport) {
     saveComponentState(target);
     lastPosition = evt.getLocation();
   }
 }
Esempio n. 2
0
 /**
  * Adds drag and drop functionality.
  *
  * @param comp component
  * @param dnd drag and drop handler
  */
 public static void addDrop(final JComponent comp, final DropHandler dnd) {
   comp.setDropTarget(
       new DropTarget(comp, DnDConstants.ACTION_COPY_OR_MOVE, null, true, null) {
         @Override
         public synchronized void drop(final DropTargetDropEvent dtde) {
           dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
           final Transferable tr = dtde.getTransferable();
           for (final Object o : contents(tr)) dnd.drop(o);
           comp.requestFocusInWindow();
         }
       });
 }