O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

340
|
Chapter 9, Drag-and-Drop
#67 Handle Dropped Images
HACK
H A C K
#67
Handle Dropped Images
Hack #67
I spy, with my little drop( ) method, something that doesn’t support
DataFlavor.imageFlavor...arrrgh!
Handling drag-and-drop from native applications [Hack #66] can be tricky
because they’re not particularly consistent about how they represent the
data being transferred to your application. Now, let’s say you want to accept
dropped images—not image files, but actual images inside of browser win-
dows, digital photo viewers, word processing and page-layout applications,
etc. There’s a constant in
DataFlavor for images, so surely you can count on
that being a flavor offered to you by the
Transferable, right?
No, of course not. That would be too easy.
Using the
dumpDataFlavors( ) strategy of the earlier URL hack, I checked out
the
DataFlavors offered by images dropped from some popular Windows
and Mac applications. The results are pretty interesting—check out
Table 9-2.
Table 9-2. DataFlavor offerings for images on various platforms
Application/platform DataFlavors
Preview 2.1 / Mac OS X 1
GraphicConverter 4.6 / Mac OS X 1
Finder / Mac OS X 1
Safari 1.3 / Mac OS X 55
Firefox 1.0 / Mac OS X 57
QuickTime Player 6.5 / Mac OS X 1
AppleWorks 6.2.9 / Mac OS X 1
MarinerWrite 3.6.4 / Mac OS X 1
iPhoto 4.0.3 / Mac OS X 1
Explorer / Windows XP 1
MSIE 6.0 / Windows XP 27
Firefox 1.0 / Windows XP 80
Paint / Windows XP N/A
Windows Picture and Fax Viewer / Windows XP N/A
Windows Media Player / Windows XP N/A
QuickTime Player 6.5.1 / Windows XP N/A
QuickTime Picture Viewer 6.5.1 / Windows XP N/A

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required