<AWT Dev> 4899516: Transferable has no DataFlavors when dragging from Gnome window to Swing

Damjan Jovanovic damjan.jov at gmail.com
Tue Sep 25 08:31:34 PDT 2007


On 9/25/07, Denis S. Fokin <Denis.Fokin at sun.com> wrote:
> Hi Damjan,
>
> Currently, in the AWT implementation there is no data flavor like
> DataFlavor.javaFileListFlavor for uri-list mime-type.
>
> What is more a change request exists related to the issue.
>
> CR "4899516 Transferable has no DataFlavors when dragging from Gnome
> window to Swing"
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
>
> You can find in the workaround section how to create a custom
> Transferable to transfer the uri-list mime-type data.
>
> So I cannot agree that AWT "has zero support for the X file drag
> specification" =)
>
> But the question about a better support is disputable.
>
> There are number of ways how to solve the task to implement DnD between
> java application and GNOME nautilus.
>
> The first one is to implement some kind of analysis in AWT code. In that
> case we could introduce a new default DataFlavor like
> DataFlavor.javaFileListFlavor.
> return from Transferable.getTransferData() a list of URIs. Note, that we
> cannot be sure, that provided by Gnome data contains files, so we cannot
> use DataFlavor.javaFileListFlavor.

It's not Gnome-specific, it's XDND specific. Files are a subset of
URIs, and DataFlavor.javaFileListFlavor is a (possibly empty) subset
of a URI list.

> The second way is to implement some TransferHandler in Swing library.

You've already done something like that for other file drop protocols.

> The third way is to give programmer a possibility to decide how to
> handle the uri-list.
>
> I do not see a problem with the third variant.

I do. You have to write platform-specific code, which defeats the
purpose of using Java, and you have to modify every existing program
that already uses drag-and-drop to support it.

> Could you describe in more details in what way do you see better support
> of X file drag specification?

There is no reliable, portable way to tell a drop is a file drop.
DataFlavor.isFlavorJavaFileListType() returns false for all flavors on
an XDND file drop. It should return true for at least one.

When you find a file drop flavor, you should be able to treat it the
same on all platforms. No "if it's a text/uri-list do this, otherwise
do that".

The X file drag specification
(http://www.newplanetsoftware.com/xdnd/dragging_files.html) is clear
that "Simple programs can reject files that are not available
locally...". So there is nothing wrong with dropping non-file URIs,
and converting a URI list to a file list. It is also fully compatible
with software already written.

At the same time, URIs are supersets of files and advanced programs
might want to use URI lists instead of file lists, or Java could even
provide an array of InputStreams that can read from the dropped
files/URIs. That could be opt-in functionality in future versions of
Java.

> Thank you,
>        Denis.

Thank you
Damjan

>
> Damjan Jovanovic wrote:
> > Hi
> >
> > >From what I can tell, Java has superb support for the XDND protocol,
> > yet it has zero support for the X file drag specification
> > (http://www.newplanetsoftware.com/xdnd/dragging_files.html) which is
> > part of that protocol. This means file drops to Java apps do not work
> > as expected on any freedesktop environment (at least Gnome, very
> > likely KDE and XFCE as well).
> >
> > I've already written an X file drag implementation for wine
> > (http://www.winehq.org/pipermail/wine-cvs/2007-June/033705.html) and I
> > think it's about time Java started working too.
> >
> > If nobody has any objections and nobody is already working on it, I'd
> > like to have a go at fixing this.
> >
> > Since text/uri-list is more general than a file list, would the right
> > approach be dropping non-file URIs?
> >
> > Thank you
> > Damjan Jovanovic
> >
>
>



More information about the awt-dev mailing list