在Mac OSX中复制文件所需的DataFlavor是什么 [英] What is the required DataFlavor to copy files in Mac OSX

查看:153
本文介绍了在Mac OSX中复制文件所需的DataFlavor是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究可以将文件复制到系统剪贴板的Java代码。

I'm currently working on Java code that can copy files into the system clipboard.

对于Windows和Linux,我已经开始工作了。对于OSX,我尝试了几种口味,但Finder中的粘贴操作从未激活。

For Windows and Linux I already got it working. For OSX I tried several flavors but the "Paste" action in Finder never cames active.

任何想法Finder需要哪些DataFlavor设置?

Any idea which DataFlavor settings are required for Finder?

使用的口味:

DataFlavor.javaFileListFlavor
URILIST_FLAVOR = new DataFlavor( "text/uri-list" );
XFILELIST_FLAVOR = new DataFlavor( "application/x-java-file-list" );
GNOMEFILELIST_FLAVOR = new DataFlavor( "x-special/gnome-copied-files" );

返回风味数据的方法:

public Object getTransferData( DataFlavor flavor ) throws UnsupportedFlavorException, IOException {
    if( FILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( DataFlavor.javaFileListFlavor.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return locallist;
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( URILIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( GNOMEFILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            // FIXME support cut and copy
            return getStreamData( files, "copy" );
        }
    } else if( XFILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return locallist;
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    }
    throw new UnsupportedFlavorException( flavor );
}

谢谢,$ b $bAndré

Thanks, André

推荐答案

也许你应该尝试 DataFlavor#javaFileListFlavor

摘自API文档:

DataFlavor#javaFileListFlavor 链接


向/从Java(和底层平台)传输文件列表DataFlavor使用此类型/子类型和java.util.List的表示类。列表的每个元素都必须/保证是java.io.File类型。
To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.

这篇关于在Mac OSX中复制文件所需的DataFlavor是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆