gpt4 book ai didi

java - 在 Mac OSX 中复制文件所需的 DataFlavor 是什么

转载 作者:搜寻专家 更新时间:2023-11-01 00:58:30 27 4
gpt4 key购买 nike

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

对于 Windows 和 Linux,我已经让它工作了。对于 OSX,我尝试了几种风格,但 Finder 中的“粘贴”操作从未激活。

知道 Finder 需要哪些 DataFlavor 设置吗?

使用的口味:

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" );

返回 flavor 数据的方法:

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 );
}

谢谢,安德烈

最佳答案

也许你应该试试 DataFlavor#javaFileListFlavor .

API 文档摘录:

DataFlavor#javaFileListFlavor ( Link )

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.

关于java - 在 Mac OSX 中复制文件所需的 DataFlavor 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3228619/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com