Example usage for java.awt.dnd DropTargetDragEvent rejectDrag

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

Introduction

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

Prototype

public void rejectDrag() 

Source Link

Document

Rejects the drag as a result of examining either the dropAction or the available DataFlavor types.

Usage

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

@Override
public void dragOver(@Nonnull final DropTargetDragEvent dtde) {
    if (acceptOrRejectDragging(dtde)) {
        dtde.acceptDrag(DnDConstants.ACTION_MOVE);
    } else {/*from  w w w  .  ja v a 2  s .  c  o  m*/
        dtde.rejectDrag();
    }
    repaint();
}

From source file:EditorDropTarget4.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));

    // 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();
    } else if (!draggingFile && !pane.isEditable()) {
        // Can't drag text to a read-only JEditorPane
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*ww w  .jav  a2  s . com*/
    } 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.mirth.connect.client.ui.TemplatePanel.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {//w w  w. j  a v  a  2 s.  co  m
        Transferable tr = dtde.getTransferable();

        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();

            while (iterator.hasNext()) {
                iterator.next();
            }
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

From source file:com.mirth.connect.client.ui.components.MirthTree.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {/* w  w  w  .j a va2s.c  o  m*/
        Transferable tr = dtde.getTransferable();

        if (parent.currentContentPage == parent.channelEditPanel.transformerPane
                && tr.isDataFlavorSupported(supportedDropFlavor)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

From source file:com.mirth.connect.client.ui.EditMessageDialog.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {/* w  ww  .ja  v  a2 s  .  c  o  m*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);

            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();
            while (iterator.hasNext()) {
                iterator.next();
            }
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

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();
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*from  www.j  av  a2 s  . co m*/
    } 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

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();
    } else if (!tree.isEditable()) {
        // Can't drag to a read-only FileTree
        DnDUtils.debugPrintln("Drop target rejecting drag");
        dtde.rejectDrag();/*w w  w  .  j  a v  a2  s. c  om*/
    } 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.mirth.connect.client.ui.editors.filter.FilterPane.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {/*from   w  ww .  j  a  va 2  s. c o m*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);

            List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            if (iterator.hasNext() && fileList.size() == 1) {
                String fileName = ((File) iterator.next()).getName();
                if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) {
                    dtde.rejectDrag();
                }
            } else {
                dtde.rejectDrag();
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {/*from   w  ww .j a  va  2s . com*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);

            List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            if (iterator.hasNext() && fileList.size() == 1) {
                String fileName = ((File) iterator.next()).getName();
                if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) {
                    dtde.rejectDrag();
                }
            } else {
                dtde.rejectDrag();
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR)
                || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

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.//from  ww  w  .ja  v a  2  s .  co 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);
    }
}