Example usage for java.awt.dnd DropTargetDragEvent isDataFlavorSupported

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

Introduction

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

Prototype


public boolean isDataFlavorSupported(DataFlavor df) 

Source Link

Document

This method returns a boolean indicating if the specified DataFlavor is supported.

Usage

From source file:ColorSink.java

public void dragEnter(DropTargetDragEvent e) {
    if (e.isDataFlavorSupported(TransferableColor.colorFlavor)
            || e.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        this.setBorder(dropBorder);
    }/*  www  . ja  va 2 s.c  om*/
}

From source file:EditorDropTarget.java

protected void checkTransferType(DropTargetDragEvent dtde) {
    // Only accept a list of files
    acceptableType = dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor);

    DnDUtils.debugPrintln("File type acceptable - " + acceptableType);
}

From source file:de.tor.tribes.ui.windows.AbstractDSWorkbenchFrame.java

@Override
public void dragEnter(DropTargetDragEvent dtde) {
    if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor)
            || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    }//from   w  w  w  .j a v a  2  s.  c  o  m
}

From source file:EditorDropTarget4.java

protected void checkTransferType(DropTargetDragEvent dtde) {
    // Accept a list of files, or data content that
    // amounts to plain text or a Unicode text string
    acceptableType = false;/*from   w w w  . j  a v a2 s.  c o m*/
    draggingFile = false;
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        acceptableType = true;
        draggingFile = true;
    } else if (dtde.isDataFlavorSupported(DataFlavor.plainTextFlavor)
            || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        acceptableType = true;
    }
    DnDUtils.debugPrintln("File type acceptable - " + acceptableType);
    DnDUtils.debugPrintln("Dragging a file - " + draggingFile);
}

From source file:ScribbleDragAndDrop.java

/**
 * This method is invoked when the user first drags something over us. If we
 * understand the data type being dragged, then call acceptDrag() to tell
 * the system that we're receptive. Also, we change our border as a "drag
 * under" effect to signal that we can accept the drop.
 *///from  w ww  . j  av a2s .c  om
public void dragEnter(DropTargetDragEvent e) {
    if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor)
            || e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        this.setBorder(dropBorder);
    }
}

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

public void dragOver(DropTargetDragEvent dtde) {
    if (!dtde.isDataFlavorSupported(supportedDropFlavor)) {
        return;//from  w  w w . j a  v a  2s. c o m
    }

    Point cursorLocationBis = dtde.getLocation();
    TreePath destinationPath = getPathForLocation(cursorLocationBis.x, cursorLocationBis.y);
    if (destinationPath != null) {
        if (((MirthTreeNode) destinationPath.getLastPathComponent()).isLeaf()) {
            this.setSelectionPath(destinationPath);
        }
    }
}

From source file:EditorDropTarget2.java

protected void checkTransferType(DropTargetDragEvent dtde) {
    // Accept a list of files, or data content that
    // amounts to plain text or a Unicode text string
    acceptableType = false;/*w w w .j ava  2  s  .c  o m*/
    draggingFile = false;

    if (DnDUtils.isDebugEnabled()) {
        DataFlavor[] flavors = dtde.getCurrentDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            DataFlavor flavor = flavors[i];
            DnDUtils.debugPrintln("Drop MIME type " + flavor.getMimeType() + " is available");
        }
    }

    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        acceptableType = true;
        draggingFile = true;
    } else if (dtde.isDataFlavorSupported(DataFlavor.plainTextFlavor)
            || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        acceptableType = true;
    }
    DnDUtils.debugPrintln("File type acceptable - " + acceptableType);
}

From source file:DragDropTreeExample.java

protected void checkTransferType(DropTargetDragEvent dtde) {
    // Accept a list of files
    acceptableType = false;//  ww w  .  j a v a  2  s  . c om
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        acceptableType = true;
    }
    DnDUtils.debugPrintln("Data type acceptable - " + acceptableType);
}

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 w  w.  jav  a2s.  c om*/
 *
 * @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.//  w  w w  .j a  v  a 2s  .  com
 *
 * @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);
    }
}