Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1006013 // Test making ImageSurface a drag&drop target v2 [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (3639L/25K/84K).

1  
!752
2  
3  
import java.awt.datatransfer.*;
4  
import java.awt.dnd.*;
5  
6  
p-awt {
7  
  final new ImageSurface is;
8  
  showFrame(jscroll(is));
9  
  
10  
  new DropTarget(is, new DropTargetAdapter {
11  
    public void drop(DropTargetDropEvent e) {
12  
      print("DropTarget: drop received");
13  
      handleFileDrop(e);
14  
    }
15  
    
16  
	  void handleFileDrop(DropTargetDropEvent evt) {
17  
  		pcall {
18  
  		  Transferable tr = evt.getTransferable();
19  
  		  DataFlavor[] flavors = tr.getTransferDataFlavors();
20  
  		  for (DataFlavor flavor : flavors) {
21  
    			print("flavor: " + flavor);
22  
    			if (flavor.isFlavorJavaFileListType()) {
23  
    			  evt.acceptDrop(evt.getDropAction());
24  
    			  L<File> list = (L) tr.getTransferData(flavor);
25  
    			  if (list.size() != 0) {
26  
    				  File file = list.get(0);
27  
    				  is.setImage(loadBufferedImage(file));
28  
    			  }
29  
    			  evt.dropComplete(true);
30  
    			  return;
31  
    			}
32  
    		}
33  
		  }
34  
		  //print("Unknown data flavors (" + flavors.length + ")");
35  
		  evt.rejectDrop();
36  
	  }
37  
  });
38  
}

Author comment

Began life as a copy of #1006011

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006013
Snippet name: Test making ImageSurface a drag&drop target v2 [WORKS]
Eternal ID of this version: #1006013/1
Text MD5: 1821cf81ba5fa1bb755613449e32ee1d
Transpilation MD5: 1b590451afa07c0d0d81d27904891ab0
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-14 05:07:45
Source code size: 1024 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 4184 / 655
Referenced in: [show references]