Almost DnD...

I've been using NetBeans quite a lot recently. One of the thing that I find really irritating is that to copy files from my desktop. I have to first add it to Favourites, then copy it over to my project. I've discuss this with a few people about this but apparently DnD from desktop onto the file explorer is not something that is currently supported.

I did not want to spend a lot of time implementing DnD in NetBeans so I did the next most logical thing; create a drop area that targets a specific directory. Here is how it works; you right click on any directory including packages and select 'Open File Drop Area'. A panel will open in the editor area. Now you drag and drop files (and directories) from your desktop onto this area. These files will be copied to the target directory. See image below:


Click to enlarge

The precompiled NBMs are available here and here; the source is available here. Whey 2 NBM? Well I want to do this module fast so instead of writing a directory copy, I used Apache Commons IO. The downside is that I have am distributing all the other classes that I'm not using.

I've tested this on Solaris and Linux but not on Windows and there might be a problem. The issue is that if you drag 2 or more files on to the drop area, the Transferable.getTransferData(flavour) method returns a String with the 2 files' URL delimited by newlines. I parse the string with a split() using "\\n". I figure that since windows uses "\\r\\n" I would still be able to break the string into individual files and then clean up the remaining "\\r" with a trim(). I'm not sure if this works. Let me know.

While this solution is not quite as elegant as dropping directly onto a node, I hope it will solve some of your file copy issues.

Only works if NetBeans is running on JDK 6. Sorry

Comments:

Post a Comment:
Comments are closed for this entry.
About

Random thought at random intervals

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today