I am trying to move files from a compressed archive to my own system (basycally, windows' eplorer) using drag and drop operations.
My only idea at the moment is to create a TransferHandler, which at startup will unpack the file in a temporary directory and configure this file as portable. Here is a snippet of code to make yourself clearer:
private class FileTransferHandler extends TransferHandler {
protected Transferable createTransferable(JComponent c) {
List<File> files = new ArrayList<File>();
try {
File temp = createTempDirectory();
String path = temp.getAbsolutePath();
decompressTo(path);
files.add(new File(path));
} catch (Exception e) { e.printStackTrace(); };
return new FileTransferable(files);
}
public int getSourceActions(JComponent c) {
return COPY;
}
}
private class FileTransferable implements Transferable {
private List<File> files;
public FileTransferable(List<File> files) {
this.files = files;
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{ DataFlavor.javaFileListFlavor };
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(DataFlavor.javaFileListFlavor);
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
return files;
}
}
(not valid: the thing that puzzles me is that it works like that: but only if I don't do anything after releasing the mouse button.)
update: , temp , DataFlavor. , temp . , .
, , , .
p.s: temp , , WinRar .
p.p.s.: , , -, .