1 | import java.awt.datatransfer.*; |
2 | import java.awt.dnd.*; |
3 | |
4 | // onDrop: voidfunc(File), but may also return false |
5 | static <A extends JComponent> A jHandleFileDrop(A c, final O onDrop) { |
6 | new DropTarget(c, new DropTargetAdapter { |
7 | public void drop(DropTargetDropEvent e) { |
8 | pcall { |
9 | Transferable tr = e.getTransferable(); |
10 | DataFlavor[] flavors = tr.getTransferDataFlavors(); |
11 | for (DataFlavor flavor : flavors) { |
12 | if (flavor.isFlavorJavaFileListType()) { |
13 | e.acceptDrop(e.getDropAction()); |
14 | File file = first((L<File>) tr.getTransferData(flavor)); |
15 | if (file != null && !isFalse(callF(onDrop, file))) |
16 | e.dropComplete(true); |
17 | ret; |
18 | } |
19 | } |
20 | } |
21 | e.rejectDrop(); |
22 | } |
23 | }); |
24 | ret c; |
25 | } |
26 | |
27 | static <A extends JComponent> A jHandleFileDrop(IVF1<File> onDrop, A c) { |
28 | ret jHandleFileDrop((O) onDrop, c); |
29 | } |
30 | |
31 | static <A extends JComponent> A jHandleFileDrop(O onDrop, A c) { |
32 | ret jHandleFileDrop(c, onDrop); |
33 | } |
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: | 629 / 678 |
Version history: | 5 change(s) |
Referenced in: | [show references] |