Java Code Examples for java.awt.dnd.DropTargetDragEvent#getCurrentDataFlavors()
The following examples show how to use
java.awt.dnd.DropTargetDragEvent#getCurrentDataFlavors() .
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: LocallDownloadDnD.java From netbeans with Apache License 2.0 | 6 votes |
@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 2
Source File: FileDropDecorator.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
private boolean isDragOk( final DropTargetDragEvent evt ) { boolean ok = false; DataFlavor[] flavors = evt.getCurrentDataFlavors(); int i = 0; while( !ok && i < flavors.length ) { final DataFlavor curFlavor = flavors[i]; if( curFlavor.equals( DataFlavor.javaFileListFlavor ) || curFlavor.isRepresentationClassReader()){ ok = true; } i++; } return ok; }
Example 3
Source File: DataObjectTransferHandler.java From nextreports-designer with Apache License 2.0 | 6 votes |
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 4
Source File: DnDUtils.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public static boolean isFileOrLinkOrText(@Nonnull final DropTargetDragEvent dtde) { boolean result = false; for (final DataFlavor flavor : dtde.getCurrentDataFlavors()) { if (flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType() || flavor.isMimeTypeEqual(MIME_MOZ_URL) || flavor.isMimeTypeEqual(MIME_TEXT_PLAIN) || flavor.isMimeTypeEqual(MIME_TEXT_HTML)) { result = true; break; } } return result; }
Example 5
Source File: DnDTree.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
protected static boolean checkDragType(@Nonnull final DropTargetDragEvent dtde) { boolean result = false; for (final DataFlavor flavor : dtde.getCurrentDataFlavors()) { final Class dataClass = flavor.getRepresentationClass(); if (FileTransferable.class.isAssignableFrom(dataClass) || flavor.isFlavorJavaFileListType()) { result = true; break; } } return result; }
Example 6
Source File: MMDEditor.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
protected static boolean checkDragType(@Nonnull final DropTargetDragEvent dtde) { boolean result = DnDUtils.isFileOrLinkOrText(dtde); if (!result) { for (final DataFlavor flavor : dtde.getCurrentDataFlavors()) { final Class dataClass = flavor.getRepresentationClass(); if (FileTransferable.class.isAssignableFrom(dataClass)) { result = true; break; } } } return result; }
Example 7
Source File: MMDGraphEditor.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
protected static boolean checkDragType(final DropTargetDragEvent dtde) { boolean result = DnDUtils.isFileOrLinkOrText(dtde); if (!result) { for (final DataFlavor flavor : dtde.getCurrentDataFlavors()) { final Class dataClass = flavor.getRepresentationClass(); if (Node.class.isAssignableFrom(dataClass) || DataObject.class.isAssignableFrom(dataClass)) { result = true; break; } } } return result; }
Example 8
Source File: QueryBuilderPanel.java From nextreports-designer with Apache License 2.0 | 5 votes |
private boolean isDragOk(DropTargetDragEvent dtde) { if (dtde.getCurrentDataFlavors().length == 0) { return false; } if (dtde.getCurrentDataFlavors()[0].equals(DBTableTransferable.DATA_FLAVOR)) { return true; } return false; }
Example 9
Source File: QueryBuilderPanel.java From nextreports-designer with Apache License 2.0 | 5 votes |
private boolean isDragOk(DropTargetDragEvent dtde) { if (dtde.getCurrentDataFlavors().length == 0) { return false; } if (dtde.getCurrentDataFlavors()[0].equals(DBProcTransferable.DATA_FLAVOR)) { return true; } return false; }
Example 10
Source File: DBTableInternalFrame.java From nextreports-designer with Apache License 2.0 | 5 votes |
private boolean isDragOk(DropTargetDragEvent dtde) { if (dtde.getCurrentDataFlavors().length < 1) { return false; } if (dtde.getCurrentDataFlavors()[0] .equals(InternalFrameTransferable.DATA_FLAVOR)) { return true; } return false; }
Example 11
Source File: TraceTabbedPane.java From pega-tracerviewer with Apache License 2.0 | 4 votes |
private boolean isDragOk(final DropTargetDragEvent evt) { boolean retValue = false; // Get data flavors being dragged DataFlavor[] dataFlavorArray = evt.getCurrentDataFlavors(); for (int i = 0; i < dataFlavorArray.length; i++) { final DataFlavor dataFlavor = dataFlavorArray[i]; if (dataFlavor.equals(DataFlavor.javaFileListFlavor) || dataFlavor.isRepresentationClassReader()) { retValue = true; break; } } return retValue; }
Example 12
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
@Override public void dragOver(DropTargetDragEvent dtde) { DataFlavor[] f = dtde.getCurrentDataFlavors(); boolean isDataFlavorSupported = f[0].getHumanPresentableName().equals(TreeNodeTransferable.NAME); if (!isDataFlavorSupported) { // This DataFlavor is not supported(e.g. files from the desktop) rejectDrag(dtde); return; } // figure out which cell it's over, no drag to self Point pt = dtde.getLocation(); TreePath path = getPathForLocation(pt.x, pt.y); if (Objects.isNull(path)) { // Dropped into the non-node locations(e.g. margin area of JTree) rejectDrag(dtde); return; } // Object draggingObject; // if (!isWebStart()) { // try { // draggingObject = dtde.getTransferable().getTransferData(FLAVOR); // } catch (Exception ex) { // rejectDrag(dtde); // return; // } // } else { // draggingObject = getSelectionPath().getLastPathComponent(); // } // MutableTreeNode draggingNode = (MutableTreeNode) draggingObject; MutableTreeNode draggingNode = (MutableTreeNode) getSelectionPath().getLastPathComponent(); DefaultMutableTreeNode targetNode = (DefaultMutableTreeNode) path.getLastPathComponent(); TreeNode parent = targetNode.getParent(); if (parent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode ancestor = (DefaultMutableTreeNode) parent; if (Arrays.asList(ancestor.getPath()).contains(draggingNode)) { // Trying to drop a parent node to a child node rejectDrag(dtde); return; } } dropTargetNode = targetNode; // (TreeNode) path.getLastPathComponent(); dtde.acceptDrag(dtde.getDropAction()); repaint(); }