* fix dnd for files on linux
This commit is contained in:
parent
6544e71507
commit
5e837fb9ce
|
@ -6,11 +6,8 @@ import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
|
|
||||||
public class FileTransferable implements Transferable {
|
public class FileTransferable implements Transferable {
|
||||||
|
@ -23,29 +20,28 @@ public class FileTransferable implements Transferable {
|
||||||
return new DataFlavor("text/uri-list;class=java.lang.String");
|
return new DataFlavor("text/uri-list;class=java.lang.String");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
// will never happen
|
// will never happen
|
||||||
Logger.getLogger(FileTransferable.class.getName()).log(Level.SEVERE, e.toString(), e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Collection<File> files;
|
|
||||||
|
private final File[] files;
|
||||||
|
|
||||||
|
|
||||||
public FileTransferable(File... files) {
|
public FileTransferable(File... files) {
|
||||||
this(Arrays.asList(files));
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FileTransferable(Collection<File> files) {
|
public FileTransferable(Collection<File> files) {
|
||||||
this.files = new ArrayList<File>(files);
|
this.files = files.toArray(new File[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
if (flavor.isFlavorJavaFileListType())
|
if (flavor.isFlavorJavaFileListType())
|
||||||
return files;
|
return Arrays.asList(files);
|
||||||
else if (flavor.equals(uriListFlavor))
|
else if (flavor.equals(uriListFlavor))
|
||||||
return getUriList();
|
return getUriList();
|
||||||
else
|
else
|
||||||
|
@ -57,10 +53,11 @@ public class FileTransferable implements Transferable {
|
||||||
* @return line separated list of file URIs
|
* @return line separated list of file URIs
|
||||||
*/
|
*/
|
||||||
private String getUriList() {
|
private String getUriList() {
|
||||||
StringBuilder sb = new StringBuilder(80 * files.size());
|
StringBuilder sb = new StringBuilder(80 * files.length);
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
sb.append("file://" + file.toURI().getPath());
|
// use URI encoded path
|
||||||
|
sb.append("file://").append(file.toURI().getRawPath());
|
||||||
sb.append("\r\n");
|
sb.append("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue