Java Code Examples for java.awt.dnd.DropTargetDragEvent#acceptDrag()

The following examples show how to use java.awt.dnd.DropTargetDragEvent#acceptDrag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public void dragEnter(DropTargetDragEvent event) {
    DataFlavor[] dataFlavors = event.getCurrentDataFlavors();
    JComponent c = (JComponent) event.getDropTargetContext().getComponent();
    TransferHandler transferHandler = c.getTransferHandler();

    if ((transferHandler != null) && transferHandler.canImport(c, dataFlavors)) {
        canImport = true;
    } else {
        canImport = false;
    }

    int dropAction = event.getDropAction();

    if (canImport && actionSupported(dropAction)) {
        event.acceptDrag(dropAction);
    } else {
        event.rejectDrag();
    }
}
 
Example 2
Source File: LocallDownloadDnD.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    accept = null;
    value = null;
    for (DataFlavor dataFlavor : dtde.getCurrentDataFlavors()) {
        Object obj = null;
        try {
            obj = dtde.getTransferable().getTransferData(dataFlavor);
        } catch (Exception ex) {
            continue;
        }
        if (dataFlavor.isFlavorJavaFileListType()) {
            accept = dataFlavor;
            value = obj;
            break;
        }
        if ("text".equals(dataFlavor.getPrimaryType()) && "uri-list".equals(dataFlavor.getSubType()) && dataFlavor.getRepresentationClass() == String.class) {
            accept = dataFlavor;
            value = (String) obj;
            break;
        }
    }
    if (accept != null) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    }
}
 
Example 3
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void dropActionChanged(DropTargetDragEvent event) {
    int dropAction = event.getDropAction();
    if (canImport && actionSupported(dropAction)) {
        event.acceptDrag(dropAction);
    } else {
        event.rejectDrag();
    }
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void dragOver(DropTargetDragEvent e) {
  if (isDragAcceptable(e)) {
    e.acceptDrag(e.getDropAction());
  } else {
    e.rejectDrag();
    return;
  }
  initTargetLine(e.getLocation());
  repaint();
}
 
Example 5
Source File: Dock.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    mDragDockable = getDockableInDrag(dtde);
    if (mDragDockable != null) {
        mDragOverNode = null;
        mDragOverLocation = null;
        updateForDragOver(dtde.getLocation());
        dtde.acceptDrag(DnDConstants.ACTION_MOVE);
    } else {
        dtde.rejectDrag();
    }
}
 
Example 6
Source File: GenericDNDHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site
 * for the <code>DropTarget</code> registered with this listener.
 *
 * @param dtde the <code>DropTargetDragEvent</code>
 */

public void dragOver( final DropTargetDragEvent dtde ) {
  final Transferable transferable = dtde.getTransferable();

  for ( int i = 0; i < acceptedFlavors.length; i++ ) {
    final DataFlavor acceptedFlavor = acceptedFlavors[ i ];
    if ( transferable.isDataFlavorSupported( acceptedFlavor ) ) {
      // a transfer from the palette.
      try {
        transferData = transferable.getTransferData( acceptedFlavor );
        position = dtde.getLocation();
        flavor = acceptedFlavor;
        final int result = updateDragOver( dtde );
        if ( result > 0 ) {
          dtde.acceptDrag( DnDConstants.ACTION_COPY );
        } else {
          transferData = null;
          position = null;
          flavor = null;
          dtde.rejectDrag();
        }
        break;
      } catch ( Exception e ) {
        if ( logger.isDebugEnabled() ) {
          logger.debug( "ReportPanel.dragOver ", e ); // NON-NLS
        }
        transferData = null;
        position = null;
        flavor = null;
        dtde.rejectDrag();
      }
    }
  }
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void dragOver(DropTargetDragEvent e) {
  if (isDropAcceptable(e)) {
    e.acceptDrag(e.getDropAction());
  } else {
    e.rejectDrag();
  }
  e.getDropTargetContext().getComponent().repaint();
}
 
Example 8
Source File: DropListener.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
private static void handleOngoingDrag(DropTargetDragEvent dtde) {
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
    } else {
        dtde.rejectDrag();
    }
}
 
Example 9
Source File: PortraitPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private static void acceptOrRejectDrag(DropTargetDragEvent dtde) {
    if (dtde.isDataFlavorSupported(DataFlavor.imageFlavor) || dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
    } else {
        dtde.rejectDrag();
    }
}
 
Example 10
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public final void dragOver(DropTargetDragEvent dtde) {
        Point pt = dtde.getLocation();
        int action = dtde.getDropAction();
        tree.autoscroll(pt);
        if (drawImage) {
                paintImage(pt);
        }
        if (canPerformAction(tree, draggedNode, action, pt)) {
                dtde.acceptDrag(action);                        
        }
        else {
                dtde.rejectDrag();
        }
}
 
Example 11
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void dragEnter(DropTargetDragEvent e) {
  if (isDragAcceptable(e)) {
    e.acceptDrag(e.getDropAction());
  } else {
    e.rejectDrag();
  }
}
 
Example 12
Source File: MMDEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void dragOver(@Nonnull final DropTargetDragEvent dtde) {
  if (acceptOrRejectDragging(dtde)) {
    dtde.acceptDrag(DnDConstants.ACTION_MOVE);
  } else {
    dtde.rejectDrag();
  }
  this.scrollPane.repaint();
}
 
Example 13
Source File: CalculationTree.java    From swing_library with MIT License 5 votes vote down vote up
private void doDragOver(DropTargetDragEvent dtde) {

		if (acceptDrag(dtde))
			dtde.acceptDrag(dtde.getDropAction());
		else
			dtde.rejectDrag();
	}
 
Example 14
Source File: MissingEventsOnModalDialogTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 15
Source File: MissingEventsOnModalDialogTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 16
Source File: MissingEventsOnModalDialogTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 17
Source File: MissingEventsOnModalDialogTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 18
Source File: MissingEventsOnModalDialogTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 19
Source File: MissingEventsOnModalDialogTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    dtde.acceptDrag(dtde.getDropAction());
}
 
Example 20
Source File: FileDragLabel.java    From Spark with Apache License 2.0 4 votes vote down vote up
@Override
public void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
       dropTargetDragEvent.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
   }