1 19 package org.netbeans.modules.openide.explorer; 20 21 import java.awt.datatransfer.DataFlavor ; 22 import java.awt.datatransfer.Transferable ; 23 import java.awt.datatransfer.UnsupportedFlavorException ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 import org.openide.util.datatransfer.ExTransferable; 30 import org.openide.util.datatransfer.ExTransferable.Multi; 31 import org.openide.util.datatransfer.MultiTransferObject; 32 33 38 public class ExternalDragAndDrop { 39 40 private ExternalDragAndDrop() { 41 } 42 43 58 public static Transferable maybeAddExternalFileDnd( Multi multi ) { 59 Transferable res = multi; 60 try { 61 MultiTransferObject mto = (MultiTransferObject) multi.getTransferData(ExTransferable.multiFlavor); 62 final ArrayList fileList = new ArrayList ( mto.getCount() ); 63 for( int i=0; i<mto.getCount(); i++ ) { 64 if( mto.isDataFlavorSupported( i, DataFlavor.javaFileListFlavor ) ) { 65 List list = (List )mto.getTransferData( i, DataFlavor.javaFileListFlavor ); 66 fileList.addAll( list ); 67 } 68 } 69 if( !fileList.isEmpty() ) { 70 ExTransferable fixed = ExTransferable.create( multi ); 71 fixed.put( new ExTransferable.Single( DataFlavor.javaFileListFlavor ) { 72 protected Object getData() throws IOException , UnsupportedFlavorException { 73 return fileList; 74 } 75 }); 76 res = fixed; 77 } 78 } catch (UnsupportedFlavorException ex) { 79 Logger.getLogger(ExternalDragAndDrop.class.getName()).log(Level.INFO, null, ex); 80 } catch (IOException ex) { 81 Logger.getLogger(ExternalDragAndDrop.class.getName()).log(Level.INFO, null, ex); 82 } 83 return res; 84 } 85 } 86 | Popular Tags |