Java 8 DropTargetDragEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DropTargetDragEvent class.

This code example shows how to use the following methods:acceptDrag, getCurrentDataFlavors, rejectDrag, getDropTargetContext
    private boolean actionSupported(int action) {
        return (action & (TransferHandler.COPY_OR_MOVE)) != TransferHandler.NONE;
    } 
 
    public void dragEnter(DropTargetDragEvent e) {
        DataFlavor[] flavors = e.getCurrentDataFlavors();
        DropTargetContext ctx = e.getDropTargetContext();
        JComponent c = (JComponent)ctx.getComponent();
        LimeTransferHandler handler = (LimeTransferHandler)c.getTransferHandler();
        DropDragInfo ddi = new DropDragInfo(e);
         
        if(handler != null && handler.canImport(c, flavors, ddi) && actionSupported(ddi.action))
            e.acceptDrag(ddi.action);
        else 
            e.rejectDrag();
    } 
 
    public void dragOver(DropTargetDragEvent e) {
        DataFlavor[] flavors = e.getCurrentDataFlavors();
        DropTargetContext ctx = e.getDropTargetContext();
6
CodeRank
This code example shows how to use the following methods:acceptDrag, getCurrentDataFlavors, getDropAction, getLocation, rejectDrag
    /* 
     * DropTargetListener methods (DropTarget is its own listener) 
     */ 
 
    public void dragEnter( DropTargetDragEvent evt ) {
        int dropAction = evt.getDropAction();
        canImport = getTransferHandler()
                   .canImport( comp, evt.getCurrentDataFlavors() );
        if ( canImport && actionSupported( dropAction ) &&
             isDropLocation( evt.getLocation() ) ) {
            evt.acceptDrag( dropAction );
        } 
        else { 
            evt.rejectDrag();
        } 
    } 
 
    public void dragOver( DropTargetDragEvent evt ) {
        int dropAction = evt.getDropAction();
        if ( canImport && actionSupported( dropAction ) && 
6
CodeRank
This code example shows how to use the following methods:acceptDrag, getDropAction, isDataFlavorSupported, rejectDrag
     */ 
    public synchronized void dragEnter(DropTargetDragEvent dtde)
    { 
        if (isDragOK(dtde))
        { 
            dtde.acceptDrag(dtde.getDropAction());
        } else 
        { 
            dtde.rejectDrag();
        } 
    } 
 
    // Returns true if the dragging operation is OK 
    private boolean isDragOK(DropTargetDragEvent dtde)
    { 
        int action = dtde.getDropAction();
        return (action == DnDConstants.ACTION_COPY || action == DnDConstants.ACTION_MOVE ||
                action == DnDConstants.ACTION_LINK) &&
            dtde.isDataFlavorSupported(DataFlavor.stringFlavor);
    } 

6
CodeRank
This code example shows how to use the following methods:isDataFlavorSupported, rejectDrag
 
    public DesktopPane(final GCViewerGui gcViewer) {
        // TODO refactor; looks very similar to GCDocument implementation 
        gcViewer.setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY, new DropTargetListener(){
            public void dragEnter(DropTargetDragEvent e) {
                if (e.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    e.acceptDrag(DnDConstants.ACTION_COPY);
                } else { 
                    e.rejectDrag();
                } 
            } 
 
            public void dragOver(DropTargetDragEvent dtde) {
            } 
 
            public void dropActionChanged(DropTargetDragEvent dtde) {
            } 
 
            public void dragExit(DropTargetEvent dte) {
            } 
6
CodeRank
This code example shows how to use the following methods:acceptDrag, getDropAction, getSourceActions, isDataFlavorSupported, rejectDrag
     * {@link #MOVE_ACTION_MODIFIERS_EX} must be down.</p> 
     * 
     * @return <code>true</code> if the event was accepted, false otherwise 
     */ 
    private boolean acceptOrRejectDragEvent(DropTargetDragEvent event) {
        this.currentDropAction = event.getDropAction();
 
        this.dragAccepted = event.isDataFlavorSupported(TransferableFileSet.getFileSetDataFlavor())
                || event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                || event.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor());
 
        if(dragAccepted && DnDContext.isDragInitiatedByMucommander()) {
            FolderPanel dragInitiator = DnDContext.getDragInitiator();
 
            if(dragInitiator==folderPanel || dragInitiator.getCurrentFolder().equalsCanonical(folderPanel.getCurrentFolder())) {
                // Refuse drag if the drag was initiated by the same FolderPanel, or if its current folder is the same 
                // as this one 
                this.dragAccepted = false;
            } 
            else { 

5
CodeRank
This code example shows how to use the following methods:getLocation, rejectDrag
 
	@Override 
	public void dragEnter(DropTargetDragEvent arg) {
 
		try { 
			Point p = arg.getLocation();
			TreePath path = tree.getPathForLocation(p.x, p.y);
			AnalyzedModuleComponent check = (AnalyzedModuleComponent) path
					.getLastPathComponent();
			String type = check.getType().toLowerCase();
			if (type.equals("root") || type.equals("application")
					|| type.equals("externalpackage")) {
				arg.rejectDrag();
			} 
		} catch (Exception e) {
			arg.rejectDrag();
		} 
 
	} 
 
	@Override 
5
CodeRank
This code example shows how to use the following methods:getLocation
     * the operable part of the drop site for the DropTarget registered with 
     * this listener. 
     */ 
    @Override 
    public void dragEnter(DropTargetDragEvent dtde) {
        overIndex = this.locationToIndex(dtde.getLocation());
        setSelectedIndex(overIndex);
    } 
 
 
    /** 
     * Records the index of the list item (if any) pointed to by the mouse cursor 
     * <p> 
     * Description copied from interface:<br> 
     * Called when a drag operation is ongoing, while the mouse pointer is still 
     * over the operable part of the drop site for the DropTarget registered with 
     * this listener. 
     */ 
    @Override 
    public void dragOver(DropTargetDragEvent dtde) {
4
CodeRank
This code example shows how to use the following methods:getLocation
    public void dragOver(DropTargetDragEvent dtde) {
        if (dropNode != null) {
            dropNode.setIsDropTarget(false);
            notifyChanged(dropNode);
        } 
        Point p = dtde.getLocation();
        dropNode = getNodeAt(p);
        if (dropNode != null) {
            dropNode.setIsDropTarget(true);
            notifyChanged(dropNode);
        } 
    } 
 
    public void dropActionChanged(DropTargetDragEvent dtde) {
    } 
 
    public void dragExit(DropTargetEvent dte) {
        isDragging = false;
        if (dropNode != null) {
            dropNode.setIsDropTarget(false);
4
CodeRank
This code example shows how to use the following methods:rejectDrag
This code example shows how to use the following methods:getLocation
    //@Override 
    public void dragOver(DropTargetDragEvent arg0) {
 
        if (kernel.getModelPanel().getFlightObject() != null) {
 
            Point p2 = arg0.getLocation();
            SwingUtilities.convertPointToScreen(p2, target);
            SwingUtilities.convertPointFromScreen(p2, kernel.getModelPanel().getFlightObject().getParent());
 
            kernel.getModelPanel().getFlightObject().setBounds(
                    (int) p2.getX() - (kernel.getModelPanel().getFlightObject().getWidth() / 2),
                    (int) p2.getY() - (kernel.getModelPanel().getFlightObject().getHeight() / 2),
                    kernel.getModelPanel().getFlightObject().getWidth(),
                    kernel.getModelPanel().getFlightObject().getHeight());
            kernel.getModelPanel().repaint();
        } 
 
    } 
 
    /** 
4
CodeRank
See Code Examples for Java 8 DropTargetDragEvent Methods: