Ever since we heard about improved drag & drop support in Java 1.6, the Ephox engineers have been thinking about how cool it would be to include this in EditLive! – allowing files to be dragged into the editor and their contents inserted directly into the document. So in a Creative Coding Afternoon a few weeks ago, I implemented it.
I did it both as a proof of concept and as something that could be put up on LiveWorks – this thing is so useful the first feedback I received was “so when is this going on our internal wiki?” 🙂
It’s not my first LiveWorks plugin, that distinction goes to the hyperlink tooltips; but I wasn’t involved in the LiveWorks posting of that one whereas the code and docs for this new plugin are almost 100% me. It’s a very good example of just how extensible ELJ is with only one minor codebase change made to support inserting the contents of:
Images (gif, jpeg, tiff, png)
MS Word Documents (only on windows)
.url files (Internet Explorer bookmarks)
The result is a lot of fun to play with 😀
You can drag as many files as you want, and as long as all of them are supported they will be inserted one after the other (this is really useful for images). The whole thing is done using standard APIs for both ELJ and Java 1.6, with the support for multiple files based on the Drag & Drop Data Transfer Swing Tutorial.
Full source code is provided, and I think this is also a handy example of how to use the new TransferSupport API added in Java 1.6. Without it, you can’t get the list of files that the user dragged until after they’ve dropped it – so there’s no way to know if any of the files in that list are supported.
As always you’ll have to download ELJ to use the plugin, but it comes with a free localhost license where you can play to your hearts content.