Example usage for java.awt.dnd DropTargetDragEvent getDropAction

List of usage examples for java.awt.dnd DropTargetDragEvent getDropAction

Introduction

In this page you can find the example usage for java.awt.dnd DropTargetDragEvent getDropAction.

Prototype

public int getDropAction() 

Source Link

Document

This method returns the user drop action.

Usage

From source file:TreeDragTest.java

public void dragOver(DropTargetDragEvent dtde) {
    TreeNode node = getNodeForEvent(dtde);
    if (node.isLeaf()) {
        dtde.rejectDrag();/*www. j a  v a2s  .  c  om*/
    } else {
        // start by supporting move operations
        //dtde.acceptDrag(DnDConstants.ACTION_MOVE);
        dtde.acceptDrag(dtde.getDropAction());
    }
}

From source file:FileTreeDropTarget.java

protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) {
    int dropAction = dtde.getDropAction();
    int sourceActions = dtde.getSourceActions();
    boolean acceptedDrag = false;

    DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is "
            + DnDUtils.showActions(dropAction));

    Point location = dtde.getLocation();
    boolean acceptableDropLocation = isAcceptableDropLocation(location);

    // Reject if the object being transferred 
    // or the operations available are not acceptable.
    if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*from  w w w.j a  va2 s .  c o  m*/
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if (!acceptableDropLocation) {
        // Can only drag to writable directory
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        // Not offering copy or move - suggest a copy
        DnDUtils.debugPrintln("Drop target offering COPY");
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
        acceptedDrag = true;
    } else {
        // Offering an acceptable operation: accept
        DnDUtils.debugPrintln("Drop target accepting drag");
        dtde.acceptDrag(dropAction);
        acceptedDrag = true;
    }

    return acceptedDrag;
}

From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java

protected boolean acceptOrRejectDragging(@Nonnull final DropTargetDragEvent dtde) {
    final int dropAction = dtde.getDropAction();

    boolean result = false;

    if (this.dragAcceptableType && (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) != 0
            && this.mindMapPanel.findTopicUnderPoint(dtde.getLocation()) != null) {
        result = true;/*from w  w  w  . ja v a  2  s.c  o  m*/
    }

    return result;
}

From source file:DragDropTreeExample.java

protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) {
    int dropAction = dtde.getDropAction();
    int sourceActions = dtde.getSourceActions();
    boolean acceptedDrag = false;

    DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is "
            + DnDUtils.showActions(dropAction));

    Point location = dtde.getLocation();
    boolean acceptableDropLocation = isAcceptableDropLocation(location);

    // Reject if the object being transferred
    // or the operations available are not acceptable.
    if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*from  www .  j  ava 2  s.c o  m*/
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if (!acceptableDropLocation) {
        // Can only drag to writable directory
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();
    } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
        // Not offering copy or move - suggest a copy
        DnDUtils.debugPrintln("Drop target offering COPY");
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
        acceptedDrag = true;
    } else {
        // Offering an acceptable operation: accept
        DnDUtils.debugPrintln("Drop target accepting drag");
        dtde.acceptDrag(dropAction);
        acceptedDrag = true;
    }

    return acceptedDrag;
}

From source file:DragDropTreeExample.java

public void dragEnter(DropTargetDragEvent dtde) {
    DnDUtils.debugPrintln("dragEnter, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Save the list of selected items
    saveTreeSelection();//from   w ww .j a v a  2 s.c  om

    // Get the type of object being transferred and determine
    // whether it is appropriate.
    checkTransferType(dtde);

    // Accept or reject the drag.
    boolean acceptedDrag = acceptOrRejectDrag(dtde);

    // Do drag-under feedback
    dragUnderFeedback(dtde, acceptedDrag);
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3.// w  ww  . j  av  a  2 s.  c  o  m
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(Component[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private Border originalBorder = appContentPanel.getBorder();
        private Border dragOverBorder = BorderFactory.createBevelBorder(1);

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        appContentPanel.setBorder(dragOverBorder);
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    appContentPanel.setBorder(originalBorder);
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        appContentPanel.setBorder(originalBorder);
                    };
                });

                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        if (checkProposedUploadFiles(fileList)) {
                            wizardStepForward();
                        }
                    }
                } catch (Exception e) {
                    String errorMessage = "Unable to accept dropped item";
                    log.error(errorMessage, e);
                    ErrorDialog.showDialog(ownerFrame, null, uploaderProperties.getProperties(), errorMessage,
                            e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3./*from w  ww. j a  v  a 2s  .  c  om*/
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(JComponent[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        ownerFrame.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ownerFrame.requestFocusInWindow();
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        uploadFiles((File[]) fileList.toArray(new File[fileList.size()]));
                    }
                } catch (Exception e) {
                    String message = "Unable to start accept dropped items";
                    log.error(message, e);
                    ErrorDialog.showDialog(ownerFrame, null, message, e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Initialise the application's File drop targets for drag and drop copying of local files
 * to S3./* www . j  ava  2 s .  c o m*/
 *
 * @param dropTargetComponents
 * the components files can be dropped on to transfer them to S3
 */
private void initDropTarget(JComponent[] dropTargetComponents) {
    DropTargetListener dropTargetListener = new DropTargetListener() {

        private boolean checkValidDrag(DropTargetDragEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrag(dtde.getDropAction());
                return true;
            } else {
                dtde.rejectDrag();
                return false;
            }
        }

        public void dragEnter(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragOver(DropTargetDragEvent dtde) {
            checkValidDrag(dtde);
        }

        public void dropActionChanged(DropTargetDragEvent dtde) {
            if (checkValidDrag(dtde)) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        objectsTable.requestFocusInWindow();
                    };
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        ownerFrame.requestFocusInWindow();
                    };
                });
            }
        }

        public void dragExit(DropTargetEvent dte) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ownerFrame.requestFocusInWindow();
                };
            });
        }

        public void drop(DropTargetDropEvent dtde) {
            if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                    && (DnDConstants.ACTION_COPY == dtde.getDropAction()
                            || DnDConstants.ACTION_MOVE == dtde.getDropAction())) {
                dtde.acceptDrop(dtde.getDropAction());
                try {
                    final List fileList = (List) dtde.getTransferable()
                            .getTransferData(DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                        new Thread() {
                            @Override
                            public void run() {
                                prepareForFilesUpload((File[]) fileList.toArray(new File[fileList.size()]));
                            }
                        }.start();
                    }
                } catch (Exception e) {
                    String message = "Unable to start accept dropped item(s)";
                    log.error(message, e);
                    ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(), message, e);
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };

    // Attach drop target listener to each target component.
    for (int i = 0; i < dropTargetComponents.length; i++) {
        new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true);
    }
}

From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java

@Override
public void dragOver(DropTargetDragEvent dtde) {
    if (canDrop(dtde)) {
        dtde.acceptDrag(dtde.getDropAction());
    } else {/*from   w  w  w .  j  a v  a  2s.c  om*/
        dtde.acceptDrag(DnDConstants.ACTION_NONE);
        dtde.rejectDrag();
    }
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

@Override
public void dragEnter(DropTargetDragEvent dtde) {
    File[] files = getDragDropPlugins(dtde.getCurrentDataFlavors(), dtde.getTransferable());
    if (files.length > 0) {
        dtde.acceptDrag(dtde.getDropAction());
    } else {//  w ww.ja  v  a  2s  . c o m
        dtde.rejectDrag();
    }
}