import java.awt.datatransfer.*; import java.awt.dnd.*; // onDrop: voidfunc(File), but may also return false static <A extends JComponent> A jHandleFileDrop(A c, final O onDrop) { new DropTarget(c, new DropTargetAdapter { public void drop(DropTargetDropEvent e) { pcall { Transferable tr = e.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (DataFlavor flavor : flavors) { if (flavor.isFlavorJavaFileListType()) { e.acceptDrop(e.getDropAction()); File file = first((L<File>) tr.getTransferData(flavor)); if (file != null && !isFalse(callF(onDrop, file))) e.dropComplete(true); ret; } } } e.rejectDrop(); } }); ret c; } static <A extends JComponent> A jHandleFileDrop(IVF1<File> onDrop, A c) { ret jHandleFileDrop((O) onDrop, c); } static <A extends JComponent> A jHandleFileDrop(O onDrop, A c) { ret jHandleFileDrop(c, onDrop); }
Began life as a copy of #1006013
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006021 |
Snippet name: | jHandleFileDrop - makes any JComponent accept file drops (drag&drop) |
Eternal ID of this version: | #1006021/6 |
Text MD5: | 11fe8c3dd1a8aecf7587c30e26d53325 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-31 19:09:47 |
Source code size: | 1039 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 616 / 660 |
Version history: | 5 change(s) |
Referenced in: | [show references] |