How to cut a file to the clipboard in Java?

I use this code in a Java Swing application to copy files to the clipboard:

final List<File> files = new ArrayList<File>();
// ... code to fill list omitted ... //

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
    new Transferable() {
        @Override
        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[] { DataFlavor.javaFileListFlavor };
        }

        @Override
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return DataFlavor.javaFileListFlavor.equals(flavor);
        }

        @Override
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            return files;
        }
    }, null
);

This works because I can go to Windows Explorer and Ctrl + V, and the files will appear (I hope it works on other OSs, although not tested). I would like to implement cut , but I do not know how to tell the system what this action is, or, alternatively, how to get feedback for each successfully copied file so that I can remove it from the original location manually.

If this is not impossible, any suggestions on how I should deal with this? I would like to be able to cut and paste into the application too (separately for file sharing with the OS browser).

+6
source share
2

, :

SWT

, , JNI-, , ...

0

"" Swing. . TransferHandler.exportToClipboard(). . exportToClipboard() - TransferHandler.getCutAction(), actionPerformed() ActionEvent() - JComponent TransferHandler, Transferable , .

. , . TransferHandler.TransferSupport.getDropAction() DND.

, , . . TransferHandler.exportDone()

. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6673481

0

All Articles